/* -------------- | / | | / | | / | * |/ | | ------ * | | | | / \ | | |\ | | | |\ | \ | | | \ | | | | \ | \ | | | \ | | \ / \ | V | | \ \__/| ----- \ | */ #include using namespace std; #define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n" #define print(x) emilia_mata_tenshi(#x, begin(x), end(x)) template void emilia_mata_tenshi(const char *s, T l, T r) { cerr << "\e[1;33m" << s << " = ["; while(l != r) { cerr << *l; cerr << (++l == r ? ']' : ','); } cerr << "\e[0m\n"; } #define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL); using ll = int64_t; using ull = uint64_t; using ld = long double; using uint = uint32_t; const double EPS = 1e-8; const int INF = 0x3F3F3F3F; const ll LINF = 4611686018427387903; const int MOD = 1e9+7; /*--------------------------------------------------------------------------------------*/ const int mod = 998244353, N = 2e5 + 25; struct fenwicktree { int arr[N]; void edt(int p, ll v) { v %= mod; for(; p < N; p += p & -p) arr[p] = (arr[p] + v) % mod; } ll que(int l, int r) { ll res = 0; for(; r; r -= r & -r) res = (res + arr[r]) % mod; for(l--; l; l -= l & -l) res = (res - arr[l] + mod) % mod; return res; } } cnt, sum, sum2, rcnt, rsum, rsum2; signed main() { EmiliaMyWife int n; cin >> n; vector> arr(n); vector v(1, -10); for(int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second, v.push_back(arr[i].second); sort(arr.begin(), arr.end()); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); for(auto &[x, y] : arr) y = lower_bound(v.begin(), v.end(), y) - v.begin(); ll ans = 0; for(const auto &[x, y] : arr) { ll t = (x + v[y]) % mod; ans = (ans + t * t % mod * cnt.que(1, y) + sum.que(1, y)) % mod; ans = (ans - 2 * t * sum2.que(1, y) % mod + mod) % mod; cnt.edt(y, 1); sum.edt(y, t * t % mod); sum2.edt(y, t); //debug(ans); t = (x - v[y] + mod) % mod; ans = (ans + t * t % mod * rcnt.que(y + 1, n) + rsum.que(y + 1, n)) % mod; ans = (ans - 2 * t * rsum2.que(y + 1, n) % mod + mod) % mod; rcnt.edt(y, 1); rsum.edt(y, t * t % mod); rsum2.edt(y, t); //debug(ans); } cout << (ans + mod) % mod << '\n'; }