#include #include #include using namespace std; int main() { int64_t N; cin >> N; vector T(N), V(N); uint64_t sizeA = 0; for (int i = 0; i < N; i++) { cin >> T[i] >> V[i]; sizeA += T[i]; } vector A(sizeA); uint64_t sumA = 0; int index = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < T[i]; j++) { A[index] = V[i]; sumA += 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; }