#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include using namespace std; //using namespace atcoder; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 //#define MOD 1000000007 #define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 #define PI acos(-1.0) const double EPS = 1e-10; using ll = long long; using Pi = pair; using Pl = pair; //using mint = modint998244353; int dh[] = {-1,1,0,0}; int dw[] = {0,0,1,-1}; template vector compress(vector &v){ vector res = v; sort(res.begin(),res.end()); res.erase(unique(res.begin(),res.end()),res.end()); for(auto &u : v){u = lower_bound(res.begin(),res.end(),u)-res.begin();} return res; } template struct BinaryIndexedTree{ vector bit; BinaryIndexedTree(int sz){ bit.resize(sz+1); } void add(int k, T x){ //k番目にxを加える for(int i = k; i < (int)bit.size(); i |= i+1) bit[i] += x; } T sum(int k){ //[0,k)の区間の総和を求める T res = 0; for(int i = k-1; i >= 0; i = (i&(i+1))-1){ res += bit[i]; } return res; } }; int main(){ int n; cin >> n; vector x(n),y(n); vector xy(n); rep(i,n){ cin >> x[i] >> y[i]; xy[i].first = x[i]; xy[i].second = y[i]; } auto f = [&](auto v){ ll s1 = 0,s2 = 0,s3 = 0; rep(i,n-1){ s1 += v[i]*v[i]%MOD*(n-i-1)%MOD; s1 %= MOD; } vector sum(n+1); rep(i,n) sum[i+1] = (sum[i]+v[i]*v[i]%MOD)%MOD; rep(i,n-1){ s3 += (sum[n]-sum[i+1]+MOD)%MOD; s3 %= MOD; } vector sum2(n+1); rep(i,n) sum2[i+1] = (sum2[i]+v[i])%MOD; rep(i,n-1){ s2 += v[i]*(sum2[n]-sum2[i+1]+MOD)%MOD; s2 %= MOD; } s2 *= 2; s2 %= MOD; ll res = (s1+s3-s2+MOD)%MOD; return res; }; ll ans = f(x)+f(y); sort(xy.begin(),xy.end()); vector comp; rep(i,n) comp.push_back(xy[i].second); compress(comp); BinaryIndexedTree bit1(n),bit2(n),bit3(n),bit4(n); //1,x,y,x*yの和 ll ans2 = 0; rep(i,n){ ll l = xy[i].first; ll r = xy[i].second; ll a1 = bit1.sum(comp[i]+1)%MOD; ll a2 = bit2.sum(comp[i]+1)%MOD; ll a3 = bit3.sum(comp[i]+1)%MOD; ll a4 = bit4.sum(comp[i]+1)%MOD; ll b1 = (bit1.sum(n)-bit1.sum(comp[i]+1))%MOD; ll b2 = (bit2.sum(n)-bit2.sum(comp[i]+1))%MOD; ll b3 = (bit3.sum(n)-bit3.sum(comp[i]+1))%MOD; ll b4 = (bit4.sum(n)-bit4.sum(comp[i]+1))%MOD; ans2 += l*r%MOD*a1%MOD; ans2 %= MOD; ans2 -= r*a2%MOD; ans2 -= l*a3%MOD; ans2 %= MOD; if(ans2 < 0) ans2 += MOD; ans2 += a4%MOD; ans2 %= MOD; ans2 += l*b3%MOD; ans2 %= MOD; ans2 += r*b2%MOD; ans2 %= MOD; ans2 -= l*r%MOD*b1%MOD; ans2 -= b4%MOD; ans2 %= MOD; if(ans2 < 0) ans2 += MOD; bit1.add(comp[i],1); bit2.add(comp[i],l); bit3.add(comp[i],r); bit4.add(comp[i],l*r%MOD); } ans2 *= 2; ans += ans2; ans %= MOD; cout << ans << endl; }