#include #include #include #include #include using namespace std; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) const i64 MOD = 998244353; using m32 = atcoder::static_modint; int lowerBoundIdx(const vector& A, int v){ return lower_bound(A.begin(),A.end(),v) - A.begin(); } m32 solve(vector> P){ int n = P.size(); sort(P.begin(),P.end()); vector Y(n); rep(i,n) Y[i] = P[i].second; sort(Y.begin(),Y.end()); atcoder::fenwick_tree G0(n); atcoder::fenwick_tree G1(n); atcoder::fenwick_tree G2(n); m32 ans = 0; for(auto p : P){ int y = lowerBoundIdx(Y,p.second); m32 w = m32(p.first) + p.second; ans += G2.sum(0,y); ans -= G1.sum(0,y) * w * 2; ans += G0.sum(0,y) * w * w; G0.add(y, 1); G1.add(y, w); G2.add(y, w * w); } return ans; } m32 solve2(vector> P){ int n = P.size(); sort(P.begin(),P.end()); int prex = -1; m32 G0 = 0; m32 G1 = 0; m32 G2 = 0; m32 ans = 0; rep(i,n){ auto p = P[i]; m32 w = p.second; if(p.first == prex){ ans += G0 * w * w; ans -= 2 * G1 * w; ans += G2; } else{ G0 = G1 = G2 = 0; } G0 += 1; G1 += w; G2 += w * w; prex = P[i].first; } return ans; } int main() { int N; cin >> N; vector> X(N); rep(i,N) cin >> X[i].first >> X[i].second; m32 ans = 0; rep(t,2){ rep(i,N) X[i].first = 1000000000 - X[i].first; ans += solve(X); } ans -= solve2(X); rep(i,N) swap(X[i].first,X[i].second); ans += solve2(X); cout << ans.val() << "\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;