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 SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 998244353

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long bipow(long long n, int m) {
    if (m == 0) return 1;
    if (m % 2 == 0) {
        n = (n * n) % MOD;
        return bipow(n, m / 2) % MOD;
    } else
        return (n * bipow(n, m - 1)) % MOD;
}

// 1-indexed
template <class X>
class FenwickTree {
    int n;
    vector<X> a;
public:
    FenwickTree(int n) : n(n), a(n+1, 0) {}
    X get(int i) {
        X sm = 0;
        for(; i > 0; i -= i&-i) sm += a[i];
        return sm;
    }
    void add(int i, X x) {
        for(; i <= n; i += i&-i) a[i] += x;
    }
    X at(int i){return get(i) - get(i-1);}
};

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> xy(N);
    vector<int> ys(N);
    REP(i, N){
        int x, y;
        cin >> x >> y;
        xy[i] = make_pair(x, y);
        ys[i] = y;
    }
    map<int, int> mp;
    sort(ys.begin(), ys.end());
    for(int y : ys) mp[y] = mp.size() + 1;
    for(auto &z : xy){
        z = make_pair(z.first, mp[z.second]);
    }
    sort(xy.begin(), xy.end());

    FenwickTree<int> A(N+10), B(N+10);
    A.add(xy[0].second, 1);
    REP(i, 1, N) B.add(xy[i].second, 1);
    long long ans = 0;
    for(int i=1; i<N-1; i++){
        int y = xy[i].second;
        B.add(y, -1);

        int a0 = A.get(y);
        int b0 = A.get(N+10) - a0;
        int b1 = B.get(y);
        int a1 = B.get(N+10) - b1;
        long long a0pow = bipow(2, a0);
        long long a1pow = bipow(2, a1);
        long long b0pow = bipow(2, b0);
        long long b1pow = bipow(2, b1);
        long long tmp0 = ((a0pow-1)*(a1pow-1))%MOD;
        long long tmp1 = ((b0pow-1)*(b1pow-1))%MOD;
        long long tmp2 = (tmp0 * tmp1) % MOD;
        tmp0 = (tmp0 * b0pow) % MOD;
        tmp0 = (tmp0 * b1pow) % MOD;
        tmp1 = (tmp1 * a0pow) % MOD;
        tmp1 = (tmp1 * a1pow) % MOD;
        long long tmp4 = (tmp0 + tmp1) % MOD;
        tmp4 += MOD - tmp2;
        tmp4 %= MOD;
        ans = (ans + tmp4) % MOD;

        A.add(y, 1);
    }
    ans += (N * bipow(2, N-1)) % MOD;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}