#include "bits/stdc++.h" using namespace std; #include #include #include using namespace std; int main() { uint64_t N; cin >> N; vector T(N), V(N); uint64_t sizeA = 0; for (uint64_t i = 0; i < N; i++) { cin >> T[i] >> V[i]; sizeA += T[i]; } vector A(sizeA, 0); uint64_t index = 0; for (uint64_t i = 0; i < N; i++) { for (uint64_t j = 0; j < T[i]; j++) { A[index] = V[i]; index++; } } uint64_t sum = 0; for (uint64_t i = 0; i < sizeA; i++) { uint64_t coef = ((i + 1) * (i + 2) / 2) * (sizeA - i); sum += coef * A[i]; sum %= 998244353; } cout << sum << endl; return 0; }