#include using namespace std; typedef long long i64; typedef unsigned long long ui64; typedef vector vi; typedef vector vvi; typedef pair pi; #define pb push_back #define sz(a) i64((a).size()) #define all(c) (c).begin(), (c).end() #define REP(s, e, i) for(i=(s); i < (e); ++i) inline void RI(i64 &i) {scanf("%lld", &(i));} inline void RVI(vi &v) { for(i64 i=0;i inline bool IN(T &S, const typename T::key_type &key) { return S.find(key) != S.end(); } template inline bool ON(const T &b, i64 idx) { return ((T(1) << idx) & b) != 0; } template struct modint { modint(T v=T(0)) : val((v >= 0 ? v : (M - ((-v) % M))) % M) {} using this_type = modint; T val; this_type operator++(int) { this_type ret = *this; val++; val %= M; return ret; } this_type operator--(int) { this_type ret = *this; val += M-1; val %= M; return ret; } this_type &operator++() { val++; val %= M; return *this; } this_type &operator--() { val += M-1; val %= M; return *this; } this_type operator+() const { return *this; } this_type operator-() const { return this_type(M-val); }; friend this_type operator+(const this_type &lhs, const this_type &rhs) { return this_type(lhs) += rhs; } friend this_type operator-(const this_type &lhs, const this_type &rhs) { return this_type(lhs) -= rhs; } friend this_type operator*(const this_type &lhs, const this_type &rhs) { return this_type(lhs) *= rhs; } friend this_type operator/(const this_type &lhs, const this_type &rhs) { return this_type(lhs) /= rhs; } this_type pow(long long b) const { this_type ret = 1, a = *this; while(b != 0) { if(b % 2 != 0) { ret *= a; } b /= 2; a = a * a; } return ret; } this_type inv() const { return pow(M-2); } this_type& operator+=(const this_type &rhs) { val += rhs.val; val %= M; return *this; } this_type& operator-=(const this_type &rhs) { val += M - rhs.val; val %= M; return *this; } this_type& operator*=(const this_type &rhs) { val *= rhs.val; val %= M; return *this; } this_type& operator/=(const this_type &rhs) { *this *= rhs.inv(); return *this; } friend bool operator==(const this_type &lhs, const this_type &rhs) { return lhs.val == rhs.val; } friend bool operator!=(const this_type &lhs, const this_type &rhs) { return lhs.val != rhs.val; } T mod() const {return M;} }; using mi = modint<998244353>; using vmi = vector; using vvmi = vector; inline mi S0(mi v) { return v; } mi inv_2 = mi(2).inv(); mi inv_6 = mi(6).inv(); inline mi S1(mi v) { return v * (v + 1) * inv_2; } inline mi S2(mi v) { return v * (v + 1) * (2 * v + 1) * inv_6; } inline mi S3(mi v) { mi s = S1(v); return s * s; } inline mi F(mi v, mi L) { return (- S3(v) + (L - 3) * S2(v) + (3 * L - 2) * S1(v) + 2 * L * S0(v)) * inv_2; } inline mi G(mi l, mi r, mi L) { return F(r-1, L) - F(l-1, L); } int main(int argc, char *argv[]) { i64 i, j, k; i64 N; cin >> N; vi T(N), V(N); mi L = 0; REP(0, N, i) { RI(T[i]); RI(V[i]); L += T[i]; } mi ans = 0; mi l = 0; REP(0, N, i) { //cerr << G(l, l + T[i], V[i]).val << endl; ans += G(l, l + T[i], L) * mi(V[i]); l += T[i]; } WI(ans.val); return 0; }