Buggy python submission (verdict: Time Limit Exceeded):
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

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)


Fixed submission:
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

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)

Buggy python submission (verdict: Time Limit Exceeded):
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

LARGE = 998244353

res = 0
for i in range(N):
    r = pow(2, N, LARGE) - 1
    r -= pow(2, left_lower[i] + left_upper[i], LARGE) - 1
    r -= pow(2, right_lower[i] + right_upper[i], LARGE) - 1
    r -= pow(2, left_lower[i] + right_lower[i], LARGE) - 1
    r -= pow(2, left_upper[i] + right_upper[i], LARGE) - 1
    r += pow(2, left_lower[i], LARGE) - 1
    r += pow(2, left_upper[i], LARGE) - 1
    r += pow(2, right_lower[i], LARGE) - 1
    r += pow(2, right_upper[i], LARGE) - 1
    res += r

print(res % LARGE)


Fixed submission:
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

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)

Buggy python submission (verdict: Time Limit Exceeded):
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

LARGE = 998244353

res = 0
for i in range(N):
    r = pow(2, N, LARGE) - 1
    r -= pow(2, left_lower[i] + left_upper[i], LARGE) - 1
    r -= pow(2, right_lower[i] + right_upper[i], LARGE) - 1
    r -= pow(2, left_lower[i] + right_lower[i], LARGE) - 1
    r -= pow(2, left_upper[i] + right_upper[i], LARGE) - 1
    r += pow(2, left_lower[i], LARGE) - 1
    r += pow(2, left_upper[i], LARGE) - 1
    r += pow(2, right_lower[i], LARGE) - 1
    r += pow(2, right_upper[i], LARGE) - 1
    res += r

print(res % LARGE)


Fixed submission:
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

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)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
# TLE


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())
hx = []
hy = []

for i in range(N):
    x, y = map(int, input().split())
    heappush(hx, (x, y))

y_list = [0] * N
for i in range(N):
    x, y = heappop(hx)
    y_list[i] = y
    heappush(hy, (y, i))

y_nor_list = [0] * N
for j in range(N):
    y, i = heappop(hy)
    y_nor_list[i] = j

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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

LARGE = 998244353

res = 0
for i in range(N):
    r = pow(2, N, LARGE) - 1
    r -= pow(2, left_lower[i] + left_upper[i], LARGE) - 1
    r -= pow(2, right_lower[i] + right_upper[i], LARGE) - 1
    r -= pow(2, left_lower[i] + right_lower[i], LARGE) - 1
    r -= pow(2, left_upper[i] + right_upper[i], LARGE) - 1
    r += pow(2, left_lower[i], LARGE) - 1
    r += pow(2, left_upper[i], LARGE) - 1
    r += pow(2, right_lower[i], LARGE) - 1
    r += pow(2, right_upper[i], LARGE) - 1
    res += r

print(res % LARGE)


Fixed submission:
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

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)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
# TLE


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())
hx = []
hy = []

for i in range(N):
    x, y = map(int, input().split())
    heappush(hx, (x, y))

y_list = [0] * N
for i in range(N):
    x, y = heappop(hx)
    y_list[i] = y
    heappush(hy, (y, i))

y_nor_list = [0] * N
for j in range(N):
    y, i = heappop(hy)
    y_nor_list[i] = j

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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

LARGE = 998244353

res = 0
for i in range(N):
    r = pow(2, N, LARGE) - 1
    r -= pow(2, left_lower[i] + left_upper[i], LARGE) - 1
    r -= pow(2, right_lower[i] + right_upper[i], LARGE) - 1
    r -= pow(2, left_lower[i] + right_lower[i], LARGE) - 1
    r -= pow(2, left_upper[i] + right_upper[i], LARGE) - 1
    r += pow(2, left_lower[i], LARGE) - 1
    r += pow(2, left_upper[i], LARGE) - 1
    r += pow(2, right_lower[i], LARGE) - 1
    r += pow(2, right_upper[i], LARGE) - 1
    res += r

print(res % LARGE)


Fixed submission:
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

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)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
# TLE


class SegmentTree(object):

    def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7):

        self.seg_func = seg_func
        self.seg_func_null = seg_func_null
        self.n = 1
        while self.n < len(init_array):
            self.n *= 2
        self.dat = [0] * (2 * self.n - 1)
        for i in range(len(init_array)):
            self.dat[self.n - 1 + i] = init_array[i]
        for i in range(self.n - 2, -1, -1):
            self.dat[i] = self.seg_func(self.dat[2 * i + 1], self.dat[2 * i + 2])

    def update(self, k, a):
        k += self.n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = self.seg_func(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    def query(self, p, q):
        # [p, q)
        if q <= p:
            return self.seg_func_null

        p += self.n - 1
        q += self.n - 2
        res = self.seg_func_null

        while q - p > 1:
            if p & 1 == 0:
                res = self.seg_func(res, self.dat[p])
            if q & 1 == 1:
                res = self.seg_func(res, self.dat[q])
                q -= 1
            p = p // 2
            q = (q-1) // 2
        if p == q:
            res = self.seg_func(res, self.dat[p])
        else:
            res = self.seg_func(self.seg_func(res, self.dat[p]), self.dat[q])

        return res


N = int(input())
hx = []
hy = []

for i in range(N):
    x, y = map(int, input().split())
    heappush(hx, (x, y))

y_list = [0] * N
for i in range(N):
    x, y = heappop(hx)
    y_list[i] = y
    heappush(hy, (y, i))

y_nor_list = [0] * N
for j in range(N):
    y, i = heappop(hy)
    y_nor_list[i] = j


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


sg_left = SegmentTree(init_array=[0]*N, seg_func=add, seg_func_null=0)
sg_right = SegmentTree(init_array=[0]*N, seg_func=add, seg_func_null=0)

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]
    left_lower[i] = sg_left.query(0, c)
    left_upper[i] = i - left_lower[i]
    sg_left.update(c, 1)

for i in range(N-1, -1, -1):
    c = y_nor_list[i]
    right_lower[i] = sg_right.query(0, c)
    right_upper[i] = N - 1 - i - right_lower[i]
    sg_right.update(c, 1)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

LARGE = 998244353

res = 0
for i in range(N):
    r = pow(2, N, LARGE) - 1
    r -= pow(2, left_lower[i] + left_upper[i], LARGE) - 1
    r -= pow(2, right_lower[i] + right_upper[i], LARGE) - 1
    r -= pow(2, left_lower[i] + right_lower[i], LARGE) - 1
    r -= pow(2, left_upper[i] + right_upper[i], LARGE) - 1
    r += pow(2, left_lower[i], LARGE) - 1
    r += pow(2, left_upper[i], LARGE) - 1
    r += pow(2, right_lower[i], LARGE) - 1
    r += pow(2, right_upper[i], LARGE) - 1
    res += r

print(res % LARGE)


Fixed submission:
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

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)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop


class SegmentTree(object):

    def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7):

        self.seg_func = seg_func
        self.seg_func_null = seg_func_null
        self.n = 1
        while self.n < len(init_array):
            self.n *= 2
        self.dat = [0] * (2 * self.n - 1)
        for i in range(len(init_array)):
            self.dat[self.n - 1 + i] = init_array[i]
        for i in range(self.n - 2, -1, -1):
            self.dat[i] = self.seg_func(self.dat[2 * i + 1], self.dat[2 * i + 2])

    def update(self, k, a):
        k += self.n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = self.seg_func(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    def query(self, p, q):
        # [p, q)
        if q <= p:
            return self.seg_func_null

        p += self.n - 1
        q += self.n - 2
        res = self.seg_func_null

        while q - p > 1:
            if p & 1 == 0:
                res = self.seg_func(res, self.dat[p])
            if q & 1 == 1:
                res = self.seg_func(res, self.dat[q])
                q -= 1
            p = p // 2
            q = (q-1) // 2
        if p == q:
            res = self.seg_func(res, self.dat[p])
        else:
            res = self.seg_func(self.seg_func(res, self.dat[p]), self.dat[q])

        return res


N = int(input())
hx = []
hy = []

for i in range(N):
    x, y = map(int, input().split())
    heappush(hx, (x, y))

y_list = [0] * N
for i in range(N):
    x, y = heappop(hx)
    y_list[i] = y
    heappush(hy, (y, i))

y_nor_list = [0] * N
for j in range(N):
    y, i = heappop(hy)
    y_nor_list[i] = j


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


sg_left = SegmentTree(init_array=[0]*N, seg_func=add, seg_func_null=0)
sg_right = SegmentTree(init_array=[0]*N, seg_func=add, seg_func_null=0)

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]
    left_lower[i] = sg_left.query(0, c)
    left_upper[i] = sg_left.query(c, N)
    sg_left.update(c, 1)

for i in range(N-1, -1, -1):
    c = y_nor_list[i]
    right_lower[i] = sg_right.query(0, c)
    right_upper[i] = sg_right.query(c, N)
    sg_right.update(c, 1)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

LARGE = 998244353

res = 0
for i in range(N):
    r = pow(2, N, LARGE) - 1
    r -= pow(2, left_lower[i] + left_upper[i], LARGE) - 1
    r -= pow(2, right_lower[i] + right_upper[i], LARGE) - 1
    r -= pow(2, left_lower[i] + right_lower[i], LARGE) - 1
    r -= pow(2, left_upper[i] + right_upper[i], LARGE) - 1
    r += pow(2, left_lower[i], LARGE) - 1
    r += pow(2, left_upper[i], LARGE) - 1
    r += pow(2, right_lower[i], LARGE) - 1
    r += pow(2, right_upper[i], LARGE) - 1
    res += r

print(res % LARGE)


Fixed submission:
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

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)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop


class SegmentTree(object):

    def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7):

        self.seg_func = seg_func
        self.seg_func_null = seg_func_null
        self.n = 1
        while self.n < len(init_array):
            self.n *= 2
        self.dat = [0] * (2 * self.n - 1)
        for i in range(len(init_array)):
            self.dat[self.n - 1 + i] = init_array[i]
        for i in range(self.n - 2, -1, -1):
            self.dat[i] = self.seg_func(self.dat[2 * i + 1], self.dat[2 * i + 2])

    def update(self, k, a):
        k += self.n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = self.seg_func(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    def query(self, p, q):
        # [p, q)
        if q <= p:
            return self.seg_func_null

        p += self.n - 1
        q += self.n - 2
        res = self.seg_func_null

        while q - p > 1:
            if p & 1 == 0:
                res = self.seg_func(res, self.dat[p])
            if q & 1 == 1:
                res = self.seg_func(res, self.dat[q])
                q -= 1
            p = p // 2
            q = (q-1) // 2
        if p == q:
            res = self.seg_func(res, self.dat[p])
        else:
            res = self.seg_func(self.seg_func(res, self.dat[p]), self.dat[q])

        return res


N = int(input())
hx = []
hy = []

for i in range(N):
    x, y = map(int, input().split())
    heappush(hx, (x, y))

y_list = [0] * N
for i in range(N):
    x, y = heappop(hx)
    y_list[i] = y
    heappush(hy, (y, i))

y_nor_list = [0] * N
for j in range(N):
    y, i = heappop(hy)
    y_nor_list[i] = j


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


sg_left = SegmentTree(init_array=[0]*N, seg_func=add, seg_func_null=0)
sg_right = SegmentTree(init_array=[0]*N, seg_func=add, seg_func_null=0)

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]
    left_lower[i] = sg_left.query(0, c)
    left_upper[i] = sg_left.query(c, N)
    sg_left.update(c, 1)

for i in range(N-1, -1, -1):
    c = y_nor_list[i]
    right_lower[i] = sg_right.query(0, c)
    right_upper[i] = sg_right.query(c, N)
    sg_right.update(c, 1)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

LARGE = 998244353

res = 0
for i in range(N):
    r = pow(2, N, LARGE) - 1
    r -= pow(2, left_lower[i] + left_upper[i], LARGE) - 1
    r -= pow(2, right_lower[i] + right_upper[i], LARGE) - 1
    r -= pow(2, left_lower[i] + right_lower[i], LARGE) - 1
    r -= pow(2, left_upper[i] + right_upper[i], LARGE) - 1
    r += pow(2, left_lower[i], LARGE) - 1
    r += pow(2, left_upper[i], LARGE) - 1
    r += pow(2, right_lower[i], LARGE) - 1
    r += pow(2, right_upper[i], LARGE) - 1
    res += r

print(res % LARGE)


Fixed submission:
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)

# print(left_lower)
# print(left_upper)
# print(right_lower)
# print(right_upper)

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)