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: Wrong Answer)

#include <iostream>
#include <map>
#include <cstring>
#include <algorithm>

using namespace std;

typedef pair<int, int> pii;
typedef map<int, int> mii;

const int Z = 1e9+7;

void upd(int bit[], int n, int x) {
    for (; x <= n; x += x & -x) {
        bit[x]++;
    }
}

int qry(int bit[], int x) {
    int r = 0;
    for (; x; x -= x & -x) {
        r += bit[x];
    }
    return r;
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    pii xy[n];
    for (int i = 0; i < n; i++) {
        cin >> xy[i].first >> xy[i].second;
    }
    sort(xy, xy+n);

    int a[n];
    for (int i = 0; i < n; i++) {
        a[i] = xy[i].second;
    }

    mii xx;
    for (int i = 0; i < n; i++) {
        xx[a[i]] = 0;
    }

    int q = 0;
    for (auto p : xx) {
        xx[p.first] = ++q;
    }

    for (int i = 0; i < n; i++) {
        a[i] = xx[a[i]];
    }

    int l[n], r[n], u[n], d[n], lu[n], ru[n], ld[n], rd[n];

    int bit[n+1];
    memset(bit, 0, sizeof(bit));
    for (int i = 0; i < n; i++) {
        ld[i] = qry(bit, a[i]);
        lu[i] = i - ld[i];
        upd(bit, n, a[i]);
    }

    memset(bit, 0, sizeof(bit));
    for (int i = n - 1; i >= 0; i--) {
        rd[i] = qry(bit, a[i]);
        ru[i] = n - 1 - i - rd[i];
        upd(bit, n, a[i]);
    }

    int p2[n+1];
    for (int i = 0; i <= n; i++) {
        p2[i] = i == 0 ? 1 : p2[i-1] * 2 % Z;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        l[i] = i;
        r[i] = n - 1 - i;
        u[i] = lu[i] + ru[i];
        d[i] = ld[i] + rd[i];

        ans = (0ll + ans + p2[n] - 1
              - p2[l[i]] - p2[r[i]] - p2[u[i]] - p2[d[i]]
              + p2[lu[i]] + p2[ld[i]] + p2[ru[i]] + p2[rd[i]]) % Z;
    }

    cout << ans << endl;

    return 0;
}