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 For(i, l, r) for (int i = (l); i <= (r); ++i)

typedef long long LL;
typedef pair<int, int> Pii;

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

const int maxn = 200000 + 5;
const int mod = 998244353;

int n;
int x[maxn], y[maxn];
int vx[maxn], vy[maxn];
int id[maxn], f[maxn];

int c[maxn];

void update(int i, int x) {
  for (; i <= n; i += i & -i) c[i] += x;
}

int query(int i) {
  int ret = 0;
  for (; i; i -= i & -i) ret += c[i];
  return ret;
}

int pow_mod(int a, int b) {
  int ret = 1;
  for (; b; a = (LL)a * a % mod, b >>= 1)
    if (b & 1) ret = (LL)ret * a % mod;
  return ret;
}

int main() {
  scanf("%d", &n);
  rep(i, n) {
    scanf("%d%d", &x[i], &y[i]);
    vx[i] = x[i], vy[i] = y[i];
  }
  sort(vx, vx + n);
  sort(vy, vy + n);
  rep(i, n) {
    x[i] = lower_bound(vx, vx + n, x[i]) - vx + 1;
    y[i] = lower_bound(vy, vy + n, y[i]) - vy + 1;
  }
  rep(i, n) id[i] = i;
  sort(id, id + n, [](int i, int j) { return x[i] < x[j]; });
  rep(j, n) {
    int i = id[j];
    f[i] = query(y[i]);
    update(y[i], 1);
  }
  int tot = (pow_mod(2, n) - 1 + mod) % mod, ret = 0;
  rep(i, n) {
    int now = tot;
    now = (now - (pow_mod(2, x[i] - 1) - 1) + mod) % mod;
    now = (now - (pow_mod(2, n - x[i]) - 1) + mod) % mod;
    now = (now - (pow_mod(2, y[i] - 1) - 1) + mod) % mod;
    now = (now - (pow_mod(2, n - y[i]) - 1) + mod) % mod;
    int ld = f[i];
    now = (now + pow_mod(2, ld) - 1) % mod;
    int rd = y[i] - 1 - ld;
    now = (now + pow_mod(2, rd) - 1) % mod;
    int lu = x[i] - 1 - ld;
    now = (now + pow_mod(2, lu) - 1) % mod;
    int ru = n - y[i] - lu;
    now = (now + pow_mod(2, ru) - 1) % mod;
    ret = (ret + now) % mod;
  }
  printf("%d\n", ret);

  return 0;
}