#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } template struct ModInt{ long long x; ModInt():x(0){} ModInt(long long y):x(y>=0?y%Mod:(Mod-(-y)%Mod)%Mod){} ModInt &operator+=(const ModInt &p){ if((x+=p.x)>=Mod) x-=Mod; return *this; } ModInt &operator-=(const ModInt &p){ if((x+=Mod-p.x)>=Mod)x-=Mod; return *this; } ModInt &operator*=(const ModInt &p){ x=(int)(1ll*x*p.x%Mod); return *this; } ModInt &operator/=(const ModInt &p){ (*this)*=p.inverse(); return *this; } ModInt operator-()const{return ModInt(-x);} ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;} ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;} ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;} ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;} bool operator==(const ModInt &p)const{return x==p.x;} bool operator!=(const ModInt &p)const{return x!=p.x;} ModInt inverse()const{ int a=x,b=Mod,u=1,v=0,t; while(b>0){ t=a/b; swap(a-=t*b,b);swap(u-=t*v,v); } return ModInt(u); } ModInt pow(long long n)const{ ModInt ret(1),mul(x); while(n>0){ if(n&1) ret*=mul; mul*=mul;n>>=1; } return ret; } friend ostream &operator<<(ostream &os,const ModInt &p){return os<>(istream &is,ModInt &a){long long t;is>>t;a=ModInt(t);return (is);} static int get_mod(){return Mod;} }; using mint=ModInt<998244353>; template struct ImplicitTreap{ private: inline int xorshift(){ static int x=122312555; static int y=336261662; static int z=558127122; static int w=917277772; int t; t=x^(x<<11); x=y;y=z;z=w; return w=(w^(w>>19))^(t^(t>>8)); } using F=function; using G=function; using H=function; struct Node{ Node *l,*r; int cnt,priority; Monoid val,acc; OperatorMonoid lazy; bool rev; Node()=default; Node(const Monoid &val,const OperatorMonoid &lazy,int priority): l(nullptr),r(nullptr),cnt(1),priority(priority),val(val),acc(val),lazy(lazy),rev(false){} } *root=nullptr; const F f; const G g; const H h; const Monoid M1; const OperatorMonoid OM0; int count(const Node *t){return t?t->cnt:0;} Monoid acc(const Node *t){return t?t->acc:M1;} Node *update(Node *t){ t->cnt=count(t->l)+count(t->r)+1; t->acc=f(f(acc(t->l),t->val),acc(t->r)); return t; } Node *propagate(Node *t){ if(t and t->rev){ t->rev=false; swap(t->l,t->r); if(t->l) t->l->rev^=1; if(t->r) t->r->rev^=1; } if(t and t->lazy!=OM0){ t->val=g(t->val,t->lazy); if(t->l){ t->l->lazy=h(t->l->lazy,t->lazy); t->l->acc=g(t->l->acc,t->lazy); } if(t->r){ t->r->lazy=h(t->r->lazy,t->lazy); t->r->acc=g(t->r->acc,t->lazy); } t->lazy=OM0; } return update(t); } Node *merge(Node *l,Node *r){ if(!l or !r) return l?l:r; if(l->priority>r->priority){ l=propagate(l); l->r=merge(l->r,r); return update(l); }else{ r=propagate(r); r->l=merge(l,r->l); return update(r); } } pair split(Node *t,int k){ if(!t) return {nullptr,nullptr}; t=propagate(t); if(k<=count(t->l)){ auto s=split(t->l,k); t->l=s.second; return {s.first,update(t)}; }else{ auto s=split(t->r,k-count(t->l)-1); t->r=s.first; return {update(t),s.second}; } } void insert(Node *&t,int k,const Monoid &x){ auto s=split(t,k); t=merge(merge(s.first,new Node(x,OM0,xorshift())),s.second); } void erase(Node *&t,int k){ auto s=split(t,k); t=merge(s.first,split(s.second,1).second); } Monoid query(Node *&t,int a,int b){ if(a>b) return M1; auto x=split(t,a); auto y=split(x.second,b-a); auto ret=acc(y.first); t=merge(x.first,merge(y.first,y.second)); return ret; } void update(Node *&t,int a,int b,const OperatorMonoid &o){ if(a>b) return ; auto x=split(t,a); auto y=split(x.second,b-a); y.first->lazy=h(y.first->lazy,o); t=merge(x.first,merge(propagate(y.first),y.second)); } void reverse(Node *&t,int a,int b){ if(a>b) return ; auto x=split(t,a); auto y=split(x.second,b-a); y.first->rev^=1; t=merge(x.first,merge(y.first,y.second)); } // [l,r)の先頭がmになるまで左シフト void rotate(Node *&t,int l,int m,int r){ reverse(t,l,r); reverse(t,l,l+r-m); reverse(t,l+r-m,r); } void dump(Node *t,typename vector::iterator &ite){ if(!t) return ; t=propagate(t); dump(t->l,ite); *ite=t->val; dump(t->r,++ite); } public: ImplicitTreap(const F &f,const G &g,const H &h,const Monoid &M1,const OperatorMonoid &OM0): f(f),g(g),h(h),M1(M1),OM0(OM0){} int size(){return count(root);} bool empty(){return !root;} void build(const vector &v){ if(v.empty()) return ; for(int i=(int)v.size()-1;i>=0;i--) insert(0,v[i]); } void insert(int k,const Monoid &x){insert(root,k,x);} void erase(int k){erase(root,k);} void erase(int l,int r){ auto x=split(root,l); auto y=split(x.second,r-l); root=merge(x.first,y.second); } void reverse(int l,int r){reverse(root,l,r);} Monoid query(int l,int r){return query(root,l,r);} void update(int l,int r,const OperatorMonoid &x){update(root,l,r,x);} vector dump(){ vector ret(size()); auto ite=begin(ret); dump(root,ite); return ret; } Monoid operator[](int idx){return query(idx,idx+1);} }; // range add range sum (sum, count) using M=pair; using OM=ll; const M M1=M(0,0); const OM OM0=0; M segf(M a,M b){ return M(a.first+b.first,a.second+b.second); } M segg(M a,OM b){ return M(a.first+a.second*b,a.second); } OM segh(OM a,OM b){ return a+b; } signed main(){ int N;cin>>N; vector x(N),y(N); rep(i,N) cin>>x[i]>>y[i]; mint res=0; { mint sx=0; mint ss=0; rep(i,N){ res+=mint(x[i])*x[i]*i+ss-sx*x[i]*2; ss+=mint(x[i])*x[i]; sx+=x[i]; } } { mint sy=0; mint ss=0; rep(i,N){ res+=mint(y[i])*y[i]*i+ss-sy*y[i]*2; ss+=mint(y[i])*y[i]; sy+=y[i]; } } { vector idx(N); iota(ALL(idx),0); sort(ALL(idx),[&](int i,int j){return x[i]>x[j];}); vector nx(N),ny(N); rep(i,N) nx[i]=x[idx[i]], ny[i]=y[idx[i]]; x=nx; y=ny; } ImplicitTreap lw(segf,segg,segh,M1,OM0),hi(segf,segg,segh,M1,OM0); vector> ysort; rep(i,N) ysort.emplace_back(y[i],1); sort(ALL(ysort)); lw.build(ysort); hi.build({}); rep(i,N){ int l=0,r=lw.size()-1,j=lw.size(); while(l<=r){ int m=(l+r)/2; if(lw[m].first==y[i]){ j=m; break; } if(y[i]<=lw[m].first) j=m,r=m-1; else l=m+1; } mint add=mint(y[i])*j-lw.query(0,j).first+lw.query(j+1,lw.size()).first-mint(y[i])*(lw.size()-1-j); lw.erase(j); l=0,r=hi.size()-1; int k=hi.size(); while(l<=r){ int m=(l+r)/2; if(y[i]<=hi[m].first) k=m,r=m-1; else l=m+1; } mint sub=mint(y[i])*mint(k)-mint(hi.query(0,k).first)+mint(hi.query(k,hi.size()).first)-mint(y[i])*(hi.size()-k); res+=(add-sub)*x[i]*2; hi.insert(k,make_pair(y[i],1)); } cout<