#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 100000000000000000 mint Nsum = 0; mint f0(mint n){ return n; } mint f1(mint n){ mint ret = n; ret *= n+1; ret /= 2; return ret; } mint f2(mint n){ mint ret = n; ret *= n+1; ret *= n*2+1; ret /= 6; return ret; } mint f3(mint n){ mint ret = f1(n); ret *= ret; return ret; } mint get(mint n){ mint ret = -f3(n); ret += Nsum * f2(n); ret += (Nsum+1) * f1(n); return ret; } mint get(mint L,mint R){ return get(R) - get(L-1); } int main(){ int N; cin>>N; vector T(N),V(N); rep(i,N){ scanf("%lld %lld",&T[i],&V[i]); Nsum += T[i]; } mint cur = 0; mint ans = 0; rep(i,N){ ans += get(cur+1,cur+T[i]) * V[i]; cur += T[i]; } ans /= 2; cout<