#include #pragma GCC optimize("Ofast") using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll I=1167167167167167167; ll Q=998244353; #define rep(i,a) for (ll i=0;i using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,const T &b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} template void print_tate(vector &v) {rep(i,v.size()) cout<>N; ll L=0; ll T[N],V[N]; rep(i,N){ cin>>T[i]>>V[i]; T[i]%=Q; L+=T[i]; L%=Q; } ll ans=0; ll X=-1,Y=-1; rep(i,N){ Y+=T[i]; ll U=((3*L-2)%Q)*((f(Y)-f(X))%Q); U%=Q; U+=((L-3)*((g(Y)-g(X))%Q))%Q; U%=Q; U+=(h(X)-h(Y))%Q; U%=Q; U+=2*L*T[i]; U=(U%Q+Q)%Q; ans+=V[i]*U; ans%=Q; X+=T[i]; } cout<<(ans*A)%Q<<"\n"; }