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)

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};

struct BIT { //1-indexed
private:
    int n,n2;
    vector<ll> bit;

public:
    BIT(vector<ll> v){
        n = v.size();
        rep(i,0,n) bit.push_back(v[i]);
        n2 = 1;
        while(n2 * 2 <= n) n2 *= 2;
    }

    ll sum(ll i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(ll i, ll x){
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }
    ll lower_bound(ll w) {
        if (w <= 0) return 0;
        ll x = 0;
        for (ll k = n2; k > 0; k /= 2) {
            if (x + k <= n && bit[x + k] < w) {
                w -= bit[x + k];
                x += k;
            }
        }
        return x + 1;
    }

};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll x[200010], y[200010];
    rep(i,0,N) cin >> x[i] >> y[i];
    vector<ll> X, Y;
    rep(i,0,N){
        X.push_back(x[i]);
        Y.push_back(y[i]);
    }
    X.push_back(-INF);
    X.push_back(INF);
    Y.push_back(-INF);
    Y.push_back(INF);
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    rep(i,0,N){
        x[i] = lower_bound(X.begin(), X.end(), x[i]) - X.begin();
        y[i] = lower_bound(Y.begin(), Y.end(), y[i]) - Y.begin();
    }
    vector<lpair> lp;
    rep(i,0,N) lp.push_back(make_pair(x[i], y[i]));
    sort(lp.begin(), lp.end());
    rep(i,0,N){
        x[i] = lp[i].first;
        y[i] = lp[i].second;
    }

    vector<ll> v(N+1, 0);
    BIT Lb(v), Rb(v);
    rep(i,0,N) Rb.add(y[i], 1);
    ll pow_mod[200010] = {};
    pow_mod[0] = 1;
    rep(i,0,N+1) pow_mod[i+1] = pow_mod[i] * 2 % MOD;
    ll ans = 0;
    rep(i,0,N){
        Rb.add(y[i], -1);
        rep(bit,0,16){
            ll RT = Rb.sum(N) - Rb.sum(y[i]);
            ll RD = Rb.sum(y[i]);
            ll LT = Lb.sum(N) - Lb.sum(y[i]);
            ll LD = Lb.sum(y[i]);
            ll b0 = ((bit>>0) & 1);
            ll b1 = ((bit>>1) & 1);
            ll b2 = ((bit>>2) & 1);
            ll b3 = ((bit>>3) & 1);
            RT = b0 ? pow_mod[RT] - 1 : 1;
            RD = b1 ? pow_mod[RD] - 1 : 1;
            LT = b2 ? pow_mod[LT] - 1 : 1;
            LD = b3 ? pow_mod[LD] - 1 : 1;
            
            ll v = RT * RD % MOD * LT % MOD * LD % MOD;
            if((b0 && b3) || (b1 && b2)) (v *= 2) %= MOD;
            (ans += v) %= MOD;
        }
        Lb.add(y[i], 1);
    }
    print(ans);
}