Problem:
Score : 600 points

Problem Statement

We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates.

For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows:

f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T)

Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.

Constraints

1 \leq N \leq 2 \times 10^5

-10^9 \leq x_i, y_i \leq 10^9

x_i \neq x_j (i \neq j)

y_i \neq y_j (i \neq j)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the sum of f(T) over all non-empty subset T of S, modulo 998244353.

Sample Input 1

3
-1 3
2 1
3 -2

Sample Output 1

13

Let the first, second, and third points be P_1, P_2, and P_3, respectively. S = \{P_1, P_2, P_3\} has seven non-empty subsets, and f has the following values for each of them:

f(\{P_1\}) = 1

f(\{P_2\}) = 1

f(\{P_3\}) = 1

f(\{P_1, P_2\}) = 2

f(\{P_2, P_3\}) = 2

f(\{P_3, P_1\}) = 3

f(\{P_1, P_2, P_3\}) = 3

The sum of these is 13.

Sample Input 2

4
1 4
2 1
3 3
4 2

Sample Output 2

34

Sample Input 3

10
19 -11
-3 -12
5 3
3 -15
8 -14
-9 -20
10 -9
0 2
-7 17
6 -6

Sample Output 3

7222

Be sure to print the sum modulo 998244353.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

ll f(ll a, ll b){return a+b;}
int other = 0;

struct segment_tree{
    int n;
    int seg[1000000];
    //要素数Nのセグメントツリーを構築
    segment_tree(int N){
        n = 1;
        while(n < N) n *= 2;
        fill_n(seg, 2*n-1, other);
    }
    //i番目の要素をxに変更(0番目から数える)
    void update(int i, ll x){
        i += n-1;
        seg[i] = x;
        while(i > 0){
            i = (i-1)/2;
            seg[i] = f(seg[2*i+1], seg[2*i+2]);
        }
    }
    //要素数N以上の最小の２べきnを取得
    ll size(){return n;}
    //query(a, b, 0, 0, n)でa番目からb-1番目までの演算の結果を取得
    ll query(int a, int b, int i, int l, int r){
        if(a >= r || b <= l) return other;
        elif(a <= l && r <= b) return seg[i];
        else{
            int vl = query(a, b, 2*i+1, l, (l+r)/2);
            int vr = query(a, b, 2*i+2, (l+r)/2, r);
            return f(vl, vr);
        }
    }
};

int main(){
    int N;
    cin >> N;
    ll e[N];
    e[0] = 1;
    rep2(i, 1, N-1) e[i] = (2*e[i-1])%MOD2;
    int x[N], y[N];
    vector<P> vecx, vecy, vec;
    rep(i, N){
        cin >> x[i] >> y[i];
        vecx.push_back(P(x[i], i));
        vecy.push_back(P(y[i], i));
    }
    sort(vecx.begin(), vecx.end());
    sort(vecy.begin(), vecy.end());
    rep(i, N){
        int px = vecx[i].second, py = vecy[i].second;
        x[px] = i, y[py] = i;
    }
    rep(i, N) vec.push_back(P(x[i], y[i]));
    sort(vec.begin(), vec.end());
    int X[N], Y[N];
    rep(i, N) X[i] = vec[i].first, Y[i] = vec[i].second;
    segment_tree segl(N), segr(N);
    ll n = segl.size();
    ll ul[N], ur[N], dl[N], dr[N];
    rep(i, N){
        dl[i] = segl.query(0, Y[i], 0, 0, n);
        ul[i] = i - dl[i];
        segl.update(Y[i], 1);
    }
    rep3(i, N-1, 0){
        dr[i] = segr.query(0, Y[i], 0, 0, n);
        ur[i] = N-1-i - dr[i]; 
        segr.update(Y[i], 1);
    }
    ll ans = (N*e[N-1])%MOD2;
    rep(i, N){
        ll a = (e[ul[i]]-1)*(e[dr[i]]-1) % MOD2;
        ll b = (e[ur[i]]-1)*(e[dl[i]]-1) % MOD2;
        ans += a * e[ur[i]+dl[i]];
        ans %= MOD2;
        ans += b * e[ul[i]+dr[i]];
        ans %= MOD2;
        ans += MOD2*MOD2 - a*b;
        ans %= MOD2;
    }
    cout << ans << endl;
}