Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02642 (python)

Fixed submission:
n = int(input())
aL = sorted(list(map(int, input().split(" "))))
# aL = sorted(list(set(aLP)))

dp = [False for _ in range(1000001)]

d = {}
for a in aL:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans = 0
for a in aL:
    if dp[a]:
        continue
    if d[a] > 1:
        c = 1
        while a * c <= 1000000:
            dp[a * c] = True
            c += 1
        continue
    ans += 1

    c = 1
    while a * c <= 1000000:
        dp[a * c] = True
        c += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
aL = sorted(list(set(list(map(int, input().split(" "))))))

dp = [False for _ in range(100001)]

if len(aL) == 1 and n != 1:
    print(0)
    exit()

ans = 0
for a in aL:
    if not dp[a]:
        ans += 1
    else:
        continue
    c = 1
    while a * c <= 100000:
        dp[a * c] = True
        c += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
aL = sorted(list(map(int, input().split(" "))))

dp = [False for _ in range(100001)]

if len(aL) == 1 and n != 1:
    print(0)
    exit()

ans = 0
for a in aL:
    if not dp[a]:
        ans += 1
    c = 1
    while a * c <= 100000:
        dp[a * c] = True
        c += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
aL = sorted(list(set(list(map(int, input().split(" "))))))

dp = [False for _ in range(200000)]

if len(aL) == 1 and n != 1:
    print(0)
    exit()

ans = 0
for a in aL:
    if not dp[a]:
        ans += 1
    c = 1
    while a * c <= 100000:
        dp[a * c] = True
        c += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
aL = sorted(list(set(list(map(int, input().split(" "))))))

dp = [False for _ in range(200002)]

if len(aL) == 1 and n != 1:
    print(0)
    exit()

ans = 0
for a in aL:
    if not dp[a]:
        ans += 1
    c = 1
    while a * c <= 200000:
        dp[a * c] = True
        c += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
aL = sorted(list(set(list(map(int, input().split(" "))))))

dp = [False for _ in range(100002)]

if len(aL) == 1 and n != 1:
    print(0)
    exit()

ans = 0
for a in aL:
    if not dp[a]:
        ans += 1
    c = 1
    while a * c <= 100000:
        dp[a * c] = True
        c += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
aL = sorted(list(set(list(map(int, input().split(" "))))))

dp = [False for _ in range(100001)]

if len(aL) == 1 and n != 1:
    print(0)
    exit()

ans = 0
for a in aL:
    if not dp[a]:
        ans += 1
    c = 1
    while a * c <= 100000:
        dp[a * c] = True
        c += 1

print(ans)
Problem p02684 (python)

Fixed submission:
import math

n, k = map(int, input().split(" "))
li = list(map(int, input().split(" ")))

fk = k
crnt = 1
st = set()
wl = []
key = crnt
cy = 0
mg = 0

for i in range(n):
    if crnt in st:
        key = crnt
        cy = i - wl.index(crnt)
        mg = wl.index(crnt)
        break
    st.add(crnt)
    wl.append(crnt)
    crnt = li[crnt - 1]

k -= mg
if cy != 0:
    k %= cy
crnt = key
if n > fk:
    k = fk
    crnt = 1
for i in range(k):
    crnt = li[crnt - 1]

print(crnt)

Buggy submission (verdict: Runtime Error):
import math

n, k = map(int, input().split(" "))
aL = list(map(int, input().split(" ")))
aFL = [False for _ in range(n)]

crnt = 1
cnt1 = 0
while True:
    if aFL[crnt - 1]:
        break
    cnt1 += 1
    aFL[crnt - 1] = True
    crnt = aL[crnt - 1]

wCrnt = crnt
cnt2 = 0
while True:
    crnt = aL[crnt - 1]
    cnt2 += 1
    if crnt == wCrnt:
        break

gp = cnt1 - cnt2

cr = crnt
for i in range((k - gp) % n):
    cr = aL[cr]

print(aL[aL[cr - 1]])

Buggy submission (verdict: Runtime Error):
import math

n, k = map(int, input().split(" "))
aL = list(map(int, input().split(" ")))
aFL = [False for _ in range(n)]

crnt = 1
cnt1 = 0
while True:
    if aFL[crnt - 1]:
        break
    cnt1 += 1
    aFL[crnt - 1] = True
    crnt = aL[crnt - 1]

wCrnt = crnt
cnt2 = 0
while True:
    crnt = aL[crnt - 1]
    cnt2 += 1
    if crnt == wCrnt:
        break

gp = cnt1 - cnt2

cr = wCrnt
for i in range((k - gp) % n):
    cr = aL[cr]

print(aL[cr])

Buggy submission (verdict: Runtime Error):
import math

n, k = map(int, input().split(" "))
aL = list(map(int, input().split(" ")))
aFL = [False for _ in range(n)]

crnt = 1
cnt1 = 0
while True:
    if aFL[crnt - 1]:
        break
    cnt1 += 1
    aFL[crnt - 1] = True
    crnt = aL[crnt - 1]

wCrnt = crnt
cnt2 = 0
while True:
    crnt = aL[crnt - 1]
    cnt2 += 1
    if crnt == wCrnt:
        break

gp = cnt1 - cnt2

cr = aL[0] - 1
for i in range((k - gp) % n):
    cr = aL[cr - 1]

print(aL[cr])
Problem p02720 (python)

Fixed submission:
import math

k = int(input())

l = [1, 2, 3, 4, 5, 6, 7, 8, 9]

c = 0
while k > len(l):
    f = l[c] - (l[c] // 10 * 10)

    if f != 0:
        l.append(l[c] * 10 + f - 1)

    l.append(l[c] * 10 + f)

    if f != 9:
        l.append(l[c] * 10 + f + 1)

    c += 1

print(l[k - 1])

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

arr = []
for i in range(10000):
    si = str(i + 1)
    for i2 in range(len(si) - 1):
        if abs(int(si[i2]) - int(si[i2 + 1])) >= 2:
            break
    else:
        arr.append(si)

print(arr[n - 1])
Problem p02743 (python)

Fixed submission:
a, b, c = map(int, input().split(" "))

if c - a - b > 0 and 4 * a * b < (c - a - b)**2:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import math
from decimal import *

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

print("Yes" Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt if else "No")

Buggy submission (verdict: Runtime Error):
import sympy

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

print("Yes" if (sympy.sqrt(a) + sympy.sqrt(b)) < sympy.sqrt(c) else "No")

Buggy submission (verdict: Runtime Error):
import sympy

a, b, c = list(map(Decimal, input().split(" ")))

print("Yes" if (sympy.sqrt(a) + sympy.sqrt(b)) < sympy.sqrt(c) else "No")
Problem p02756 (python)

Fixed submission:
import math

s = input()
i = int(input())

isR = False
head = []
tail = []

for _ in range(i):
    q = input().split(" ")

    if q[0] == "1":
        isR = not isR
    else:
        if isR:
            if q[1] == "1":
                tail.append(q[2])
            else:
                head.append(q[2])
        else:
            if q[1] == "1":
                head.append(q[2])
            else:
                tail.append(q[2])

ans = "".join(head[::-1]) + s + "".join(tail)

if isR:
    print(ans[::-1])
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
 import math

s = input()
i = int(input())

isR = False
for _ in range(i):
    q = input().split(" ")

    if q[0] == "1":
        isR = not isR
    else:
        if isR:
            if q[1] == "1":
                s = s + q[2]
            else:
                s = q[2] + s
        else:
            if q[1] == "1":
                s = q[2] + s
            else:
                s = s + q[2]

if isR:
    print(s[::-1])
else:
    print(s)
Problem p02761 (python)

Fixed submission:
import math

n, m = map(int, input().split(" "))

ans = list([0 for _ in range(n)])

err = False
for i in range(m):
    s, c = map(int, input().split(" "))
    if s == 1 and c == 0:
        if n == 1:
            print(0)
            exit()
        err = True
    elif ans[s - 1] == 0:
        ans[s - 1] = c
    elif not ans[s - 1] == c:
        err = True

if ans[0] == 0:
    ans[0] = 1

if (n == 1 and ans[0] == 0) or (n == 1 and m == 0):
    print(0)
    exit()

if err:
    print(-1)
    exit()

print("".join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
import sys

n, m = list(map(int, input().split()))
ar = [list(map(int, input().split())) for _ in range(m)]
ans = [0 for _ in range(n)]

for a in ar:
    if a[0] == 1 and a[1] == 0:
        print(-1)
        sys.exit()
    if ans[a[0] - 1] != 0 and ans[a[0] - 1] != a[1]:
        print(-1)
        sys.exit()
    ans[a[0] - 1] = a[1]

if ans[0] == 0:
    if ans[1] == 0:
        ans[1] = 1
    ans[0] = 1

ans = int("".join(map(str, ans)))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

n, m = list(map(int, input().split()))
ar = [list(map(int, input().split())) for _ in range(m)]
ans = [0 for _ in range(n)]

for a in ar:
    if ans[a[0] - 1] != 0 and ans[a[0] - 1] != a[1]:
        print(-1)
        sys.exit()
    ans[a[0] - 1] = a[1]

if ans[0] == 0:
    if ans[1] == 0:
        ans[1] = 1
    ans[0] = 1

ans = int("".join(map(str, ans)))
print(ans)
Problem p02995 (python)

Fixed submission:
from fractions import gcd

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


def lcm(x, y):
    return (x * y) // gcd(x, y)


def sj(base, i1, i2):
    cz = base // i1
    dz = base // i2
    cd = base // lcm(i1, i2)
    return base - (cz + dz - cd)


print(sj(b, c, d) - sj(a - 1, c, d))

Buggy submission (verdict: Runtime Error):
import math

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


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def sj(base, i1, i2):
    cz = base // i1
    dz = base // i2
    cd = base // lcm(i1, i2)
    return base - (cz + dz - cd)


print(sj(b, c, d) - sj(a - 1, c, d))
Problem p02928 (python)

Fixed submission:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
cnt2 = 0
for i, ai in enumerate(a):
    for j in range(i, n):
        if ai > a[j]:
            cnt += 1
    if i > 0:
        for j in range(i):
            if ai > a[j]:
                cnt2 += 1

if k % 2 == 0:
    mul = (1 + k) * (k // 2)
else:
    mul = (1 + k) * (k // 2) + (k // 2 + 1)
mul2 = 0
if k > 1:
    k -= 1
    if k % 2 == 0:
        mul2 = (1 + k) * (k // 2)
    else:
        mul2 = (1 + k) * (k // 2) + (k // 2 + 1)
print(((cnt * mul) + (cnt2 * mul2)) % 1000000007)

Buggy submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
cnt2 = 0
for i, ai in enumerate(a):
    for j in range(i, n):
        if ai > a[j]:
            cnt += 1
    if i > 0:
        for j in range(i):
            if ai > a[j]:
                cnt2 += 1

if k % 2 == 0:
    mul = (1 + k) * (k // 2)
else:
    mul = (1 + k) * (k // 2) + (k // 2 + 1)
if k > 1:
    k -= 1
    if k % 2 == 0:
        mul2 = (1 + k) * (k // 2)
    else:
        mul2 = (1 + k) * (k // 2) + (k // 2 + 1)
print(((cnt * mul) + (cnt2 * mul2)) % 1000000007)
Problem p03076 (python)

Fixed submission:
x = []
for _ in range(5):
    x.append(int(input()))
t = 0
wt = []
for a in x:
    t += a
    m = a % 10
    if m > 0:
      wt.append(10-m)
if len(wt) > 1:
    wt.sort()
    wt.pop()
    for x in wt:
        t += x
print(t)

Buggy submission (verdict: Runtime Error):
x = []
for _ in range(5):
    x.append(int(input()))
t = 0
wt = []
for a in x:
    t += a
    m = a % 10
    if m > 0:
      wt.append(10-m)
wt.sort()
wt.pop()
for x in wt:
    t += x
print(t)
Problem p02720 (python)

Fixed submission:
K = int(input())
lun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
cnt = 0

while(len(lun) < K):
  target = lun[cnt]
  num = target % 10
  if num != 0:
      lun.append(target * 10 + num - 1)
  lun.append(target * 10 + num)
  if num != 9:
      lun.append(target * 10 + num + 1)
  cnt += 1

print(lun[K-1])

Buggy submission (verdict: Runtime Error):
K = int(input())
lun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
cnt = 0

while(len(lun) < K):
  target = lun[cnt]
  num = target % 10
  print(lun,target,num)
  if num != 0:
      lun.append(target * 10 + num - 1)
  lun.append(target * 10 + num)
  if num != 9:
      lun.append(target * 10 + num + 1)
  cnt += 1

print(lun[K-1])
Problem p02748 (python)

Fixed submission:
def main():
    A,B,M = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x = [list(map(int,input().split())) for _ in range(M)]

    ans = min(a)+min(b)
    for i1,i2,discount in x:
        sum = a[i1-1]+b[i2-1]-discount
        ans = min(ans,sum)

    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(10**9)

    A,B,M = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x = [list(map(int,input().split())) for _ in range(M)]

    ans = min(a)+min(b)
    for i1,i2,discount in x:
        sum = a[i1-1]+a[i2-1]-discount
        ans = min(ans,sum)

    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [list(map(int,input().split())) for _ in range(M)]

ans = min(a)+min(b)
for i1,i2,discount in x:
    sum = a[i1-1]+a[i2-1]-discount
    ans = min(ans,sum)

print(ans)

Buggy submission (verdict: Runtime Error):
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [list(map(int,input().split())) for _ in range(M)]

ans = min(a)+min(b)
for i1,i2,discount in x:
    sum = a[i1-1]+a[i2-1]-discount
    ans = min(ans,sum)

print(ans)
Problem p02756 (python)

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    s = input()
    s = s[0:len(s)-1]
    Q = int(input())
    head = []
    tail = []

    flg = 0 # 0:sonomama 1:gyakuten
    for _ in range(Q):
        q = input().split()
        if q[0] == "1":
            if flg == 0:
                flg = 1
            else:
                flg = 0
        elif q[0]=="2":
            index,tmp = q[1],q[2]
            if (index == "1" and flg ==0) or (index == "2" and flg ==1):
                head.append(tmp)
            elif (index == "2" and flg == 0) or (index == "1" and flg == 1):
                tail.append(tmp)

    s1 = "".join(head)
    s1 = s1[::-1]
    s2 = "".join(tail)
    ans = s1 + s + s2
    if flg == 1:
        ans = ans[::-1]

    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    s = input()
    s = s[0:len(s)-1]
    Q = int(input())
    lq = [input().split() for _ in range(Q)]

    flg = 0 # 0:sonomama 1:gyakuten
    for q in lq:
        if q[0] == "1":
            if flg == 0:
                flg = 1
            else:
                flg = 0
        elif q[0]=="2":
            if (q[1] == "1" and flg ==0) or (q[1] == "2" and flg ==1):
                q[2] += s
                s = q[2]
            elif (q[1] == "2" and flg == 0) or (q[1] == "1" and flg == 1):
                s += q[2]

    if flg==1:
        s = s[::-1]
    print(s)

if __name__ == '__main__':
    main()
Problem p02780 (python)

Fixed submission:
import itertools 
N,K =list(map(int,input().split()))
p =list(map(int,input().split()))
E = [0] * N

for i in range(N):
  E[i]=(p[i]+1)/2
acc = [0]
acc += list(itertools.accumulate(E))

ans = 0
for i in range(N-K+1):
  ans = max(acc[i+K] - acc[i], ans)

print(ans)

Buggy submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
E = [0]*N

for i in range(N):
  E[i] = (p[i]+1)/2
  

for i in range(N-2):
  if i == 0:
    ans = sum(E[i:i+K])
  else:
    ans = max(ans,sum(E[i:i+K]))
print(ans)
Problem p02802 (python)

Fixed submission:
N,M = list(map(int,input().split()))

lac = [0]*(N+1)
lpcnt = [0]*(N+1)

for i in range(M):
  s = input().split()
  n = int(s[0])
  if s[1] == "AC":
    lac[n] =1
    continue
  if s[1] == "WA" and lac[n] == 0:
    lpcnt[n] += 1

cnt = 0
for i in range(N+1):
  if lac[i] == 1:
    cnt += lpcnt[i]
  
print(sum(lac), end=" ")
print(cnt)

Buggy submission (verdict: Runtime Error):
s = input().rstrip().split()
N,M = int(s[0]),int(s[1])

a=[]
for i in range(M):
  a.append(input().rstrip().split())

pen =0
AClist =[]
ACflag= [0]*N
#print(a,len(a))

for i in range(len(a)):
  if a[i][1] == "AC" and ACflag[int(a[i][0])] == 0:
    AClist.append(a[i])
    ACflag[int(a[i][0])] = 1
  if a[i][1] == "WA" and ACflag[int(a[i][0])] == 0:
    pen += 1

print(len(AClist),pen)
Problem p02811 (python)

Fixed submission:
s = input().rstrip().split()
K,X =int(s[0]),int(s[1])
if K*500>=X:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
K,X =int(input()),int(input())
if K*500>=X:
  print("Yes")
else:
  print("No")
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500*500)


N = int(input())
edges = [list(map(int,input().split())) for _ in range(N-1)]
A = [[] for _ in range(N+1)]

for edge in edges:
  A[edge[0]].append([edge[1],edge[2]])
  A[edge[1]].append([edge[0],edge[2]])
  
depth = [-1] * (N+1)
depth[1] = 0

def dfs(A,s):
  for v in A[s]:
    if depth[v[0]] == -1:
      depth[v[0]] = depth[s] + v[1]
      dfs(A,v[0])
      
dfs(A,1)

for d in depth[1:]:
  if d % 2 == 0:
    print(0)
  else:
    print(1)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
edges = [list(map(int,input().split())) for _ in range(N-1)]
A = [[] for _ in range(N+1)]

for edge in edges:
  A[edge[0]].append([edge[1],edge[2]])
  A[edge[1]].append([edge[0],edge[2]])
  
depth = [-1] * (N+1)
depth[1] = 0

def dfs(A,s):
  for v in A[s]:
    if depth[v[0]] == -1:
      depth[v[0]] = depth[s] + v[1]
      dfs(A,v[0])
      
dfs(A,1)

for d in depth[1:]:
  if d % 2 == 0:
    print(0)
  else:
    print(1)
Problem p02678 (python)

Fixed submission:
n, m = map(int, input().split())

edges = [ [] for _ in range(n) ]

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

INF = 10 ** 6

def dijkstra_travel(edges):
    dists = [ INF  for _ in range(n) ]
    paths = [ None for _ in range(n) ]

    dists[0] = 0
    paths[0] = 0

    next_travel = [ 0 ]

    def travel_adjacent():
        n = next_travel.pop(0)

        adjacent_nodes = list(
            map(
                lambda node: (node, paths[node]),
                edges[n],
            )
        )

        for node, path in adjacent_nodes:
            if path is None or dists[node] > dists[n] + 1:
                dists[node] = dists[n] + 1
                paths[node] = n
                next_travel.append(node)


    while len(next_travel) > 0:
        travel_adjacent()

    return paths[1:]

result = dijkstra_travel(edges)

if all(map(lambda x: x is not None, result)):
    print('Yes')

    for x in result:
        print(x + 1)

else:
    print('No')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

edges = [ [] for _ in range(n) ]

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

INF = 10 ** 6

def dijkstra_travel(edges):
    dists = [ INF  for _ in range(n) ]
    paths = [ None for _ in range(n) ]

    dists[0] = 0
    paths[0] = 0

    def travel_adjacent(n):
        adjacent_nodes = list(
            map(
                lambda node: (node, paths[node]),
                edges[n],
            )
        )

        next_travel = []

        for node, path in adjacent_nodes:
            if path is None or dists[node] > dists[n] + 1:
                dists[node] = dists[n] + 1
                paths[node] = n
                next_travel.append(node)

        for x in next_travel:
            travel_adjacent(x)

    travel_adjacent(0)

    return paths[1:]

result = dijkstra_travel(edges)

if all(map(lambda x: x is not None, result)):
    print('Yes')

    for x in result:
        print(x + 1)

else:
    print('No')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

edges = [ [] for _ in range(n) ]

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

INF = 10 ** 10

def dijkstra_travel(edges):
    paths = [ None for _ in range(n) ]
    paths[0] = 0

    def travel_adjacent(n):
        adjacent_nodes = list(
            map(
                lambda x: paths[x],
                edges[n],
            )
        )

        next_travel = []

        for i, node in enumerate(adjacent_nodes):
            if node is None:
                paths[edges[n][i]] = n
                next_travel.append(edges[n][i])

        for x in next_travel:
            travel_adjacent(x)

    travel_adjacent(0)

    return paths[1:]

result = dijkstra_travel(edges)

if all(map(lambda x: x is not None, result)):
    print('Yes')

    for x in result:
        print(x + 1)

else:
    print('No')
Problem p02786 (python)

Fixed submission:
from math import log2

n = int(log2(int(input())))

print(2 ** (n + 1) - 1)

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

print(2 ** (n + 1) - 1)
Problem p02936 (python)

Fixed submission:
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

N, Q = map(int, input().split())

graph   = [ [] for _ in range(N) ]
queries = { p: 0 for p in range(N) }

for _ in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())

    queries[p - 1] += x

answer = [ 0 ] * N

def dfs(p, p_before, acc):
    acc += queries[p]

    answer[p] = acc

    for child in graph[p]:
        if child == p_before:
            continue

        dfs(child, p, acc)

dfs(0, -1, 0)

print(*answer)

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

N, Q = map(int, input().split())

graph   = [ [] for _ in range(N) ]
queries = { p: 0 for p in range(N) }

for _ in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())

    queries[p - 1] += x

answer = [ 0 ] * N

def dfs(p, p_before, acc):
    acc += queries[p]

    answer[p] = acc

    for child in graph[p]:
        if child == p_before:
            continue

        dfs(child, acc)

dfs(0, -1, 0)

print(*answer)
Problem p03044 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def dfs(v, p, c):
    color[v] = c
    for e in graph[v]:
        if e[0] == p: continue
        if e[1] % 2: dfs(e[0], v, 1-c)
        else: dfs(e[0], v, c)


n = int(input())
color = [-1 for _ in range(n)]
graph = [[] for _ in range(n)]

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

dfs(0, -1, 1)
for i in range(n):
    print(color[i])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def dfs(v, p, c):
    color[v] = c
    for e in graph[v]:
        if e[0] == p: continue
        if e[1] % 2: dfs(e[0], v, 1-c)
        else: dfs(e[0], v, c)


n = int(input())
color = [-1 for _ in range(n)]
graph = [[] for _ in range(n)]

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

dfs(0, -1, 1)
for i in range(n):
    print(color[i])

Buggy submission (verdict: Runtime Error):
def dfs(v, p, c):
    color[v] = c
    for e in graph[v]:
        if e[0] == p: continue
        if e[1] % 2: dfs(e[0], v, 1-c)
        else: dfs(e[0], v, c)
    return


n = int(input())
color = [-1 for _ in range(n)]
graph = [[] for _ in range(n)]

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

dfs(0, -1, 1)
for i in range(n):
    print(color[i])
Problem p03523 (python)

Fixed submission:
l = []
a = 'AKIHABARA'

def rec(s, i):
    if i == len(a):
        l.append(s)
        return
    if a[i] == 'A':
        rec(s, i+1)
    rec(s + a[i], i+1)

rec('', 0)
print("YES" if input() in l else "NO")

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    regex re("^A?KIHA?BA?RA?$");
    cout << (regex_match(s, re) ? "YES\n" : "NO\n");
    return 0;
}