Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# おなじみ 1/w = ...の形からもっていくとw = ..が導出できた

N = int(input())
for n in range(1, 3501):
    for h in range(1, 3501):
        t = 4 * n * h - N * (h + n)
        if t == 0 or t < 0:
            continue
        w = (N * n * h) / t
        if int(w) == w:
            w = int(w)
            print(h, n, w)
            exit()


Fixed submission:
# おなじみ 1/w = ...の形からもっていくとw = ..が導出できた

N = int(input())
for n in range(1, 3501):
    for h in range(1, 3501):
        t = 4 * n * h - N * (h + n)
        if t == 0 or t < 0:
            continue
        w = (N * n * h) / t
        if int(w) == w:
            w = int(w)
            print(h, n, w)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
# 二回訪れたら終了、それまでに2に行ったらOK
# インデックスと値を入れ替えながらやってみる
n = int(input())
dic = []
for i in range(n):
    dic.append(int(input()))

used = []
tmp = 1
ans = 0
while True:
    target = dic[tmp - 1]
    if target == 2:
        print(ans + 1)  # 次の一手で決まるので
        exit()
    if target in used:
        print(-1)
        exit()
    tmp = target
    used.append(tmp)
    ans += 1


Fixed submission:
# 二回訪れたら終了、それまでに2に行ったらOK
# インデックスと値を入れ替えながらやってみる
n = int(input())
dic = []
for i in range(n):
    dic.append(int(input()))

used = [False for _ in range(10 ** 5 + 1)]
tmp = 1
ans = 0
while True:
    target = dic[tmp - 1]
    if target == 2:
        print(ans + 1)  # 次の一手で決まるので
        exit()
    if used[target]:
        print(-1)
        exit()
    tmp = target
    used[tmp] = True
    ans += 1
Buggy python submission (verdict: Time Limit Exceeded):
# 最大値の最小値、ちょうどn/2臭い
# あとは帳尻合わせが効きそう
# 14とかだと7+4+2+1 （7+5+2でも7+4+3でもいい
# かと思いきや 1+2+3+4+5で15いくので, 5+4+3+2でよかった
# 10^7なので毎回足してもどうせ間に合う。これで答えの集合のうち最大値は確定
# あとはそれでnを引いて0になるまで

n = int(input())
ans = []
cur = 0

while cur != n:
    tmp = 0
    for i in range(1, n + 1 - cur):
        if i + tmp >= n - cur:
            tmp = i
            break
        tmp += i
    ans.append(tmp)
    cur += tmp
    # print("tmp = {}, cur = {}".format(tmp, cur))
# print(ans)
for a in ans:
    print(a)


Fixed submission:
# 最大値の最小値、ちょうどn/2臭い
# あとは帳尻合わせが効きそう
# 14とかだと7+4+2+1 （7+5+2でも7+4+3でもいい
# かと思いきや 1+2+3+4+5で15いくので, 5+4+3+2でよかった
# 10^7なので毎回足してもどうせ間に合う。これで答えの集合のうち最大値は確定
# あとはそれでnを引いて0になるまで -> これだと間に合わない

n = int(input())
ans = []
cur = 0

while cur != n:
    tmp = 0
    for i in range(1, n + 1 - cur):
        if i + tmp >= n - cur:
            tmp = i
            break
        tmp += i
    ans.append(tmp)
    cur += tmp
    # print("tmp = {}, cur = {}".format(tmp, cur))
# print(ans)
for a in ans:
    print(a)
Buggy python submission (verdict: Runtime Error):
s = input()
ans = []
for x in s:
    if x == "0" or x == "1":
        ans.append(x)
    else:
        ans.pop()
print("".join(ans))


Fixed submission:
s = input()
ans = []
for x in s:
    if x == "0" or x == "1":
        ans.append(x)
    else:
        if len(ans) > 0:
            ans.pop()
print("".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x


n = int(input())
a = np.array(list(map(int,input().split())),np.int64)


gcd_all = a[0]
for i in range(1,n):
    gcd_all = gcd(gcd_all,a[i])
    
if gcd_all>1:
    print("not coprime")
    sys.exit()

amax = a.max()

aflag = np.zeros(amax,np.int64)
aflag[a-1] = 1

for i in range(2,amax+1):
    index = (np.arange(amax//i)+1)*i - 1
    count = aflag[index].sum()
    if count>=2:
        print("setwise coprime")
        sys.exit()
else:
    print("pairwise coprime")

Fixed submission:
import sys
import numpy as np
from numba import njit,i8,void

@njit(i8(i8,i8),cache=True)
def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

@njit(i8(i8[:]),cache=True)
def get_gcd(a):
    gcd_all = a[0]
    for i in range(1,a.size):
        gcd_all = gcd(gcd_all,a[i])
    return gcd_all

@njit(i8(i8[:]),cache=True)
def judge_setwise(a):
    amax = a.max()
    aflag = np.zeros(amax,np.int64)
    aflag[a-1] = 1

    for i in range(2,amax+1):
        index = (np.arange(amax//i)+1)*i - 1
        count = aflag[index].sum()
        if count>=2:
            print("setwise coprime")
            return 0
    else:
        print("pairwise coprime")
        return 0

        
n = int(input())
a = np.array(list(map(int,input().split())),np.int64)


if get_gcd(a)>1:
    print("not coprime")
else:
    judge_setwise(a)
Buggy python submission (verdict: Time Limit Exceeded):
R,C,K = map(int,input().split())
item = [[0]*C for _ in range(R)]
for _ in range(K):
    r,c,v = map(int,input().split())
    item[r-1][c-1] = v
    

dp = [[[0]*4 for _ in range(C+1)] for _ in range(R+1)]

for ri in range(R):
    for ci in range(C):
        dp[ri+1][ci+1][0] = max(dp[ri+1][ci][0], dp[ri][ci+1][3])
        dp[ri+1][ci+1][1] = max(dp[ri+1][ci][1], dp[ri+1][ci][0]+item[ri][ci], dp[ri][ci+1][3]+item[ri][ci], dp[ri+1][ci+1][0])
        dp[ri+1][ci+1][2] = max(dp[ri+1][ci][2], dp[ri+1][ci][1]+item[ri][ci], dp[ri+1][ci+1][1])
        dp[ri+1][ci+1][3] = max(dp[ri+1][ci][3], dp[ri+1][ci][2]+item[ri][ci], dp[ri+1][ci+1][2])

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

Fixed submission:
import sys
import numpy as np
from numba import njit,i8

R,C,K = map(int,input().split())
item = np.zeros((R,C),np.int64)
for _ in range(K):
    r,c,v = map(int,input().split())
    item[r-1][c-1] = v
    

@njit(i8(i8[:,:],i8,i8), cache = True)
def solve(item,R,C):
    dp = np.zeros((R+1,C+1,4),np.int64)
    for ri in range(R):
        for ci in range(C):
            dp[ri+1][ci+1][0] = max(dp[ri+1][ci][0], dp[ri][ci+1][3])
            dp[ri+1][ci+1][1] = max(dp[ri+1][ci][1], dp[ri+1][ci][0]+item[ri][ci], dp[ri][ci+1][3]+item[ri][ci], dp[ri+1][ci+1][0])
            dp[ri+1][ci+1][2] = max(dp[ri+1][ci][2], dp[ri+1][ci][1]+item[ri][ci], dp[ri+1][ci+1][1])
            dp[ri+1][ci+1][3] = max(dp[ri+1][ci][3], dp[ri+1][ci][2]+item[ri][ci], dp[ri+1][ci+1][2])
        

    return dp[-1][-1][3]

print(solve(item,R,C))
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
from collections import defaultdict

n = int(input())

xysame, upright, downright = {},{},{}
u_list = ("U","R","D","L")
for u in u_list:
    xysame[u] = defaultdict(list)
    upright[u] = defaultdict(list)
    downright[u] = defaultdict(list)

for _ in range(n):
    x,y,u = input().split()
    x,y = int(x),int(y)
    if u == "U" or "D":
        xysame[u][x].append(y)
    else:
        xysame[u][y].append(x)
    upright[u][y-x].append(x)
    downright[u][y+x].append(x)
    
for u in u_list:
    for key in xysame[u].keys():
        xysame[u][key].sort()
    for key in upright[u].keys():
        upright[u][key].sort()
    for key in downright[u].keys():
        downright[u][key].sort()

INF = 10**6
ans = INF


def line(low,high,type_ = 1):
    ret = INF
    for k,v in low.items():
        if high[k] == []: continue

        for vi in v:
            index = bisect_left(high[k], vi)
            if index == len(high[k]): conitnue
            ret = min(ret,(high[k][index]-vi)/type_)
    return ret

ans = min(ans, line(xysame["U"],xysame["D"],2))
ans = min(ans, line(xysame["R"],xysame["L"],2))
ans = min(ans, line(upright["R"],upright["D"],1))
ans = min(ans, line(upright["U"],upright["L"],1))
ans = min(ans, line(downright["R"],downright["U"],1))
ans = min(ans, line(downright["D"],downright["L"],1))

ans = int(ans*10)
if ans ==INF*10: ans = "SAFE"
    
print(ans)

Fixed submission:
from bisect import bisect_left
from collections import defaultdict

n = int(input())

xysame, upright, downright = {},{},{}
u_list = ("U","R","D","L")
for u in u_list:
    xysame[u] = defaultdict(list)
    upright[u] = defaultdict(list)
    downright[u] = defaultdict(list)

for _ in range(n):
    x,y,u = input().split()
    x,y = int(x),int(y)
    if u == "U" or u == "D":
        xysame[u][x].append(y)
    else:
        xysame[u][y].append(x)
    upright[u][y-x].append(x)
    downright[u][y+x].append(x)
    
for u in u_list:
    for key in xysame[u].keys():
        xysame[u][key].sort()
    for key in upright[u].keys():
        upright[u][key].sort()
    for key in downright[u].keys():
        downright[u][key].sort()

INF = 10**6
ans = INF


def line(low,high,type_ = 1):
    ret = INF
    for k,v in low.items():
        if high[k] == []: continue

        for vi in v:
            index = bisect_left(high[k], vi)
            if index == len(high[k]): continue
            ret = min(ret,(high[k][index]-vi)/type_)
    return ret

ans = min(ans, line(xysame["U"],xysame["D"],2))
ans = min(ans, line(xysame["R"],xysame["L"],2))
ans = min(ans, line(upright["R"],upright["D"],1))
ans = min(ans, line(upright["U"],upright["L"],1))
ans = min(ans, line(downright["R"],downright["U"],1))
ans = min(ans, line(downright["D"],downright["L"],1))

ans = int(ans*10)
if ans ==INF*10: ans = "SAFE"
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = input()
popcount_x = x.count("1")
popcount_x1 = popcount_x + 1
popcount_x2 = popcount_x - 1


div1 = [0]*n
div2 = [0]*n
cur1 = 1
cur2 = 1
for i in range(n):
    cur1 %= popcount_x1
    cur2 %= popcount_x2
    div1[i] = cur1
    div2[i] = cur2
    cur1 *= 2
    cur2 *= 2


fn = [0]*n
for i in range(1,n):
    popcount = bin(i)[2:].count("1")
    fn[i] = fn[(i)%popcount] + 1

    
x_div1 = sum(int(x[i]) * div1[-i-1] for i in range(n)) % popcount_x1
x_div2 = sum(int(x[i]) * div2[-i-1] for i in range(n)) % popcount_x2

for i in range(n):
    if x[i] == "0": 
        xi_div = (x_div1 + div1[-i-1]) % popcount_x1
        print(fn[xi_div] + 1)
    else:
        xi_div = (x_div2 - div2[-i-1]) % popcount_x2
        print(fn[xi_div] + 1)

Fixed submission:
n = int(input())
x = input()
popcount_x = x.count("1")
popcount_x1 = popcount_x + 1
popcount_x2 = popcount_x - 1

if popcount_x2 == 0: popcount_x2 = -1

div1 = [0]*n
div2 = [0]*n
cur1 = 1
cur2 = 1
for i in range(n):
    cur1 %= popcount_x1
    cur2 %= popcount_x2
    div1[i] = cur1
    div2[i] = cur2
    cur1 *= 2
    cur2 *= 2


fn = [0]*n
for i in range(1,n):
    popcount = bin(i)[2:].count("1")
    fn[i] = fn[(i)%popcount] + 1

    
x_div1 = sum(int(x[i]) * div1[-i-1] for i in range(n)) % popcount_x1
x_div2 = sum(int(x[i]) * div2[-i-1] for i in range(n)) % popcount_x2

for i in range(n):
    if x[i] == "0": 
        xi_div = (x_div1 + div1[-i-1]) % popcount_x1
        print(fn[xi_div] + 1)
    else:
        if popcount_x2 == -1:
            print(0)
        else:
            xi_div = (x_div2 - div2[-i-1]) % popcount_x2
            print(fn[xi_div] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353
 
n,s = map(int, input().split())
a = list(map(int,input().split()))

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

fac_inv2 = pow(2,MOD-2,MOD)

for i in range(n):
    if a[i]<=s:
        dp[i+1][a[i]-1] = dp[i][a[i]-1] + 1
    for j in range(min(a[i]-1,s)):
        dp[i+1][j] = dp[i][j]
    for j in range(s-a[i]):
        dp[i+1][j+a[i]] = dp[i][j+a[i]] + (dp[i][j] * fac_inv2) %MOD
        dp[i+1][j+a[i]] %= MOD

ans = dp[-1][-1]

ans *= pow(2,n-1,MOD)
ans %= MOD
print(ans)

Fixed submission:
import numpy as np

MOD = 998244353
 
n,s = map(int, input().split())
a = list(map(int,input().split()))


fac_inv2 = pow(2,MOD-2,MOD)

dp = np.zeros(s,"int64")

for i in range(n):
    
    newdp = dp.copy()
    if a[i]<s:
        newdp[a[i]:] += dp[:s-a[i]] * fac_inv2 % MOD
    if a[i]<=s:
        newdp[a[i]-1] += 1
    dp = newdp % MOD

ans = dp[-1]
ans *= pow(2,n-1,MOD)
ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

n,a,b,c = map(int,input().split())

abc = {"A":a,"B":b,"C":c}

s = [input() for _ in range(n)]

ans = [None]*n
i = 0
while i <n:
    x = s[i][0]
    y = s[i][1]
    if abc[x] == 0 and abc[y] ==0:
        print("No")
        sys.exit()
    elif abc[x] == 1 and abc[y] ==1 and i<n-1:
        if s[i] == s[i+1]:
            ans[i] = x
            ans[i+1] = y
            i += 1
        elif x in s[i+1]:
            ans[i] = x
            abc[x] += 1
            abc[y] -= 1
        else:
            abc[i] = y
            abc[x] -= 1
            abc[y] += 1
    else:
        if abc[x]<=abc[y]:
            ans[i] = x
            abc[x] += 1
            abc[y] -= 1
        else:
            ans[i] = y
            abc[x] -= 1
            abc[y] += 1
    i += 1
    
print("Yes")
print("\n".join(ans))

Fixed submission:
import sys

n,a,b,c = map(int,input().split())

abc = {"A":a,"B":b,"C":c}

s = [input() for _ in range(n)]

ans = [None]*n
i = 0
while i <n:
    x = s[i][0]
    y = s[i][1]
    if abc[x] == 0 and abc[y] ==0:
        print("No")
        sys.exit()
    elif abc[x] == 1 and abc[y] ==1 and i<n-1:
        if s[i] == s[i+1]:
            ans[i] = x
            ans[i+1] = y
            i += 1
        elif x in s[i+1]:
            ans[i] = x
            abc[x] += 1
            abc[y] -= 1
        else:
            ans[i] = y
            abc[x] -= 1
            abc[y] += 1
    else:
        if abc[x]<=abc[y]:
            ans[i] = x
            abc[x] += 1
            abc[y] -= 1
        else:
            ans[i] = y
            abc[x] -= 1
            abc[y] += 1
    i += 1
    
print("Yes")
print("\n".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for _ in range(q):
    query = input()
    if query[0] == "1":
        s = s[::-1]
    else:
        t,f,c = query.split()
        if f == "1":
            s = c + s
        else:
            s = s + c
print(s)

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

reverse_flag = 0
head = ""
back = ""
for _ in range(q):
    query = input()
    if query[0] == "1":
        reverse_flag ^= 1
    else:
        t,f,c = query.split()
        f = int(f) + reverse_flag
        if f%2 == 1:
            head = c + head
        else:
            back = back + c
s = head + s + back
print(s if reverse_flag%2 == 0 else s[::-1])
Buggy python submission (verdict: Runtime Error):
def calc(n,k):
    while n[0] == '0' :n=n[1:]
    
    digit = len(n)
    if digit < k:
        return 0
    
    comb = [1]*(k+1)
    for i in range(1,k+1):
        comb[i] = comb[i-1] * (digit-i) //i
    if k==1:
        return 9*comb[1] + int(n[0])
    elif k==2:
        return (9**2)*comb[2] + (int(n[0])-1) * 9*comb[1] + calc(n[1:],1)
    elif k==3:
        return (9**3)*comb[3] + (int(n[0])-1) * (9**2) * comb[2] + calc(n[1:],2)

n=input()
k=int(input())
print(calc(n,k))

Fixed submission:
def calc(n,k):
    while n[0] == '0' and len(n)>1:
        n=n[1:]
    
    digit = len(n)
    if digit < k:
        return 0
    
    comb = [1]*(k+1)
    for i in range(1,k+1):
        comb[i] = comb[i-1] * (digit-i) //i
    if k==1:
        return 9*comb[1] + int(n[0])
    elif k==2:
        return (9**2)*comb[2] + (int(n[0])-1) * 9*comb[1] + calc(n[1:],1)
    elif k==3:
        return (9**3)*comb[3] + (int(n[0])-1) * (9**2) * comb[2] + calc(n[1:],2)

n=input()
k=int(input())
print(calc(n,k))

Buggy python submission (verdict: Runtime Error):
def calc(n,k):
    digit = len(n)
    comb = [1]*(k+1)
    for i in range(1,k+1):
        comb[i] = comb[i-1] * (digit-i) //i
    if k==1:
        return 9*comb[1] + int(n[0])
    elif k==2:
        return (9**2)*comb[2] + (int(n[0])-1) * 9*(digit-1) + calc(n[1:],1)
    elif k==3:
        return (9**3)*comb[3] + (int(n[0])-1) * (9**2) * comb[2] + calc(n[1:],2)

n=input()
k=int(input())
print(calc(n,k))

Fixed submission:
def calc(n,k):
    while n[0] == '0' and len(n)>1:
        n=n[1:]
    
    digit = len(n)
    if digit < k:
        return 0
    
    comb = [1]*(k+1)
    for i in range(1,k+1):
        comb[i] = comb[i-1] * (digit-i) //i
    if k==1:
        return 9*comb[1] + int(n[0])
    elif k==2:
        return (9**2)*comb[2] + (int(n[0])-1) * 9*comb[1] + calc(n[1:],1)
    elif k==3:
        return (9**3)*comb[3] + (int(n[0])-1) * (9**2) * comb[2] + calc(n[1:],2)

n=input()
k=int(input())
print(calc(n,k))
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
n,k,*a=map(int,open(0).read().split())
a.sort()
comb = 1
ans = 0
for i in range(k,n+1):
    ans += (a[i-1] - a[-i]) * (comb % MOD)
    comb = comb * i // (i-k+1)
    ans = ans%MOD
print(ans)

Fixed submission:
MOD = 10**9 + 7
n,k,*a=map(int,open(0).read().split())
a.sort()
comb = 1
ans = 0
for i in range(k,n+1):
    ans += (a[i-1] - a[-i]) *comb 
    comb = comb * i * pow(i-k+1,MOD-2,MOD) % MOD
    ans = ans%MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
n,k,*a=map(int,open(0).read().split())
a.sort()
comb = 1
ans = 0
for i in range(k,n+1):
    ans += (a[i-1] - a[-i]) * comb
    comb = comb * i // (i-k+1)
    ans = ans%MOD
print(ans)

Fixed submission:
MOD = 10**9 + 7
n,k,*a=map(int,open(0).read().split())
a.sort()
comb = 1
ans = 0
for i in range(k,n+1):
    ans += (a[i-1] - a[-i]) *comb 
    comb = comb * i * pow(i-k+1,MOD-2,MOD) % MOD
    ans = ans%MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

n,m=map(int,input().split())
a=tuple(map(int,input().split()))
a.sort()
lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm,i)
for i in a:
    if (lcm//i)%2 == 0:
        print(0)
        sys.exit()
print((m+lcm//2)//lcm)

Fixed submission:
import sys

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

n,m=map(int,input().split())
a=tuple(map(int,input().split()))

lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm,i)
for i in a:
    if (lcm//i)%2 == 0:
        print(0)
        sys.exit()
print((m+lcm//2)//lcm)

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

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

n,m=map(int,input().split())
a=tuple(map(int,input().split()))

lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm,i)
for i in a:
    if (lcm/i)%2 == 0:
        print(0)
        sys.exit()
print((m+lcm//2)//lcm)

Fixed submission:
import sys

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

n,m=map(int,input().split())
a=tuple(map(int,input().split()))

lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm,i)
for i in a:
    if (lcm//i)%2 == 0:
        print(0)
        sys.exit()
print((m+lcm//2)//lcm)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

a,b=map(int,input().split())
c=gcd(a,b)
ans = 1
div = 2
first_flag=1
while c>1:
    while c%div == 0:
        c /= div
        if first_flag == 1:
            ans += 1
            first_flag = 0 
    div += 1
    first_flag = 1
print(ans)

Fixed submission:
def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

a,b=map(int,input().split())
c=gcd(a,b)
ans = 1
div = 2
first_flag=1
while c>1:
    if  div**2 > c:
        ans +=1
        break
    while c%div == 0:
        c /= div
        if first_flag == 1:
            ans += 1
            first_flag = 0 
    div += 1
    first_flag = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

a,b=map(int,input().split())
c=gcd(a,b)
ans = 1
div = 2
first_flag=1
while c>1:
    while c%div == 0:
        c /= div
        if first_flag == 1:
            ans += 1
            first_flag = 0 
    div = div+1
    first_flag = 1
print(ans)

Fixed submission:
def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

a,b=map(int,input().split())
c=gcd(a,b)
ans = 1
div = 2
first_flag=1
while c>1:
    if  div**2 > c:
        ans +=1
        break
    while c%div == 0:
        c /= div
        if first_flag == 1:
            ans += 1
            first_flag = 0 
    div += 1
    first_flag = 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
edge=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)

score=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    update_n = [p-1]
    while update_n:
        current_n = update_n.pop(0)
        score[current_n] += x
        update_n += edge[current_n]
print(*score)

Fixed submission:
n,q=map(int,input().split())
edge=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)

base_score = [0]*n
for i in range(q):
    p,x=map(int,input().split())
    base_score[p-1] += x
    
score=[0]*n

for i,bs in enumerate(base_score):
    score[i] = bs
    for j in edge[i]:
        base_score[j] += bs

print(*score)
Buggy python submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
ma=max(a)
ma_index=a.index(ma)
for i in range(n):
    if i==ma_index:
        print(*max(a[:i]+a[i+1:]))
    else:
        print(ma)

Fixed submission:
n,*a=map(int,open(0).read().split())
ma=max(a)
ma_index=a.index(ma)
for i in range(n):
    if i==ma_index:
        print(max(a[:i]+a[i+1:]))
    else:
        print(ma)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
set_a=set(a)
if len(set_a)==3:
    set_a = list(set_a)
    num0 = a.count(set_a[0])
    num1 = a.count(set_a[1])
    num2 = a.count(set_a[2])
    if (set_a[0]^set_a[1]^set_a[2]==0) and (num0==num2) and (num1==num2):
        print('Yes')
    else:
        print('No')
elif len(set_a)==2:
    num0 = a.count(set_a[0])
    num1 = a.count(set_a[1])
    if (0 in set_a) and (num0==num1):
        print('Yes')
    else:
        print('No')
elif len(set_a)==1:
    if 0 in a:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
set_a=set(a)
if len(set_a)==3:
    set_a = list(set_a)
    num0 = a.count(set_a[0])
    num1 = a.count(set_a[1])
    num2 = a.count(set_a[2])
    if (set_a[0]^set_a[1]^set_a[2]==0) and (num0==num2) and (num1==num2):
        print('Yes')
    else:
        print('No')
elif len(set_a)==2:
    set_a = list(set_a)
    num0 = a.count(set_a[0])
    num1 = a.count(set_a[1])
    if (set_a[0]==0 and num1 == num0*2)or(set_a[1]==0 and num0==num1*2):
        print('Yes')
    else:
        print('No')
elif len(set_a)==1:
    if 0 in set_a:
        print('Yes')
    else:
        print('No')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import math
def c_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,k=map(int,input().split())
for i in range(1,k+1):
    print((c_count(n-k+1,i)%(10**9+7)) * (c_count(k-1,i-1)%(10**9+7)))

Fixed submission:
import math
def c_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,k=map(int,input().split())
for i in range(1,k+1):
    if i <= n-k+1:
        print(((c_count(n-k+1,i)%(10**9+7)) * (c_count(k-1,i-1)%(10**9+7)))%(10**9+7))
    else:
        print(0)