Buggy python submission (verdict: Time Limit Exceeded):
class segTree:
  inf = 0
  def __init__(self, num):
    self.N = 1
    while self.N < num:
      self.N *= 2
    self.T = [self.inf] * (2 * self.N - 1)
  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 + self.N - 1
    self.T[k] += 1
    while k > 0:
      k = (k - 1) // 2
      self.T[k] += 1
  def getV(self, l, r):
    return self.getVs(l, r, 0, 0, self.N - 1)
  def getVs(self, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return self.T[k]
    t = (kl + kr) // 2
    if l > t:
      return self.getVs(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return self.getVs(l, r , 2 * k + 1, kl, t)
    return self.do(self.getVs(l, r , 2 * k + 1, kl,t),
              self.getVs(l, r , 2 * k + 2, t + 1, kr))

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 = segTree(N)
for i in range(N):
  t = Sl.getV(0, R[xy[i][1]])
  LU[i] = i - t
  LD[i] = t
  Sl.update(R[xy[i][1]])

Sr = segTree(N)
for i in range(N-1 , -1 , -1):
  t = Sr.getV(0, 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)


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

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


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)

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

Buggy python submission (verdict: Time Limit Exceeded):
class segTree:
  inf = 0
  def __init__(self, num):
    self.N = 1
    while self.N < num:
      self.N *= 2
    self.T = [self.inf] * (2 * self.N - 1)
  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 + self.N - 1
    self.T[k] += 1
    while k > 0:
      k = (k - 1) // 2
      self.T[k] += 1
  def getV(self, l, r):
    return self.getVs(l, r, 0, 0, self.N - 1)
  def getVs(self, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return self.T[k]
    t = (kl + kr) // 2
    if l > t:
      return self.getVs(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return self.getVs(l, r , 2 * k + 1, kl, t)
    return self.do(self.getVs(l, r , 2 * k + 1, kl,t),
              self.getVs(l, r , 2 * k + 2, t + 1, kr))


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 = segTree(N)
for i in range(N):
  t = Sl.getV(0, R[xy[i][1]])
  LU[i] = i - t
  LD[i] = t
  Sl.update(R[xy[i][1]])

Sr = segTree(N)
for i in range(N-1 , -1 , -1):
  t = Sr.getV(0, 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)

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

Buggy python submission (verdict: Time Limit Exceeded):
class segTree:
  inf = 0
  def __init__(self, num):
    self.N = 1
    while self.N < num:
      self.N *= 2
    self.T = [self.inf] * (2 * self.N - 1)
  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 + self.N - 1
    self.T[k] += 1
    while k > 0:
      k = (k - 1) // 2
      self.T[k] += 1
  def getV(self, l, r):
    return self.getVs(l, r, 0, 0, self.N - 1)
  def getVs(self, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return self.T[k]
    t = (kl + kr) // 2
    if l > t:
      return self.getVs(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return self.getVs(l, r , 2 * k + 1, kl, t)
    return self.do(self.getVs(l, r , 2 * k + 1, kl,t),
              self.getVs(l, r , 2 * k + 2, t + 1, kr))


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 = segTree(N)
for i in range(N):
  t = Sl.getV(0, R[xy[i][1]])
  LU[i] = i - t
  LD[i] = t
  Sl.update(R[xy[i][1]])

Sr = segTree(N)
for i in range(N-1 , -1 , -1):
  t = Sr.getV(0, 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)

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