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-----
3
-1 3
2 1
3 -2

-----Sample Output-----
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.

Difficulty: MEDIUM_HARD

Solutions:
import sys
input = sys.stdin.readline
N = int(input())
POINT = [list(map(int, input().split())) for i in range(N)]
mod = 998244353
compression_dict_x = {a: ind for (ind, a) in enumerate(sorted(set([p[0] for p in POINT])))}
POINT = [[compression_dict_x[x] + 1, y] for (x, y) in POINT]
P_Y = sorted(POINT, key=lambda x: x[1])
LEN = len(compression_dict_x)
BIT = [0] * (LEN + 1)

def update(v, w):
	while v <= LEN:
		BIT[v] += w
		v += v & -v

def getvalue(v):
	ANS = 0
	while v != 0:
		ANS += BIT[v]
		v -= v & -v
	return ANS
ANS = 4 * N + (pow(2, N, mod) - 1) * (N - 4) % mod
for i in range(N):
	(x, y) = P_Y[i]
	left = getvalue(x)
	ANS = (ANS + pow(2, left, mod) + pow(2, i - left, mod) - 2) % mod
	update(x, 1)
P_Y.reverse()
BIT = [0] * (LEN + 1)
for i in range(N):
	(x, y) = P_Y[i]
	left = getvalue(x)
	ANS = (ANS + pow(2, left, mod) + pow(2, i - left, mod) - 2) % mod
	update(x, 1)
print(ANS)


from operator import itemgetter
import sys
input = sys.stdin.readline
mod = 998244353

def bit_add(i):
	while i <= n:
		tree[i] += 1
		i += i & -i

def bit_sum(i):
	s = 0
	while i > 0:
		s += tree[i]
		i -= i & -i
	return s
n = int(input())
xy = [[i + 1] + list(map(int, input().split())) for i in range(n)]
data = [[] for i in range(n + 1)]
for i in [1, 2]:
	xy.sort(key=itemgetter(i))
	for j in range(n):
		data[xy[j][0]].append(j + 1)
data = sorted(data[1:])
lst = []
for (i1, i2) in data:
	lst.append(i2)
lsls = [1] * (n + 1)
for i in range(1, n + 1):
	lsls[i] = lsls[i - 1] * 2 % mod
for i in range(n + 1):
	lsls[i] -= 1
s = pow(2, n, mod) - 1
tree = [0] * (n + 1)
ans = 0
for i in range(n):
	y = lst[i]
	num = bit_sum(y)
	bit_add(y)
	(a, b, c, d) = (i - num, num, y - 1 - num, n - y - i + num)
	zzz = lsls[i] + lsls[n - i - 1] + lsls[n - y] + lsls[y - 1]
	yyy = lsls[a] + lsls[b] + lsls[c] + lsls[d]
	t = (zzz % mod - yyy % mod) % mod
	ans = (ans + s - t) % mod
print(ans)


class BIT:

	def __init__(self, n):
		self.tree = [0] * (n + 1)
		self.tree[0] = None

	def sum(self, i):
		s = 0
		i += 1
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def range(self, l, r):
		return sum(r) - sum(l - 1)

	def add(self, i, x):
		i += 1
		while i <= n:
			self.tree[i] += x
			i += i & -i
import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
n = int(input())
xyi = []
for i in range(n):
	a = [int(i) for i in readline().split()]
	xyi.append(a + [i])
dame_x = [0] * n
dame_y = [0] * n
dame_xy = [0] * n
MOD = 998244353
sxyi = sorted(xyi, key=lambda x: x[1])
modosu = [i for (x, y, i) in sxyi]
zaatu = [0] * n
for (j, zj) in enumerate(modosu):
	zaatu[zj] = j
pow2 = [1] * (n + 1)
for i in range(n):
	pow2[i + 1] = pow2[i] * 2 % MOD
for (j, (x, y, i)) in enumerate(sxyi):
	dame_y[i] = pow2[j] - 1 + pow2[n - j - 1] - 1
xyi.sort()
bit = BIT(n)
for (j, (x, y, i)) in enumerate(xyi):
	dame_x[i] = pow2[j] - 1 + pow2[n - j - 1] - 1
	c = bit.sum(zaatu[i])
	dame_xy[i] += pow2[c] - 1 + pow2[j - c] - 1
	bit.add(zaatu[i], 1)
bit = BIT(n)
for (j, (x, y, i)) in enumerate(reversed(xyi)):
	c = bit.sum(zaatu[i])
	dame_xy[i] += pow2[c] - 1 + pow2[j - c] - 1
	bit.add(zaatu[i], 1)
ans = n * (pow2[n] - 1) % MOD
for (dx, dy, dxy) in zip(dame_x, dame_y, dame_xy):
	ans += -dx - dy + dxy
print(ans % MOD)


import sys
input = sys.stdin.readline
N = int(input())
p = []
for i in range(N):
	(x, y) = map(int, input().split())
	p.append([x, y])
mod = 998244353
pow = [1]
for i in range(N):
	pow.append(pow[-1] * 2 % mod)
p.sort(key=lambda x: x[1])
for i in range(N):
	p[i][1] = i + 1
data = [[0 for i in range(4)] for i in range(N)]
n = N
BIT = [0] * (n + 1)

def BIT_query(idx):
	if idx == 0:
		return 0
	res_sum = 0
	while idx > 0:
		res_sum += BIT[idx]
		idx -= idx & -idx
	return res_sum

def BIT_update(idx, x):
	while idx <= n:
		BIT[idx] += x
		idx += idx & -idx
	return
p.sort()
for i in range(N):
	(x, y) = p[i]
	(a, b) = (i, BIT_query(y))
	data[i][0] = a - b
	data[i][3] = b
	BIT_update(y, 1)
BIT = [0] * (n + 1)
for i in range(N - 1, -1, -1):
	(x, y) = p[i]
	(a, b) = (N - 1 - i, BIT_query(y))
	data[i][1] = a - b
	data[i][2] = b
	BIT_update(y, 1)
ans = 0
for i in range(N):
	ban = 0
	for j in range(4):
		ban += (pow[data[i][j]] - 1) * pow[data[i][j - 1]]
		ban %= mod
	ans += pow[N] - ban - 1
	ans %= mod
print(ans)


import sys
sys.setrecursionlimit(10 ** 7)
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right
from collections import deque, defaultdict
from collections import Counter
from itertools import accumulate, combinations, permutations, product
from heapq import heapify, heappop, heappush
from functools import reduce, lru_cache
from decimal import Decimal

def input():
	x = sys.stdin.readline()
	return x[:-1] if x[-1] == '\n' else x

def printe(*x):
	print('## ', *x, file=sys.stderr)

def printl(li):
	_ = print(*li, sep='\n') if li else None

def argsort(s, return_sorted=False):
	inds = sorted(range(len(s)), key=lambda k: s[k])
	if return_sorted:
		return (inds, [s[i] for i in inds])
	return inds

def alp2num(c, cap=False):
	return ord(c) - 97 if not cap else ord(c) - 65

def num2alp(i, cap=False):
	return chr(i + 97) if not cap else chr(i + 65)

def matmat(A, B):
	(K, N, M) = (len(B), len(A), len(B[0]))
	return [[sum([A[i][k] * B[k][j] for k in range(K)]) for j in range(M)] for i in range(N)]

def matvec(M, v):
	(N, size) = (len(v), len(M))
	return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]

def T(M):
	(n, m) = (len(M), len(M[0]))
	return [[M[j][i] for j in range(n)] for i in range(m)]

def binr(x):
	return bin(x)[2:]

def bitcount(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x += x >> 8
	x += x >> 16
	x += x >> 32
	return x & 127

class BIT:

	def __init__(self, max_n):
		self.size = max_n + 1
		self.tree = [0] * self.size
		self.depth = self.size.bit_length()
		self.tot = 0

	def initialize(self, seq):
		tree = self.tree
		size = self.size
		self.tot = 0
		for (i, x) in enumerate(seq, 1):
			self.tot += x
			tree[i] += x
			j = i + (i & -i)
			if j < size:
				tree[j] += tree[i]

	def __repr__(self):
		return self.tree.__repr__()

	def sum(self, i):
		tree = self.tree
		s = 0
		while i:
			s += tree[i]
			i -= i & -i
		return s

	def add(self, i, val):
		tree = self.tree
		size = self.size
		while i < size:
			tree[i] += val
			i += i & -i
		self.tot += val

	def find(self, k):
		if k > self.tot:
			return self.size
		tree = self.tree
		size = self.size
		(x, sx) = (0, 0)
		dx = 1 << self.depth
		for i in range(self.depth - 1, -1, -1):
			dx = 1 << i
			if x + dx >= size:
				continue
			y = x + dx
			sy = sx + tree[y]
			if sy < k:
				(x, sx) = (y, sy)
		return x + 1

def main():
	mod = 998244353
	N = int(input())
	S = tuple((tuple(map(int, input().split())) for i in range(N)))
	xs = []
	ys = []
	for (x, y) in S:
		xs.append(x)
		ys.append(y)
	ixsort = argsort(xs)
	iysort = argsort(ys)
	s = [[0, 0] for _ in range(N)]
	for i in range(N):
		s[ixsort[i]][0] = i
		s[iysort[i]][1] = i
	s.sort()
	xsmall = BIT(N)
	xlarge = BIT(N)
	for i in range(0, N):
		xlarge.add(s[i][1] + 1, 1)
	p2 = [0] * (N + 1)
	p2[0] = 1
	for i in range(1, N + 1):
		p2[i] = p2[i - 1] * 2 % mod
	ans = 0
	p2n = p2[N]
	for (i, (x, y)) in enumerate(s):
		xlarge.add(y + 1, -1)
		lxsy = xlarge.sum(y + 1)
		lxly = xlarge.tot - lxsy
		sxsy = xsmall.sum(y + 1)
		sxly = xsmall.tot - sxsy
		xsmall.add(y + 1, 1)
		t = 1
		t += p2[lxsy] + p2[lxly] + p2[sxly] + p2[sxsy] - 4
		t %= mod
		t += p2[lxly + lxsy] - p2[lxly] - p2[lxsy] + 1
		t += p2[lxly + sxly] - p2[sxly] - p2[lxly] + 1
		t += p2[sxsy + lxsy] - p2[sxsy] - p2[lxsy] + 1
		t += p2[sxsy + sxly] - p2[sxsy] - p2[sxly] + 1
		t %= mod
		ans += p2n - t
		ans %= mod
	print(ans)
main()


import sys
input = sys.stdin.readline
mod = 998244353

def sub(a, b):
	return (a % mod + mod - b % mod) % mod

class SegTree:

	def __init__(self, init_val, n, ide_ele, seg_func):
		self.segfunc = seg_func
		self.num = 2 ** (n - 1).bit_length()
		self.ide_ele = ide_ele
		self.seg = [self.ide_ele] * 2 * self.num
		for i in range(n):
			self.seg[i + self.num - 1] = init_val[i]
		for i in range(self.num - 2, -1, -1):
			self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

	def update(self, k, x):
		k += self.num - 1
		self.seg[k] = x
		while k + 1:
			k = (k - 1) // 2
			self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

	def query(self, p, q):
		if q <= p:
			return self.ide_ele
		p += self.num - 1
		q += self.num - 2
		res = self.ide_ele
		while q - p > 1:
			if p & 1 == 0:
				res = self.segfunc(res, self.seg[p])
			if q & 1 == 1:
				res = self.segfunc(res, self.seg[q])
				q -= 1
			p = p // 2
			q = (q - 1) // 2
		if p == q:
			res = self.segfunc(res, self.seg[p])
		else:
			res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
		return res

def main():
	(n,) = list(map(int, input().split()))
	t = 1
	dd = [t]
	for _ in range(n):
		t = 2 * t % mod
		dd.append(t)
	(xs, ys) = ([], [])
	for _ in range(n):
		(x, y) = list(map(int, input().split()))
		xs.append(x)
		ys.append(y)
	ini = sorted(list(range(n)), key=lambda x: xs[x])
	for (i, yi) in enumerate(sorted(list(range(n)), key=lambda x: ys[x])):
		ys[yi] = i
	nys = [ys[i] for i in ini]
	ss1 = SegTree([0] * n, n, 0, lambda x, y: x + y)
	r = 0
	for (i, y) in enumerate(nys):
		ss1.update(y, 1)
		d = ss1.query(0, y)
		c = i - d
		b = n - 1 - y - c
		a = n - 1 - b - c - d
		r = (r + sub(dd[b + c] + dd[c + d] + dd[d + a] + dd[a + b], dd[a] + dd[b] + dd[c] + dd[d])) % mod
	print(sub(dd[n] * n % mod, (r + n) % mod))
main()


class BIT:

	def __init__(self, n):
		self.tree = [0] * (n + 1)
		self.tree[0] = None

	def sum(self, i):
		s = 0
		i += 1
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def range(self, l, r):
		return sum(r) - sum(l - 1)

	def add(self, i, x):
		i += 1
		while i <= n:
			self.tree[i] += x
			i += i & -i
import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
n = int(input())
xyi = [[int(i) for i in readline().split()] + [j] for j in range(n)]
ABi = [0] * n
CDi = [0] * n
MOD = 998244353
sxyi = sorted(xyi, key=lambda x: x[1])
zaatu = [0] * n
for j in range(n):
	zaatu[sxyi[j][2]] = j
for (j, (x, y, i)) in enumerate(sxyi):
	ABi[i] = n - j - 1
	CDi[i] = j
pow2 = [1] * (n + 1)
for i in range(n):
	pow2[i + 1] = pow2[i] * 2 % MOD
xyi.sort()
bit = BIT(n)
ans = n * (pow2[n] - 1) % MOD
for (j, (x, y, i)) in enumerate(xyi):
	AB = ABi[i]
	CD = CDi[i]
	BC = j
	AD = n - j - 1
	c = bit.sum(zaatu[i])
	C = c
	B = j - c
	ans -= pow2[AB] - 1 + pow2[CD] - 1
	ans -= pow2[BC] - 1 + pow2[AD] - 1
	ans += pow2[C] - 1 + pow2[CD - C] - 1 + pow2[B] - 1 + pow2[AB - B] - 1
	bit.add(zaatu[i], 1)
print(ans % MOD)


from bisect import bisect_left as bl
N = int(input())
P = 998244353
NN = 18
XX = [0] * (2 ** (NN + 1) - 1)
pow2 = [1]
for _ in range(1, 202020):
	pow2.append(pow2[-1] * 2 % P)

def addvalue(j):
	i = 2 ** NN + j - 1
	while i >= 0:
		XX[i] += 1
		i = (i - 1) // 2

def rangesum(a, b):
	l = a + (1 << NN)
	r = b + (1 << NN)
	s = 0
	while l < r:
		if l % 2:
			s += XX[l - 1]
			l += 1
		if r % 2:
			r -= 1
			s += XX[r - 1]
		l >>= 1
		r >>= 1
	return s
X = []
Y = []
XY = []
for _ in range(N):
	(x, y) = map(int, input().split())
	X.append(x)
	Y.append(y)
	XY.append((x, y))
X = sorted(X)
Y = sorted(Y)
XY = sorted(XY, key=lambda x: x[1])
DX = {}
for i in range(N):
	DX[X[i]] = i
ans = 0
U = 0
for (x, y) in XY:
	a = rangesum(0, DX[x])
	L = bl(X, x)
	b = U - a
	d = L - a
	c = N - a - b - d - 1
	ans = (ans + pow2[N] - (pow2[a + b] + pow2[b + c] + pow2[c + d] + pow2[d + a] - pow2[a] - pow2[b] - pow2[c] - pow2[d] + 1)) % P
	U += 1
	addvalue(DX[x])
print(ans)


import sys
from operator import itemgetter
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
n = ni()
co = []
for i in range(n):
	co.append(na())
co.sort(key=itemgetter(1))
for i in range(n):
	co[i][1] = i
ft = [0] * (n + 5)
co.sort(key=itemgetter(0), reverse=True)
ups = [0] * n
downs = [0] * n

def addfenwick(ft, i, v):
	if v == 0 or i < 0:
		return
	i += 1
	while i < len(ft):
		ft[i] += v
		i += i & -i

def sumfenwick(ft, i):
	s = 0
	i += 1
	while i > 0:
		s += ft[i]
		i -= i & -i
	return s
for i in range(n):
	c = co[i]
	downs[n - 1 - i] = sumfenwick(ft, c[1])
	ups[n - 1 - i] = i - downs[n - 1 - i]
	addfenwick(ft, c[1], 1)
ft = [0] * (n + 5)
co = co[::-1]
mod = 998244353
ps = [0] * (n + 5)
ps[0] = 1
for i in range(1, n + 4):
	ps[i] = ps[i - 1] * 2 % mod
ans = 0
for i in range(n):
	c = co[i]
	d = sumfenwick(ft, c[1])
	u = i - d
	ans += (ps[d] - 1) * (ps[ups[i]] - 1) * ps[u + downs[i]]
	ans += (ps[u] - 1) * (ps[downs[i]] - 1) * ps[d + ups[i]]
	ans -= (ps[d] - 1) * (ps[ups[i]] - 1) * (ps[downs[i]] - 1) * (ps[u] - 1)
	ans += ps[n - 1]
	addfenwick(ft, c[1], 1)
ans %= mod
if ans < 0:
	ans += mod
print(ans)


from operator import itemgetter

class BIT:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def sum(self, i):
		s = 0
		i += 1
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		i += 1
		while i <= self.size:
			self.tree[i] += x
			i += i & -i
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort(key=itemgetter(1))
for i in range(N):
	xy[i][1] = i
xy.sort(key=itemgetter(0))
y = [xy[i][1] for i in range(N)]
mod = 998244353
p2 = [1] * (N + 1)
for i in range(N):
	p2[i + 1] = p2[i] * 2 % mod
bit1 = BIT(N)
bit2 = BIT(N)
for i in range(N):
	bit2.add(i, 1)
ans = 0
for i in range(N):
	bit1.add(y[i], 1)
	bit2.add(y[i], -1)
	n1 = bit1.sum(N - 1) - bit1.sum(y[i])
	n2 = bit1.sum(y[i] - 1)
	n3 = bit2.sum(N - 1) - bit2.sum(y[i])
	n4 = bit2.sum(y[i] - 1)
	ans += 1
	ans += p2[n1] - 1 + (p2[n2] - 1) + (p2[n3] - 1) + (p2[n4] - 1)
	ans += (p2[n1] - 1) * (p2[n2] - 1) + (p2[n3] - 1) * (p2[n4] - 1) + (p2[n1] - 1) * (p2[n3] - 1) + (p2[n2] - 1) * (p2[n4] - 1) + 2 * (p2[n1] - 1) * (p2[n4] - 1) + 2 * (p2[n2] - 1) * (p2[n3] - 1)
	ans += 2 * ((p2[n1] - 1) * (p2[n2] - 1) * (p2[n3] - 1) + (p2[n1] - 1) * (p2[n2] - 1) * (p2[n4] - 1) + (p2[n1] - 1) * (p2[n3] - 1) * (p2[n4] - 1) + (p2[n2] - 1) * (p2[n3] - 1) * (p2[n4] - 1))
	ans += 2 * (p2[n1] - 1) * (p2[n2] - 1) * (p2[n3] - 1) * (p2[n4] - 1)
	ans %= mod
print(ans)


from operator import itemgetter

class BIT:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i
mod = 998244353
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort(key=itemgetter(1))
for i in range(N):
	xy[i][1] = i + 1
xy.sort(key=itemgetter(0))
pow2 = [1] * (N + 1)
for i in range(N):
	pow2[i + 1] = 2 * pow2[i] % mod
ans = pow2[N - 1] * N % mod
bit = BIT(N)
for i in range(N):
	l1 = bit.sum(xy[i][1])
	l2 = i - l1
	r1 = xy[i][1] - l1 - 1
	r2 = N - xy[i][1] - l2
	bit.add(xy[i][1], 1)
	ans += (pow2[l2] - 1) * (pow2[r1] - 1) * pow2[r2] * pow2[l1]
	ans += (pow2[r2] - 1) * (pow2[l1] - 1) * (pow2[l2] + pow2[r1] - 1)
	ans %= mod
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
mod = 998244353
from operator import itemgetter
l.sort(key=itemgetter(1))
for i in range(n):
	l[i][1] = i
l.sort(key=itemgetter(0))
No = 2
while No <= n:
	No *= 2
tree = [0] * (2 * No)

def add(k, x):
	k += No - 1
	while k >= 0:
		tree[k] += x
		k = (k - 1) // 2

def query(l, r):
	L = l + No - 1
	R = r + No - 1
	s = 0
	while L <= R:
		if R & 1:
			s += tree[R]
			R -= 2
		else:
			R -= 1
		if L & 1:
			L -= 1
		else:
			s += tree[L]
		L >>= 1
		R >>= 1
	return s
pow2 = [1 for i in range(n + 2)]
t = 2
for i in range(1, n + 2):
	pow2[i] = t
	t *= 2
	t %= mod
ans = 0
for (x, y) in l:
	lu = query(y, n)
	ld = query(0, y)
	ru = n - 1 - y - lu
	rd = y - ld
	ans += pow2[n - 1] + (pow2[lu] - 1) * (pow2[rd] - 1) % mod * (pow2[ru] + pow2[ld] - 1 + (pow2[ld] - 1) * (pow2[ru] - 1)) % mod + (pow2[ld] - 1) * (pow2[ru] - 1) % mod * (pow2[rd] + pow2[lu] - 1) % mod
	ans %= mod
	add(y, 1)
print(ans)


def main():
	from sys import stdin
	input = stdin.readline
	mod = 998244353
	n = int(input())
	xy = [list(map(int, input().split())) for _ in [0] * n]
	ans = 0
	pow_2 = [1]
	j = 1
	for i in range(n):
		j = j * 2 % mod
		pow_2.append(j)
	p2 = pow_2[n - 1]
	xy.sort(key=lambda x: x[1])
	xy = [(x, i + 1) for (i, (x, y)) in enumerate(xy)]
	xy.sort()

	class BIT:

		def __init__(self, n):
			self.n = n
			self.maxbit = 2 ** (len(bin(self.n)) - 3)
			self.bit = [0] * (self.n + 1)
			self.allsum = 0

		def all_plus(self):
			self.bit = [0] + [i & -i for i in range(1, self.n + 1)]
			self.allsum = self.n

		def add(self, i, v):
			x = i
			self.allsum += v
			while x < self.n + 1:
				self.bit[x] += v
				x += x & -x

		def sum(self, i):
			ret = 0
			x = i
			while x > 0:
				ret += self.bit[x]
				x -= x & -x
			return ret
	bit_left = BIT(n)
	bit_right = BIT(n)
	bit_right.all_plus()
	for (i, (x, y)) in enumerate(xy):
		bit_right.add(y, -1)
		A = bit_left.sum(y)
		B = i - A
		C = bit_right.sum(y)
		D = n - i - 1 - C
		bit_left.add(y, 1)
		ans += (pow_2[A] - 1) * (pow_2[D] - 1) * pow_2[B + C]
		ans += (pow_2[B] - 1) * (pow_2[C] - 1) * pow_2[A + D]
		ans -= (pow_2[B] - 1) * (pow_2[C] - 1) * (pow_2[A] - 1) * (pow_2[D] - 1)
		ans += p2
		ans = ans % mod
	print(ans)
main()


import sys
input = sys.stdin.readline
mod = 998244353

def sub(a, b):
	return (a % mod + mod - b % mod) % mod

def main():
	(n,) = list(map(int, input().split()))
	t = 1
	dd = [t]
	for _ in range(n):
		t = 2 * t % mod
		dd.append(t)
	(xs, ys) = ([], [])
	for _ in range(n):
		(x, y) = list(map(int, input().split()))
		xs.append(x)
		ys.append(y)
	ini = sorted(list(range(n)), key=lambda x: xs[x])
	for (i, yi) in enumerate(sorted(list(range(n)), key=lambda x: ys[x])):
		ys[yi] = i
	nys = [ys[i] for i in ini]
	tree = [0] * (n + 1)
	r = 0
	for (i, y) in enumerate(nys):
		j = y + 1
		while j <= n:
			tree[j] += 1
			j += j & -j
		d = 0
		j = y
		while j > 0:
			d += tree[j]
			j -= j & -j
		c = i - d
		b = n - 1 - y - c
		a = n - 1 - b - c - d
		r = (r + sub(dd[b + c] + dd[c + d] + dd[d + a] + dd[a + b], dd[a] + dd[b] + dd[c] + dd[d])) % mod
	print(sub(dd[n] * n % mod, (r + n) % mod))
main()


class Bit:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i
import sys
input = sys.stdin.readline
mod = 998244353

def sub(a, b):
	return (a % mod + mod - b % mod) % mod

def main():
	(n,) = list(map(int, input().split()))
	t = 1
	dd = [t]
	for _ in range(n):
		t = 2 * t % mod
		dd.append(t)
	(xs, ys) = ([], [])
	for _ in range(n):
		(x, y) = list(map(int, input().split()))
		xs.append(x)
		ys.append(y)
	ini = sorted(list(range(n)), key=lambda x: xs[x])
	for (i, yi) in enumerate(sorted(list(range(n)), key=lambda x: ys[x])):
		ys[yi] = i
	nys = [ys[i] for i in ini]
	ss1 = Bit(n)
	r = 0
	for (i, y) in enumerate(nys):
		ss1.add(y + 1, 1)
		d = ss1.sum(y)
		c = i - d
		b = n - 1 - y - c
		a = n - 1 - b - c - d
		r = (r + sub(dd[b + c] + dd[c + d] + dd[d + a] + dd[a + b], dd[a] + dd[b] + dd[c] + dd[d])) % mod
	print(sub(dd[n] * n % mod, (r + n) % mod))
main()


import sys
input = sys.stdin.readline

def solve():
	MOD = 998244353
	N = int(input())
	pts = [tuple(map(int, input().split())) for _ in range(N)]
	iXs = list(range(N))
	iXs.sort(key=lambda iX: pts[iX][0])
	iYs = list(range(N))
	iYs.sort(key=lambda iY: pts[iY][1])
	odrYs = [0] * N
	for (odrY, iY) in enumerate(iYs):
		odrYs[iY] = odrY

	def init(As):
		numPow2 = 2 ** (len(As) - 1).bit_length()
		data = [0] * (numPow2 + 1)
		return (data, numPow2)

	def addValue(iA, A):
		iA += 1
		while iA <= numPow2:
			data[iA] += A
			iA += iA & -iA

	def getSum(iA):
		iA += 1
		ans = 0
		while iA > 0:
			ans += data[iA]
			iA -= iA & -iA
		return ans
	numPtss = [[0] * 4 for _ in range(N)]
	(data, numPow2) = init([0] * N)
	for (odr, iX) in enumerate(iXs):
		y = odrYs[iX]
		num = getSum(y)
		numPtss[iX][0] = num
		numPtss[iX][1] = odr - num
		addValue(y, 1)
	(data, numPow2) = init([0] * N)
	for (odr, iX) in enumerate(reversed(iXs)):
		y = odrYs[iX]
		num = getSum(y)
		numPtss[iX][2] = num
		numPtss[iX][3] = odr - num
		addValue(y, 1)

	def getPows(base, n, MOD):
		pows = [1] * (n + 1)
		for x in range(1, n + 1):
			pows[x] = pows[x - 1] * base % MOD
		return pows
	pow2s = getPows(2, N, MOD)
	ans = 0
	for numPts in numPtss:
		num = pow2s[N - 1]
		nums = [pow2s[k] for k in numPts]
		num += (nums[0] - 1) * nums[1] * nums[2] * (nums[3] - 1) % MOD
		num += nums[0] * (nums[1] - 1) * (nums[2] - 1) * nums[3] % MOD
		num -= (nums[0] - 1) * (nums[1] - 1) * (nums[2] - 1) * (nums[3] - 1) % MOD
		ans += num % MOD
		ans %= MOD
	print(ans)
solve()


import sys
input = sys.stdin.readline
N = int(input())
POINT = [list(map(int, input().split())) for i in range(N)]
mod = 998244353
PX = [p[0] for p in POINT]
PY = [p[1] for p in POINT]
compression_dict_x = {a: ind for (ind, a) in enumerate(sorted(set(PX)))}
compression_dict_y = {a: ind for (ind, a) in enumerate(sorted(set(PY)))}
for i in range(N):
	POINT[i] = [compression_dict_x[POINT[i][0]] + 1, compression_dict_y[POINT[i][1]] + 1]
P_Y = sorted(POINT, key=lambda x: x[1])
LEN = len(compression_dict_x)
BIT = [0] * (LEN + 1)

def update(v, w):
	while v <= LEN:
		BIT[v] += w
		v += v & -v

def getvalue(v):
	ANS = 0
	while v != 0:
		ANS += BIT[v]
		v -= v & -v
	return ANS
ALL = pow(2, N, mod) - 1
ANS = ALL * N % mod
for i in range(N):
	ANS = (ANS - (pow(2, i, mod) - 1) * 4) % mod
for i in range(N):
	(x, y) = P_Y[i]
	up = getvalue(x)
	ANS = (ANS + pow(2, up, mod) + pow(2, i - up, mod) - 2) % mod
	update(x, 1)
P_Y2 = P_Y[::-1]
BIT = [0] * (LEN + 1)
for i in range(N):
	(x, y) = P_Y2[i]
	down = getvalue(x)
	ANS = (ANS + pow(2, down, mod) + pow(2, i - down, mod) - 2) % mod
	update(x, 1)
print(ANS)


N = int(input())
XY = []
for _ in range(N):
	(x, y) = map(int, input().split())
	XY.append((x, y))

class Bit:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i
from operator import itemgetter

def solve():
	p_list = XY[:]
	p_list = sorted(p_list, key=itemgetter(1))
	p_list = [(x, y, i + 1) for (i, (x, y)) in enumerate(p_list)]
	p_list = sorted(p_list)
	power = [1] * N
	for i in range(1, N):
		power[i] = power[i - 1] * 2 % 998244353
	bit = Bit(N)
	ans = 0
	for (i, (x, y, r)) in enumerate(p_list):
		tmp = bit.sum(r)
		a = tmp
		b = i - tmp
		c = r - tmp - 1
		d = N - r + 1 - (i - tmp) - 1
		bit.add(r, 1)
		_a = power[a] - 1
		_b = power[b] - 1
		_c = power[c] - 1
		_d = power[d] - 1
		ret = (_a + 1) * (_d + 1) * _c * _b
		ret += (_b + 1) * (_c + 1) * _a * _d
		ret -= _a * _b * _c * _d
		ret += power[N - 1]
		ans += ret % 998244353
	print(ans % 998244353)
solve()


import sys
import bisect
MOD = 998244353

class BitIndexedTree(object):

	def __init__(self, N):
		self.V = [0] * N
		self.N = N

	def __getitem__(self, key):
		return self.sum(key, key + 1)

	def __setitem__(self, key, value):
		diff = value - self[key]
		self.add(diff, key)

	def add(self, w, a):
		if w == 0:
			return
		x = a
		while x <= self.N:
			self.V[x - 1] += w
			x += x & -x

	def sum(self, start=0, end=0):
		if end <= start:
			return 0
		if start > 0:
			return self.sum(0, end) - self.sum(0, start)
		x = end
		ret = 0
		while x > 0:
			ret += self.V[x - 1]
			x -= x & -x
		return ret

def solve(N: int, P: 'List[tuple]'):
	res = 0
	power = [1] * N
	for i in range(1, N):
		power[i] = power[i - 1] * 2 % MOD
	P.sort(key=lambda x: x[1])
	for (i, p) in enumerate(P):
		p[1] = i
	P.sort()
	for (i, p) in enumerate(P):
		p[0] = i
	left = BitIndexedTree(N)
	right = BitIndexedTree(N)
	ll = [0] * N
	lg = [0] * N
	gl = [0] * N
	gg = [0] * N
	for (i, p) in enumerate(P):
		ll[i] = left.sum(0, p[1])
		lg[i] = i - ll[i]
		left.add(1, p[1] + 1)
	for (i, p) in enumerate(P[::-1]):
		gl[-1 - i] = right.sum(0, p[1])
		gg[-1 - i] = i - gl[-1 - i]
		right.add(1, p[1] + 1)
	for (a1, a2, a3, a4) in zip(gg, lg, ll, gl):
		b1 = power[a1]
		b2 = power[a2]
		b3 = power[a3]
		b4 = power[a4]
		res += (b1 - 1) * (b3 - 1) * b2 * b4
		res += (b2 - 1) * (b4 - 1) * b1 * b3
		res -= (b1 - 1) * (b2 - 1) * (b3 - 1) * (b4 - 1)
		res += b1 * b2 * b3 * b4
		res %= MOD
	print(res)
	return

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	P = [()] * N
	for i in range(N):
		x = int(next(tokens))
		y = int(next(tokens))
		P[i] = [x, y]
	solve(N, P)
main()


from operator import itemgetter

class Bit:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort(key=itemgetter(1))
for i in range(N):
	XY[i][1] = i
XY.sort(key=itemgetter(0))
y_nor_list = [xy[1] for xy in XY]
sg_left = Bit(N)
sg_right = Bit(N)
left_lower = [0] * N
left_upper = [0] * N
right_lower = [0] * N
right_upper = [0] * N
for i in range(N):
	c = y_nor_list[i] + 1
	left_lower[i] = sg_left.sum(c)
	left_upper[i] = i - left_lower[i]
	sg_left.add(c, 1)
for i in range(N - 1, -1, -1):
	c = y_nor_list[i] + 1
	right_lower[i] = sg_right.sum(c)
	right_upper[i] = N - 1 - i - right_lower[i]
	sg_right.add(c, 1)
LARGE = 998244353
pow2m1 = [0] * (N + 1)
for i in range(1, N + 1):
	pow2m1[i] = (2 * pow2m1[i - 1] + 1) % LARGE
res = 0
for i in range(N):
	r = pow2m1[N]
	r -= pow2m1[left_lower[i] + left_upper[i]]
	r -= pow2m1[right_lower[i] + right_upper[i]]
	r -= pow2m1[left_lower[i] + right_lower[i]]
	r -= pow2m1[left_upper[i] + right_upper[i]]
	r += pow2m1[left_lower[i]]
	r += pow2m1[left_upper[i]]
	r += pow2m1[right_lower[i]]
	r += pow2m1[right_upper[i]]
	res += r
print(res % LARGE)


import sys
from operator import itemgetter
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline

class BinaryIndexedTree:

	def __init__(self, n):
		self.n = n
		self.data = [0] * (n + 1)

	def add(self, _i, x):
		i = _i
		while i <= self.n:
			self.data[i] += x
			i += i & -i

	def sum(self, _i):
		i = _i
		res = 0
		while i:
			res += self.data[i]
			i -= i & -i
		return res

	def bisect_left(self, _w):
		w = _w
		if w <= 0:
			return 0
		i = 0
		k = 1 << self.n.bit_length() - 1
		while 0 < k:
			if i + k <= self.n and self.data[i + k] < w:
				w -= self.data[i + k]
				i += k
			k = k >> 1
		return i + 1

def solve():
	MOD = 998244353
	N = int(rl())
	xy = [[0, 0] for _ in range(N)]
	for i in range(N):
		(xy[i][0], xy[i][1]) = map(int, rl().split())
	compress = sorted(xy, key=itemgetter(1))
	for i in range(N):
		compress[i][1] = i
	compress.sort(key=itemgetter(0), reverse=True)
	bit = BinaryIndexedTree(N)
	ups = [0] * N
	downs = [0] * N
	for i in range(N):
		com = compress[i][1] + 1
		downs[N - 1 - i] = bit.sum(com)
		ups[N - 1 - i] = i - downs[N - 1 - i]
		bit.add(com, 1)
	bit = BinaryIndexedTree(N)
	compress = compress[::-1]
	pow_of_2 = [1]
	for _ in range(N):
		pow_of_2.append(pow_of_2[-1] * 2 % MOD)
	ans = 0
	for i in range(N):
		com = compress[i][1] + 1
		d = bit.sum(com)
		u = i - d
		ans = (ans + (pow_of_2[d] - 1) * (pow_of_2[ups[i]] - 1) * pow_of_2[u + downs[i]]) % MOD
		ans = (ans + (pow_of_2[u] - 1) * (pow_of_2[downs[i]] - 1) * pow_of_2[d + ups[i]]) % MOD
		ans = (ans - (pow_of_2[d] - 1) * (pow_of_2[ups[i]] - 1) * (pow_of_2[downs[i]] - 1) * (pow_of_2[u] - 1)) % MOD
		ans = (ans + pow_of_2[N - 1]) % MOD
		bit.add(com, 1)
	print(ans)
solve()


import sys
import math
input = sys.stdin.readline

class BIT:

	def __init__(self, len_A):
		self.N = len_A + 10
		self.bit = [0] * (len_A + 10)

	def query(self, i):
		res = 0
		idx = i + 1
		while idx:
			res += self.bit[idx]
			idx -= idx & -idx
		return res

	def update(self, i, x):
		idx = i + 1
		while idx < self.N:
			self.bit[idx] += x
			idx += idx & -idx

	def lower_left(self, w):
		if w < 0:
			return -1
		x = 0
		k = 1 << self.N.bit_length() - 1
		while k > 0:
			if x + k < self.N and self.bit[x + k] < w:
				w -= self.bit[x + k]
				x += k
			k //= 2
		return x
N = int(input())
xy = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])
P = 998244353
for i in range(N):
	xy[i][1] = i
xy = sorted(xy)
for i in range(N):
	xy[i][0] = i
(ld, lu, rd, ru) = ([-1] * N, [-1] * N, [-1] * N, [-1] * N)
bit = BIT(N)
for i in range(N):
	ld[i] = bit.query(xy[i][1])
	lu[i] = bit.query(N) - ld[i]
	bit.update(xy[i][1], 1)
bit = BIT(N)
for i in range(N - 1, -1, -1):
	rd[i] = bit.query(xy[i][1])
	ru[i] = bit.query(N) - rd[i]
	bit.update(xy[i][1], 1)
ans = 0
for i in range(N):
	ans = (ans + pow(2, N, P) - 1) % P
	ans = (ans - (pow(2, rd[i] + ru[i], P) - 1)) % P
	ans = (ans - (pow(2, ld[i] + lu[i], P) - 1)) % P
	ans = (ans - (pow(2, rd[i] + ld[i], P) - 1)) % P
	ans = (ans - (pow(2, ru[i] + lu[i], P) - 1)) % P
	ans = (ans + (pow(2, ru[i], P) - 1)) % P
	ans = (ans + (pow(2, rd[i], P) - 1)) % P
	ans = (ans + (pow(2, lu[i], P) - 1)) % P
	ans = (ans + (pow(2, ld[i], P) - 1)) % P
print(ans)


import itertools
import os
import sys
from collections import defaultdict
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(2147483647)
INF = float('inf')
IINF = 10 ** 18
MOD = 998244353

class BinaryIndexedTree:

	def __init__(self, size):
		self._bit = [0] * (size + 1)
		self._size = size

	def add(self, i, w):
		x = i
		while x <= self._size:
			self._bit[x] += w
			x += x & -x

	def sum(self, i):
		ret = 0
		x = i
		while x > 0:
			ret += self._bit[x]
			x -= x & -x
		return ret

	def __len__(self):
		return self._size

def compress(li):
	ret = [0] * len(li)
	rank = 0
	prev = None
	for (a, i) in sorted([(a, i) for (i, a) in enumerate(li)]):
		if a != prev:
			rank += 1
		ret[i] = rank
	return ret
N = int(sys.stdin.readline())
XY = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

def test():
	ret = 0
	counts = defaultdict(int)
	for selection in itertools.product([0, 1], repeat=N):
		if not any(selection):
			continue
		xs = set([XY[i][0] for (i, s) in enumerate(selection) if s])
		ys = set([XY[i][1] for (i, s) in enumerate(selection) if s])
		xl = min(xs)
		xr = max(xs)
		yl = min(ys)
		yr = max(ys)
		r = 0
		for (x, y) in XY:
			r += xl <= x <= xr and yl <= y <= yr
		ret += r
		counts[r] += 1
	return ret
XY.sort()
Y = [y for (_, y) in XY]
Y = compress(Y)
LL = []
LG = []
GL = []
GG = []
bit = BinaryIndexedTree(size=N)
for (i, y) in enumerate(Y):
	ll = bit.sum(y)
	lg = i - ll
	gl = y - ll - 1
	gg = N - y - lg
	LL.append(ll)
	LG.append(lg)
	GL.append(gl)
	GG.append(gg)
	bit.add(y, 1)
pow2 = [1] * N
p = 1
for i in range(N - 1):
	p = p * 2 % MOD
	pow2[i + 1] = p
ans = 0
for (ll, lg, gl, gg) in zip(LL, LG, GL, GG):
	ans += pow2[N - 1]
	a = (pow2[ll] - 1) * (pow2[gg] - 1) % MOD * pow2[N - ll - gg - 1]
	b = (pow2[lg] - 1) * (pow2[gl] - 1) % MOD * pow2[N - lg - gl - 1]
	c = (pow2[ll] - 1) * (pow2[gg] - 1) % MOD * (pow2[lg] - 1) * (pow2[gl] - 1) % MOD
	ans += a + b - c
	ans %= MOD
print(ans)


class Bit:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def __iter__(self):
		psum = 0
		for i in range(self.size):
			csum = self.sum(i + 1)
			yield (csum - psum)
			psum = csum
		raise StopIteration()

	def __str__(self):
		return str(list(self))

	def sum(self, i):
		if not 0 <= i <= self.size:
			raise ValueError('error!')
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		if not 0 <= i < self.size:
			raise ValueError('error!')
		i += 1
		while i <= self.size:
			self.tree[i] += x
			i += i & -i

	def __getitem__(self, key):
		if not 0 <= key < self.size:
			raise IndexError('error!')
		return self.sum(key + 1) - self.sum(key)

	def __setitem__(self, key, value):
		if not 0 <= key < self.size:
			raise IndexError('error!')
		self.add(key, value - self[key])
from operator import itemgetter
import sys
input = sys.stdin.readline
mod = 998244353
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort(key=itemgetter(1))
for i in range(N):
	XY[i][1] = i
XY.sort(key=itemgetter(0))
bitL = Bit(N)
bitR = Bit(N)
L = []
R = [0] * N
for (_, y) in XY:
	L.append(bitL.sum(y))
	bitL.add(y, 1)
for (i, (_, y)) in zip(range(N - 1, -1, -1), XY[::-1]):
	R[i] = bitR.sum(y)
	bitR.add(y, 1)
ans = N * pow(2, N - 1, mod) % mod
for (i, (ld, rd)) in enumerate(zip(L, R)):
	lu = i - ld
	ru = N - 1 - i - rd
	(p_lu, p_ld, p_ru, p_rd) = (pow(2, lu, mod), pow(2, ld, mod), pow(2, ru, mod), pow(2, rd, mod))
	d = p_ru * p_ld * (p_lu - 1) * (p_rd - 1) + p_lu * p_rd * (p_ru - 1) * (p_ld - 1) - (p_lu - 1) * (p_rd - 1) * (p_ru - 1) * (p_ld - 1)
	ans = (ans + d) % mod
print(ans)