Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import sys
input = sys.stdin.readline

q = int(input())
a = [input().rstrip() for _ in range(q)]

dic = collections.Counter(a)

keys = [k for k, v in dic.items() if v == max(dic.values())]
keys_s = sorted(keys)
for i in keys_s:
    print(i)


Fixed submission:
import collections
import sys
input = sys.stdin.readline

q = int(input())
a = [input().rstrip() for _ in range(q)]

dic = collections.Counter(a)

ma = max(dic.values())
keys = [k for k, v in dic.items() if v == ma]
keys_s = sorted(keys)
for i in keys_s:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import sys
input = sys.stdin.readline

q = int(input())
a = [input().rstrip() for _ in range(q)]

dic = collections.Counter(a)

keys = [k for k, v in dic.items() if v == max(dic.values())]
keys_s = sorted(keys)
for i in keys_s:
    print(i)


Fixed submission:
import collections
import sys
input = sys.stdin.readline

q = int(input())
a = [input().rstrip() for _ in range(q)]

dic = collections.Counter(a)

ma = max(dic.values())
keys = [k for k, v in dic.items() if v == ma]
keys_s = sorted(keys)
for i in keys_s:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

q = int(input())
a = [input() for _ in range(q)]

dic = collections.Counter(a)

keys = [k for k, v in dic.items() if v == max(dic.values())]
keys_s = sorted(keys)
for i in keys_s:
    print(i)
    

Fixed submission:
import collections
import sys
input = sys.stdin.readline

q = int(input())
a = [input().rstrip() for _ in range(q)]

dic = collections.Counter(a)

ma = max(dic.values())
keys = [k for k, v in dic.items() if v == ma]
keys_s = sorted(keys)
for i in keys_s:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
q = int(input())
a = [input() for _ in range(q)]
dic = {}

for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
keys = [k for k, v in dic.items() if v == max(dic.values())]
keys_s = sorted(keys)
for i in keys_s:
    print(i)


Fixed submission:
import collections
import sys
input = sys.stdin.readline

q = int(input())
a = [input().rstrip() for _ in range(q)]

dic = collections.Counter(a)

ma = max(dic.values())
keys = [k for k, v in dic.items() if v == ma]
keys_s = sorted(keys)
for i in keys_s:
    print(i)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
dmg = []
cost = []

for i in range(m):
    a, b = map(int, input().split())
    dmg.append(a)
    cost.append(b)

inf = 10**9
dp = [inf] * 10001
dp[0] = 0

for i in range(m):
    for j in range(n):
        if dp[j] != inf:
            dp[j + dmg[i]] = min(dp[j + dmg[i]], dp[j] + cost[i])
print(min(dp[n:]))


Fixed submission:
n, m = map(int, input().split())
dmg = []
cost = []

for i in range(m):
    a, b = map(int, input().split())
    dmg.append(a)
    cost.append(b)

inf = 10**9
dp = [inf] * 30000
dp[0] = 0

for i in range(m):
    for j in range(n):
        if dp[j] != inf:
            dp[j + dmg[i]] = min(dp[j + dmg[i]], dp[j] + cost[i])
print(min(dp[n:]))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
dmg = []
cost = []

for i in range(m):
    a, b = map(int, input().split())
    dmg.append(a)
    cost.append(b)

inf = 10**9
dp = [inf] * 2 * n
dp[0] = 0

for i in range(m):
    for j in range(n):
        if dp[j] != inf:
            dp[j + dmg[i]] = min(dp[j + dmg[i]], dp[j] + cost[i])
print(min(dp[n:]))


Fixed submission:
n, m = map(int, input().split())
dmg = []
cost = []

for i in range(m):
    a, b = map(int, input().split())
    dmg.append(a)
    cost.append(b)

inf = 10**9
dp = [inf] * 30000
dp[0] = 0

for i in range(m):
    for j in range(n):
        if dp[j] != inf:
            dp[j + dmg[i]] = min(dp[j + dmg[i]], dp[j] + cost[i])
print(min(dp[n:]))
Buggy python submission (verdict: Runtime Error):
mod = (10 ** 9) + 7
lim = 1100000

fct = [0] * lim
inv_f = [0] * lim

fct[0] = 1
for i in range(1, lim):
    fct[i] = fct[i - 1] * i % mod

inv_f[lim - 1] = pow(fct[lim - 1], -1, mod)

for i in range(lim - 1, 0, -1):
    inv_f[i - 1] = inv_f[i] * i % mod


def nCk(a, b):
    if a < b:
        return 0
    else:
        return fct[a] * inv_f[b] * inv_f[a - b] % mod


n, k = map(int, input().split())
s = list(map(int, input().split()))
s.sort()

s_max = 0
s_min = 0

for i in range(k - 1, n):
    s_max = s_max + s[i] * nCk(i, k - 1)
    s_max %= mod

for i in range(n - k + 1):
    s_min = s_min + s[i] * nCk(n - i - 1, k - 1)
    s_min %= mod

print((s_max-s_min) % mod)
# print(s_max, s_min)


Fixed submission:
mod = (10 ** 9) + 7
lim = 1100000

fct = [0] * lim
inv_f = [0] * lim

fct[0] = 1
for i in range(1, lim):
    fct[i] = fct[i - 1] * i % mod

inv_f[lim - 1] = pow(fct[lim - 1], mod - 2, mod)

for i in range(lim - 1, 0, -1):
    inv_f[i - 1] = inv_f[i] * i % mod


def nCk(a, b):
    if a < b:
        return 0
    else:
        return fct[a] * inv_f[b] * inv_f[a - b] % mod


n, k = map(int, input().split())
s = list(map(int, input().split()))
s.sort()

s_max = 0
s_min = 0

for i in range(k - 1, n):
    s_max = s_max + s[i] * nCk(i, k - 1)
    s_max %= mod

for i in range(n - k + 1):
    s_min = s_min + s[i] * nCk(n - i - 1, k - 1)
    s_min %= mod

print((s_max-s_min) % mod)
# print(s_max, s_min)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(map(int, input().split()))
mod = 10**9 + 7
m = len(bin(max(s))) - 2
p = [0] * m
q = [0] * m

for i in s:
    for j in range(m):
        if (i >> j) & 1 == 1:
            p[j] += 1
        else:
            q[j] += 1

res = 0
r = 1
for k in range(m):
    res += p[k] * q[k] % mod * r
    res %= mod
    r = r * 2 % mod
print(res)


Fixed submission:
n = int(input())
s = list(map(int, input().split()))
mod = 10**9 + 7
m = len(bin(max(s))) - 2
p = [0] * m
q = [0] * m

for i in s:
    for j in range(m):
        if (i >> j) & 1 == 1:
            p[j] += 1
        else:
            q[j] += 1

res = 0
r = 1
for k in range(m):
    res += p[k] * q[k] % mod * r
    res %= mod
    r = r * 2 % mod
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())
lis = tuple(input())

ans = tuple(itertools.combinations(lis, 3))

result = []
for line in ans:
    if line not in result:
        result.append(line)
print(len(result))


Fixed submission:
n = int(input())
s = input()

dp1 = [[0 for i in range(10)] for _ in range(n + 1)]
dp2 = [[0 for i in range(100)] for _ in range(n + 1)]
dp3 = [[0 for i in range(1000)] for _ in range(n + 1)]

for i in range(n):
    dp1[i + 1][int(s[i])] = 1
    for j in range(10):
        if dp1[i][j]:
            dp2[i + 1][j * 10 + int(s[i])] = 1
            dp1[i + 1][j] = 1
    for j in range(100):
        if dp2[i][j]:
            dp3[i + 1][j * 10 + int(s[i])] = 1
            dp2[i + 1][j] = 1
    for j in range(1000):
        if dp3[i][j]:
            dp3[i + 1][j] = 1

print(sum(dp3[n]))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())
lis = list(input())

ans = list(itertools.combinations(lis, 3))
anss = tuple(set(ans))
print(len(anss))

Fixed submission:
n = int(input())
s = input()

dp1 = [[0 for i in range(10)] for _ in range(n + 1)]
dp2 = [[0 for i in range(100)] for _ in range(n + 1)]
dp3 = [[0 for i in range(1000)] for _ in range(n + 1)]

for i in range(n):
    dp1[i + 1][int(s[i])] = 1
    for j in range(10):
        if dp1[i][j]:
            dp2[i + 1][j * 10 + int(s[i])] = 1
            dp1[i + 1][j] = 1
    for j in range(100):
        if dp2[i][j]:
            dp3[i + 1][j * 10 + int(s[i])] = 1
            dp2[i + 1][j] = 1
    for j in range(1000):
        if dp3[i][j]:
            dp3[i + 1][j] = 1

print(sum(dp3[n]))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())
lis = list(input())

ans = list(itertools.combinations(lis, 3))
print(len(set(ans)))


Fixed submission:
n = int(input())
s = input()

dp1 = [[0 for i in range(10)] for _ in range(n + 1)]
dp2 = [[0 for i in range(100)] for _ in range(n + 1)]
dp3 = [[0 for i in range(1000)] for _ in range(n + 1)]

for i in range(n):
    dp1[i + 1][int(s[i])] = 1
    for j in range(10):
        if dp1[i][j]:
            dp2[i + 1][j * 10 + int(s[i])] = 1
            dp1[i + 1][j] = 1
    for j in range(100):
        if dp2[i][j]:
            dp3[i + 1][j * 10 + int(s[i])] = 1
            dp2[i + 1][j] = 1
    for j in range(1000):
        if dp3[i][j]:
            dp3[i + 1][j] = 1

print(sum(dp3[n]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = input()

if d[:n//2] == d[n/2:]:
    print("Yes")
else:
    print("No")

Fixed submission:
n = int(input())
d = input()
if n % 2 == 1:
    print("No")
elif d[:n//2] == d[n//2:]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
m = int(input())
a = {}
for i in range(2, int(m**0.5)+1):
    if m % i == 0:
        n = m // i
        a[i] = n
b = min(a.values())
if b < 10: print("Yes")
else: print("No")
  

Fixed submission:
m = int(input())
a = {}
for i in range(1, int(m**0.5)+1):
    if m % i == 0:
        n = m // i
        a[i] = n
b = min(a.values())
if b < 10: print("Yes")
else: print("No")
Buggy python submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
h = x/a**2

if h >= b/2:
    tanth = a / (b - h) / 2
else:
    tanth = 2 * a * h / b**2

theta = math.degrees(math.atan(tanth))
print(90 - theta)


Fixed submission:
import math
a, b, x = map(int, input().split())
h = x/a**2

if b == h:
    print(0)
elif h >= b/2:
    tanth = a / (b - h) / 2
    theta = math.degrees(math.atan(tanth))
    print(90 - theta)
else:
    tanth = 2 * a * h / b**2
    theta = math.degrees(math.atan(tanth))
    print(90 - theta)

Buggy python submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
h = x/a**2
tanth = a / (b - h) / 2
theta = math.degrees(math.atan(tanth))
print(90 - theta)

Fixed submission:
import math
a, b, x = map(int, input().split())
h = x/a**2

if b == h:
    print(0)
elif h >= b/2:
    tanth = a / (b - h) / 2
    theta = math.degrees(math.atan(tanth))
    print(90 - theta)
else:
    tanth = 2 * a * h / b**2
    theta = math.degrees(math.atan(tanth))
    print(90 - theta)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())
lis = list(map(int,input().split()))

a = tuple(itertools.combinations(lis,3))
b = 0

for i in a:
    if i[0] < i[1] + i[2] and i[1] < i[2] + i[0] and i[2] < i[0] + i[1]:
        b += 1
print(b)


Fixed submission:
import bisect

n = int(input())
lis = list(map(int,input().split()))

a = sorted(lis, reverse=True)
c = sorted(lis)
d = 0

for i in range(n):
    for j in range(i + 1, n):
        e = c[:-j-1]
        b = bisect.bisect_right(e, int(a[i]-a[j]))
        d += max(0, len(e) - b)
print(d)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lis = list(map(int, input().split()))
a = list(range(1, n+1))
print(*[1+lis.index(i) for i in a])


Fixed submission:
n = int(input())
lis = list(map(int, input().split()))
a = [0]*n

for i, item in enumerate(lis):
    a[item - 1] = i + 1

print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lis = list(map(int, input().split()))
print(*[1+lis.index(i) for i in range(1, n+1)])


Fixed submission:
n = int(input())
lis = list(map(int, input().split()))
a = [0]*n

for i, item in enumerate(lis):
    a[item - 1] = i + 1

print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lis = list(map(int,input().split()))
a = []

for i in range(1,n+1):
    a.append(1+lis.index(i))

print(*a)


Fixed submission:
n = int(input())
lis = list(map(int, input().split()))
a = [0]*n

for i, item in enumerate(lis):
    a[item - 1] = i + 1

print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lis = list(map(int,input().split()))
 
k = [1+lis.index(l) for l in range(1,n+1)]
 
print(*k)


Fixed submission:
n = int(input())
lis = list(map(int, input().split()))
a = [0]*n

for i, item in enumerate(lis):
    a[item - 1] = i + 1

print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lis = list(map(int,input().split()))

k = [1+lis.index(l) for l in range(1,n+1)]

print(*k)


Fixed submission:
n = int(input())
lis = list(map(int, input().split()))
a = [0]*n

for i, item in enumerate(lis):
    a[item - 1] = i + 1

print(*a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n == "Sunny":
  print("Cloudy")
elif n== "Cloudy":
  print("Rainy")
else:
  print("Sunny")

Fixed submission:
n = str(input())
if n == "Sunny":
  print("Cloudy")
elif n== "Cloudy":
  print("Rainy")
else:
  print("Sunny")

Buggy python submission (verdict: Runtime Error):
n = int(input())
print(n)


Fixed submission:
n = str(input())
if n == "Sunny":
  print("Cloudy")
elif n== "Cloudy":
  print("Rainy")
else:
  print("Sunny")
Buggy python submission (verdict: Runtime Error):
import heapq

n,m=map(int,input().split())
a=list[map(int,input().split())]
b=[-int(i) for i in a]

heapq.heapify(b)

for i in range(m):
    x=heapq.heappop(b)//2
    heapq.heappush(b,x)

print(-sum(b))


Fixed submission:
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-int(i) for i in a]

heapq.heapify(b)

for i in range(m):
    x=-heapq.heappop(b)//2
    heapq.heappush(b,-x)

print(-sum(b))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
money = list(map(int, input().split()))
 
for i in range(M):
  money[money.index(max(money))]//=2
 
print(sum(money))

Fixed submission:
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-int(i) for i in a]

heapq.heapify(b)

for i in range(m):
    x=-heapq.heappop(b)//2
    heapq.heappush(b,-x)

print(-sum(b))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
money = list(map(int, input().split()))
 
for i in range(M):
  money[money.index(max(money))]//=2
 
print(sum(money))

Fixed submission:
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-int(i) for i in a]

heapq.heapify(b)

for i in range(m):
    x=-heapq.heappop(b)//2
    heapq.heappush(b,-x)

print(-sum(b))

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
money = list(map(int, input().split()))

for i in range(M):
  money[money.index(max(money))]//=2

print(sum(modey))

Fixed submission:
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-int(i) for i in a]

heapq.heapify(b)

for i in range(m):
    x=-heapq.heappop(b)//2
    heapq.heappush(b,-x)

print(-sum(b))
Buggy python submission (verdict: Runtime Error):
print(N^3)

Fixed submission:
N=int(input())
print(N**3)

Buggy python submission (verdict: Runtime Error):
def pwd(N):
  return N^3

pwd(N)

Fixed submission:
N=int(input())
print(N**3)
Buggy python submission (verdict: Runtime Error):
List=[list(map(int,input().split())) for i in range(4)]

a=sum(List[2])
b=int(len(List[1]))

for i in range(b-1):
  if List[1][i+1]-List[1][i] == 1:
    a+=List[3][i+1]

print(a)

Fixed submission:
List=[list(map(int,input().split())) for i in range(4)]

a=sum(List[2])
b=int(len(List[1]))

for i in range(b-1):
  if List[1][i+1]-List[1][i] == 1:
    a+=List[3][List[1][i]-1]

print(a)

Buggy python submission (verdict: Runtime Error):
Row=int(input())
List=[list(map(int,input().split())) for i in range(Row)]

a=0

for i in List[0]:
  a+=List[1][i-1]

for i in range(len(List[0])-1):
  if List[1][i]-List[1][i+1] == 1:
    a+=List[2][i-1]

print(a)

Fixed submission:
List=[list(map(int,input().split())) for i in range(4)]

a=sum(List[2])
b=int(len(List[1]))

for i in range(b-1):
  if List[1][i+1]-List[1][i] == 1:
    a+=List[3][List[1][i]-1]

print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)
from functools import lru_cache
from math import hypot

n = int(input())
s = [list(map(int, input().split())) for i in range(n)]


@lru_cache(maxsize=None)
def subsum(i, a, b):
    if i == n:
        return hypot(a, b)
    res1 = subsum(i + 1, a + s[i][0], b + s[i][1])
    res2 = subsum(i + 1, a, b)
    return max(res1, res2)


print(subsum(0, 0, 0))


Fixed submission:
def solve():
    from math import atan2, pi, hypot
    n = int(input())
    txy = []
    sx, sy = 0, 0
    for i in range(n):
        a, b = map(int, input().split())
        theta_0 = atan2(b, a)
        sx += a
        sy += b
        txy.append((theta_0, a, b))
    txy.sort()
    ans = hypot(sx, sy)
    for i in range(n):
        for j in range(i + 1, n):
            tx, ty = 0, 0
            for k in range(i, j):
                theta, x, y = txy[k]
                tx += x
                ty += y
                ans = max(ans, hypot(tx, ty))
                ans = max(ans, hypot(sx - tx, sy - ty))
    print(ans)

solve()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10*6)

n, q = map(int, input().split())
graph = [[] for _ in range(n)]

for i in range(n - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph[u].append(v)
    graph[v].append(u)

ans = [0] * n

for i in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x


def dfs(cur, par):
    for chl in graph[cur]:
        if chl == par:
            continue
        ans[chl] += ans[cur]
        dfs(chl, cur)


dfs(0, -1)
print(*ans)


Fixed submission:
from collections import deque

n, q = map(int, input().split())
cnt = [0] * (n + 1)
g = [[] for _ in range(n + 1)]

for _ in range(n - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for _ in range(q):
    u, v = map(int, input().split())
    cnt[u] += v

q = deque()
q.append(1)
checked = [0] * (n + 1)

while q:
    v = q.pop()
    checked[v] = 1
    for u in g[v]:
        if checked[u] == 1:
            continue
        cnt[u] += cnt[v]
        q.append(u)
print(*cnt[1:])

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10*6)

n, q = map(int, input().split())
graph = [[] for _ in range(n)]

for i in range(n - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph[u].append(v)
    graph[v].append(u)

ans = [0] * n

for i in range(q):
    p, x = map(int, input().split())
    ans[p-1] = x


def dfs(cur, par):
    for chl in graph[cur]:
        if chl == par:
            continue
        ans[chl] += ans[cur]
        dfs(chl, cur)


dfs(0, -1)
print(*ans)


Fixed submission:
from collections import deque

n, q = map(int, input().split())
cnt = [0] * (n + 1)
g = [[] for _ in range(n + 1)]

for _ in range(n - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for _ in range(q):
    u, v = map(int, input().split())
    cnt[u] += v

q = deque()
q.append(1)
checked = [0] * (n + 1)

while q:
    v = q.pop()
    checked[v] = 1
    for u in g[v]:
        if checked[u] == 1:
            continue
        cnt[u] += cnt[v]
        q.append(u)
print(*cnt[1:])
Buggy python submission (verdict: Runtime Error):
import heapq

n, m = map(int, input().split())
lis = []
for i in range(n + 1):
    lis.append([])

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
heapq.heapify(cnd)
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)


Fixed submission:
import heapq

n, m = map(int, input().split())
lis = []
for i in range(m + 1):
    lis.append([])

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
heapq.heapify(cnd)
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)

Buggy python submission (verdict: Runtime Error):
import heapq

n, m = map(int, input().split())
lis = []
for i in range(n + 1):
    lis.append([])

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
heapq.heapify(cnd)
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)


Fixed submission:
import heapq

n, m = map(int, input().split())
lis = []
for i in range(m + 1):
    lis.append([])

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
heapq.heapify(cnd)
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
# ref: https://atcoder.jp/contests/abc136/submissions/6696160
# ref: https://atcoder.jp/contests/abc136/submissions/6708692

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)


Fixed submission:
# ref: https://atcoder.jp/contests/abc136/submissions/6696160
# ref: https://atcoder.jp/contests/abc136/submissions/6708692
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)