#pragma GCC optimize("Ofast") #pragma GCC target("avx2") char*mmap(); #define rd(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} #define wt(v) {long _z=v;do*--wp=_z%10+48;while(_z/=10);} #define rep(v,e) for(long v=0;v<e;++v) #define MD 998244353 #define inv24 291154603 int t[300001]; int v[300001]; main(){ long s=0,l=0,r=0; char*rp=mmap(0l,1l<<25,1,2,0,0ll); rd(n); rep(i,n){ rd(ti); s+=ti%=MD; t[i]=ti; rd(vi); v[i]=vi; } s%=MD; rep(i,n){ l+=t[i]; l-=l>=MD?MD:0; r+=l*(l+1)%MD*(l+2)%MD*(s*4-(l-1)*3)%MD*(v[i]-v[i+1])%MD; } r=r%MD*inv24%MD; r+=r>=0?0:MD; char wbuf[64],*wp=wbuf+sizeof wbuf; wt(r); write(1,wp,wbuf+sizeof wbuf-wp); _exit(0); }