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 <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 998244353;
constexpr ll modsize = 200010;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
	if (modsize == 0) abort();
	fac[0] = 1; fac[1] = 1; inv[1] = 1;
	facinv[0] = 1; facinv[1] = 1;
	for (ll i = 2; i < modsize; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		facinv[i] = facinv[i - 1] * inv[i] % mod;
	}
}

ll modinv(ll a) {
	if (a == 0) abort();
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

ll modpow(ll a, ll b) {
	ll ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[n - k] % mod;
}

ll modhom(ll n, ll k) {
	if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
	if (n == 0 && k == 0) return 1;
	return fac[n + k - 1] * facinv[k] % mod * facinv[n - 1] % mod;
}

constexpr int RSQ = 1;
constexpr int RMQ = 2;
constexpr int RmQ = 3;

template<class T> class segtree {
	int n, mode;
	vector<T> data;
	T id;
public:
	segtree(int _n, int _mode) {
		n = 1;
		mode = _mode;
		while (n < _n + 2) n <<= 1;
		if (mode == 1) id = 0;
		else if (mode == 2) id = -INF;
		else if (mode == 3) id = INF;
		data = vector<T>(2 * n, id);
	}
	T operation(T a, T b) {
		if (mode == 1) return a + b;
		else if (mode == 2) return max(a, b);
		else if (mode == 3) return min(a, b);
	}
	void change(int i, T x) {
		i += n;
		data[i] = x;
		while (i > 1) {
			i >>= 1;
			data[i] = operation(data[i << 1], data[i << 1 | 1]);
		}
	}
	void add(int i, T x) { change(i, data[i + n] + x); }
	T get(int a, int b) {
		T left = id; T right = id;
		a += n; b += n;
		while (a < b) {
			if (a & 1) left = operation(left, data[a++]);
			if (b & 1) right = operation(data[--b], right);
			a >>= 1; b >>= 1;
		}
		return operation(left, right);
	}
	T get_all() { return data[1]; }
	T operator[](int i) { return data[i + n]; }
};

vector<int> shrink(vector<int> vec) {
	int vecsize = vec.size();
	vector<int> tmpvec = vec;
	sort(tmpvec.begin(), tmpvec.end());
	tmpvec.erase(unique(tmpvec.begin(), tmpvec.end()), tmpvec.end());
	vector<int> res(vecsize);
	for (int i = 0; i < vecsize; i++) res[i] = lower_bound(tmpvec.begin(), tmpvec.end(), vec[i]) - tmpvec.begin();
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	modcalc();

	int n;
	cin >> n;
	vector<int> x(n), y(n);
	rep(i, n) cin >> x[i] >> y[i];
	x = shrink(x); y = shrink(y);
	vector<P> p(n);
	rep(i, n) {
		p[i].first = x[i];
		p[i].second = y[i];
	}
	sort(all(p));
	rep(i, n) {
		x[i] = p[i].first;
		y[i] = p[i].second;
	}
	vector<int> c1(n), c2(n), c3(n), c4(n);
	segtree<int> seg1(n, RSQ);
	rep(i, n) {
		c1[i] = seg1.get(y[i] + 1, n + 1);
		c3[i] = seg1.get(0, y[i]);
		seg1.add(y[i], 1);
	}
	segtree<int> seg2(n, RSQ);
	for (int i = n - 1; i >= 0; i--) {
		c2[i] = seg2.get(y[i] + 1, n + 1);
		c4[i] = seg2.get(0, y[i]);
		seg2.add(y[i], 1);
	}
	ll ans = modpow(2, n - 1)*n%mod;
	rep(i, n) {
		ans += (modpow(2, c1[i]) - 1)*(modpow(2, c4[i]) - 1) % mod*modpow(2, c2[i]) % mod*modpow(2, c3[i]) % mod;
		ans += (modpow(2, c2[i]) - 1)*(modpow(2, c3[i]) - 1) % mod*modpow(2, c1[i]) % mod*modpow(2, c4[i]) % mod;
		ans -= (modpow(2, c1[i]) - 1)*(modpow(2, c4[i]) - 1) % mod*(modpow(2, c2[i]) - 1) % mod*(modpow(2, c3[i]) - 1) % mod;
	}
	cout << (ans % mod + mod) % mod << '\n';
}