#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } template class Compress{ public: vector data; int offset; Compress(vector data_, int offset=0): offset(offset){ data = data_; sort(begin(data), end(data)); data.erase(unique(begin(data), end(data)), end(data)); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; using P = pair; struct S{ mint cnt, x, y, xy; S(mint cnt, mint x, mint y, mint xy): cnt(cnt), x(x), y(y), xy(xy) {} }; S op(S x, S y){ return S(x.cnt+y.cnt, x.x+y.x, x.y+y.y, x.xy+y.xy); } S e(){ return S(mint(0), mint(0), mint(0), mint(0)); } using Seg = atcoder::segtree; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector

vp; vector xs, ys; for(int i = 0; i < n; i++){ int x, y; cin >> x >> y; vp.push_back({x, y}); xs.push_back(x); ys.push_back(y); } auto sum_diff_square = [&](vector xs){ mint sum = 0, sum_square = 0; for(int x: xs){ sum += x; sum_square += mint(x)*mint(x); } mint sum_prod = (sum*sum-sum_square)/2; return sum_square*(n-1) - sum_prod*2; }; mint ans = sum_diff_square(xs)+sum_diff_square(ys); auto cp = Compress(ys); Seg seg(cp.size()); sort(vp.begin(), vp.end()); for(auto [x, y]: vp){ int yi = cp[y]; mint xy = mint(x)*mint(y); S sl = seg.prod(0, yi); ans += (sl.xy + xy*sl.cnt - (sl.x*y + sl.y*x))*2; S sr = seg.prod(yi, cp.size()); ans += (sr.x*y + sr.y*x - (sr.xy + xy*sr.cnt))*2; seg.set(yi, op(S(mint(1), mint(x), mint(y), xy), seg.get(yi))); } cout << ans << endl; }