Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
scores = [k] * n
for _ in range(q):
    i = int(input()) - 1
    for j in range(n):
        if i == j:
            continue
        scores[j] -= 1
for s in scores:
    print('Yes' if s > 0 else 'No')

Fixed submission:
n, k, q = map(int, input().split())
scores = {i: 0 for i in range(n)}
for _ in range(q):
    i = int(input()) - 1
    scores[i] += 1
for i in range(n):
    print('Yes' if k - (q - scores[i]) > 0 else 'No')
Buggy python submission (verdict: Runtime Error):
import heapq

n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
heapq._heapify_max(prices)
for _ in range(m):
    p = heapq._heappop_max(prices)
    heapq.heappush(prices, p // 2)
print(sum(prices))

Fixed submission:
import heapq

n, m = map(int, input().split())
prices = [-int(p) for p in input().split()]
heapq.heapify(prices)
for _ in range(m):
  p = heapq.heappop(prices)
  heapq.heappush(prices, p / 2)
print(-sum(int(p) for p in prices))

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

n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
heapq._heapify_max(prices)
for _ in range(m):
    prices[0] //= 2
    heapq._heapify_max(prices)
print(sum(prices))

Fixed submission:
import heapq

n, m = map(int, input().split())
prices = [-int(p) for p in input().split()]
heapq.heapify(prices)
for _ in range(m):
  p = heapq.heappop(prices)
  heapq.heappush(prices, p / 2)
print(-sum(int(p) for p in prices))

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

n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
heapq._heapify_max(prices)
for _ in range(m):
    p = heapq._heappop_max(prices) // 2
    prices.append(p)
    heapq._siftdown_max(prices, 0, n - 1)
print(sum(prices))

Fixed submission:
import heapq

n, m = map(int, input().split())
prices = [-int(p) for p in input().split()]
heapq.heapify(prices)
for _ in range(m):
  p = heapq.heappop(prices)
  heapq.heappush(prices, p / 2)
print(-sum(int(p) for p in prices))

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

n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
heapq._heapify_max(prices)
for _ in range(m):
    p = heapq._heappop_max(prices) // 2
    heapq.heappush(prices, p)
print(sum(prices))

Fixed submission:
import heapq

n, m = map(int, input().split())
prices = [-int(p) for p in input().split()]
heapq.heapify(prices)
for _ in range(m):
  p = heapq.heappop(prices)
  heapq.heappush(prices, p / 2)
print(-sum(int(p) for p in prices))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
prices.sort()
for _ in range(m):
    prices[-1] //= 2
    prices.sort()
print(sum(prices))

Fixed submission:
import heapq

n, m = map(int, input().split())
prices = [-int(p) for p in input().split()]
heapq.heapify(prices)
for _ in range(m):
  p = heapq.heappop(prices)
  heapq.heappush(prices, p / 2)
print(-sum(int(p) for p in prices))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
for _ in range(m):
    j, p = max(enumerate(prices), key=lambda x: x[1])
    prices[j] //= 2
print(sum(prices))

Fixed submission:
import heapq

n, m = map(int, input().split())
prices = [-int(p) for p in input().split()]
heapq.heapify(prices)
for _ in range(m):
  p = heapq.heappop(prices)
  heapq.heappush(prices, p / 2)
print(-sum(int(p) for p in prices))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, k = map(int, input().split())
dp = [0] * n
dp[0] = 1
dp[1] = -1
delta = []
for _ in range(k):
    l, r = map(int, input().split())
    delta.append((l, 1))
    delta.append((r+1, -1))

total = 0
for i in range(n):
    total += dp[i]
    for p, d in delta:
        if i + p >= n:
            continue
        dp[i + p] += total * d
print(total % MOD)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, k = map(int, input().split())
dp = [0] * n
dp[0] = 1
dp[1] = -1
delta = []
for _ in range(k):
    l, r = map(int, input().split())
    delta.append((l, 1))
    delta.append((r+1, -1))

total = 0
for i in range(n):
    total += dp[i]
    total %= MOD
    for p, d in delta:
        if i + p >= n:
            continue
        dp[i + p] += total * d
        dp[i + p] %= MOD
print(total % MOD)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

if n == 1:
    if a[0] == b[0]:
        print("No")
    else:
        print(*b)
        
left = 0
lv = b[0]
for i in range(n):
    if b[i] != lv:
        right = i
        break

for i in range(n - 1):
    if a[i] != b[i]:
        left += 1
        if right == left:
            right += 1
    else:
        if a[i] == b[right]:
            while b[right] == a[i]:
                right += 1
                if right == n:
                    print("No")
                    exit()
        b[i], b[right] = b[right], b[i]
        left += 1
        if right == left:
            right += 1

if a[-1] != b[-1]:
    print(*b)
    exit()
if a[-2] != b[-1] and a[-1] != b[-2]:
    b[-1], b[-2] = b[-2], b[-1]
    print(*b)
    exit()
print("No")

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import random

n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
# n = 10
# a = []
# b = []
# for _ in range(10):
#     a.append(random.randrange(1, 4))
#     b.append(random.randrange(1, 4))
# a.sort()
# b.sort()
# print(*a)
# print(*b)

b.reverse()

same_val = None
same_id = []
for i, (ai, bi) in enumerate(zip(a, b)):
    if ai == bi:
        same_val = ai
        same_id.append(i)

changeable = []
for i, (ai, bi) in enumerate(zip(a, b)):
    if b[i] != same_val and a[i] != same_val:
        changeable.append(i)

if len(same_id) > len(changeable):
    print("No")
    exit()
for s, c in zip(same_id, changeable):
    b[s], b[c] = b[c], b[s]

print("Yes")
print(*b)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline


n = int(input())
a = [int(item) for item in input().split()]
prev = a[0]
a_uniq = [a[0]]
for item in a:
    if item == prev:
        continue
    a_uniq.append(item)
    prev = item

increasing = None
if a_uniq[0] < a_uniq[1]:
    increasing = True
else:
    increasing = False

money = 1000
kabu = 0
if increasing:
    p = money // a[0]
    money -= p * a[0]
    kabu = p

prev = a_uniq[0]
ans = 1000
for item in a_uniq[1:]:
    if item < prev and increasing:
        money += kabu * prev
        kabu = 0
        increasing = False
        ans = max(ans, money)
    if item > prev and not increasing:
        p = money // prev
        money -= p * prev
        kabu = p
        increasing = True
    prev = item
if kabu:
    money += a_uniq[-1] * kabu
    ans = max(ans, money)
print(ans)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline


n = int(input())
a = [int(item) for item in input().split()]
prev = a[0]
a_uniq = [a[0]]
for item in a:
    if item == prev:
        continue
    a_uniq.append(item)
    prev = item

if len(a_uniq) == 1:
    print(1000)
    exit()

increasing = None
if a_uniq[0] < a_uniq[1]:
    increasing = True
else:
    increasing = False

money = 1000
kabu = 0
if increasing:
    p = money // a[0]
    money -= p * a[0]
    kabu = p

prev = a_uniq[0]
ans = 1000
for item in a_uniq[1:]:
    if item < prev and increasing:
        money += kabu * prev
        kabu = 0
        increasing = False
        ans = max(ans, money)
    if item > prev and not increasing:
        p = money // prev
        money -= p * prev
        kabu = p
        increasing = True
    prev = item
if kabu:
    money += a_uniq[-1] * kabu
    ans = max(ans, money)
print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
x = [int(item) for item in list(input().rstrip())]
x.reverse()

ones = x.count(1)
aug = ones + 1
dim = ones - 1

modaug = 0
moddim = 0
for i, item in enumerate(x):
    if item == 1:
        modaug += pow(2, i, aug)
        modaug %= aug
        moddim += pow(2, i, dim)
        moddim %= dim

cnt = [-1] * (2*10**5 + 1)
cnt[0] = 0; cnt[1] = 1
for i in range(1, 2*10**5 + 1):
    val = i
    num = bin(val).count("1")
    cnt[i] = cnt[val % num] + 1

ans = []
for i, item in enumerate(x):
    if item == 0:
        tmp = modaug + pow(2, i, aug)
        tmp %= aug
    else:
        tmp = moddim - pow(2, i, dim)
        tmp %= dim
    ans.append(cnt[tmp] + 1)

ans.reverse()
for item in ans:
    print(item)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
x = [int(item) for item in list(input().rstrip())]
x.reverse()

ones = x.count(1)
aug = ones + 1
dim = ones - 1

modaug = 0
moddim = 0
for i, item in enumerate(x):
    if item == 1:
        modaug += pow(2, i, aug)
        modaug %= aug
        if dim != 0:
            moddim += pow(2, i, dim)
            moddim %= dim

cnt = [-1] * (2*10**5 + 10)
cnt[0] = 0; cnt[1] = 1
for i in range(1, 2*10**5 + 10):
    val = i
    num = bin(val).count("1")
    cnt[i] = cnt[val % num] + 1

ans = []
for i, item in enumerate(x):
    if item == 0:
        tmp = modaug + pow(2, i, aug)
        tmp %= aug
    else:
        if dim == 0:
            ans.append(0)
            continue
        else:
            tmp = moddim - pow(2, i, dim)
            tmp %= dim
    ans.append(cnt[tmp] + 1)

ans.reverse()
for item in ans:
    print(item)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
dp = [[0] * (d - b + 1) for _ in range(c - a + 1)]

dp[0][0] = 1
for i in range(c - a + 1):
    for j in range(d - b + 1):
        if i > 0:
            dp[i][j] += dp[i-1][j] * (b+j)
        if j > 0:
            dp[i][j] += dp[i][j-1] * (a+i)
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1] * (b+j-1) * (a+i-1)
        dp[i][j] %= 998244353

print(dp[-1][-1])

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
dp = [[0] * (d - b + 1) for _ in range(c - a + 1)]

dp[0][0] = 1
for i in range(c - a + 1):
    for j in range(d - b + 1):
        if i > 0:
            dp[i][j] += dp[i-1][j] * (b+j)
        if j > 0:
            dp[i][j] += dp[i][j-1] * (a+i)
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1] * (b+j-1) * (a+i-1)
        dp[i][j] %= 998244353

print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353
 
n, s = map(int, input().split())
a = [int(item) for item in input().split()]
# dp[i-th item][j val] : tuple(cnt, used cnt)
dp = [[dict() for _ in range(s+1)] for _ in range(n + 1)]
dp[0][0][0] = 1
 
for i, item in enumerate(a):
    for j in range(s):
        for uc, c in dp[i][j].items():
            if uc not in dp[i+1][j]:
                dp[i+1][j][uc] = c
            else:
                dp[i+1][j][uc] += c
            if j + item > s:
                continue
            if uc + 1 not in dp[i+1][j + item]:
                dp[i+1][j + item][uc + 1] = c
            else:
                dp[i+1][j + item][uc + 1] += c
 
ans = 0
for dics in dp:
    for key, val in dics[-1].items():
        ans += pow(2, n - key, MOD) * val
        ans %= MOD
print(ans)


Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, s = map(int, input().split())
a = [int(item) for item in input().split()]

dp = [[0] * (s + 1) for _ in range(n+1)]
dp[0][0] = 1

for i, item in enumerate(a):
    for j in range(s, -1, -1):
        if dp[i][j] == 0:
            continue
        if j + item <= s:
            dp[i+1][j+item] += dp[i][j] 
        dp[i+1][j] += dp[i][j] * 2
        dp[i+1][j] %= MOD

print(dp[-1][-1] % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, s = map(int, input().split())
a = [int(item) for item in input().split()]
# dp[i-th item][j val] : tuple(cnt, used cnt)
dp = [[dict() for _ in range(s+1)] for _ in range(n + 1)]
dp[0][0][0] = 1

for i, item in enumerate(a):
    for j in range(s):
        for uc, c in dp[i][j].items():
            if uc not in dp[i+1][j]:
                dp[i+1][j][uc] = c
            else:
                dp[i+1][j][uc] += c
            if j + item > s:
                continue
            if uc + 1 not in dp[i+1][j + item]:
                dp[i+1][j + item][uc + 1] = c
            else:
                dp[i+1][j + item][uc + 1] += c

ans = 0
for dics in dp:
    for key, val in dics[-1].items():
        ans += pow(2, n - key, MOD) * val
        ans %= MOD
print(ans)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, s = map(int, input().split())
a = [int(item) for item in input().split()]

dp = [[0] * (s + 1) for _ in range(n+1)]
dp[0][0] = 1

for i, item in enumerate(a):
    for j in range(s, -1, -1):
        if dp[i][j] == 0:
            continue
        if j + item <= s:
            dp[i+1][j+item] += dp[i][j] 
        dp[i+1][j] += dp[i][j] * 2
        dp[i+1][j] %= MOD

print(dp[-1][-1] % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    edge[u].append(v)
    edge[v].append(u)

ans = [-1] * n
def bfs(p, v):
    dq = deque()
    dq.append((p, v))
    while dq:
        p, v = dq.popleft()
        if ans[v] == -1:
            ans[v] = p
        for nv in edge[v]:
            if nv == p:
                continue
            if ans[nv] == -1:
                dq.append((v, nv))

bfs(-1, 0)
if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for item in ans[1:]:
        print(item + 1)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    edge[u].append(v)
    edge[v].append(u)

ans = [-2] * n
def bfs(p, v):
    dq = deque()
    dq.append((p, v))
    while dq:
        p, v = dq.popleft()
        if ans[v] == -1:
            ans[v] = p
        for nv in edge[v]:
            if nv == p:
                continue
            if ans[nv] == -2:
                dq.append((v, nv))
                ans[nv] = -1 

bfs(-1, 0)
if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for item in ans[1:]:
        print(item + 1)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    edge[u].append(v)
    edge[v].append(u)

ans = [-1] * n
def bfs(p, v):
    dq = deque()
    dq.append((p, v))
    while dq:
        p, v = dq.popleft()
        if ans[v] == -1:
            ans[v] = p
        for nv in edge[v]:
            if nv == p:
                continue
            if ans[nv] == -1:
                dq.append((v, nv))

bfs(-1, 0)
if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for item in ans[1:]:
        print(item + 1)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    edge[u].append(v)
    edge[v].append(u)

ans = [-2] * n
def bfs(p, v):
    dq = deque()
    dq.append((p, v))
    while dq:
        p, v = dq.popleft()
        if ans[v] == -1:
            ans[v] = p
        for nv in edge[v]:
            if nv == p:
                continue
            if ans[nv] == -2:
                dq.append((v, nv))
                ans[nv] = -1 

bfs(-1, 0)
if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for item in ans[1:]:
        print(item + 1)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math
MOD = 10**9 + 7

n = int(input())
fish = dict() 
for _ in range(n):
    a, b = map(int, input().split())
    a_abs = abs(a); b_abs = abs(b)
    g = math.gcd(a_abs, b_abs)
    if (a > 0 and b > 0) or (a < 0 and b < 0): 
        key = (a_abs // g, b_abs // g)
    else:
        key = (a_abs // g, -b_abs // g)
    if key not in fish:
        fish[key] = 1
    else:
        fish[key] += 1

ans = 1
for a, b in fish:
    if fish[(a, b)] == 0:
        continue
    if b < 0:
        inv_key = (-b, a)
    else:
        inv_key = (b, -a)
    if inv_key in fish:
        val1 = ans * (pow(2, fish[(a, b)], MOD) - 1)
        val2 = ans * (pow(2, fish[inv_key], MOD) - 1)
        fish[inv_key] = 0
        ans = val1 + val2 + ans
    else:
        val1 = ans * (pow(2, fish[(a, b)], MOD) - 1)
        ans = val1 + ans
    ans %= MOD
print((ans - 1) % MOD)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math
MOD = 10**9 + 7

n = int(input())
fish = dict() 
azero = 0
bzero = 0
abzero = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        abzero += 1
        continue
    if a == 0:
        azero += 1
        continue
    if b == 0:
        bzero += 1
        continue
    a_abs = abs(a); b_abs = abs(b)
    g = math.gcd(a_abs, b_abs)
    if (a > 0 and b > 0) or (a < 0 and b < 0): 
        key = (a_abs // g, b_abs // g)
    else:
        key = (a_abs // g, -b_abs // g)
    if key not in fish:
        fish[key] = 1
    else:
        fish[key] += 1

ans = 1
for a, b in fish:
    if fish[(a, b)] == 0:
        continue
    if b < 0:
        inv_key = (-b, a)
    else:
        inv_key = (b, -a)
    if inv_key in fish:
        val1 = ans * (pow(2, fish[(a, b)], MOD) - 1)
        val2 = ans * (pow(2, fish[inv_key], MOD) - 1)
        fish[inv_key] = 0
        ans = val1 + val2 + ans
    else:
        val1 = ans * (pow(2, fish[(a, b)], MOD) - 1)
        ans = val1 + ans
    ans %= MOD
# think a == 0 or b == 0
val1 = ans * (pow(2, azero, MOD) - 1)
val2 = ans * (pow(2, bzero, MOD) - 1)
ans = val1 + val2 + ans
ans += abzero
print((ans - 1) % MOD)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import heapq
INF = 10**9

MAX_SILVER = 3000 

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
        return self.dist

n, m, s = map(int, input().split())
edge = [[] for _ in range(n * MAX_SILVER)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1; v -= 1
    for i in range(a, MAX_SILVER):
        edge[u*MAX_SILVER + i].append((v*MAX_SILVER + i-a, b))
        edge[v*MAX_SILVER + i].append((u*MAX_SILVER + i-a, b))

for v in range(n):
    c, d = map(int, input().split())
    for i in range(MAX_SILVER - 100):
        edge[v*MAX_SILVER + i].append((v*MAX_SILVER + i + c, d))

DIJK = Dijkstra(edge)
dist = DIJK.calc(s)

for v in range(1, n): 
    ret = INF
    for val in range(MAX_SILVER):
        if dist[v*MAX_SILVER + val] < ret:
            ret = dist[v*MAX_SILVER + val]
    print(ret)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import heapq
INF = 10**18

MAX_SILVER = 3000 

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
        return self.dist

n, m, s = map(int, input().split())
edge = [[] for _ in range(n * MAX_SILVER)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1; v -= 1
    for i in range(a, MAX_SILVER):
        edge[u*MAX_SILVER + i].append((v*MAX_SILVER + i-a, b))
        edge[v*MAX_SILVER + i].append((u*MAX_SILVER + i-a, b))

for v in range(n):
    c, d = map(int, input().split())
    for i in range(MAX_SILVER - 100):
        edge[v*MAX_SILVER + i].append((v*MAX_SILVER + i + c, d))

DIJK = Dijkstra(edge)
if s > 2500:
    s = 2500
dist = DIJK.calc(s)

for v in range(1, n): 
    ret = INF
    for val in range(MAX_SILVER):
        if dist[v*MAX_SILVER + val] < ret:
            ret = dist[v*MAX_SILVER + val]
    print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math

k = int(input())
ret = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for k in range(1, k+1):
            ret += math.gcd(math.gcd(i, j), k)
print(ret)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
try:
    from math import gcd
except:
    from fractions import gcd

k = int(input())

memo = [[0] * 201 for _ in range(201)]
for i in range(201):
    for j in range(201):
        memo[i][j] = gcd(i, j)
ret = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            val = memo[a][b]
            ret += memo[val][c]
print(ret)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, s = map(int, input().split())
a = [int(item) for item in input().split()]

dp = [[0] * (s+1) for _ in range(n)]
dp[0][0] = 1
if a[0] <= s:
    dp[0][a[0]] = 1
ans = 0
for i, item in enumerate(a[1:]):
    for j in range(s+1):
        # Not use item
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        # Do use item
        if j + item <= s:
            dp[i+1][j + item] += dp[i][j]
            dp[i+1][j + item] %= MOD
    # Start from i
    dp[i+1][item] += 1
    dp[i+1][0] += 1
    ans += dp[i+1][s]

print(ans)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, s = map(int, input().split())
a = [int(item) for item in input().split()]

dp = [[0] * (s+1) for _ in range(n)]
dp[0][0] = 1
if a[0] <= s:
    dp[0][a[0]] = 1
ans = 0
for i, item in enumerate(a[1:]):
    for j in range(s+1):
        # Not use item
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        # Do use item
        if j + item <= s:
            dp[i+1][j + item] += dp[i][j]
            dp[i+1][j + item] %= MOD
    # Start from i
    if item <= s:
        dp[i+1][item] += 1
    dp[i+1][0] += 1
    ans += dp[i+1][s]
    ans %= MOD

print(ans)