AtCoder Beginner Contest 136 - Enclosed Points

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.

Source: atcoder | 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)


N = int(input())
xy = [tuple(map(int, input().split())) for _ in range(N)]
mod = 998244353

class BIT:

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

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

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

	def query(self, i, j=None):
		if j is None:
			return self.el[i]
		return self.sum(j) - self.sum(i)
xy2 = []
for i in range(N):
	(x, y) = xy[i]
	x += 10 ** 9
	y += 10 ** 9
	xy2.append(y << 80 | x << 40 | i)
xy2 = sorted(xy2)
mask = (1 << 40) - 1
y_order = [0] * N
y_compress = {}
for (j, y) in enumerate(xy2):
	i = y & mask
	y >>= 40
	x = y & mask
	x -= 10 ** 9
	y >>= 40
	y -= 10 ** 9
	y_order[i] = j
	y_compress[y] = j + 1
xy2 = []
for i in range(N):
	(x, y) = xy[i]
	x += 10 ** 9
	y += 10 ** 9
	xy2.append(x << 80 | y << 40 | i)
xy2 = sorted(xy2)
mask = (1 << 40) - 1
bit = BIT(N)
ans = 0
for x in xy2:
	i = x & mask
	x >>= 40
	y = x & mask
	y -= 10 ** 9
	x >>= 40
	x -= 10 ** 9
	y = y_compress[y]
	bit.add(y, 1)
	n1 = bit.query(y - 1, N) - 1
	n2 = bit.query(0, y) - 1
	n3 = N - y - n1
	n4 = y - n2 - 1
	prod14 = (pow(2, n1, mod) - 1) * (pow(2, n4, mod) - 1) * pow(2, n2 + n3, mod) % mod
	prod23 = (pow(2, n2, mod) - 1) * (pow(2, n3, mod) - 1) * pow(2, n1 + n4, mod) % mod
	prod1234 = (pow(2, n1, mod) - 1) * (pow(2, n4, mod) - 1) * (pow(2, n2, mod) - 1) * (pow(2, n3, mod) - 1) % mod
	ans += pow(2, N - 1, mod) + prod14 + prod23 - prod1234
	ans %= mod
print(ans)


from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 20

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def I():
	return int(sys.stdin.buffer.readline())

def LS():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]

def SRL(n):
	return [list(S()) for i in range(n)]

def MSRL(n):
	return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353

class BIT:

	def __init__(self, size):
		self.bit = [0] * size
		self.size = size

	def add(self, i, w):
		x = i + 1
		while x <= self.size:
			self.bit[x - 1] += w
			x += x & -x
		return

	def sum(self, i):
		res = 0
		x = i + 1
		while x:
			res += self.bit[x - 1]
			x -= x & -x
		return res
n = I()
X = []
Y = []
XY = []
for (x, y) in LIR(n):
	Y += [y]
	X += [x]
co_to_ind = {e: i for (i, e) in enumerate(sorted(Y))}
Y = [co_to_ind[k] for k in Y]
Y = [Y[i] for i in sorted(range(n), key=lambda j: X[j])]
pow2 = [1]
for i in range(n):
	pow2 += [pow2[-1] * 2 % mod]
ans = pow2[n - 1] * n % mod
bit = BIT(n)
for (i, y) in enumerate(Y):
	bit.add(y, 1)
	ld = bit.sum(y - 1)
	lu = i - ld
	rd = y - ld
	ru = n - y - 1 - lu
	ans = ans + (pow2[ld] - 1) * (pow2[ru] - 1) % mod * pow2[lu] % mod * pow2[rd] % mod
	ans = ans + (pow2[lu] - 1) * (pow2[rd] - 1) % mod * pow2[ld] % mod * pow2[ru] % mod
	ans = ans - (pow2[ld] - 1) * (pow2[ru] - 1) % mod * (pow2[rd] - 1) % mod * (pow2[lu] - 1) % mod
print(ans % mod)


import sys
input = sys.stdin.readline
N = int(input())
XY = [tuple(map(int, input().split())) for i in range(N)]
XY.sort(key=lambda x: x[0])
ys = []
for (_, y) in XY:
	ys.append(y)
ys.sort()
yd = {y: i for (i, y) in enumerate(ys)}

class BinaryIndexedTree:

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

	def add(self, x, w):
		x += 1
		while x <= self.N:
			self.bit[x] += w
			x += x & -x

	def _sum(self, x):
		ret = 0
		while x > 0:
			ret += self.bit[x]
			x -= x & -x
		return ret

	def sum(self, l, r):
		return self._sum(r) - self._sum(l)

	def __str__(self):
		arr = [self.sum(i, i + 1) for i in range(self.N)]
		return str(arr)
lbit = BinaryIndexedTree(N)
lu = []
ld = []
for (i, (_, y)) in enumerate(XY):
	d = lbit._sum(yd[y])
	u = i - d
	lu.append(u)
	ld.append(d)
	lbit.add(yd[y], 1)
rbit = BinaryIndexedTree(N)
ru = []
rd = []
for (i, (_, y)) in enumerate(XY[::-1]):
	d = rbit._sum(yd[y])
	u = i - d
	ru.append(u)
	rd.append(d)
	rbit.add(yd[y], 1)
MOD = 998244353
ans = 0
for (a, b, c, d) in zip(ld, lu, rd[::-1], ru[::-1]):
	(pa, pb, pc, pd) = (pow(2, a, MOD), pow(2, b, MOD), pow(2, c, MOD), pow(2, d, MOD))
	ans += (pa - 1) * (pd - 1) * pb * pc
	ans += (pb - 1) * (pc - 1) * pa * pd
	ans -= (pa - 1) * (pb - 1) * (pc - 1) * (pd - 1)
	ans %= MOD
ans += N * pow(2, N - 1, MOD)
ans %= MOD
print(ans)


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
input = sys.stdin.readline
MOD = 998244353
n = int(input())
xy = []
y_index = dict()
for i in range(n):
	(x, y) = [int(item) for item in input().split()]
	xy.append((x, y))
xy.sort(key=lambda x: x[1])
for (i, (_, y)) in enumerate(xy):
	y_index[y] = i
xy.sort()
cnt = [0] * (n + 1)

def BIT_sum(i):
	ret = 0
	while i > 0:
		ret += cnt[i]
		i -= i & -i
	return ret

def BIT_add(i):
	while i <= n:
		cnt[i] += 1
		i += i & -i
	return
points_in_quad = [[0] * n for _ in range(4)]
seen = 0
for (i, (x, y)) in enumerate(xy):
	index = y_index[y]
	points_in_quad[2][i] = BIT_sum(index + 1)
	points_in_quad[1][i] = seen - points_in_quad[2][i]
	BIT_add(index + 1)
	seen += 1
seen = 0
cnt = [0] * (n + 1)
for (i, (x, y)) in enumerate(xy[::-1]):
	index = y_index[y]
	points_in_quad[3][n - 1 - i] = BIT_sum(index + 1)
	points_in_quad[0][n - 1 - i] = seen - points_in_quad[3][n - 1 - i]
	BIT_add(index + 1)
	seen += 1
pow2 = []
a = 1
for i in range(n + 1):
	pow2.append(a)
	a *= 2
	a %= MOD
ans = 0
for i in range(n):
	free1 = pow2[points_in_quad[0][i]]
	free2 = pow2[points_in_quad[1][i]]
	free3 = pow2[points_in_quad[2][i]]
	free4 = pow2[points_in_quad[3][i]]
	fix24 = (free2 - 1) * (free4 - 1) % MOD
	fix13 = (free1 - 1) * (free3 - 1) % MOD
	ans -= fix24 * fix13 % MOD
	ans += free1 * free3 % MOD * fix24 % MOD
	ans += free2 * free4 % MOD * fix13 % MOD
	ans %= MOD
ans += pow2[n - 1] * n % MOD
print(ans % MOD)


from itertools import product
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 998244353

class BinaryIndexTree:

	def __init__(self, N):
		if isinstance(N, int):
			self.N = N
			self.depth = N.bit_length()
			self.tree = [0] * (N + 1)
			self.elem = [0] * (N + 1)
		elif isinstance(N, list):
			self.N = len(N)
			self.depth = self.N.bit_length()
			self.tree = [0] + N
			self.elem = [0] + N
			self._init()
		else:
			raise 'INVALID INPUT: input must be int or list'

	def _init(self):
		size = self.N
		for i in range(1, self.N):
			if i + (i & -i) > size:
				continue
			self.tree[i + (i & -i)] += self.tree[i]

	def add(self, i, x):
		self.elem[i] += x
		while i <= self.N:
			self.tree[i] += x
			i += i & -i

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

	def lower_bound(self, val):
		if val <= 0:
			return 0
		i = 0
		k = 1 << self.depth
		while k:
			if i + k <= self.N and self.tree[i + k] < val:
				val -= self.tree[i + k]
				i += k
			k >>= 1
		return i + 1

def F(a, b, c, d):
	res = 0
	nums = (a, b, c, d)
	ox = tuple((pow(2, i, mod) for i in nums))
	o = tuple((i - 1 for i in ox))
	res += ox[0] * o[1] * ox[2] * o[3]
	res %= mod
	res += o[0] * ox[1] * o[2] * ox[3]
	res %= mod
	res -= o[0] * o[1] * o[2] * o[3]
	res %= mod
	res += ox[0] * ox[1] * ox[2] * ox[3]
	res %= mod
	return res
N = int(input())
XY = sorted((tuple(map(int, input().split())) for _ in range(N)))
(_, Y) = zip(*XY)
ytoi = {y: i for (i, y) in enumerate(sorted(set(Y)), 1)}
bit_R = BinaryIndexTree([1] * N)
bit_L = BinaryIndexTree(N)
ans = 0
for (i, y) in enumerate(Y, 1):
	R = N - i
	L = i - 1
	y = ytoi[y]
	bit_R.add(y, -1)
	c4 = bit_R.sum(y)
	c1 = R - c4
	c3 = bit_L.sum(y)
	c2 = L - c3
	ans += F(c1, c2, c3, c4)
	ans %= mod
	bit_L.add(y, 1)
print(ans)


import sys
input = sys.stdin.readline

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return list(map(int, input().split()))

def main():
	mod = 998244353

	class SegTree:

		def __init__(self, N, ide, segfunc=min):
			self.ide_ele = ide
			self.segfunc = segfunc
			self.num = 2 ** (N - 1).bit_length()
			self.seg = [self.ide_ele] * 2 * self.num

		def setL(self, init_val):
			for i in range(self.num):
				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:
				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
	N = I()
	Y = [0] * N
	from collections import defaultdict
	ddy = defaultdict(int)
	L = [[0, 0, 0] for _ in range(N)]
	for i in range(N):
		(x, y) = MI()
		Y[i] = y
		L[i] = [x, y, i]
	Y.sort()
	for i in range(N):
		ddy[Y[i]] = i
	POW = [1]
	for i in range(N + 5):
		p = POW[-1] * 2 % mod
		POW.append(p)
	cnt = [[0, 0, 0, 0] for _ in range(N)]
	L.sort()
	seg = SegTree(N, 0, lambda a, b: a + b)
	for j in range(N):
		i = L[j][2]
		y = L[j][1]
		yy = ddy[y]
		temp = seg.query(yy, N)
		cnt[i][0] = temp
		cnt[i][1] = j - temp
		seg.update(yy, 1)
	seg = SegTree(N, 0, lambda a, b: a + b)
	for j in range(N):
		i = L[-1 - j][2]
		y = L[-1 - j][1]
		yy = ddy[y]
		temp = seg.query(yy, N)
		cnt[i][2] = temp
		cnt[i][3] = j - temp
		seg.update(yy, 1)

	def calc(cnt_item):
		(lu, ld, ru, rd) = cnt_item
		temp = POW[N - 1]
		temp += (POW[lu] - 1) * (POW[rd] - 1) % mod
		temp += (POW[ld] - 1) * (POW[ru] - 1) % mod
		temp += (POW[lu] - 1) * (POW[ld] - 1) * (POW[ru] - 1) % mod
		temp += (POW[lu] - 1) * (POW[ld] - 1) * (POW[rd] - 1) % mod
		temp += (POW[lu] - 1) * (POW[ru] - 1) * (POW[rd] - 1) % mod
		temp += (POW[ld] - 1) * (POW[ru] - 1) * (POW[rd] - 1) % mod
		temp += (POW[lu] - 1) * (POW[ld] - 1) * (POW[ru] - 1) * (POW[rd] - 1) % mod
		temp %= mod
		return temp
	ans = 0
	for i in range(N):
		ans = (ans + calc(cnt[i])) % mod
	print(ans)
main()


import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
con = 998244353
INF = float('inf')

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):

	def __init__(self, N):
		self.N0 = 2 ** (N - 1).bit_length()
		self.data = [0] * (2 * self.N0)

	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.data[2 * k + 1] + self.data[2 * k + 2]

	def query(self, l, r):
		L = l + self.N0
		R = r + self.N0 + 1
		m = 0
		while L < R:
			if R & 1:
				R -= 1
				m += self.data[R - 1]
			if L & 1:
				m += self.data[L - 1]
				L += 1
			L >>= 1
			R >>= 1
		return m

def main():
	N = int(input())
	XY = [None] * N
	X = [None] * N
	Y = [None] * N
	for i in range(N):
		(x, y) = getlist()
		XY[i] = [x, y]
		X[i] = x
		Y[i] = y
	X.sort()
	Y.sort()
	Dx = defaultdict(int)
	Dy = defaultdict(int)
	for i in range(N):
		Dx[X[i]] = i
		Dy[Y[i]] = i
	for i in range(N):
		XY[i] = (Dx[XY[i][0]], Dy[XY[i][1]])
	XY.sort(key=lambda x: x[0])
	YY = [XY[i][1] for i in range(N)]
	Segleft = SegmentTree(N)
	Segright = SegmentTree(N)
	ans = pow(2, N - 1, con) * N
	ans %= con
	yLU = [0] * N
	yLD = [0] * N
	yRU = [0] * N
	yRD = [0] * N
	Segleft.update(YY[0], 1)
	for i in range(1, N - 1):
		y = YY[i]
		yLD[i] = Segleft.query(0, y)
		yLU[i] = Segleft.query(y, N - 1)
		Segleft.update(y, 1)
	Segright.update(YY[N - 1], 1)
	for i in range(N - 2, 0, -1):
		y = YY[i]
		yRD[i] = Segright.query(0, y)
		yRU[i] = Segright.query(y, N - 1)
		Segright.update(y, 1)
	for i in range(1, N - 1):
		lu = yLU[i]
		ru = yRU[i]
		ld = yLD[i]
		rd = yRD[i]
		a = pow(2, lu, con)
		b = pow(2, ru, con)
		c = pow(2, ld, con)
		d = pow(2, rd, con)
		if rd != 0 and lu != 0:
			ans += (d - 1) * (a - 1) * b * c
		if ld != 0 and ru != 0:
			ans += (c - 1) * (b - 1) * a * d
		if rd != 0 and lu != 0 and (ld != 0) and (ru != 0):
			ans -= (a - 1) * (b - 1) * (c - 1) * (d - 1)
		ans %= con
	print(ans)
main()


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()


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
write = lambda x: sys.stdout.write(x + '\n')

def init(bit, values):
	for (i, v) in enumerate(values):
		add(bit, i + 1, v)

def query(bit, i):
	res = 0
	while i > 0:
		res += bit[i]
		i -= i & -i
	return res

def add(bit, i, x):
	if i == 0:
		raise RuntimeError
	while i <= len(bit) - 1:
		bit[i] += x
		i += i & -i
	return
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
from bisect import bisect_left

def press(l):
	xs = sorted(set(l))
	inds = [None] * len(l)
	for (i, item) in enumerate(l):
		inds[i] = bisect_left(xs, item)
	return (xs, inds)
(_, indx) = press([item[0] for item in xy])
(_, indy) = press([item[1] for item in xy])
xy = []
for i in range(n):
	xy.append(indy[i] + indx[i] * n)
xy.sort()
M = 998244353
pows = [0] * (n + 1)
v = 1
for i in range(n + 1):
	pows[i] = v - 1
	v *= 2
	v %= M
ans = pows[n] * n % M
bit = [0] * (n + 1)
for i in range(n):
	(x, y) = divmod(xy[i], n)
	ans -= pows[i] + pows[n - i - 1]
	ans += pows[query(bit, y + 1)] + pows[i - query(bit, y + 1)]
	add(bit, y + 1, 1)
	ans %= M
from operator import itemgetter
xy.sort(key=lambda item: item % n)
bit = [0] * (n + 1)
for i in range(n):
	(x, y) = divmod(xy[i], n)
	ans -= pows[i] + pows[n - i - 1]
	ans += pows[i - query(bit, x + 1)]
	add(bit, x + 1, 1)
	ans %= M
bit = [0] * (n + 1)
for i in range(n - 1, -1, -1):
	(x, y) = divmod(xy[i], n)
	ans += pows[n - 1 - i - query(bit, x + 1)]
	add(bit, x + 1, 1)
	ans %= M
print(ans % M)


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
input = sys.stdin.readline
N = int(input())
mod = 998244353
a = []
ys = []
for _ in range(N):
	(x, y) = map(int, input().split())
	a.append((x, y))
	ys.append(y)

def compress(init_val):
	t = sorted(set(init_val))
	d = dict([[t[i], i] for i in range(len(t))])
	res = [0] * len(init_val)
	for i in range(len(init_val)):
		res[i] = d[init_val[i]]
	return res
ys = compress(ys)
a = [(a[i][0], ys[i] + 1) for i in range(N)]
a.sort()

class BIT:

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

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

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

	def get(self, i, j=None):
		if j is None:
			return self.el[i]
		return self.sum(j) - self.sum(i)

	def lowerbound(self, s):
		x = 0
		y = 0
		for i in range(self.n.bit_length(), -1, -1):
			k = x + (1 << i)
			if k <= self.n and y + self.data[k] < s:
				y += self.data[k]
				x += 1 << i
		return x + 1
fwkl = BIT(N)
fwkr = BIT(N)
ls = [0] * N
rs = [0] * N
for i in range(N):
	ls[i] = fwkl.sum(a[i][1])
	fwkl.add(a[i][1], 1)
for i in range(N - 1, -1, -1):
	rs[i] = fwkr.sum(a[i][1])
	fwkr.add(a[i][1], 1)
table = [pow(2, i, mod) - 1 for i in range(N)]
pw = lambda x: table[x]
res = 0
for i in range(N):
	(ld, rd) = (ls[i], rs[i])
	lu = i - ld
	ru = N - i - rd - 1
	for k in range(16):
		d = [0] * 4
		t = 1
		if k & 1:
			t *= pw(ld)
			t %= mod
			d[0] = 1
			d[2] = 1
		if k & 2:
			t *= pw(lu)
			t %= mod
			d[0] = 1
			d[3] = 1
		if k & 4:
			t *= pw(rd)
			t %= mod
			d[1] = 1
			d[2] = 1
		if k & 8:
			t *= pw(ru)
			t %= mod
			d[1] = 1
			d[3] = 1
		res += t * 2 ** (sum(d) == 4)
		res %= mod
print(res)


import sys

class BIT:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)
		self.p = 2 ** (n.bit_length() - 1)
		self.dep = n.bit_length()

	def get(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

	def bl(self, v):
		if v <= 0:
			return -1
		s = 0
		k = self.p
		for _ in range(self.dep):
			if s + k <= self.size and self.tree[s + k] < v:
				s += k
				v -= self.tree[s + k]
			k //= 2
		return s + 1

def compress(L):
	L2 = list(set(L))
	L2.sort()
	C = {v: k for (k, v) in enumerate(L2, 1)}
	return (L2, C)
N = int(input())
mod = 998244353
ans = N * pow(2, N - 1, mod) % mod
points = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
points.sort()
(_, PY) = map(list, zip(*points))
(_, Ci) = compress(PY)
PY = [Ci[p] for p in PY]
T1 = BIT(N)
T2 = BIT(N)
for i in range(1, N + 1):
	T2.add(i, 1)
for i in range(N):
	y = PY[i]
	c = T1.get(y)
	d = T2.get(y) - 1 - c
	a = i - c
	b = N - 1 - a - c - d
	T1.add(y, 1)
	a2 = pow(2, a, mod)
	b2 = pow(2, b, mod)
	c2 = pow(2, c, mod)
	d2 = pow(2, d, mod)
	ans += (a2 - 1) * b2 * c2 * (d2 - 1) + a2 * (b2 - 1) * (c2 - 1) * d2 - (a2 - 1) * (b2 - 1) * (c2 - 1) * (d2 - 1)
	ans %= mod
print(ans)


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

class BIT:

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

	def add(self, i, x):
		while i <= self.size:
			self.bit[i] += x
			i += i & -i

	def sum_to_i(self, i):
		s = 0
		while i > 0:
			s += self.bit[i]
			i -= i & -i
		return s
n = int(input())
XY = []
Y = []
for _ in range(n):
	(x, y) = map(int, input().split())
	XY.append((x, y))
	Y.append(y)
Y.sort()
y_dict = {y: i + 1 for (i, y) in enumerate(Y)}
XY = [(x, y_dict[y]) for (x, y) in XY]
XY.sort()
bit = BIT(n)
pow_2 = [1]
for _ in range(n):
	pow_2.append(pow_2[-1] * 2 % mod)
ans = 0
for (i, (x, y)) in enumerate(XY):
	a = bit.sum_to_i(y)
	b = i - a
	c = y - a - 1
	d = n - i - 1 - c
	bit.add(y, 1)
	(pa, pb, pc, pd) = (pow_2[a], pow_2[b], pow_2[c], pow_2[d])
	tmp = pow_2[n - 1]
	tmp += (pa - 1) * (pd - 1) * pb * pc % mod
	tmp += (pb - 1) * (pc - 1) * pa * pd % mod
	tmp -= (pa - 1) * (pb - 1) * (pc - 1) * (pd - 1) % mod
	ans += tmp
	ans %= mod
print(ans)


def f_encolsed_points(MOD=998244353):
	import sys
	input = sys.stdin.readline

	class BIT(object):

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

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

		def add(self, index, value=1):
			while index <= self.size:
				self.tree[index] += value
				index += index & -index
	N = int(input())
	Pos = [[int(i) for i in input().split()] for j in range(N)]
	Pos.sort()
	(_, pos_y) = zip(*Pos)
	y_comp = {y: i for (i, y) in enumerate(sorted(pos_y), 1)}
	pow_2 = [1]
	for _ in range(N):
		pow_2.append(pow_2[-1] * 2 % MOD)
	ans = 0
	tree = BIT(N)
	for (left, (_x, _y)) in enumerate(Pos):
		y = y_comp[_y]
		right = N - 1 - left
		down = y - 1
		up = N - 1 - down
		lower_left = tree.sum(y)
		tree.add(y, 1)
		upper_left = left - lower_left
		lower_right = down - lower_left
		upper_right = right - lower_right
		count = pow_2[N] - (pow_2[up] + pow_2[down] + pow_2[left] + pow_2[right]) + (pow_2[upper_left] + pow_2[lower_left] + pow_2[upper_right] + pow_2[lower_right]) - 1
		ans += count
		ans %= MOD
	return ans
print(f_encolsed_points())


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)


def examA():
	N = DI() / dec(7)
	ans = N
	print(N)
	return

def examB():
	ans = 0
	print(ans)
	return

def examC():
	ans = 0
	print(ans)
	return

def examD():
	ans = 0
	print(ans)
	return

def examE():
	ans = 0
	print(ans)
	return

def examF():

	def compress(list1):
		list2 = sorted(set(list1))
		memo = {value: index for (index, value) in enumerate(list2)}
		for i in range(len(list1)):
			list1[i] = memo[list1[i]]
		return (memo, len(list2))

	class Bit:

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

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

		def add(self, i, x=1):
			i += 1
			while i <= self.size:
				self.tree[i] += x
				i += i & -i
			return

		def search(self, x):
			i = 0
			s = 0
			step = 1 << self.size.bit_length() - 1
			while step:
				if i + step <= self.size and s + self.tree[i + step] < x:
					i += step
					s += self.tree[i]
				step >>= 1
			return i

		def debug(self, k):
			return [self.sum(i) for i in range(k)]

		def inversion(self, A=[3, 10, 1, 8, 5]):
			res = 0
			for (i, p) in enumerate(A):
				self.add(p, 1)
				res += i + 1 - self.sum(p)
			return res
	N = I()
	S = [LI() for _ in range(N)]
	X = []
	Y = []
	for (x, y) in S:
		X.append(x)
		Y.append(y)
	(X_memo, _) = compress(X)
	(Y_memo, _) = compress(Y)
	L = [-1] * N
	for i in range(N):
		(x, y) = S[i]
		L[X_memo[x]] = Y_memo[y]
	bit = Bit(N)
	ans = pow(2, N - 1, mod2) * N % mod2
	cnt = 0
	for (i, p) in enumerate(L):
		cur1 = N - p - bit.sum(N - 1) + bit.sum(p) - 1
		cur2 = bit.sum(p)
		rest = N - cur1 - cur2 - 1
		cnt += (pow(2, cur2, mod2) - 1) * (pow(2, cur1, mod2) - 1) * pow(2, rest, mod2)
		cur3 = p - bit.sum(p)
		cur4 = bit.sum(N - 1) - bit.sum(p)
		rest = N - cur3 - cur4 - 1
		cnt += (pow(2, cur3, mod2) - 1) * (pow(2, cur4, mod2) - 1) * pow(2, rest, mod2)
		cnt -= (pow(2, cur2, mod2) - 1) * (pow(2, cur1, mod2) - 1) * (pow(2, cur3, mod2) - 1) * (pow(2, cur4, mod2) - 1)
		bit.add(p, 1)
		cnt %= mod2
	ans += cnt
	ans %= mod2
	print(ans)
	return

def test():
	i = I()
	li = LI()
	lsi = LSI()
	si = LS()
	print(i)
	print(li)
	print(lsi)
	print(si)
	return
from decimal import getcontext, Decimal as dec
import sys, bisect, itertools, heapq, math, random
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def I():
	return int(input())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def DI():
	return dec(input())

def LDI():
	return list(map(dec, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = dec('0.000000000001')
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}
getcontext().prec = 28
sys.setrecursionlimit(10 ** 7)
examF()


import sys

class BIT:

	def __init__(self, n):
		self.n = n
		self.bit = [0] * n

	def add(self, k, x):
		while k < self.n:
			self.bit[k] += x
			k |= k + 1

	def sum(self, k):
		s = 0
		while k >= 0:
			s += self.bit[k]
			k = (k & k + 1) - 1
		return s
input = sys.stdin.readline
MOD = 998244353
N = int(input())
(X, Y) = ([], [])
(xs, ys) = ({}, {})
pow2 = [1]
for i in range(N):
	pow2.append(pow2[-1] * 2 % MOD)
for i in range(N):
	(x, y) = map(int, input().split())
	xs[x] = 0
	ys[y] = 0
	X.append(x)
	Y.append(y)
s = 0
for i in sorted(X):
	xs[i] = s
	s += 1
s = 0
for i in sorted(Y):
	ys[i] = s
	s += 1
for i in range(N):
	X[i] = xs[X[i]]
	Y[i] = ys[Y[i]]
P = [i for i in range(N)]
P = sorted(P, key=lambda k: X[k])
bit1 = BIT(N)
bit2 = BIT(N)
for i in range(N):
	bit2.add(i, 1)
ans = 0
for i in P:
	y = Y[i]
	bit2.add(y, -1)
	A = bit1.sum(y)
	B = bit2.sum(y)
	C = bit1.sum(N - 1) - bit1.sum(y - 1)
	D = bit2.sum(N - 1) - bit2.sum(y - 1)
	ans += pow2[N - 1]
	ans %= MOD
	ans += (pow2[A] - 1) * (pow2[D] - 1) * pow2[B] * pow2[C]
	ans %= MOD
	ans += pow2[A] * pow2[D] * (pow2[B] - 1) * (pow2[C] - 1)
	ans %= MOD
	ans += MOD - (pow2[A] - 1) * (pow2[D] - 1) * (pow2[B] - 1) * (pow2[C] - 1) % MOD
	ans %= MOD
	bit1.add(y, 1)
print(ans)


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

def compress_coordinate(x: list, key=None, reverse=False):
	zipped = {}
	unzipped = {}
	for (i, xi) in enumerate(sorted(set(x), key=None, reverse=reverse)):
		zipped[xi] = i + 1
		unzipped[i + 1] = xi
	return (zipped, unzipped)

class BIT1:

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

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

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

	def bisect_left(self, w):
		if w <= 0:
			return 0
		idx = 0
		k = 1 << self.n.bit_length() - 1
		while k > 0:
			if idx + k <= self.n and self.bit[idx + k] < w:
				w -= self.bit[idx + k]
				idx += k
			k = k >> 1
		return idx + 1
MOD = 998244353
n = int(input())
x_list = []
y_list = []
for i in range(n):
	(x, y) = map(int, input().split())
	x_list.append(x)
	y_list.append(y)
(x_zipped, x_unzipped) = compress_coordinate(x_list)
(y_zipped, y_unzipped) = compress_coordinate(y_list)
p = []
for (i, (x, y)) in enumerate(zip(x_list, y_list)):
	p.append((x_zipped[x], y_zipped[y], i))
info = [[0] * 5 for _ in range(n)]
p.sort(key=itemgetter(0))
bit1 = BIT1(n)
for (m, (px, py, idx)) in enumerate(p):
	bit1.add(py, 1)
	s_left = bit1.sum(py) - 1
	s_right = m + 1 - s_left - 1
	info[idx][2] = s_right
	info[idx][3] = s_left
p.sort(key=itemgetter(0), reverse=True)
bit2 = BIT1(n)
for (m, (px, py, idx)) in enumerate(p):
	bit2.add(py, 1)
	s_left = bit2.sum(py) - 1
	s_right = m + 1 - s_left - 1
	info[idx][1] = s_right
	info[idx][4] = s_left
ans = 0
for (_, c1, c2, c3, c4) in info:
	c1 = pow(2, c1, MOD) - 1
	c2 = pow(2, c2, MOD) - 1
	c3 = pow(2, c3, MOD) - 1
	c4 = pow(2, c4, MOD) - 1
	ans += 1
	ans += c1 + c2 + c3 + c4
	ans += c1 * c3 * 2 + c2 * c4 * 2
	ans += c1 * c2 + c2 * c3 + c3 * c4 + c4 * c1
	ans += (c2 * c3 * c4 + c1 * c3 * c4 + c1 * c2 * c4 + c1 * c2 * c3) * 2
	ans += c1 * c2 * c3 * c4 * 2
	ans %= MOD
print(ans)


import sys

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())
xys = []
ys = []
for line in sys.stdin:
	(x, y) = map(int, line.split())
	xys.append((x, y))
	ys.append(y)
ys.sort()
y_dict = {y: i + 1 for (i, y) in enumerate(ys)}
xys = [(x, y_dict[y]) for (x, y) in xys]
xys.sort()
bit = Bit(n)
p2d = [1]
for i in range(n):
	p2d.append(p2d[-1] * 2 % MOD)
ans = 0
for (i, (x, y)) in enumerate(xys):
	a = bit.sum(y)
	b = i - a
	c = y - a - 1
	d = n - i - 1 - c
	bit.add(y, 1)
	(pa, pb, pc, pd) = (p2d[a], p2d[b], p2d[c], p2d[d])
	tmp = p2d[n - 1]
	tmp += (pa - 1) * (pd - 1) * (pb + pc - 1) % MOD
	tmp += (pb - 1) * (pc - 1) % MOD * pa * pd % MOD
	ans = (ans + tmp) % MOD
print(ans)


import sys

def solve():
	readline = sys.stdin.readline
	write = sys.stdout.write
	MOD = 998244353
	N = int(readline())
	P = [list(map(int, readline().split())) for i in range(N)]
	P.sort()
	Y = [y for (x, y) in P]

	def compress(X):
		(*XS,) = set(X)
		XS.sort()
		return list(map({e: i for (i, e) in enumerate(XS)}.__getitem__, X))
	Y = compress(Y)
	data = [0] * (N + 1)

	def add(k, x):
		while k <= N:
			data[k] += x
			k += k & -k

	def get(k):
		s = 0
		while k:
			s += data[k]
			k -= k & -k
		return s
	pow2 = [1] * (N + 1)
	r = 1
	for i in range(1, N + 1):
		pow2[i] = r = r * 2 % MOD

	def gen(add, get, pow2):
		for (i, y) in enumerate(Y):
			v = get(y + 1)
			add(y + 1, 1)
			p1 = pow2[v]
			p0 = pow2[y - v]
			q1 = pow2[i - v]
			q0 = pow2[N - y - 1 - (i - v)]
			yield ((p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % MOD)
	write('%d\n' % ((sum(gen(add, get, pow2)) + N * pow2[N] - N) % MOD))
solve()


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)


I = [int(_) for _ in open(0).read().split()]
(N, X, Y) = (I[0], I[1::2], I[2::2])
mod = 998244353

def compress_coord(raw):
	v_i = {}
	for (i, v) in enumerate(sorted(set(raw))):
		v_i[v] = i
	return v_i

class BinaryIndexedTree:

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

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

	def add(self, i, x):
		while i <= self.n:
			self.dat[i] += x
			i += i & -i
xi = compress_coord(X)
yj = compress_coord(Y)
X = [xi[x] for x in X]
Y = [yj[y] for y in Y]
LL = [0] * (2 * N)
LR = [0] * (2 * N)
RL = [0] * (2 * N)
RR = [0] * (2 * N)
sortXY = sorted(zip(X, Y))
bit = BinaryIndexedTree(N + 10)
for (x, y) in sortXY:
	LL[x] = bit.sum(y + 1)
	LR[x] = bit.sum(N + 1) - bit.sum(y + 1)
	bit.add(y + 1, 1)
bit = BinaryIndexedTree(N + 10)
for (x, y) in sortXY[::-1]:
	RL[x] = bit.sum(y + 1)
	RR[x] = bit.sum(N + 1) - bit.sum(y + 1)
	bit.add(y + 1, 1)
ans = N * (pow(2, N, mod) - 1) % mod
for (ll, lr, rl, rr) in zip(LL, LR, RL, RR):
	a = pow(2, ll + lr, mod)
	b = pow(2, rl + rr, mod)
	c = pow(2, ll + rl, mod)
	d = pow(2, lr + rr, mod)
	e = pow(2, ll, mod)
	f = pow(2, lr, mod)
	g = pow(2, rl, mod)
	h = pow(2, rr, mod)
	ans -= a + b + c + d
	ans += e + f + g + h
	ans %= mod
print(ans)


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

class BIT:

	def __init__(self, n):
		self.size = n
		self.tree = [0 for _ in range(n + 1)]
		self.p = 2 ** (n.bit_length() - 1)
		self.dep = n.bit_length()

	def get(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

	def bl(self, v):
		if v <= 0:
			return -1
		s = 0
		k = self.p
		for _ in range(self.dep):
			if s + k <= self.size and self.tree[s + k] < v:
				s += k
				v -= self.tree[s + k]
			k //= 2
		return s + 1

def compress(L):
	L2 = list(set(L))
	L2.sort()
	C = {v: k for (k, v) in enumerate(L2, 1)}
	return (L2, C)

def main():
	n = int(input())
	ans = n * pow(2, n - 1, MOD) % MOD
	xy = []
	for _ in range(n):
		xy.append(tuple(map(int, input().split())))
	xy.sort()
	py = [_xy[1] for _xy in xy]
	(_, Cy) = compress(py)
	py = [Cy[p] for p in py]
	BIT1 = BIT(n)
	for i in range(n):
		y = py[i]
		c = BIT1.get(y)
		d = y - c - 1
		a = i - c
		b = n - 1 - a - c - d
		a2 = pow(2, a, MOD)
		b2 = pow(2, b, MOD)
		c2 = pow(2, c, MOD)
		d2 = pow(2, d, MOD)
		ans += (a2 - 1) * b2 * c2 * (d2 - 1)
		ans += a2 * (b2 - 1) * (c2 - 1) * d2
		ans -= (a2 - 1) * (b2 - 1) * (c2 - 1) * (d2 - 1)
		ans %= MOD
		BIT1.add(y, 1)
	print(ans)
main()


import sys
input = sys.stdin.readline
mod = 998244353
n = int(input())
XY = sorted((tuple(map(int, input().split())) for _ in range(n)))
(X, Y) = zip(*XY)
L = {y: i + 1 for (i, y) in enumerate(sorted(Y))}
Y = tuple((L[y] for y in Y))
BIT = [0] * (n + 1)

def add(i):
	while i <= n:
		BIT[i] += 1
		i += i & -i

def acc(i):
	res = 0
	while i:
		res += BIT[i]
		i -= i & -i
	return res
A = [0] * n
B = [0] * n
C = [0] * n
D = [0] * n
for (i, y) in enumerate(Y):
	A[i] = acc(y)
	B[i] = i - A[i]
	add(y)
BIT = [0] * (n + 1)
for i in range(n - 1, -1, -1):
	y = Y[i]
	C[i] = acc(y)
	D[i] = n - 1 - i - C[i]
	add(y)
ans = pow(2, n - 1, mod) * n % mod
for (a, b, c, d) in zip(A, B, C, D):
	a = pow(2, a, mod)
	b = pow(2, b, mod)
	c = pow(2, c, mod)
	d = pow(2, d, mod)
	temp = (a - 1) * b * c * (d - 1) + a * (b - 1) * (c - 1) * d - (a - 1) * (b - 1) * (c - 1) * (d - 1)
	ans += temp
	ans %= mod
print(ans)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 998244353
N = int(input())
XY = [[int(x) for x in input().split()] for _ in range(N)]
XY.sort()
(X, Y) = zip(*XY)
Y_rank = {x: i for (i, x) in enumerate(sorted(Y), 1)}

def BIT_update(tree, x):
	while x <= N:
		tree[x] += 1
		x += x & -x

def BIT_sum(tree, x):
	ret = 0
	while x:
		ret += tree[x]
		x -= x & -x
	return ret
pow2 = [1]
for _ in range(N):
	pow2.append(pow2[-1] * 2 % MOD)
answer = 0
tree = [0] * (N + 1)
for (L, (x, y)) in enumerate(XY):
	y = Y_rank[y]
	R = N - 1 - L
	D = y - 1
	U = N - 1 - D
	LD = BIT_sum(tree, y)
	BIT_update(tree, y)
	LU = L - LD
	RD = D - LD
	RU = R - RD
	cnt = pow2[N]
	cnt -= pow2[L]
	cnt -= pow2[R]
	cnt -= pow2[D]
	cnt -= pow2[U]
	cnt += pow2[LD]
	cnt += pow2[LU]
	cnt += pow2[RD]
	cnt += pow2[RU]
	cnt -= 1
	answer += cnt
answer %= MOD
print(answer)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

class Seg_sum:

	def __init__(self, x):
		self.ide_ele_min = 0
		self.func = lambda a, b: a + b
		self.n = len(x)
		self.num_max = 2 ** (self.n - 1).bit_length()
		self.x = [self.ide_ele_min] * 2 * self.num_max
		for (i, num) in enumerate(x, self.num_max):
			self.x[i] = num
		for i in range(self.num_max - 1, 0, -1):
			self.x[i] = self.func(self.x[i << 1], self.x[(i << 1) + 1])

	def update(self, i, x):
		i += self.num_max
		self.x[i] = x
		while i > 0:
			i = i // 2
			self.x[i] = self.func(self.x[i << 1], self.x[(i << 1) + 1])

	def query(self, i, j):
		res = self.ide_ele_min
		if i >= j:
			return res
		i += self.num_max
		j += self.num_max - 1
		while i <= j:
			if i == j:
				res = self.func(res, self.x[i])
				break
			if i & 1:
				res = self.func(res, self.x[i])
				i += 1
			if not j & 1:
				res = self.func(res, self.x[j])
				j -= 1
			i = i >> 1
			j = j >> 1
		return res
n = int(readline())
xy = [list(map(int, i.split())) for i in readlines()]
mod = 998244353
xy.sort()
ys = [i[1] for i in xy]
ys.sort()
y_rank = {}
for (i, y) in enumerate(ys):
	y_rank[y] = i
point = [[0, 0] for _ in range(n)]
for (i, (x, y)) in enumerate(xy):
	point[i][0] = i
	point[i][1] = y_rank[y]
seg = Seg_sum([0] * (n + 10))
cnt = [[0, 0, 0, 0] for _ in range(n)]
for (x, y) in point:
	cnt[x][2] = seg.query(0, y)
	cnt[x][1] = seg.query(y, n)
	cnt[x][0] = n - y - 1 - cnt[x][1]
	cnt[x][3] = y - cnt[x][2]
	seg.update(y, 1)
ex2 = [1] * n
for i in range(1, n):
	ex2[i] = ex2[i - 1] * 2 % mod
ans = ex2[n - 1] * n % mod
for (n1, n2, n3, n4) in cnt:
	ans += (ex2[n1] - 1) * (ex2[n3] - 1) * ex2[n2 + n4]
	ans %= mod
	ans += (ex2[n2] - 1) * (ex2[n4] - 1) * ex2[n1 + n3]
	ans %= mod
	ans -= (ex2[n1] - 1) * (ex2[n2] - 1) * (ex2[n3] - 1) * (ex2[n4] - 1)
	ans %= mod
print(ans)


def main():
	import sys
	from operator import itemgetter
	input = sys.stdin.readline

	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())
	X_raw = [0] * N
	Y_raw = [0] * N
	for i in range(N):
		(x, y) = map(int, input().split())
		X_raw[i] = x
		Y_raw[i] = y
	val2idx_X = {}
	val2idx_Y = {}
	for i in range(N):
		val2idx_X[X_raw[i]] = i
		val2idx_Y[Y_raw[i]] = i
	X_raw.sort()
	Y_raw.sort()
	X = [0] * N
	Y = [0] * N
	for i in range(N):
		X[val2idx_X[X_raw[i]]] = i + 1
		Y[val2idx_Y[Y_raw[i]]] = i + 1
	XY = [(x, y) for (x, y) in zip(X, Y)]
	XY.sort(key=itemgetter(0))
	bit_ul = Bit(N + 2)
	bit_ur = Bit(N + 2)
	ul = []
	ur = []
	for (x, y) in XY:
		ul.append(bit_ul.sum(y))
		ur.append(bit_ur.sum(N + 1) - bit_ur.sum(y))
		bit_ul.add(y, 1)
		bit_ur.add(y, 1)
	bit_dl = Bit(N + 2)
	bit_dr = Bit(N + 2)
	dl = []
	dr = []
	for (x, y) in reversed(XY):
		dl.append(bit_dl.sum(y))
		dr.append(bit_dr.sum(N + 1) - bit_dr.sum(y))
		bit_dl.add(y, 1)
		bit_dr.add(y, 1)
	dl.reverse()
	dr.reverse()
	ans = 0
	two_N = pow(2, N, mod) - 1
	for i in range(N):
		half = ((pow(2, ul[i] + ur[i], mod) + pow(2, dl[i] + dr[i], mod)) % mod + (pow(2, ul[i] + dl[i], mod) + pow(2, ur[i] + dr[i], mod)) % mod) % mod
		qu = ((pow(2, ul[i], mod) + pow(2, ur[i], mod)) % mod + (pow(2, dl[i], mod) + pow(2, dr[i], mod)) % mod) % mod
		ans = ((ans + two_N) % mod + (-half + qu) % mod) % mod
	print(ans)
main()


import sys, queue, math, copy, itertools, bisect, collections, heapq

def main():
	MOD = 998244353
	LI = lambda : [int(x) for x in sys.stdin.readline().split()]
	NI = lambda : int(sys.stdin.readline())
	N = NI()
	dat = [LI() for _ in range(N)]
	dat.sort()
	yo = [y for (_, y) in dat]
	yo.sort()
	up = [0] * N
	dw = [0] * N
	bit = [0] * (N + 1)

	def bit_add(i):
		while i <= N:
			bit[i] += 1
			i += i & -i

	def bit_sum(i):
		ret = 0
		while i > 0:
			ret += bit[i]
			i -= i & -i
		return ret
	for i in range(N):
		(x, y) = dat[i]
		y = bisect.bisect_left(yo, y) + 1
		up[i] = bit_sum(y)
		bit_add(y)
	bit = [0] * (N + 1)
	for i in range(N - 1, -1, -1):
		(x, y) = dat[i]
		y = bisect.bisect_left(yo, y) + 1
		dw[i] = bit_sum(y)
		bit_add(y)
	ans = N * pow(2, N - 1, MOD)
	for i in range(N):
		a = i - up[i]
		b = up[i]
		c = N - (i + 1) - dw[i]
		d = dw[i]
		p = pow(2, a + d, MOD) - 1 - (pow(2, a, MOD) - 1) - (pow(2, d, MOD) - 1)
		q = pow(2, b + c, MOD) - 1 - (pow(2, b, MOD) - 1) - (pow(2, c, MOD) - 1)
		x = p * (pow(2, b, MOD) + pow(2, c, MOD) - 1)
		y = q * (pow(2, a, MOD) + pow(2, d, MOD) - 1)
		z = p * q
		ans = (ans + x + y + z) % MOD
	print(ans)
main()


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()


MOD = 998244353
import bisect
import sys
input = sys.stdin.readline
N = int(input())
P = [list(map(int, input().split())) for i in [0] * N]

class SegmentTree:

	def __init__(self, data):
		N = len(data)
		self.l = 2 ** (N - 1).bit_length()
		self.data = [0] * self.l + data + [0] * (self.l - N)
		for i in range(self.l - 1, 0, -1):
			self.data[i] = self.data[2 * i] + self.data[2 * i + 1]

	def set(self, i, val):
		i += self.l
		self.data[i] = val
		i = i // 2
		while i > 0:
			self.data[i] = self.data[2 * i] + self.data[2 * i + 1]
			i = i // 2

	def get(self, i, j):
		i += self.l
		j += self.l
		s = 0
		while j - i > 0:
			if i & 1:
				s += self.data[i]
				i += 1
			if j & 1:
				s += self.data[j - 1]
				j -= 1
			i = i // 2
			j = j // 2
		return s
(X, Y) = map(list, zip(*P))
X.sort()
Y.sort()
compY = {y: cy for (cy, y) in enumerate(Y)}
Psorted = sorted(P)
compP = [[n, compY[y]] for (n, (_, y)) in enumerate(Psorted)]
n1s = []
seg = SegmentTree([0] * N)
for (_, y) in compP[::-1]:
	n1s.append(seg.get(y, N))
	seg.set(y, 1)
n1s = n1s[::-1]
pows = [1]
for i in range(1, N):
	pows.append(pows[-1] * 2 % MOD)
ans = (-4 * sum(pows) - N + N * pow(2, N, MOD)) % MOD
for (n, (x, y)) in enumerate(Psorted):
	lower = bisect.bisect_left(Y, y)
	upper = N - 1 - lower
	left = n
	right = N - n - 1
	n1 = n1s[n]
	n2 = upper - n1
	n3 = left - n2
	n4 = right - n1
	ans += pows[n1] + pows[n2] + pows[n3] + pows[n4]
	ans %= MOD
print(ans)


import sys
input = sys.stdin.readline
from collections import *

def compress(l):
	l = list(set(l))
	l.sort()
	idx = defaultdict(int)
	for i in range(len(l)):
		idx[l[i]] = i
	return idx

class BIT:

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

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

	def acc(self, i):
		s = 0
		while i > 0:
			s += self.bit[i]
			i -= i & -i
		return s
N = int(input())
xy = [tuple(map(int, input().split())) for _ in range(N)]
xy.sort(key=lambda t: t[0])
idx = compress([xy_i[1] for xy_i in xy])
lbit = BIT(N)
rbit = BIT(N)
for i in range(N):
	rbit.add(i, 1)
ans = 0
MOD = 998244353
for i in range(N):
	y = xy[i][1]
	rbit.add(idx[y], -1)
	a = i - lbit.acc(idx[y])
	b = lbit.acc(idx[y])
	c = rbit.acc(idx[y])
	d = N - 1 - i - rbit.acc(idx[y])
	add = 2 * pow(2, N - 1, MOD) - 1
	add = (add - (pow(2, a, MOD) - 1)) % MOD
	add = (add - (pow(2, b, MOD) - 1)) % MOD
	add = (add - (pow(2, c, MOD) - 1)) % MOD
	add = (add - (pow(2, d, MOD) - 1)) % MOD
	add = (add - (pow(2, a + b, MOD) - pow(2, a, MOD) - pow(2, b, MOD) + 1)) % MOD
	add = (add - (pow(2, b + c, MOD) - pow(2, b, MOD) - pow(2, c, MOD) + 1)) % MOD
	add = (add - (pow(2, c + d, MOD) - pow(2, c, MOD) - pow(2, d, MOD) + 1)) % MOD
	add = (add - (pow(2, d + a, MOD) - pow(2, d, MOD) - pow(2, a, MOD) + 1)) % MOD
	ans += add
	ans %= MOD
	lbit.add(idx[y], 1)
print(ans)


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()


import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def li():
	return map(int, stdin.readline().split())

def li_():
	return map(lambda x: int(x) - 1, stdin.readline().split())

def lf():
	return map(float, stdin.readline().split())

def ls():
	return stdin.readline().split()

def ns():
	return stdin.readline().rstrip()

def lc():
	return list(ns())

def ni():
	return int(stdin.readline())

def nf():
	return float(stdin.readline())

class CombTools(object):

	def __init__(self, cap: int, mod: int):
		self.cap = cap
		self.mod = mod
		self.inv = self._calc_inv()
		self.fac = self._calc_fac()
		self.fac_inv = self._calc_fac_inv()

	def _calc_inv(self):
		inv = [0, 1]
		for i in range(2, self.cap + 1):
			inv.append((self.mod - self.mod // i * inv[self.mod % i]) % self.mod)
		return inv

	def _calc_fac(self):
		fac = [1]
		for i in range(1, self.cap + 1):
			fac.append(i * fac[-1] % self.mod)
		return fac

	def _calc_fac_inv(self):
		fac_inv = [1]
		for i in range(1, self.cap + 1):
			fac_inv.append(self.inv[i] * fac_inv[-1] % self.mod)
		return fac_inv

	def nCr(self, n: int, r: int):
		if r > n:
			raise ValueError('n must be larger than r (n={}, r={})'.format(n, r))
		return self.fac[n] * self.fac_inv[n - r] * self.fac_inv[r] % self.mod

class BIT(object):

	def __init__(self, n: int):
		self.bitree = [0] * (pow(2, (n - 1).bit_length()) + 1)
		self.size = len(self.bitree) - 1

	def add(self, index, value):
		while index <= self.size:
			self.bitree[index] += value
			index += -index & index

	def get(self, index):
		ans = 0
		while index > 0:
			ans += self.bitree[index]
			index -= -index & index
		return ans
n = ni()
xs = []
ys = []
ps = []
MOD = 998244353
for _ in range(n):
	(xi, yi) = li()
	xs.append(xi)
	ys.append(yi)
	ps.append([xi, yi])
xcomp = {xi: i + 1 for (i, xi) in enumerate(sorted(xs))}
ycomp = {yi: i + 1 for (i, yi) in enumerate(sorted(ys))}
pcomp = [[xcomp[xi], ycomp[yi]] for (xi, yi) in zip(xs, ys)]
pcomp.sort()
ans = 0
ct = CombTools(n, MOD)
for i in range(1, n + 1):
	ans += i * ct.nCr(n, i)
	ans %= MOD
leftBIT = BIT(n)
rightBIT = BIT(n)
for (_, yi) in pcomp:
	rightBIT.add(yi, 1)
pow2 = [pow(2, i, MOD) for i in range(n + 1)]
for (_, yi) in pcomp:
	rightBIT.add(yi, -1)
	nw = leftBIT.get(n) - leftBIT.get(yi)
	ne = rightBIT.get(n) - rightBIT.get(yi)
	sw = leftBIT.get(yi)
	se = rightBIT.get(yi)
	ans += (pow2[nw] - 1) * (pow2[se] - 1) * (pow2[ne] * pow2[sw])
	ans += (pow2[sw] - 1) * (pow2[ne] - 1) * (pow2[se] * pow2[nw])
	ans -= (pow2[nw] - 1) * (pow2[ne] - 1) * (pow2[sw] - 1) * (pow2[se] - 1)
	ans %= MOD
	leftBIT.add(yi, 1)
print(ans)


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()


from bisect import bisect_right, bisect_left

class BITbisect:

	def __init__(self, InputProbNumbers):
		self.ind_to_co = [-10 ** 18]
		self.co_to_ind = {}
		for (ind, num) in enumerate(sorted(list(set(InputProbNumbers)))):
			self.ind_to_co.append(num)
			self.co_to_ind[num] = ind + 1
		self.max = len(self.co_to_ind)
		self.data = [0] * (self.max + 1)

	def __str__(self):
		retList = []
		for i in range(1, self.max + 1):
			x = self.ind_to_co[i]
			if self.count(x):
				c = self.count(x)
				for _ in range(c):
					retList.append(x)
		return '[' + ', '.join([str(a) for a in retList]) + ']'

	def __getitem__(self, key):
		key += 1
		s = 0
		ind = 0
		l = self.max.bit_length()
		for i in reversed(range(l)):
			if ind + (1 << i) <= self.max:
				if s + self.data[ind + (1 << i)] < key:
					s += self.data[ind + (1 << i)]
					ind += 1 << i
		if ind == self.max or key < 0:
			raise IndexError('BIT index out of range')
		return self.ind_to_co[ind + 1]

	def __len__(self):
		return self._query_sum(self.max)

	def __contains__(self, num):
		if not num in self.co_to_ind:
			return False
		return self.count(num) > 0

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

	def _add(self, i, x):
		while i <= self.max:
			self.data[i] += x
			i += i & -i

	def push(self, x):
		if not x in self.co_to_ind:
			raise KeyError('The pushing number didnt initialized')
		self._add(self.co_to_ind[x], 1)

	def delete(self, x):
		if not x in self.co_to_ind:
			raise KeyError('The deleting number didnt initialized')
		if self.count(x) <= 0:
			raise ValueError('The deleting number doesnt exist')
		self._add(self.co_to_ind[x], -1)

	def count(self, x):
		return self._query_sum(self.co_to_ind[x]) - self._query_sum(self.co_to_ind[x] - 1)

	def bisect_right(self, x):
		if x in self.co_to_ind:
			i = self.co_to_ind[x]
		else:
			i = bisect_right(self.ind_to_co, x) - 1
		return self._query_sum(i)

	def bisect_left(self, x):
		if x in self.co_to_ind:
			i = self.co_to_ind[x]
		else:
			i = bisect_left(self.ind_to_co, x)
		if i == 1:
			return 0
		return self._query_sum(i - 1)
mod = 998244353
import sys
input = sys.stdin.readline
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
Ys = []
for (x, y) in XY:
	Ys.append(y)
XY.sort()
D = [[0, 0, 0, 0] for _ in range(N)]
B1 = BITbisect(Ys)
for (i, (x, y)) in enumerate(XY):
	k = B1.bisect_left(y)
	D[i][0] = k
	D[i][1] = i - k
	B1.push(y)
B2 = BITbisect(Ys)
for i in reversed(range(N)):
	(x, y) = XY[i]
	k = B2.bisect_left(y)
	D[i][2] = k
	D[i][3] = N - 1 - i - k
	B2.push(y)
N2 = [1]
for _ in range(N):
	N2.append(N2[-1] * 2 % mod)
ans = 0
for i in range(N):
	(a, b, c, d) = D[i]
	p = N2[N] - 1 - (N2[a + b] + N2[b + d] + N2[d + c] + N2[c + a]) % mod + (N2[a] + N2[b] + N2[c] + N2[d]) % mod
	ans = (ans + p) % mod
print(ans)


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)


class BIT:
	ini = 0

	def __init__(self, num):
		self.N = 1
		while self.N <= num:
			self.N *= 2
		self.T = [self.ini] * self.N

	def do(self, l, r):
		return l + r

	def set(self, L):
		for i in range(len(L)):
			self.update(i, L[i])

	def update(self, x):
		k = x + 1
		self.T[k - 1] += 1
		k += k & -k
		while k <= N:
			self.T[k - 1] += 1
			k += k & -k

	def getV(self, x):
		ans = self.T[x - 1]
		x -= x & -x
		while x != 0:
			ans += self.T[x - 1]
			x -= x & -x
		return ans
import sys
input = sys.stdin.readline
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
MOD = 998244353
xy.sort(key=lambda x: x[1])
R = {}
for i in range(N):
	R[xy[i][1]] = i
xy.sort()
LU = [0] * N
LD = [0] * N
RU = [0] * N
RD = [0] * N
Sl = BIT(N)
for i in range(N):
	t = Sl.getV(R[xy[i][1]])
	LU[i] = i - t
	LD[i] = t
	Sl.update(R[xy[i][1]])
Sr = BIT(N)
for i in range(N - 1, -1, -1):
	t = Sr.getV(R[xy[i][1]])
	RU[i] = N - 1 - i - t
	RD[i] = t
	Sr.update(R[xy[i][1]])
ans = 0
PL = [1]
for i in range(N + 1):
	PL.append(PL[-1] * 2 % MOD)

def na(x):
	return PL[x] - 1
for i in range(N):
	t = PL[N - 1]
	t = (t + na(LU[i]) * na(RD[i])) % MOD
	t = (t + na(LD[i]) * na(RU[i])) % MOD
	t = (t + na(LU[i]) * na(LD[i]) * na(RU[i])) % MOD
	t = (t + na(LU[i]) * na(LD[i]) * na(RD[i])) % MOD
	t = (t + na(LU[i]) * na(RD[i]) * na(RU[i])) % MOD
	t = (t + na(LD[i]) * na(RD[i]) * na(RU[i])) % MOD
	t = (t + na(LU[i]) * na(LD[i]) * na(RD[i]) * na(RU[i])) % MOD
	ans = (ans + t) % MOD
print(ans)


import sys
S = sys.stdin.readlines()

def Binit(B, siz):
	while len(B) < siz + 1:
		B.append(0)
	while len(B) > siz + 1:
		del B[-1]
	for i in range(siz + 1):
		B[i] = 0
	B.append(siz)

def Badd(B, a, x):
	z = a
	while z <= B[-1]:
		B[z] += x
		z += z & -z

def Bsum(B, a):
	r = 0
	z = a
	while z > 0:
		r += B[z]
		z -= z & -z
	return r

def Bssum(B, a, b):
	return Bsum(B, max(a, b)) - Bsum(B, min(a, b) - 1)
N = int(S[0])
X = [list(map(int, S[i + 1].split())) for i in range(N)]
X.sort()
for i in range(N):
	X[i][0] = i
D = dict()
Y = sorted([X[i][1] for i in range(N)])
for i in range(N):
	D[Y[i]] = i
for i in range(N):
	X[i][1] = D[X[i][1]]
(B1, B2) = ([], [])
Binit(B1, N + 1)
Binit(B2, N + 1)
for i in range(N):
	Badd(B2, i + 1, 1)
mod = 998244353
P = N * pow(2, N - 1, mod) % mod
Z = [[1, 1, 1, 1], [1, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [1, 0, 0, 1], [0, 1, 1, 1], [0, 1, 1, 0]]
A = 0
for i in range(N):
	Badd(B2, X[i][1] + 1, -1)
	V = [Bsum(B1, X[i][1] + 1), Bsum(B2, X[i][1] + 1)]
	W = [pow(2, V[0], mod) - 1, pow(2, i - V[0], mod) - 1, pow(2, V[1], mod) - 1, pow(2, N - i - 1 - V[1], mod) - 1]
	for j in range(7):
		A = 1
		if Z[j][0]:
			A = A * W[0] % mod
		if Z[j][1]:
			A = A * W[1] % mod
		if Z[j][2]:
			A = A * W[2] % mod
		if Z[j][3]:
			A = A * W[3] % mod
		P = (P + A) % mod
	Badd(B1, X[i][1] + 1, 1)
print(P)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

class BitSum:

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

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

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

def main():
	md = 998244353
	n = II()
	xy = LLI(n)
	yy = set()
	for (x, y) in xy:
		yy.add(y)
	ytoj = {y: j for (j, y) in enumerate(sorted(yy))}
	ans = n * (pow(2, n, md) - 1) - 4 * (pow(2, n, md) - 1 - n)
	ans %= md
	xy.sort()
	bit = BitSum(200005)
	for (i, [x, y]) in enumerate(xy):
		j = ytoj[y]
		c = bit.sum(j - 1)
		ans += pow(2, c, md) - 1
		ans += pow(2, i - c, md) - 1
		ans %= md
		bit.add(j, 1)
	bit = BitSum(200005)
	for (i, [x, y]) in enumerate(xy[::-1]):
		j = ytoj[y]
		c = bit.sum(j - 1)
		ans += pow(2, c, md) - 1
		ans += pow(2, i - c, md) - 1
		ans %= md
		bit.add(j, 1)
	print(ans)
main()


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

class BIT:

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

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

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

	def get_sum(self, l, r):
		return self._sum(r) - self._sum(l)
n = int(input())
info = [tuple([i] + list(map(int, input().split()))) for i in range(n)]
MOD = 998244353
ans = [[0] * n for i in range(4)]
info = sorted(info, key=itemgetter(1))
to_ind = {x[2]: ind for (ind, x) in enumerate(sorted(info, key=itemgetter(2)))}
bit = BIT(n)
for j in range(n):
	(i, x, y) = info[j]
	tmp = bit.get_sum(0, to_ind[y])
	ans[2][i] = tmp
	ans[3][i] = j - tmp
	bit.add(to_ind[y], 1)
bit = BIT(n)
for j in range(n)[::-1]:
	(i, x, y) = info[j]
	tmp = bit.get_sum(0, to_ind[y])
	ans[1][i] = tmp
	ans[0][i] = n - j - 1 - tmp
	bit.add(to_ind[y], 1)
res = 0
pow2 = [1] * (n + 10)
for i in range(n):
	pow2[i + 1] = pow2[i] * 2
	pow2[i + 1] %= MOD
ans = list(zip(*ans))
for (a1, a2, b1, b2) in ans:
	res += (pow2[a1] - 1) * (pow2[b1] - 1) * pow2[a2 + b2]
	res %= MOD
	res += (pow2[a2] - 1) * (pow2[b2] - 1) * pow2[a1 + b1]
	res %= MOD
	res += pow2[n - 1]
	res -= (pow2[a1] - 1) * (pow2[a2] - 1) * (pow2[b1] - 1) * (pow2[b2] - 1)
	res %= MOD
print(res % MOD)


import sys
import array
from operator import itemgetter

def main():
	input = sys.stdin.readline
	md = 998244353
	n = int(input())
	tl = n + 1
	ft = [0] * tl
	xy = [[0] * 2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for (x, y) in xy]
	(*YS,) = set(yxi)
	YS.sort()
	yxi = list(map({e: i for (i, e) in enumerate(YS)}.__getitem__, yxi))
	ct = [0] * (n + 1)
	ct[0] = 1
	for i in range(1, n + 1):
		ct[i] = ct[i - 1] * 2 % md
	cnt = tuple(ct)

	def upd(i):
		i += 1
		while i <= n:
			ft[i] += 1
			i += i & -i

	def get(i):
		i += 1
		ret = 0
		while i != 0:
			ret += ft[i]
			i -= i & -i
		return ret

	def calc(get, upd):
		for (i, y) in enumerate(yxi):
			v = get(y)
			upd(y)
			p1 = cnt[v]
			p0 = cnt[y - v]
			q1 = cnt[i - v]
			q0 = cnt[n - y - 1 - (i - v)]
			yield ((p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md)
	print((sum(calc(get, upd)) + n * cnt[n] - n) % md)
main()


import sys
readline = sys.stdin.readline

class BIT:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)
		self.p = 2 ** (n.bit_length() - 1)
		self.dep = n.bit_length()

	def get(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

	def bl(self, v):
		if v <= 0:
			return -1
		s = 0
		k = self.p
		for _ in range(self.dep):
			if s + k <= self.size and self.tree[s + k] < v:
				s += k
				v -= self.tree[s + k]
			k //= 2
		return s + 1

def compress(L):
	L2 = list(set(L))
	L2.sort()
	C = {v: k for (k, v) in enumerate(L2)}
	return (L2, C)
MOD = 998244353
N = int(readline())
XY = [list(map(int, readline().split())) for _ in range(N)]
XY.sort()
Z = [-10 ** 10]
for (x, y) in XY:
	Z.append(y)
(_, CC) = compress(Z)
XY = [(x, CC[y]) for (x, y) in XY]
(SS, SB, BS, BB) = ([None] * N, [None] * N, [None] * N, [None] * N)
T = BIT(N)
for i in range(N):
	k = i
	y = XY[i][1]
	l = T.get(y)
	SS[i] = l
	SB[i] = k - l
	T.add(y, 1)
T = BIT(N)
for i in range(N - 1, -1, -1):
	k = N - 1 - i
	y = XY[i][1]
	l = T.get(y)
	BS[i] = l
	BB[i] = k - l
	T.add(y, 1)
P2 = [1] * 1341398
for i in range(1, len(P2)):
	P2[i] = P2[i - 1] * 2 % MOD
ans = 0
for i in range(N):
	ss = SS[i]
	sb = SB[i]
	bs = BS[i]
	bb = BB[i]
	ans = (ans + P2[N - 1]) % MOD
	ans = (ans + P2[N - 1 - ss - bb] * (P2[ss] - 1) * (P2[bb] - 1)) % MOD
	ans = (ans + P2[N - 1 - sb - bs] * (P2[sb] - 1) * (P2[bs] - 1)) % MOD
	ans = (ans - (P2[sb] - 1) * (P2[bs] - 1) * (P2[ss] - 1) * (P2[bb] - 1)) % MOD
print(ans)


from bisect import bisect_left
import sys
input = sys.stdin.readline
N = int(input())
xy = [[int(i) for i in input().split()] for _ in range(N)]
xy.sort()
ylist = [y for (_, y) in xy]
ylist.sort()
for i in range(N):
	xy[i] = [i, bisect_left(ylist, xy[i][1])]
MOD = 998244353

def bit_sum(i):
	s = 0
	while i > 0:
		s += bit[i]
		i -= i & -i
	return s

def bit_add(i, x):
	while i <= N:
		bit[i] += x
		i += i & -i
lu = [0] * N
ld = [0] * N
ru = [0] * N
rd = [0] * N
power = [1]
for _ in range(N):
	power.append(power[-1] * 2 % MOD)
bit = [0] * (N + 1)
for (i, (x, y)) in enumerate(xy):
	ld[i] = bit_sum(y + 1)
	lu[i] = i - ld[i]
	bit_add(y + 1, 1)
bit = [0] * (N + 1)
for (i, (x, y)) in enumerate(xy[::-1]):
	rd[N - i - 1] = bit_sum(y + 1)
	ru[N - i - 1] = i - rd[N - i - 1]
	bit_add(y + 1, 1)
ret = 0
for i in range(N):
	ret += (power[lu[i]] - 1) * power[ld[i]] * power[ru[i]] * (power[rd[i]] - 1)
	ret += power[lu[i]] * (power[ld[i]] - 1) * (power[ru[i]] - 1) * power[rd[i]]
	ret -= (power[lu[i]] - 1) * (power[ld[i]] - 1) * (power[ru[i]] - 1) * (power[rd[i]] - 1)
	ret += power[lu[i]] * power[ld[i]] * power[ru[i]] * power[rd[i]]
	ret %= MOD
print(ret)


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()


N = int(input())
XY = [[int(x) for x in input().split()] for i in range(N)]
mod = 998244353
XY.sort()
(X, Y) = zip(*XY)
Y_rank = {x: i for (i, x) in enumerate(sorted(Y), 1)}
BIT = [0] * (N + 1)

def append_BIT(x):
	while x <= N:
		BIT[x] += 1
		x += x & -x

def sum_BIT(x):
	ret = 0
	while x:
		ret += BIT[x]
		x &= x - 1
	return ret
pow2 = [1]
for i in range(N):
	pow2.append(pow2[-1] * 2 % mod)
ret = 0
for i in range(N):
	y = Y_rank[Y[i]]
	L = i
	R = N - i - 1
	D = y - 1
	U = N - D - 1
	LD = sum_BIT(y)
	append_BIT(y)
	LU = L - LD
	RU = U - LU
	RD = D - LD
	ret += pow2[N] - 1 - pow2[L] - pow2[R] - pow2[U] - pow2[D] + pow2[LD] + pow2[LU] + pow2[RU] + pow2[RD]
ret %= mod
print(ret)


import sys
input = sys.stdin.readline
n = int(input())
XY = sorted((list(map(int, input().split())) for _ in range(n)))
(X, Y) = zip(*XY)
Y_rank = {z: i for (i, z) in enumerate(sorted(Y), 1)}
mod = 998244353

class BIT:

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

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

	def add(self, i, j):
		while i <= self.n:
			self.data[i] += j
			i += i & -i
po2 = [1]
for i in range(200200):
	po2.append(po2[-1] * 2 % mod)
b = BIT(n)
res = 0
for (L, (x, y)) in enumerate(XY):
	y = Y_rank[y]
	A = b.sum(y)
	B = L - A
	D = y - 1 - A
	C = n - 1 - A - B - D
	res += po2[n] - (po2[A + B] + po2[B + C] + po2[C + D] + po2[D + A]) + (po2[A] + po2[B] + po2[C] + po2[D]) - 1
	res %= mod
	b.add(y, 1)
print(res)


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
mod = 998244353
from collections import defaultdict
DX = defaultdict(int)
DY = defaultdict(int)
(XY, X, Y) = ([], [], [])
for _ in range(n):
	(x, y) = map(int, input().split())
	X.append(x)
	Y.append(y)
	XY.append((x, y))
X.sort()
Y.sort()
XY.sort(key=lambda x: x[0])
for (i, x) in enumerate(X):
	DX[x] = i + 1
for (i, y) in enumerate(Y):
	DY[y] = i + 1
XY2 = []
for (x, y) in XY:
	XY2.append((DX[x], DY[y]))
A = [[0] * 4 for _ in range(n)]
n_max = 2 * 10 ** 5
nn = n_max.bit_length() + 1
BIT = [0] * 2 ** nn
BIT.insert(0, 0)

def bitsum(BIT, i):
	s = 0
	while i > 0:
		s += BIT[i]
		i -= i & -i
	return s

def bitadd(BIT, i, x):
	while i <= 2 ** nn:
		BIT[i] += x
		i += i & -i
	return BIT
for i in range(n):
	(x, y) = XY2[i]
	ct = bitsum(BIT, y)
	A[i][2] += ct
	A[i][1] += i - ct
	bitadd(BIT, y, 1)
BIT = [0] * 2 ** nn
BIT.insert(0, 0)
for i in range(n)[::-1]:
	(x, y) = XY2[i]
	ct = bitsum(BIT, y)
	A[i][3] += ct
	A[i][0] += n - 1 - i - ct
	bitadd(BIT, y, 1)
P = [0] * n
P[0] = 1
for i in range(1, n):
	P[i] = P[i - 1] * 2 % mod

def f(x):
	return P[x]
ans = 0
for (a, b, c, d) in A:
	ans += 2 * f(a + b + c + d) - f(a + b) - f(b + c) - f(c + d) - f(d + a) + f(a) + f(b) + f(c) + f(d) - 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
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)


mod = 998244353

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, *XY) = map(int, open(0).read().split())
(X, Y) = (XY[::2], XY[1::2])
memo = {y: i for (i, y) in enumerate(sorted(Y))}
Y = [y for (x, y) in sorted(zip(X, map(memo.get, Y)), key=lambda p: p[0])]
P = [1]
for i in range(N):
	P.append(P[-1] * 2 % mod)
ans = P[N - 1] * N % mod
bit = BIT(N)
for (i, y) in enumerate(Y):
	bit.add(y + 1, 1)
	ld = bit.sum(y)
	lu = i - ld
	rd = y - ld
	ru = N - y - 1 - lu
	(A, B, C, D) = (P[ru], P[lu], P[ld], P[rd])
	ans += (C - 1) * (A - 1) % mod * (B * D % mod) % mod
	ans += (B - 1) * (D - 1) % mod * (C * A % mod) % mod
	ans -= (C - 1) * (A - 1) % mod * ((D - 1) * (B - 1) % mod) % mod
	ans %= mod
print(ans)


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 sys

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
input = sys.stdin.readline
from collections import defaultdict
mod = 998244353
n = int(input())
p2t = [1]
for i in range(n):
	p2t.append(p2t[-1] * 2 % mod)
dcy = defaultdict(int)
xy = [list(map(int, input().split())) for i in range(n)]
xy.sort()
yls = list(zip(*xy))[1]
yls = list(yls)
for i in range(n):
	dcy[yls[i]] = i
yls.sort()
yind = [0 for i in range(n)]
for i in range(n):
	ind = dcy[yls[i]]
	yind[ind] = i
xyd = []
for i in range(n):
	xyd.append((i, yind[i]))
ans = 0
bit = Bit(n + 1)
for i in range(n):
	(x, y) = xyd[i]
	upper = n - y - 1
	right = n - x - 1
	ld = bit.sum(y + 1)
	ru = upper + right + ld - n + 1
	rd = right - ru
	lu = upper - ru
	p2lu = p2t[lu]
	p2rd = p2t[rd]
	p2ru = p2t[ru]
	p2ld = p2t[ld]
	ans += (p2lu - 1) * (p2rd - 1) * p2t[ld + ru] % mod + (p2ld - 1) * (p2ru - 1) * p2t[lu + rd] % mod + p2t[n - 1] - (p2lu - 1) * (p2rd - 1) * (p2ld - 1) * (p2ru - 1) % mod
	ans %= mod
	bit.add(y + 1, 1)
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)


import bisect
from collections import defaultdict

class SegTree:

	def __init__(self, N, function, basement):
		self.n = N
		self.K = (self.n - 1).bit_length()
		self.f = function
		self.b = basement
		self.seg = [basement] * (2 ** (self.K + 1) + 1)
		X = 2 ** self.K

	def update(self, k, value):
		X = 2 ** self.K
		k += X
		self.seg[k] += value
		while k:
			k = k >> 1
			self.seg[k] = self.f(self.seg[k << 1], self.seg[k << 1 | 1])

	def query(self, L, R):
		num = 2 ** self.K
		L += num
		R += num
		vL = self.b
		vR = self.b
		while L < R:
			if L & 1:
				vL = self.f(vL, self.seg[L])
				L += 1
			if R & 1:
				R -= 1
				vR = self.f(self.seg[R], vR)
			L >>= 1
			R >>= 1
		return self.f(vL, vR)

def aggfunc(x, y):
	return x + y

def Press(lists):
	lists.sort()
	d = defaultdict(int)
	now = -float('inf')
	index = 0
	for i in range(len(lists)):
		if lists[i] > now:
			index += 1
			d[lists[i]] = index
			now = lists[i]
		elif lists[i] == now:
			d[lists[i]] = index
	return d
mod = 998244353
N = int(input())
Point = []
for i in range(N):
	(x, y) = map(int, input().split())
	Point.append((x, y, i))

def modifie():
	Point.sort(key=lambda x: (x[1], x[0]))
	X = []
	for (x, y, i) in Point:
		X.append(x)
	modified_point_x = Press(X)
	return modified_point_x
modified_point_x = modifie()
segtree = SegTree(N + 1, aggfunc, 0)
below_below = defaultdict(int)
for i in range(N):
	(x, y, index) = Point[i]
	segtree.update(modified_point_x[x], 1)
	below_below[Point[i]] = segtree.query(0, modified_point_x[x] + 1)
(X, Y) = ([], [])
for (x, y, index) in Point:
	X.append(x)
	Y.append(y)
X.sort()
Y.sort()
ans = 0
powers = [1 for i in range(3 * 10 ** 5)]
for i in range(1, 3 * 10 ** 5):
	powers[i] = powers[i - 1] * 2 % mod

def pows(K):
	return powers[K]
for i in range(N):
	(x, y, index) = Point[i]
	ZZ = below_below[Point[i]] - 1
	XX = bisect.bisect_right(X, x) - ZZ - 1
	WW = bisect.bisect_right(Y, y) - ZZ - 1
	YY = N - 1 - XX - ZZ - WW
	ss = pow(2, N, mod) - 1 - pows(XX) - pows(YY) - pows(ZZ) - pows(WW) + 4 - (pows(XX) - 1) * (pows(YY) - 1) - (pows(YY) - 1) * (pows(WW) - 1) - (pows(ZZ) - 1) * (pows(WW) - 1) - (pows(ZZ) - 1) * (pows(XX) - 1)
	ans += ss
print(ans % mod)


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
mod = 998244353

def main():
	n = int(input())
	XY = []
	X = set()
	Y = set()
	for i in range(n):
		(x, y) = map(int, input().split())
		XY.append((x, y))
		X.add(x)
		Y.add(y)
	X = list(X)
	Y = list(Y)
	X.sort()
	Y.sort()
	dx = {}
	for (i, x) in enumerate(X):
		dx[x] = i
	dy = {}
	for (i, y) in enumerate(Y):
		dy[y] = i
	XY.sort()
	XY = [(dx[x], dy[y]) for (x, y) in XY]

	class BIT:

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

		def init(self, init_val):
			for (i, v) in enumerate(init_val):
				self.add(i, v)

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

		def sum(self, i, j):
			return self._sum(j) - self._sum(i)

		def _sum(self, i):
			res = 0
			while i > 0:
				res += self.bit[i]
				i -= i & -i
			return res

		def lower_bound(self, x):
			s = 0
			pos = 0
			depth = self.n.bit_length()
			v = 1 << depth
			for i in range(depth, -1, -1):
				k = pos + v
				if k <= self.n and s + self.bit[k] < x:
					s += self.bit[k]
					pos += v
				v >>= 1
			return pos
	UL = [0] * n
	UR = [0] * n
	LL = [0] * n
	LR = [0] * n
	bit = BIT(2 * 10 ** 5 + 5)
	for i in range(n):
		(x, y) = XY[i]
		LL[i] = bit.sum(0, y + 1)
		UL[i] = i - LL[i]
		bit.add(y, 1)
	bit = BIT(2 * 10 ** 5 + 5)
	for i in reversed(range(n)):
		(x, y) = XY[i]
		LR[i] = bit.sum(0, y + 1)
		UR[i] = n - 1 - i - LR[i]
		bit.add(y, 1)
	ans = 0
	for i in range(n):
		ans += (pow(2, UL[i], mod) - 1) * (pow(2, LR[i], mod) - 1) * pow(2, UR[i], mod) * pow(2, LL[i], mod)
		ans += pow(2, UL[i], mod) * pow(2, LR[i], mod) * (pow(2, UR[i], mod) - 1) * (pow(2, LL[i], mod) - 1)
		ans -= (pow(2, UL[i], mod) - 1) * (pow(2, LR[i], mod) - 1) * (pow(2, UR[i], mod) - 1) * (pow(2, LL[i], mod) - 1)
		ans += pow(2, UL[i], mod) * pow(2, LR[i], mod) * pow(2, UR[i], mod) * pow(2, LL[i], mod)
		ans %= mod
	print(ans)
main()