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

Fixed submission:
x, y =  map(int, input().split())

max_num = 4 * x
min_num = 2 * x

if y % 2 == 1:
    print('No')
elif (min_num <= y) and (max_num >= y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
x, y = int(input().split())

max_num = 4 * x
min_num = 2 * x

if y % 2 == 1:
    print('No')
elif (min_num <= y) and (max_num >= y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
x, y = input().split()

max_num = 4 * x
min_num = 2 * x

if y % 2 == 1:
    print('No')
elif (min_num <= y) and (max_num >= y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
x, y = input().split()

if y % 2 == 1:
    print('No')

max_num = 4 * x
min_num = 2 * x

if (min_num <= y) and (max_num >= y):
    print('Yes')
else:
    print('No')
Problem p02641 (python)

Fixed submission:
import numpy as np
x, n = map(int, input().split())
num_list = list(map(int,input().split()))
num_list = sorted(num_list)
num_100 = list(range(-100, 102))

if n ==0:
    print(x)
else:
 for num in num_list:
     num_100.remove(num)

 numbers1 = np.array(num_100)
 numbers2 = numbers1 - x
 numbers3 = np.abs(numbers2)
 min_index = numbers3.argmin()
 print(numbers1[min_index])

Buggy submission (verdict: Runtime Error):
import numpy as np
x, n = map(int, input().split())
num_list = list(map(int,input().split()))
num_list = sorted(num_list)
num_100 = list(range(1, 101))

for num in num_list:
    numbers = num_100.remove(num)

numbers1 = np.array(numbers)
numbers2 = numbers - x
numbers3 = np.abs(numbers)
min_index = numbers.argmin()
print(numbers1[min_index])

Buggy submission (verdict: Runtime Error):
import numpy as np
x, n = map(int, input().split())
num_list = list(map(int,input().split()))
num_100 = list(range(1, 101))

for num in num_list:
    numbers = num_100.remove(num)

numbers1 = np.array(numbers)
numbers2 = numbers - x
numbers3 = np.abs(numbers)
min_index = numbers.argmin()
print(numbers1[min_index])
Problem p02657 (python)

Fixed submission:
a, b = (int(x) for x in input().split())
print(a * b)

Buggy submission (verdict: Runtime Error):
a, b = int(input().split())
print(a * b)

Buggy submission (verdict: Runtime Error):
a, b = int(input())
print(a *b)

Buggy submission (verdict: Runtime Error):
print(a * b)

Buggy submission (verdict: Runtime Error):
int(A * B)

Buggy submission (verdict: Runtime Error):
A * B
Problem p02658 (python)

Fixed submission:
N = int(input())
A = map(int, input().split())
 
res = 1
 
for a in sorted(A):
    res *= a
    if res > 10 ** 18:
        print("-1")
        exit()
print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = input().split()
a_int = [int(n) for n in a]
ans = 1
for num in a_int:
    if ans !> 10**18:
        ans *= num
    else:
        print(-1)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
a = input().split()
b = 1
for num in range(n):
  b = b * a[num]
if b > 10**18:
  b = -1
print(b)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
a = input().split()
b = 1
for num in a:
  b = b * num
if b > 10**18:
  b = -1
print(b)
Problem p02687 (python)

Fixed submission:
s = str(input())
if s == 'ABC':
  print('ARC')
else:
  print('ABC')

Buggy submission (verdict: Runtime Error):
s = str(input())
if s == 'ABC':
  print('ARC)
else:
  print('ABC')
Problem p02765 (python)

Fixed submission:
N, R = map(int, input().split())
if N >= 10:
  I = R
  print(I)
else:
  I = R+100*(10-N)
  print(I)

Buggy submission (verdict: Runtime Error):
N, R = map(int, input().split())
if N >= 10:
  I == R
  print(I)
else:
  I = R+100*(10-N)
  print(I)
Problem p02630 (python)

Fixed submission:
import collections
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
a = [int(s) for s in data[1].split()]
q = int(data[2].split()[0])

sum = sum(a)

l = []
for i in range(q):
    l.append(int(data[i+3].split()[0]))
    l.append(int(data[i+3].split()[1]))

d = collections.Counter(a)

for i in range(q):
    sum += (l[2*i+1]-l[2*i]) * d[l[2*i]]
    d[l[2*i+1]] += d[l[2*i]]
    d[l[2*i]] = 0
    print(sum)

Buggy submission (verdict: Runtime Error):
"""
input.txt

2
1 2
3
1 100
2 100
100 1000

"""

from sys import stdin
data = stdin.readlines()

n = int(data[0])
a = [int(s) for s in data[1].split()]
q = int(data[2])

i = 1
l = []
while i <= q:
    l.append(int(data[i+2].split()[0]))
    l.append(int(data[i+2].split()[1]))
    i += 1

dic = {}
for s in range(1,10**5):
    tmp = {s: a.count(s)}
    dic.update(tmp)

s = sum(a)
i = 1
while i <= q:
    s = s + (l[2*i-1]-l[2*i-2]) * dic[l[2*i-2]]
    print(s)
    dic[l[2*i-1]] += dic[l[2*i-2]]
    dic[l[2*i-2]] = 0
    i += 1
Problem p02639 (python)

Fixed submission:
from sys import stdin
data = stdin.readline().rstrip()


b = [int(s) for s in data.split()]
print(b.index(0)+1)

Buggy submission (verdict: Runtime Error):
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
a = [int(s) for s in data[1].split()]
a = sorted(a)

max = a[-1]

l = [0]*(max+1)

for i in a:
    l[i] += 1
    if l[i] == 1:
        for j in range(i*2,max+1,i):
            l[j] = 2
print(l.count(1))
Problem p02657 (python)

Fixed submission:
from sys import stdin
data = stdin.readline().rstrip()

a = int(data.split()[0])
b = int(data.split()[1])

print(a * b)

Buggy submission (verdict: Runtime Error):
from sys import stdin
data = stdin.readlines()

a = int(data[0])
b = [int(s) for s in data[1].split()]

i = 0
ans = 1
while i <= a-1:
    ans = ans * b[i]
    i += 1
if ans > 10 ** 18:
    ans = -1

print(ans)
Problem p02678 (python)

Fixed submission:
def function():
    N,M = map(int, input().split())
    paths = []
    for _ in range(N+1):
        paths.append([])
    
    for _m in range(M):
        A,B = map(int, input().split())
        paths[A].append(B)
        paths[B].append(A)
    
    dist = [-1]*(N+1)
    dist[1] = 0
    pre = [-1]*(N+1)
    q = [1] # 1からスタート
    while len(q) != 0:
        i = q.pop(0)
        for ne in paths[i]:
            if dist[ne] == -1:
                dist[ne] = dist[i]+1
                pre[ne] = i
                q.append(ne)
    #print(dist)
    print('Yes')
    pre.pop(0)
    pre.pop(0)
    for d in pre:
        print(d)

if __name__ == '__main__':
    function()

Buggy submission (verdict: Runtime Error):
def function():
    N,M = map(int, input().split())
    paths = []
    for _m in range(M+1):
        paths.append([])    
    
    for _m in range(M):
        A,B = map(int, input().split())
        paths[A].append(B)
        paths[B].append(A)
    
    dist = [-1]*(N+1)
    dist[1] = 0
    pre = [-1]*(N+1)
    q = [1] # 1からスタート
    while len(q) != 0:
        i = q.pop(0)
        for ne in paths[i]:
            if dist[ne] == -1:
                dist[ne] = dist[i]+1
                pre[ne] = i
                q.append(ne)
    #print(dist)
    print('Yes')
    pre.pop(0)
    pre.pop(0)
    for d in pre:
        print(d)

if __name__ == '__main__':
    function()

Buggy submission (verdict: Runtime Error):
def function():
    N,M = map(int, input().split())
    paths = []
    for _m in range(M+1):
        paths.append([])    
    
    for _m in range(M):
        A,B = map(int, input().split())
        paths[A].append(B)
        paths[B].append(A)
    
    dist = [-1]*(N+1)
    dist[1] = 0
    pre = [-1]*(N+1)
    q = [1] # 1からスタート
    while len(q) != 0:
        i = q.pop()
        for ne in paths[i]:
            if dist[ne] == -1:
                dist[ne] = dist[i]+1
                pre[ne] = i
                q.append(ne)
    #print(dist)
    print('Yes')
    pre.pop(0)
    pre.pop(0)
    for d in pre:
        print(d)

if __name__ == '__main__':
    function()

Buggy submission (verdict: Runtime Error):
def function():
    N,M = map(int, input().split())
    paths = []
    for _m in range(M+1):
        paths.append([])    
    
    for _m in range(M):
        A,B = map(int, input().split())
        paths[A].append(B)
        paths[B].append(A)
    
    dist = [-1]*(N+1)
    dist[1] = 0
    pre = [-1]*(N+1)
    q = [1] # 1からスタート
    while len(q) != 0:
        i = q.pop()
        for ne in paths[i]:
            if dist[ne] == -1:
                dist[ne] = dist[i]+1
                pre[ne] = i
                q.append(ne)
    #print(dist)
    print('Yes')
    pre.pop()
    pre.pop()
    for d in pre:
        print(d)

if __name__ == '__main__':
    function()
Problem p02684 (python)

Fixed submission:
def function():
    _N,K = map(int, input().split())
    teleportes = list(map(int, input().split()))

    # ループを見つける
    i,count = 0,0
    visited = [-1] * len(teleportes) # 訪れた街にチェック
    while True :
        if visited[i] == -1: # 最初に訪れた
            visited[i] = count # 何番目に訪れたかを記録
            i = teleportes[i] - 1
            count += 1
        else:
            loops = count - visited[i] # 以前訪れてから何回旅したか
            break
    
    if K <= visited[i]:
        i = 0
    else:
        K -= visited[i]
        K %= loops
    for _k in range(K):
        i = teleportes[i] - 1
    print(i+1)

if __name__ == '__main__':
    function()

Buggy submission (verdict: Runtime Error):
def function(arg1, arg2):
    N,K = map(int, arg1.split())
    teleportes = list(map(int, arg2.split()))
    checked = [0] * len(teleportes) # 訪れた街にチェック

    i = 0
    c = 1
    while True :
        nextTerminal = teleportes[i] - 1
        if checked[i] == 0:
            checked[i] = c # 何番目に訪れたか
            i = nextTerminal
            c += 1
        else:
            loops = c - checked[i] # 以前訪れてから何回旅したか
            
            break
    
    if K <= i:
        goal = teleportes[K]
    else:
        k = 0
        nextTerminal = 0
        while k in range((K-i)%loops + i):
            nextTerminal = teleportes[nextTerminal] - 1
            goal = nextTerminal + 1
            k+=1
    return str(goal)

if __name__ == '__main__':
    print(function(input(),input()))
Problem p02742 (python)

Fixed submission:
h,w=map(int,input().split())
if h == 1 or w == 1:
  print(1)
else:
  div,mod=divmod(h*w,2)
  print(div+mod)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
div,mod=divmod(h*w)
print(div+mod)
Problem p02988 (python)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  pre=p[i-1]
  cur=p[i]
  nex=p[i+1]
  if (pre<cur and cur<nex) or(pre>cur and cur>nex):
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=list(map(int,input()))
ans=0
for i in range(1,n-1):
  pre=p[i-1]
  cur=p[i]
  nex=p[i+1]
  if (pre<cur and cur<nex) or(pre>cur and cur>nex):
    ans+=1
print(ans)
Problem p03160 (python)

Fixed submission:
N=int(input())
h=list(map(int,input().split()))
DP=[0]*N
DP[0]=0
DP[1]=abs(h[1]-h[0])+DP[0]
i=2
while i<N:
  DP[i]=min(abs(h[i]-h[i-1])+DP[i-1],abs(h[i]-h[i-2])+DP[i-2])
  i+=1
print(DP[-1])

Buggy submission (verdict: Runtime Error):
def main():
  n=int(input())
  dp=[[0,0,0]]
  for i in range(1,n+1):
    a,b,c=map(int,input().split())
    dp.append([
      dp[i-1][0]+max(b,c),
      dp[i-1][1]+max(a,c),
      dp[i-1][2]+max(a,b)
    ]
  print(max(dp[n]))
Problem p03162 (python)

Fixed submission:
def main():
  n=int(input())
  dp=[[0,0,0]]
  for i in range(1,n+1):
    a,b,c=map(int,input().split())
    dp.append([max(dp[i-1][1],dp[i-1][2])+a,max(dp[i-1][0],dp[i-1][2])+b,max(dp[i-1][0],dp[i-1][1])+c])
    #print(dp)
  print(max(dp[n]))
if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  n=int(input())
  dp=[[0,0,0]]
  for i in range(1,n+1):
    a,b,c=map(int,input().split())
    dp.append([
      dp[i-1][0]+max(b,c),
      dp[i-1][1]+max(a,c),
      dp[i-1][2]+max(a,b)
    ]
  print(max(dp[n]))
Problem p03400 (python)

Fixed submission:
import math
N=int(input())
D,X=map(int,input().split())
choco=[0]*D
ans=0
for _ in range(N):
  A=int(input())
  ans+=math.ceil(D/A)
print(ans+X)

Buggy submission (verdict: Runtime Error):
5
30 44
26
18
81
18
6
Problem p02628 (python)

Fixed submission:
n, k = map(int, input().split())
p = sorted(list(map(int, input().split())))
ans = 0
for i in range(k):
    ans += p[i]
print(ans)

Buggy submission (verdict: Runtime Error):
1 1
1000
Problem p02641 (python)

Fixed submission:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            if i == -1000:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)

Buggy submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            print(i)
            if i == -100:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
now = 1
chk = [0] * n
flg = True
count = 0
if k < 10 ** 7:
    for i in range(k):
        now = a[now - 1]
else:
    while flg:
        count += 1
        now = a[now - 1]
        if chk[now - 1] == 0 and now != 1:
            chk[now - 1] = count
        else:
            flg = False
            if (k - count) != 0 and (count - chk[now - 1]) != 0:
                rem = (k - count) % (count - chk[now - 1])
            else:
                rem = 0
    else:
        for i in range(rem):
            now = a[now - 1]
            count += 1
print(now)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
now = 1
chk = [0] * n
flg = True
count = 0
chk[0] = 1
if k < 10 ** 5:
    for i in range(k):
        now = a[now - 1]
else:
    while flg:
        count += 1
        now = a[now - 1]
        if chk[now - 1] == 0:
            chk[now - 1] = count
        else:
            flg = False
            rem = (k - count) % (count - chk[now - 1])
    else:
        for i in range(rem):
            now = a[now - 1]
print(now)
Problem p02741 (python)

Fixed submission:
N = int(input())
Lists = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(Lists[N-1])

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
M = H * W
M2 = M // 2
modm = M % 2
if modm == 0:
    print(M2)
else:
    print(M2 + 1)
Problem p02608 (python)

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


import math

# def equation(a, b, c):
#     D = (b**2 - 4*a*c) ** (1/2)
#     x_1 = (-b + D) / (2 * a)
#     x_2 = (-b - D) / (2 * a)

#     return x_1, x_2



def main():
    n = int(input())

    ans = [0]*(n+1)

    for x in range(1, int(math.sqrt(n))):
        for y in range(1, int(math.sqrt(n))):
            for z in range(1, int(math.sqrt(n))):

                e = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if e >= 1 and e <= n:
                    ans[int(e)] += 1

    for i in range(len(ans)-1):
        print(ans[i+1])




                # x_1, x_2 = equation(1, y+z, y**2 + y*z + z**2 - n)

                # if isinstance(x_1, float):
                #     x_1 = round(x_1, 5)
                #     if x_1.is_integer() == True and x_1 >= 1:
                #         cnt += 1

                # if isinstance(x_2, float):
                #     x_2 = round(x_2, 5)
                #     if x_2.is_integer() == True and x_2 >= 1:
                #         cnt += 1

        # print(cnt)




if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
def equation(a, b, c):
    D = (b**2 - 4*a*c) ** (1/2)
    x_1 = (-b + D) / (2 * a)
    x_2 = (-b - D) / (2 * a)

    return x_1, x_2



def main():
    N = int(input())

    for n in range(1, N+1):
        cnt = 0
        for y in range(1, int(math.root(n))):
            for z in range(1, int(math.root(n))):
                x_1, x_2 = equation(1, y+z, y**2 + y*z + z**2 - n)

                if isinstance(x_1, float):
                    x_1 = round(x_1, 5)
                    if x_1.is_integer() == True and x_1 >= 1:
                        cnt += 1

                if isinstance(x_2, float):
                    x_2 = round(x_2, 5)
                    if x_2.is_integer() == True and x_2 >= 1:
                        cnt += 1

        print(cnt)




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

Fixed submission:
from collections import defaultdict

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

route = defaultdict(int)
i = 0
loop = []
tail = []

while route[i] < 2:

    if route[i] == 0:
        tail.append(i)
    else:
        loop.append(i)
    
    route[i] += 1
    i = a[i] - 1

if len(tail) > k:
    print(tail[k] + 1)
else:
    temp = len(tail) - len(loop)
    print(loop[(k-temp) % len(loop)] + 1)

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

route = []
i = 0

while True:
    ne = a[i]

    if i not in route and len(route) <= k:
        route.append(i)
    else:
        temp = len(route) - len(route[i:])
        if k <= temp:
            print(route[k] + 1)
            # print([i+1 for i in route])
        else:
            print(a[(k-temp)%len(route[i:])])
        break

    i = ne - 1

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

route = []
i = 0

while True:
    ne = a[i]

    if i not in route:
        route.append(i)
    else:
        temp = len(route) - len(route[i:])
        if k <= temp:
            print(route[k])
        else:
            print(a[(k-temp)%len(route[i:])])
        break

    i = ne - 1

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

route = []
i = 0

# 方針は合っていたが，
while True:
    ne = a[i]

    if i not in route:
        route.append(i)
    else:
        temp = len(route) - len(route[i:])
        if k < temp:
            print(a[k])
        else:
            print(a[(k-temp)%len(route[i:])])
        break

    i = ne - 1

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

route = []
i = 0

while True:
    ne = a[i]

    if i not in route:
        route.append(i)
    else:
        temp = len(route) - len(route[i:])
        print(a[(k-temp)%len(route[i:])])
        break

    i = ne - 1

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

route = []
i = 0

while True:
    ne = a[i]

    if i not in route:
        route.append(i)
    else:
        k = k - (len(route) - len(route[i:]))
        print(a[k%len(route[i:])])
        break

    i = ne - 1

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

route = []
i = 0
count = 0

while count < k:
    ne = a[i]
    count += 1

    if i not in route:
        route.append(i)
    else:
        k = k - (len(route) - len(route[i:]))
        print(a[k%len(route[i:])])
        break

    i = ne - 1
Problem p02923 (python)

Fixed submission:
def main():
    n = int(input())
    h = list(map(int, input().split()))

    score = []

    j = 0
    for i in range(n-1):
        if i != 0:
            j = next_j
        cnt = 0
        while True:
            if j >= n-1 or h[j] < h[j+1]:
                score.append(cnt)
                next_j = j+1
                break
            else:
                h[j] >= h[j+1]
                cnt += 1
                j += 1

    if n == 1:
        print(0)
    else:
        print(max(score))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    h = list(map(int, input().split()))

    score = []

    j = 0
    for i in range(n-1):
        if i != 0:
            j = next_j
        cnt = 0
        while True:
            if j >= n-1 or h[j] < h[j+1]:
                score.append(cnt)
                next_j = j+1
                break
            else:
                h[j] >= h[j+1]
                cnt += 1
                j += 1

    print(max(score))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    h = list(map(int, input().split()))

    score = []

    for i in range(n-1):
        j = i
        cnt = 0
        while True:
            if j >= n-1 or h[j] < h[j+1]:
                score.append(cnt)
                break
            else:
                h[j] >= h[j+1]
                cnt += 1
                j += 1

    print(max(score))


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

Fixed submission:
# 早くなるおまじない
import sys
input = sys.stdin.buffer.readline

# 再帰関数の呼び出し制限
sys.setrecursionlimit(3 * 10 ** 5)

# 深さが一つ前のやつのresの値を足す
# dfsはおk，ここで累積和を使う発想が出てこなかった
# def dfs(node, prev):
#     visited.add(node)
#     if prev != 0:
#         res[node-1] += res[prev-1]
#     for i in dic[node]:
#         if i not in visited:
#             prev = node
#             dfs(i, prev)

def dfs(node, prev, visited, res, dic):
    visited.add(node)
    if prev != 0:
        res[node-1] += res[prev-1]
    for i in dic[node]:
        if i not in visited:
            prev = node
            dfs(i, prev, visited, res, dic)


def main():
    n,q = map(int,input().split())

    dic = {}
    for i in range(n-1):
        aa, bb = map(int,input().split())

        if aa not in dic:
            dic[aa] = set()
            dic[aa].add(bb)
        else:
            dic[aa].add(bb)

        if bb not in dic:
            dic[bb] = set()
            dic[bb].add(aa)
        else:
            dic[bb].add(aa)


    p = []
    x = []
    for _ in range(q):
        s, t = map(int,input().split())
        p.append(s)
        x.append(t)

    res = [0]*n
    for i in range(q):
        res[p[i]-1] += x[i]

    visited = set()

    dfs(1, 0, visited, res, dic)
    print(*res, sep=" ")

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# 早くなるおまじない
import sys
input = sys.stdin.buffer.readline

# 再帰関数の呼び出し制限
sys.setrecursionlimit(3 * 10 ** 5)

# 深さが一つ前のやつのresの値を足す
# dfsはおk，ここで累積和を使う発想が出てこなかった
def dfs(node, prev):
    visited.add(node)
    if prev != 0:
        res[node-1] += res[prev-1]
    for i in dic[node]:
        if i not in visited:
            prev = node
            dfs(i, prev)


def main():
    n,q = map(int,input().split())

    dic = {}
    for i in range(n-1):
        aa, bb = map(int,input().split())

        if aa not in dic:
            dic[aa] = set()
            dic[aa].add(bb)
        else:
            dic[aa].add(bb)

        if bb not in dic:
            dic[bb] = set()
            dic[bb].add(aa)
        else:
            dic[bb].add(aa)


    p = []
    x = []
    for _ in range(q):
        s, t = map(int,input().split())
        p.append(s)
        x.append(t)

    res = [0]*n
    for i in range(q):
        res[p[i]-1] += x[i]

    visited = set()

    dfs(1, 0)
    print(*res, sep=" ")

if __name__ == '__main__':
    main()