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

Fixed submission:
a = int(input())
print(max(j ** i for j in range(32) for i in range(2, 10) if j ** i <= a))

Buggy submission (verdict: Runtime Error):
a = int(input())
n = []
for i in range(2, 10):
  for j in range(32):
	if j ** i <= a:
      n.append(j ** i)
print(max(n))

Buggy submission (verdict: Runtime Error):
a = int(input())
n = []
for i in range(2, 10):
  for j in range(32):
	if j ** i <= a:
      n.append(j ** i)
print(max(n))

Buggy submission (verdict: Runtime Error):
import math
a = int(input())
for i in range(a, 0, -1):
  for j in range(2, 10):
    if i == int(math.paw(i, 1/j)) ** j:
      print(i)
      break
  else:
    continue
  break
Problem p03371 (python)

Fixed submission:
a, b, c, x, y = map(int, input().split())
print(min(a*x+b*y, 2*c*x + b*max(0,y-x), 2*c*y + a*max(0, x-y)))

Buggy submission (verdict: Runtime Error):
a, b, c, x, y = map(int, input().split())
print(min(a*x+b*y, 2*c*x + b*max(0,y-x), 2*c*y + a*max(0, x-y))
Problem p03377 (python)

Fixed submission:
a, b, x = map(int, input().split())
if a == x or (a + b >= x and a < x):
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
print("YES" if a <= x and a + b >= x or "NO")
Problem p03378 (python)

Fixed submission:
a, b, c = map(int, input().split())
s = list(map(int, input().split()))
l, r = 0, 0
for i in s:
  if i < c:
    l += 1
  else:
    r += 1
print(min(l, r))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
s = list(map(int, input().split()))
for i in s:
  if i < c:
    l += 1
  else:
    r += 1
print(min(l, r))
Problem p03386 (python)

Fixed submission:
a, b, k = map(int, input().split())
n = range(a, b+1)
for i in sorted(set(n[:k]) | set(n[-k:])):
  print(i)

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
n = list(range(a, b+1))
for i in n:
  if i in n[:k] + n[-k:]:
    print(i)

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
nums = list(range(a, b+1))
for i in range(a, b+1):
  if nums.index(i) <= k - 1 or nums[::-1].index(i) <= k - 1:
    print(i)
Problem p03448 (python)

Fixed submission:
a, b, c, x = map(int, open(0).read().split())
ans = 0
for i in range(a + 1):
  for j in range(b + 1):
    for k in range(c + 1):
      if 500 * i + 100 * j + 50 * k == x:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
a, b, c, x = map(int, open(0).read().split())
ans = 0
for i in range(a + 1):
  for j in range(b + 1):
    if (x - (i * 500 + j * 100)) % (c * 50) == 0:
      ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
a, b, c, x = map(int, open(0).read().split())
ans = 0
for i in range(x // a + 1):
  for j in range(x // b + 1):
    if (x - (a * i + b * j)) % c == 0
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
a, b, c, x = map(int, open(0).read().split())
ans = 0
for i in range(x // a + 1):
  for j in range(x // b + 1):
    for k in range(x // c + 1):
      if i * a + j * b + k * c == x:
        ans += 1
print(ans)
Problem p03474 (python)

Fixed submission:
a, b = map(int, input().split())
s = input()
print("Yes" if s.count("-") == 1 and s[a] == "-" else "No")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print("Yes" if input()[a] == "-" and input().count("-") == 1 else "No")
Problem p03485 (python)

Fixed submission:
a, b = map(int, input().split())
print((a + b + 1) // 2)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().spoit())
print((a + b + 1) // 2)
Problem p03494 (python)

Fixed submission:
n = int(input())
print(min(bin(int(i))[::-1].find("1") for i in input().split()))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split())
while True:
  for i in range(n):
    if a[i] % 2 == 1:
      break
    a[i] = a[i] // 2
  else:
    ans += 1
    continue
  break
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split())
while True:
  for i in range(n):
    if a[i] % 2 == 1:
      break
    a[i] //= 2
  else:
    ans += 1
    continue
  break
print(ans)
Problem p03563 (python)

Fixed submission:
a = int(input())
b = int(input())
print(2 * b - a)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(2b - a)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(2b - a)
Problem p03598 (python)

Fixed submission:
n = int(input())
k = int(input())
nums = list(map(int, input().split()))
print(2 * sum([min(k - i, i) for i in nums]))

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(input())
nums = list(map(int, input().split()))
a = []
for i in n:
  a.append(2 * min(k-nums[i], nums[i]))
print(min(a))

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(input())
nums = list(map(int, input().split()))
a = 0
for i in n:
  a += (2 * min(k-nums[i], nums[i]))
print(a)
Problem p03624 (python)

Fixed submission:
s = list(input())
for i in range(ord("a"), ord("z") + 1):
  if chr(i) not in s:
    print(chr(i))
    break
else:
  print("None")

Buggy submission (verdict: Runtime Error):
s = list(input())
t = [chr(i) for i in range(ord("a"), ord("z") + 1)]
for i in s:
  t.remove(i)
if t:
  print(t[0])
else:
  print("None")

Buggy submission (verdict: Runtime Error):
s = list(input())
t = [chr(i) for i in range(ord("a"), ord("z") + 1)]
for i in s:
  t.remove(i)
print(t[0])
Problem p03644 (python)

Fixed submission:
n = int(input())
a = []
for i in range(1, n+1):
  c = 0
  while True:
    if i % 2 != 0:
      break
    i = i // 2
    c += 1
  a.append(c)
print(a.index(max(a)) + 1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(1, n+1):
  while True:
    if i % 2 != 0:
      break
    i = i // 2
    c += 1
  a.append(c)
print(a.index(max(a)) + 1)
Problem p03657 (python)

Fixed submission:
a, b = map(int, input().split())
print("Possible" if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0 else "Impossible")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print("Possible" if a % 3 == 0 or b % 3 == 0 or (a + b) % == 0 else "Impossible")
Problem p03658 (python)

Fixed submission:
n, k = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
print(sum(s[n-k:]))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
print(sum(s[len(n) - k:]))
Problem p03671 (python)

Fixed submission:
p = sorted(list(map(int, input().split())))
print(p[0] + p[1])

Buggy submission (verdict: Runtime Error):
p = sorted([map(int, input().split())])
print(p[0] + p[1])
Problem p03672 (python)

Fixed submission:
n = input()[:-1]
while n[:len(n)//2] != n[len(n)//2:]:
  n = n[:-1]
print(len(n))

Buggy submission (verdict: Runtime Error):
n = input()[:-1]
while n[:len(n)//2] != [len(n)//2:]:
  n = n[:-1]
print(len(n))
Problem p03680 (python)

Fixed submission:
import sys 
N = list(map(int, sys.stdin))
bot = N[1]
for i in range(N[0]):
  if bot == 2:
    print(i+1)
    break
  bot = N[bot]
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
s = [1]
t = 1
ans = 0
for i in range(n):
  a.append(int(input())
while t != 2:
  t = a[t-1]
  s.append(t)
  if s.count(t) == 2:
    ans = -1
    break
  ans += 1
print(ans)
Problem p03711 (python)

Fixed submission:
n1 = [1, 3, 5, 7, 8, 10, 12]
n2 = [4, 6, 9, 11]

a, b = map(int, input().split())
print("Yes" if a in n1 and b in n1 or a in n2 and b in n2 else "No")

Buggy submission (verdict: Runtime Error):
n1 = set([1, 3, 5, 7, 8, 10, 12])
n2 = set([4, 6, 9, 11])
n3 = set([2])
nums = set(map(int, input().split())
print("Yes" if nums <= n1 or nums <= n2 or nums <= n3 else "No")
Problem p03759 (python)

Fixed submission:
a, b, c = map(int, input().split())
if b - a == c - b:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input()split())
if b - a == c - b:
  print("YES")
else:
  print("NO")
Problem p03760 (python)

Fixed submission:
o, e = input(), input() + " "
for x, y in zip(o, e):
  print(x + y, end="")

Buggy submission (verdict: Runtime Error):
# coding: utf-8

odd = raw_input()
even = raw_input()

res = ""
for (o, e) in zip(odd, even):
    res = res + o + e

print res if len(odd) - len(even) == 0 else res + odd[-1]
Problem p03814 (python)

Fixed submission:
n = input()
print(n.rfind("Z") - n.find("A") + 1)

Buggy submission (verdict: Runtime Error):
n = input()
a = n.index("A")
n = len(n) - n[::-1].index("Z") - 1
print(len(n[a:n+1]))

Buggy submission (verdict: Runtime Error):
n = input()
a = n.index("A")
n = len(n) - n[::-1].index("Z")
print(len(n[a:n+1]))
Problem p03844 (python)

Fixed submission:
a, op, b = input().split()
a = int(a)
b = int(b)
if op == "+":
  print(a + b)
else:
  print(a - b)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = map(int, input().split())
k = int(input())
s = sum(p)
for i in range(k):
  a, b = map(int, input().split())
  print(s - p[a-1] + b)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
k = int(input())
s = sum(p)
for i in range(k):
  a, b = map(int, input().split())
  print(s - p[a-1] + b)
Problem p03919 (python)

Fixed submission:
w = []
for i in range(ord("A"), ord("Z") + 1):
  w.append(chr(i))
  
a, b = map(int, input().split())
for i in range(a):
  row = input().split()
  for j in range(b):
    if row[j] == "snuke":
      print(w[j] + str(i + 1))

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [input().split() for i in range(h)]
for i in range(h):
  for j in range(w):
    if a[i][w] == "snuke":
      print(chr(ord("A") + j) + str(i + 1))
      exit()

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [input().split() for i in range(h)]
for i in range(h):
  for j in range(w):
    a[i][j] == "snuke":
      print(chr(ord("A") + j) + str(i + 1))
      exit()

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [input().split() for i in range(h)]
for i in range(h):
  for j in range(w):
    a[i][w] == "snuke":
      print(chr(ord("A") + j) + str(i + 1))
      exit()
Problem p03943 (python)

Fixed submission:
lst = list(map(int, input().split()))
lst.sort()
if lst[0] + lst[1] == lst[2]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
lst = list(map(int, input().split))
lst.sort()
if lst[0] + lst[1] == lst[2]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
lst = sorted(list(map(int, input().split)))
if lst[0] + lst[1] == lst[2]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
nums = list(map(int, input().split()))
ans = 0
for i in nums:
  if i == sum(nums.remove(i)):
    ans += 1
    break
if ans > 0:
  print("YES")
else:
  print("NO")
Problem p03962 (python)

Fixed submission:
l = set(list(map(int, input().split())))
print(len(l))

Buggy submission (verdict: Runtime Error):
l = set(list(map, input().split()))
print(len(l))
Problem p03970 (python)

Fixed submission:
n = input()
ans = 0
a = "CODEFESTIVAL2016"
for i, j in zip(n, a):
  if i != j:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = input()
a = 0
a = "CODEFESTIVAL2016"
for i, j in zip(n, a):
  if i != j:
    a += 1
print(a)
Problem p03992 (python)

Fixed submission:
n = input()
print(n[:4], n[4:])

Buggy submission (verdict: Runtime Error):
n = input()
print(" ".join(n[:4], n[4:]))
Problem p03998 (python)

Fixed submission:
A = input()
B = input()
C = input()
n = A[0]
A = A[1:]
while True:
  if n == "a":
    if len(A) == 0:
      print("A")
      break
    n = A[0]
    A = A[1:]

  elif n == "b":
    if len(B) == 0:
      print("B") 
      break
    n = B[0]
    B = B[1:]
  else:
    if len(C) == 0:
      print("C")
      break
    n = C[0]
    C = C[1:]

Buggy submission (verdict: Runtime Error):
S = {i: input() for i in "abc"}
n = "a"
while S[n]:
  n = S[n].pop(0)
  
print(n.upper())

Buggy submission (verdict: Runtime Error):
S = [n: list(input()) for n in "abc"]
i = "a"
while S[i]:
  i = S[i].pop(0)
  
print(i.upper())
Problem p04011 (python)

Fixed submission:
n = int(input())
k = int(input())
x = int(input())
y = int(input())
if n <= k:
  print(n * x)
else:
  print(k * x + (n - k) * y)

Buggy submission (verdict: Runtime Error):
n, k, x, y = map(int, input().split())
if n <= k:
  print(n * x)
else:
  print(k * x + (n - k) * y)
Problem p04012 (python)

Fixed submission:
n = input()
ans = 0
for i in set(n):
  if n.count(i) % 2 == 0:
    ans += 1
    
if ans == len(set(n)):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = input()
ans = 0
for i ih set(n):
  if n.count(i) % 2 == 0:
    ans += 1
    
if ans == len(set(n)):
  print("Yes")
else:
  print("No")
Problem p04033 (python)

Fixed submission:
a, b = map(int, input().split())
if a <= 0 <= b:
  print("Zero")
elif a > 0:
  print("Positive")
else:
  if (b - a + 1) % 2 == 0:
    print("Positive")
  else:
    print("Negative")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
s = list(range(a, b+1))
if 0 in s:
  print("Zero")
else:
  c = 0
  for i in s:
    if i < 0:
      c += 1
  if c % 2 == 0:
    print("Positive")
  else:
    print("Negative")
Problem p04043 (python)

Fixed submission:
nums = list(map(int, input().split()))
if nums.count(5) == 2 and nums.count(7) == 1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
nums = map(int, input().split())
if nums.count(5) == 2 and nums.count(7) == 1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
nums = map(int, input().split(" "))
if nums.count(5) == 2 and nums.count(7) == 1:
  print("YES")
else:
  print("NO")
Problem p04044 (python)

Fixed submission:
n, l = map(int, input().split())
a = []
for i in range(n):
  a.append(input())
a.sort()
b = ""
for i in a:
  b += i
print(b)

Buggy submission (verdict: Runtime Error):
l, n = map(int, input().split())
a = []
for i in range(n):
  a.append(input())
a.sort()
b = ""
for i in a:
  b += a
print(b)
Problem p04047 (python)

Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())))
s = 0
for i in range(2 * n):
  if i % 2 == 0:
    s += a[i]
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = sorted(map(int, input().split()))
s = 0
for i in range(2n-1):
  s += min(a[i], a[i+1])
print(s)
Problem p02765 (python)

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

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
for i in range(30):
    if n >= k**(i-1) and n < k**i:
        print(i)
Problem p02921 (python)

Fixed submission:
s=input()
t=input()
count=0
for i in range(3):
  if s[i]==t[i]:
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
import sys
a,b=map(int,input().split())
if b==1:
  print("0")
  sys.exit()
p=1
ans=0
for i in range(0,20):
  p+=a-1
  ans+=1
  if p>=b:
    print(ans)
    sys.exit()
Problem p02922 (python)

Fixed submission:
import sys
a,b=map(int,input().split())
if b==1:
  print("0")
  sys.exit()
p=1
ans=0
for i in range(0,20):
  p+=a-1
  ans+=1
  if p>=b:
    print(ans)
    sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
a,b=map(int,input().split())
if b==1:
  print("0")
  sus.exit()
p=1
ans=0
for i in range(0,20):
  p+=a-1
  ans+=1
  if p>=b:
    print(ans)
    sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
a,b=map(int,input().split())
if b=1:
  print("0")
  sus.exit()
p=1
ans=0
for i in range(0,20):
  p+=a-1
  ans+=1
  if p>=b:
    print(ans)
    sys.exit()
Problem p03219 (python)

Fixed submission:
x,y=map(int,input().split())
print(int(x+y/2))

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
printint((x+y/2))
Problem p03238 (python)

Fixed submission:
n=int(input())
if n==1:
   print("Hello World")
else:
   a=int(input())
   b=int(input())
   print(a+b)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=int(input())
b=int(input())
if n==1:
  print("Hello World")
else:
  print(a+b)
Problem p02981 (python)

Fixed submission:
n,a,b = map(int,input().split())
if n*a>b:
  print(b)
else:
  print(a*n)

Buggy submission (verdict: Runtime Error):
import math

n,d = map(int,input().split())
xy = [list(map(float,input().split())) for i in range(n)]
count = 0
for i in range(n):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis += (xy[i][k]-xy[j][k])**2
    dis = math.sqrt(dis)
    if dis.is_integer():
      count +=1
      
print(count)

Buggy submission (verdict: Runtime Error):
import math

n,d = map(int,input().split())
xy = [list(map(float,input().split())) for i in range(n)]
count = 0
for i in range(n):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis += (xy[i][k]-xy[j][k])**2
    dis = math.sqrt(dis)
    if dis.is_integer():
      count +=1
      
print(count)
Problem p02642 (python)

Fixed submission:
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    As.sort()

    setA = set(As)
    setDel = set()

    cands = []

    for a in As:
        if a in setDel:
            continue

        i = 1
        while a*i <= As[-1]:
            if a*i in setA:
                setDel.add(a*i)
            i += 1

        cands.append(a)

    # 重複する数字を調べる
    dic = {}
    for a in As:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1

    ans = 0
    for x in cands:
        if dic[x] > 1:
            continue
        ans += 1

    print(ans)


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    As.sort()

    setA = set(As)
    setDel = set()

    cands = []

    for a in As:
        if a in setDel:
            continue

        i = 1
        while a*i <= As[-1]:
            if a*i in setA:
                setDel.add(a*i)
            i += 1

        cands.append(a)

    # 重複する数字を調べる
    dic = {}
    for a in As:
        if not a in dic:
            dic[a] = 0
        elif dic[a] == 1:
            cands.remove(a)
        dic[a] += 1

    print(len(cands))


if __name__ == "__main__":
    solve()
Problem p02844 (python)

Fixed submission:
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    S = input()

    """
    3桁の数字がijkだとして、それを作れるかを全探索で数えていく
    平均計算量は、(3750*10)*(7500*10)*(15000*10) = O(10**4 * 10**4 * 10**5) = O(10**13)
    """

    ans = 0
    for i in range(0, 10):
        idx = S.find(str(i))  # 平均計算量15000
        if idx == -1:
            continue
        for j in range(0, 10):
            jdx = S[idx+1:].find(str(j))  # 平均計算量7500
            if jdx == -1:
                continue
            for k in range(0, 10):
                if str(k) in S[idx+1+jdx+1:]:  # 平均計算量3750
                    ans += 1

    print(ans)


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    S: string = input()

    """
    3桁の数字がijkだとして、それを作れるかを全探索で数えていく
    平均計算量は、(3750*10)*(7500*10)*(15000*10) = O(10**4 * 10**4 * 10**5) = O(10**13)
    """

    ans = 0
    for i in range(0, 10):
        idx = S.find(str(i))  # 平均計算量15000
        if idx == -1:
            continue
        for j in range(0, 10):
            jdx = S[idx+1:].find(str(j))  # 平均計算量7500
            if jdx == -1:
                continue
            for k in range(0, 10):
                if str(k) in S[idx+1+jdx+1:]:  # 平均計算量3750
                    ans += 1

    print(ans)


if __name__ == "__main__":
    solve()
Problem p02888 (python)

Fixed submission:
# -*- coding:utf-8 -*-
import bisect

def solve():
    N = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()

    # O(N^2 * logN)の全探索で解く
    ans = 0
    for a_i in range(N):
        for b_i in range(a_i+1, N):
            c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
            if c_i > b_i:
                ans += c_i - b_i - 1
            else:
                pass

    print(ans)

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-
import bisect

def solve():
    N = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()

    # O(N^2 * logN)の全探索で解く
    ans = 0
    for a_i in range(N):
        for b_i in range(a+1, N):
            c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
            if c_i > b_i:
                ans += c_i - b_i - 1
            else:
                pass

    print(ans)

if __name__ == "__main__":
    solve()
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
N, Q = map(int, sys.stdin.readline().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(N-1)]
p_x = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

rin = [[] for _ in range(N)]
for v in a_b:
    rin[v[0]-1].append(v[1]-1)
    rin[v[1]-1].append(v[0]-1)

score = [0 for _ in range(N)]
for ele in p_x:
    score[ele[0]-1] +=ele[1]
#print(score)

def dfs(p, bp=-1):
    for c in rin[p]:
        if c != bp:
            #print(c)
            score[c]+= score[p]
            dfs(c, p)

dfs(0)
print(*score)

Buggy submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def solve():
    import sys
    sys.setrecursionlimit(2*10**5)

    N, Q = list(map(int, sys.stdin.readline().split()))

    tree = [[] for _ in range(N)]  # 木構造
    for _ in range(N-1):
        a, b = list(map(int, sys.stdin.readline().split()))
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)

    anss = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, sys.stdin.readline().split()))
        anss[p-1] += x

    def dfs(a, p):
        """
        a:対象番号
        p:親番号
        """
        for b in tree[a]:
            if b == p: continue
            anss[b] += anss[a]
            dfs(b, a)

    dfs(0, -1)

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


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def solve():
    import sys
    sys.setrecursionlimit(2*10**5)

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

    tree = [[] for _ in range(N)]  # 木構造
    anss = [0 for _ in range(N)]
    for _ in range(N-1):
        a, b = list(map(int, input().split()))
        tree[a-1].append(b-1)

    def dfs(a, x):
        anss[a] += x

        for b in tree[a]:
            dfs(b, x)

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

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


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def solve():
    N, Q = list(map(int, input().split()))

    tree = [[] for _ in range(N)]  # 木構造
    anss = [0 for _ in range(N)]
    for _ in range(N-1):
        a, b = list(map(int, input().split()))
        tree[a-1].append(b-1)

    def dfs(a, x):
        anss[a] += x

        for b in tree[a]:
            dfs(b, x)

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

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


if __name__ == "__main__":
    solve()