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++ (GCC 9.2.1) (judge verdict: Accepted)

// 2020-08-14 20:06:13
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
const int mod = 998244353;
struct mint {
  ll val;
  constexpr mint(ll v = 0) noexcept : val(v % mod) {
    if (val < 0) val += mod;
  }
  constexpr mint operator + (const mint& rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator - (const mint& rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator * (const mint& rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator / (const mint& rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint operator ~ () const noexcept {
    ll a = this->val, b = mod, u = 1, v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      u -= t * v;
      ll c = a; a = b; b = c;
      ll w = u; u = v; v = w;
    }
    if (u < 0) u += mod;
    u %= mod;
    return u;
  }
  constexpr mint& operator += (const mint& rhs) noexcept {
    val += rhs.val;
    if (val >= mod) val -= mod;
    return *this;
  }
  constexpr mint& operator -= (const mint& rhs) noexcept {
    if (val < rhs.val) val += mod;
    val -= rhs.val;
    return *this;
  }
  constexpr mint& operator *= (const mint& rhs) noexcept {
    val = val * rhs.val % mod;
    return *this;
  }
  constexpr mint& operator /= (const mint& rhs) noexcept {
    val = val * (~(mint(rhs))).val % mod;
    return *this;
  }
  friend mint modpow (mint a, ll n) noexcept {
    auto res = mint(1);
    while(n > 0) {
      if(n&1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend std::ostream& operator << (std::ostream& os, const mint& a) noexcept {
    return os << a.val;
  }
  friend std::string debug_s (mint a) noexcept {
    return std::to_string(a.val);
  }
};
struct FenwickTree {
  int N;
  vll bit;
  void init(int n) {
    N = n;
    bit.assign(n+2, 0);
  }
  void add(int i, ll a) {
    while(i <= N) {
      bit[i] += a;
      // chmax(bit[i], a);
      i += (i & -i);
    }
  }
  ll sum(int i) {
    ll res = 0;
    while(i > 0) {
      res += bit[i];
      // chmax(res, bit[i]);
      i -= (i & -i);
    }
    return res;
  }
  int lower_bound(ll w) {
    int k = 1;
    while(k <= N) k *= 2;
    k /= 2;
    int x = 0;
    while(k > 0) {
      if(x+k <= N && bit[x+k] < w) {
        w -= bit[x+k];
        x += k;
      }
      k /= 2;
    }
    return x+1;
  }
};

mint mpw2[200020];
void answer() {
  mpw2[0] = 1;
  rep(i, 200010) mpw2[i+1] = mpw2[i] * 2;
  int n;
  cin >> n;
  vector<P> ps(n); // x, y
  map<int, int> mpx, mpy;
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    ps[i] = P(x, y);
    mpx[x] = 0;
    mpy[y] = 0;
  }
  {
    int i = 0;
    for(auto& m : mpx) m.second = ++i;
    i = 0;
    for(auto& m : mpy) m.second = ++i;
  }
  mint memo[200020][3];
  {
    FenwickTree bit;
    bit.init(n);
    sort(ALL(ps));
    for(const auto& p : ps) {
      int x, y;
      tie(x, y) = p;
      int xi = mpx[x], yi = mpy[y];
      int b = bit.sum(yi);
      int a = bit.sum(n) - b;
      memo[xi][0] = (mpw2[a] - 1) * mpw2[b];
      memo[xi][1] = mpw2[a] * (mpw2[b] - 1);
      memo[xi][2] = (mpw2[a] - 1) * (mpw2[b] - 1);
      bit.add(yi, 1);
    }
  }
  {
    FenwickTree bit;
    bit.init(n);
    sort(RALL(ps));
    for(const auto& p : ps) {
      int x, y;
      tie(x, y) = p;
      int xi = mpx[x], yi = mpy[y];
      int d = bit.sum(yi);
      int c = bit.sum(n) - d;
      memo[xi][0] *= mpw2[c] * (mpw2[d] - 1);
      memo[xi][1] *= (mpw2[c] - 1) * mpw2[d];
      memo[xi][2] *= (mpw2[c] - 1) * (mpw2[d] - 1);
      bit.add(yi, 1);
    }
  }
  mint ans = 0;
  for(const auto& p : ps) {
    int x, y;
    tie(x, y) = p;
    int xi = mpx[x], yi = mpy[y];
    ans += mpw2[n-1];
    ans += memo[xi][0];
    ans += memo[xi][1];
    ans -= memo[xi][2];
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}