#include using namespace std; const long long MOD = 998244353; template struct binary_indexed_tree{ int N; vector BIT; binary_indexed_tree(int N): N(N), BIT(N + 1, 0){ } void add(int i, T x){ i++; while (i <= N){ BIT[i] += x; BIT[i] %= MOD; i += i & -i; } } T sum(int i){ T ans = 0; while (i > 0){ ans += BIT[i]; ans %= MOD; i -= i & -i; } return ans; } T sum(int L, int R){ return (sum(R) - sum(L) + MOD) % MOD; } }; int main(){ int N; cin >> N; vector x(N), y(N); for (int i = 0; i < N; i++){ cin >> x[i] >> y[i]; } vector> P(N); for (int i = 0; i < N; i++){ P[i] = make_pair(x[i], y[i]); } sort(P.begin(), P.end()); for (int i = 0; i < N; i++){ x[i] = P[i].first; y[i] = P[i].second; } long long x1 = 0, x12 = 0, x2 = 0; for (int i = 0; i < N; i++){ x12 += x[i] * x1; x12 %= MOD; x1 += x[i]; x1 %= MOD; x2 += x[i] * x[i]; x2 %= MOD; } long long y1 = 0, y12 = 0, y2 = 0; for (int i = 0; i < N; i++){ y12 += y[i] * y1; y12 %= MOD; y1 += y[i]; y1 %= MOD; y2 += y[i] * y[i]; y2 %= MOD; } long long ans = 0; ans += x2 * (N - 1); ans -= x12 * 2 % MOD; ans += y2 * (N - 1); ans -= y12 * 2 % MOD; ans += MOD * 2; vector yc = y; sort(yc.begin(), yc.end()); yc.erase(unique(yc.begin(), yc.end()), yc.end()); int cnt = yc.size(); binary_indexed_tree BIT1(cnt), BITx(cnt), BITy(cnt), BITxy(cnt); long long ans2 = 0; for (int i = 0; i < N; i++){ int pos = lower_bound(yc.begin(), yc.end(), y[i]) - yc.begin(); ans2 += x[i] * y[i] % MOD * BIT1.sum(0, pos) % MOD; ans2 -= x[i] * BITy.sum(0, pos) % MOD; ans2 -= y[i] * BITx.sum(0, pos) % MOD; ans2 += BITxy.sum(0, pos); ans2 -= x[i] * y[i] % MOD * BIT1.sum(pos, cnt) % MOD; ans2 += x[i] * BITy.sum(pos, cnt); ans2 += y[i] * BITx.sum(pos, cnt); ans2 -= BITxy.sum(pos, cnt); ans2 += MOD * 4; BIT1.add(pos, 1); BITx.add(pos, x[i]); BITy.add(pos, y[i]); BITxy.add(pos, x[i] * y[i]); } ans2 *= 2; ans += ans2; ans %= MOD; cout << ans << endl; }