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;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define int ll
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 998244353;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

template <ll mod>
class Fp {
public:
    ll val;

private:
    inline void calc_mod(ll &v) {
        if (v >= mod)
            v -= mod;
    }

public:
    Fp() {}
    Fp(ll v) : val(v % mod) {
        if (val < 0)
            val += mod;
    }
    Fp operator+=(const Fp &in) {
        val += in.val;
        calc_mod(val);
        return *this;
    }
    Fp operator+(const Fp &in) const {
        return Fp(*this) += in;
    }
    Fp &operator-=(const Fp &in) {
        val -= in.val;
        calc_mod(val);
        if (val < 0)
            val += mod;
        return *this;
    }
    Fp operator-(const Fp &in) const {
        return Fp(*this) -= in;
    }
    Fp &operator*=(const Fp &in) {
        val = val * in.val % mod;
        return *this;
    }
    Fp operator*(const Fp &in) const {
        return Fp(*this) *= in;
    }
    Fp &operator/=(const Fp &in) {
        *this *= modpow(in, mod - 2);
        return *this;
    }
    Fp operator/(const Fp &in) const {
        return Fp(*this) /= in;
    }
    bool operator==(const Fp &in) const {
        return val == in.val;
    }
    bool operator!=(const Fp &in) const {
        return val != in.val;
    }
    friend Fp modpow(const Fp &in, ll n) {
        if (n == 0)
            return 1;
        if (n & 1) {
            return in * modpow(in * in, n / 2);
        } else {
            return modpow(in * in, n / 2);
        }
    }
    friend istream &operator>>(istream &is, Fp<mod> &fp) {
        is >> fp.val;
        return is;
    }

    friend ostream &operator<<(ostream &os, Fp<mod> &fp) {
        os << fp.val;
        return os;
    }
};
using modll = Fp<mod>;
class Factorial {
public:
    vector<modll> fact, finv;
    Factorial(ll n) : fact(n + 1, modll(1)), finv(n + 1, modll(1)) {
        for (int i = 2; i <= n; i++) {
            modll tmp(i);
            fact[i] = fact[i - 1] * tmp;
            finv[i] = finv[i - 1] / tmp;
        }
    }
    modll com(const ll &n, const ll &k) {
        if (n < k || n < 0 || k < 0)
            return modll(0);
        return fact[n] * finv[k] * finv[n - k];
    }
};

class SegmentTree {
public:
    vector<int> node;
    int size;
    int n;
    SegmentTree() {}
    SegmentTree(vector<int> in) {
        int in_sz = in.size();
        n = 1;
        while (n < in_sz) {
            n *= 2;
        }
        size = n * 2 - 1;
        node.resize(size, 0);
        for (int i = 0; i < in_sz; i++) {
            node[n - 1 + i] = in[i];
        }
        init_dfs(0);
    }

    int init_dfs(int now) {
        if (2 * now + 1 >= size)
            return node[now];
        node[now] = init_dfs(2 * now + 1) + init_dfs(2 * now + 2);
        return node[now];
    }

    void add(int index, int val) {
        index += n - 1;
        node[index] += val;
        while (index > 0) {
            index = (index - 1) / 2;
            node[index] = node[2 * index + 1] + node[2 * index + 2];
        }
    }

    void update(int index, int val) {
        index += n - 1;
        node[index] = val;
        while (index > 0) {
            index = (index - 1) / 2;
            node[index] = node[2 * index + 1] + node[2 * index + 2];
        }
    }

    int query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    int _query(int a, int b, int now, int l, int r) {
        if (r <= a || b <= l)
            return 0;
        if (a <= l && r <= b)
            return node[now];
        int val_l = _query(a, b, 2 * now + 1, l, (l + r) / 2);
        int val_r = _query(a, b, 2 * now + 2, (l + r) / 2, r);
        return val_l + val_r;
    }
};

signed main() {
    modll ans = 0;
    cin >> N;
    vector<pair<int, int>> xy(N);
    vi x(N), y(N);
    for (int i = 0; i < N; i++) {
        scanf("%ld %ld", &xy[i].first, &xy[i].second);
        x[i] = xy[i].first;
        y[i] = xy[i].second;
    }
    sort(all(x));
    sort(all(y));
    map<int, int> mpx;
    map<int, int> mpy;
    for (int i = 0; i < N; i++) {
        mpx[x[i]] = i;
        mpy[y[i]] = i;
    }
    sort(all(xy));
    SegmentTree stall(vi(N, 0)), stx(vi(N, 0));
    for (int i = 0; i < N; i++) {
        int x = xy[i].first;
        int y = xy[i].second;
        stall.add(mpy[y], 1);
    }
    for (int i = 0; i < N; i++) {
        int x = xy[i].first;
        int y = xy[i].second;
        int indy = mpy[y];
        vi quad(4);
        dump(indy);
        quad[1] = stx.query(indy + 1, N);
        quad[2] = stx.query(0, indy);
        quad[0] = stall.query(indy + 1, N) - quad[1];
        quad[3] = stall.query(0, indy) - quad[2];
        for (int bit = 0; bit < 16; bit++) {
            vi b(4);
            for (int j = 0; j < 4; j++) {
                b[j] = ((bit >> j) & 1);
            }
            modll tmp = 1;
            for (int j = 0; j < 4; j++) {
                if (b[j] == 1) {
                    tmp *= (modpow(modll(2), quad[j]) - 1);
                }
            }
            if ((b[0] == 1 && b[2] == 1) || (b[1] == 1 && b[3] == 1)) {
                ans += tmp * 2;
            } else {
                ans += tmp;
            }
            dump(b, quad, ans);
        }
        stx.add(indy, 1);
        dump(quad);
    }
    cout << ans << endl;
}