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

Fixed submission:
s = input()
n = []
op = []

def calc(lst,n,op):
  if lst:
    op.append('+')
    p = calc(lst[:-1],n+lst[-1],op)
    if p:
      return p
    op.pop()
    op.append('-')
    n = calc(lst[:-1],n-lst[-1],op)
    if n:
      return n
    op.pop()
  else:
    if n == 7:
      return op
    else:
      return None
  
    

for i in range(3):
  n.append(int(s[3-i]))
op = calc(n,int(s[0]),op)
print('{}{}{}{}{}{}{}=7'.format(s[0],op[0],s[1],op[1],s[2],op[2],s[3]))

Buggy submission (verdict: Runtime Error):
s = input()

def func(ac,s,op):
  next = s[0]
  if len(s) ==1:
    if ac + next == 7:
      print(str+'+'+s[0]+'=7')
      exit(0)
    if ac - next == 7:
      print(str+'-'+s[0]+'=7')
      exit(0)
  else:
    func(ac+next,s[1:],op+'+'+str(next))
    func(ac-next,s[1:],op+'-'+str(next))
  
func(int(s[0]),s[1:],s[0])
Problem p03546 (python)

Fixed submission:
h,w = map(int,input().split())
c = [[int(i) for i in input().split()] for _ in range(10)]
A = {i:0 for i in range(10)}
for _ in range(h):
  for i in input().split():
    if i != '-1':
      A[int(i)] += 1
    

for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min(c[i][k] + c[k][j],c[i][j])
      

ans = 0
for i in range(10):
  ans += c[i][1] * A[i]
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
c = [[int(i) for i in input().split()] for _ in range(10)]
A = {i:0 for i in range(10)}
for _ in range(h):
  for i in input().split():
    A[int(i)] += 1
    

for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min(c[i][k] + c[k][j],c[i][j])
      

ans = 0
for i in range(10):
  ans += c[i][1] * A[i]
print(ans)
Problem p03557 (python)

Fixed submission:
n = int(input())
AS = list(map(int,input().split()))
AS.sort()
BS = list(map(int,input().split()))
CS = list(map(int,input().split()))
CS.sort()
import bisect
  
ans = 0
for b in range(n):
  ans += bisect.bisect_left(AS,BS[b])*(n-bisect.bisect_right(CS,BS[b]))

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
AS = list(int,input().split())
AS.sort()
BS = list(int,input().split())
BS.sort()
CS = list(int,input().split())
CS.sort()
import bisect
AB  = [0 for _ in range(n)]
BC  = [0 for _ in range(n)]
a = 0
for b in range(n):
  AB[b] = bisect.bisect_left(AS,BS[b])
  
for b in range(n):
  BC[b] = n-bisect.bisect_left(CS,BS[b])

ans = 0
for i in range(n):
  ans += AB[b] * BS[b]
print(ans)
Problem p03563 (python)

Fixed submission:
r = int(input())
g = int(input())   
print(2 * g -r)

Buggy submission (verdict: Runtime Error):
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if (c == t[0] or c == '?') and (i+len(t) < len(s)-1):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        s[i+j] =  t[j]
      print(s.replace('?', 'a')[::-1])
      break
else:
  print('UNRESTORABLE')
Problem p03565 (python)

Fixed submission:
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if (c == t[0] or c == '?') and (i+len(t) < len(s)+1):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      str_list = list(s)
      for j in range(len(t)):
        str_list[i+j] =  t[j]
      s = ''.join(str_list)
      print(s.replace('?', 'a')[::-1])
      break
else:
  print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if (c == t[0] or c == '?') and (i+len(t) < len(s)-1):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        s[i+j] =  t[j]
      print(s.replace('?', 'a')[::-1])
      break
else:
  print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if c == t[0] and (i+len(t) < len(s)):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        s[i+j] =  t[j]
      print(s.replace('?', 'a')[::-1])
      break
else:
  print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if c == t[0] and (i+len(t) < len(s)):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        s[i+j] =  t[j]
      print(s.replace('?', 'a')[;;-1])
      break
else:
  print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if c == t[0] and (i+len(t) < len(s)):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        s[i+j] =  t[j]
      print(s.replace('?', 'a'))
      break
else:
  print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if c == t[0]:
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        s[i+j] =  t[j]
print(s.replace('?', 'a'))
Problem p03575 (python)

Fixed submission:
n,m = map(int,input().split())
graph = {i:[] for i in range(1,n+1)}

for _ in range(m):
  a,b = map(int,input().split())
  graph[a].append(b)
  graph[b].append(a)
  
bridge = set([])

ans = 0
while 1:
  count = 0
  for i in range(1,n+1):
    if len(graph[i]) == 1:
      count += 1
      a = graph[i][0]
      graph[a].remove(i)
      graph[i] = []
  ans += count
  if count == 0:
    break
  else:
    count = 0
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
graph = {i+1:[] for i in range(1,n+1)}

for _ in range(m):
  a,b = map(int,input().split())
  graph[a].append(b)
  graph[b].append(a)
  
bridge = set([])

ans = 0
while 1:
  count = 0
  for i in range(1,n+1):
    if len(graph[i]) == 1:
      count += 1
      a = graph[i]
      graph[a].remove(i)
      graph[i] = []
  ans += count
  if count == 0:
    break
  else:
    count = 0
print(ans)
Problem p03637 (python)

Fixed submission:
_ = int(input())
an = list(map(int,input().split()))

odd = list(filter((lambda x:x%2==1),an))
div4 = list(filter((lambda x:x%4 ==0),an))
div2 = set(an).difference(set(odd)).difference(set(div4))
if len(div2) == 0:
  div4.append(0)
if len(odd) <= len(div4):
  print('Yes')
else:
  print('No')

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

odd = filter((lambda x:x%2==1),an)
div4 = filter((lambda x:x%4 ==0),an)
div2 = set(an).difference(set(odd)).difference(set(div4))
if len(div2) == 0:
  div4.append(0)
if len(odd) <= len(div4)+1:
  print('Yes')
else:
  print('No')
Problem p03673 (python)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
from collections import deque

B = deque([])

for i in range(n):
  if i %2:
    B.appendleft(A[i])
  else:
    B.append(A[i])
B = list(B)
if n%2:
  B = B[::-1]
print(*B)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
from collections import deque

B = deque([])

for i in range(n):
  if i %2:
    B.appendleft(A[i])
  else:
    B.append(A[i])
    
if n%2:
  B = B[::-1]
print(*B)

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

B = []

for i in range(n):
  if i %2:
    B = [A[i]] + B
  else:
    B = B.append(A[i])
    
if n%2:
  B = B[::-1]
print(*B)
Problem p03695 (python)

Fixed submission:
n = int(input())
ai = list(map(int,input().split()))
aj = list(map(lambda x:int(x/400),ai))
rainbow = 0
for e in aj:
  if e >= 8:
    rainbow += 1
ak= set(aj)
ans = 0
for e in ak:
  if e < 8:
    ans += 1
print(max(1,ans) ,end='')
print(' ' ,end = '')
print(ans+ rainbow)

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

col = [0 for _ in range(9)]
for a in A:
  if a >= 3200:
    col[8] += 1
  col[a//400] += 1
print(sum(col[:-1]), sum(col))
Problem p03720 (python)

Fixed submission:
n,m = map(int,input().split())
graph = {i:[] for i in range(1, n+1)}
for _ in range(m):
  a,b = map(int,input().split())
  graph[a].append(b)
  graph[b].append(a)
for i in range(1, n+1):
  print(len(graph[i]))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
graph = {i:[] for i in range(1, n+1)}
for _ in range(m):
  a,b = map(int,input().split())
  graph[a].append(b)
  graph[b].append(a)
for i in range(1, n+1):
  print(len(graphp[i]))
Problem p03845 (python)

Fixed submission:
n = int(input())
T = list(map(int,input().split()))
ans = sum(T)
m = int(input())
for i in range(m):
  p, x = map(int,input().split())
  print(ans-T[p-1]+x)

Buggy submission (verdict: Runtime Error):
n = int(input().split())
T = list(map(int,input().split()))
ans = sum(T)
m = int(input())
for i in range(m):
  p, x = map(int,input().split())
  print(ans-T[p-1]+x)
Problem p03854 (python)

Fixed submission:
s = input()
dp = [0 for i in range(len(s)+1)]
dp[0] = 1
words = ['eraser', 'erase', 'dreamer', 'dream']

for i in range(len(s)):
  i += 1
  for sent in words:
    before = i - len(sent)
    if before < 0:
      continue
    if dp[before] == 1 and s[before:i] == sent:
      dp[i] = 1
print('YES' if dp[-1] else 'NO')

Buggy submission (verdict: Runtime Error):
s = input()

while s:
  if len(s) > 6 and s[0:7] == 'dreamer':
    s = s[7:]
    if s != [] and s[0] == 'a':
      s = 'er' + s
    continue
  elif len(s)>5 and s[0:6] == 'eraser':
    s = s[6:]
    continue
  elif len(s) > 4 and s[0:5] in ('dream', 'erase'):
    s = s[5:]
    continue
  else:
    print('NO')
    exit(0)
print('YES')

Buggy submission (verdict: Runtime Error):
s = input()

while s:
  if s[0:7] == 'dreamer':
    s = s[7:]
    if s != [] and s[0] == 'a':
      s = 'er' + s
    continue
  elif s[0:6] == 'eraser':
    s = s[6:]
    continue
  elif s[0:5] in ('dream', 'erase'):
    s = s[5:]
    continue
  else:
    print('NO')
    exit(0)
print('YES')

Buggy submission (verdict: Runtime Error):
s = input()

while s:
  if s[0:7] == 'dreamer':
    s = s[7:]
    if s[0] == 'a':
      s = 'er' + s
    continue
  elif s[0:6] == 'eraser':
    s = s[6:]
    continue
  elif s[0:5] in ('dream', 'erase'):
    s = s[5:]
    continue
  else:
    print('NO')
    exit(0)
print('YES')
Problem p03910 (python)

Fixed submission:
n = int(input())
r = 10**7+1
l = 1

def f(n):
  return (n**2+n)//2

while r-l> 1:
  if f((l+r)//2)>n:
    r = (l+r)//2
  else:
    l = (l+r)//2

l = l+1
rm = (l+1)*l//2-n
ans = list(range(1, l+1))
ans.remove(rm)
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
n = int(input())
r = 10**7+1
l = 1

def f(n):
  return n**2+n

while r-l>1:
  if f((l+r)//2)>n:
    r = (l+r)//2
  else:
    l = (l+r)//2
l = l+1
rm = (l+1)*l//2-n
ans = list(range(1, l+1))
ans.remove(rm)
for a in ans:
  print(a)
Problem p03944 (python)

Fixed submission:
h,w,n = map(int,input().split())
d = {1:0,2:h,3:0,4:w}
for _ in range(n):
  x,y,a = map(int,input().split())
  if a %2:
    d[a] = max(d[a],[x,y][a//2]) 
  else:
    d[a] = min(d[a],[x,y][a//2-1])

if d[1] > d[2] or d[3] > d[4]:
  print(0)
else:
  ans = (d[2]-d[1]) * (d[4]-d[3])
  print(ans)

Buggy submission (verdict: Runtime Error):
w,h,n = map(int,input().split())
d = {1:0,2:h,3:0,4:w}
for _ in range(n):
  x,y,a = map(int,input().split())
  if a %2:
    d[a] = max(d[a],[x,y][a//2]) 
  else:
    d[a] = min(d[a],[x,y][a//2])

if d[1] > d[2] or d[3] > d[4]:
  print(0)
else:
  ans = (d[2]-d[1]+1) * (d[4]-d[3]+1)
  print(ans)
Problem p04001 (python)

Fixed submission:
s = input()
n = len(s)
ans = 0

for i in range(2**(n-1)):
  form = s
  bit = []
  for _ in range(n-1):
    bit.append(i%2)
    i =  i//2

  for j in range(n-1):
    if bit[j]:
      form = form[:n-j-1] + '+' + form[n-j-1:]

    
  ans += eval(form)
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
cand = []

def func(ac,yet,sum):
  next = int(yet[0])
  
  
  if len(yet) ==1:
    cand.append(sum+ ac+ next)
    cand.append(sum+ ac*10+ next)
  else:
    func(next, yet[1:],ac+sum)
    func(ac*10+next, yet[1:],sum)

func(int(s[0]),s[1:],0)
print(sum(cand))

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
ans = 0

for i in range(2**(n-1)):
  form = s
  bit = []
  for _ in range(n-1):
    bit.append(i%2)
    i =  i//2
  
  for j in range(n):
    if bit[j]:
      form = form[:n-j] + '+' + form[n-j:]
    
  ans += form.eval()
print(ans)
Problem p04019 (python)

Fixed submission:
s = input()

def f(a,b):
  return (a in s and b not in s) or (b in s and a not in s)
  
if f('W', 'E') or f('N', 'S'):
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()

def f(a,b):
  return (a in s and b not in s) or (b in s and a not in s):
  
if f('W', 'E') or f('N', 'S'):
  print('No')
else:
  print('Yes')
Problem p02732 (python)

Fixed submission:
import collections

n = int(input())
li = list(map(int, input().split()))
counter = collections.Counter(li)

sum_count = sum([n*(n-1)//2 for n in counter.values()])

for k in range(n):
    print(sum_count - counter[li[k]] + 1)

Buggy submission (verdict: Runtime Error):
import collections
import math

n = int(input())
li = list(map(int, input().split()))
counter = collections.Counter(li)


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

sum_count = sum([combinations_count(n, 2) for n in counter.values()])

for k in range(n):
    print(sum_count - counter[li[k]] + 1)

Buggy submission (verdict: Runtime Error):
import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
li = list(map(int, input().split()))
counter = collections.Counter(li)

sum_count = sum([combinations_count(n, 2) for n in counter.values()])

for k in range(n):
    print(sum_count - counter[li[k]] + 1)
Problem p02760 (python)

Fixed submission:
table_1 = input().split()
table_2 = input().split()
table_3 = input().split()
bingo_card = table_1 + table_2 + table_3

N = int(input())

for _ in range(N):
    b = str(int(input()))
    if b in bingo_card:
        bingo_card[bingo_card.index(b)] = True
        
if bingo_card[0] == bingo_card[1] == bingo_card[2]:
    print('Yes')
elif bingo_card[3] == bingo_card[4] == bingo_card[5]:
    print('Yes')
elif bingo_card[6] == bingo_card[7] == bingo_card[8]:
    print('Yes')
elif bingo_card[0] == bingo_card[3] == bingo_card[6]:
    print('Yes')
elif bingo_card[1] == bingo_card[4] == bingo_card[7]:
    print('Yes')
elif bingo_card[2] == bingo_card[5] == bingo_card[8]:
    print('Yes')
elif bingo_card[0] == bingo_card[4] == bingo_card[8]:
    print('Yes')
elif bingo_card[2] == bingo_card[4] == bingo_card[6]:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import numpy as np


def main():
    bingo_card = np.array([list(map(int, input().split())) for _ in range(3)])
    counter = int(input())

    for _ in range(counter):
        bingo_card = np.where(bingo_card == int(input()), 0, bingo_card)

    vertical_bingo = min(np.sum(bingo_card, axis=0)) == 0
    horizontal_bingo = min(np.sum(bingo_card, axis=1)) == 0

    diag_normal_bingo = bingo_card[0][0] == 0 and bingo_card[1][1] == 0 and bingo_card[2][2] == 0
    diag_reverse_bingo = bingo_card[0][2] == 0 and bingo_card[1][1] == 0 and bingo_card[2][0] == 0

    if vertical_bingo or horizontal_bingo or diag_normal_bingo or diag_reverse_bingo:
        print('Yes')
        exit()
    else:
        print('No')


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

Fixed submission:
import numpy as np

n = int(input())
x = list(map(int, input().split()))
p = round(sum(x) / len(x))
x_arr = np.array(x)
print(sum((x_arr - p) ** 2))

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
x = list(map(int, input().split()))
p = round(sum(x) / len(x))
x_arr = np.array(x)
print(sum((x_arr - p) ** 2))
Problem p02802 (python)

Fixed submission:
import numpy as np


def main():
    n, m = map(int, input().split())
    ac = np.array([0] * n)
    pena = np.array([0] * n)
    # 
    for _ in range(m):
        p, s = map(str, input().split())
        p = int(p) - 1
        if ac[p] == 0 and s == 'WA':
            pena[p] += 1
        else:
            ac[p] = 1
    print(sum(ac), sum(ac * pena))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    ac = [0] * m
    pena = [0] * m

    for _ in range(m):
        p, s = map(str, input().split())
        p = int(p) - 1
        if ac[p] == 0 and s == 'WA':
            pena[p] += 1
        else:
            ac[p] = 1
    print()


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    ac = [0] * m
    pena = [0] * m

    for _ in range(m):
        p, s = map(str, input().split())
        p = int(p) - 1
        if ac[p] == 0 and s == 'WA':
            pena[p] += 1
        else:
            ac[p] = 1
    print()


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

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


# def gen_counter(stop=10):
#     index = 1
#     while True:
#         if stop < index:
#             break
#         yield index
#         index += 1


N = int(input())
res = (N - 1) * N // 2
print(res)


# arr = np.arange(1, N + 1)
# t_arr = np.append(arr[1:], arr[0])
# print(sum(arr % t_arr))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
D = [int(input()) for _ in range(N)]
"""

import numpy as np

N = int(input())
arr = np.arange(1, N + 1)
t_arr = np.append(arr[1:], arr[0])
print(sum(arr % t_arr))


# def main():


# if __name__ == '__main__':
#     main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
D = [int(input()) for _ in range(N)]
"""

import numpy as np

N = int(input())
arr = np.arange(1, N + 1)
t_arr = np.append(arr[1:], arr[0])

mod_arr = arr % t_arr
print(sum(mod_arr))


# def main():


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

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N, Q = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N - 1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N + 1)
for p, x in PX:
    value[p] += x

q = [(1, 0)]
while q:
    x, parent = q.pop()
    value[x] += value[parent]
    for y in graph[x]:
        if y == parent:
            continue
        q.append((y, x))

ans = ' '.join(map(str, value[1:]))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


class Node:
    def __init__(self, parent, left):
        """
        Left-child, Right-sibiling
        """
        self.parent = parent
        self.left = left
        self.right = []
        self.point = 0

    def __str__(self):
        return f'parent = {self.parent}, left = {self.left}, right = {self.right}, point = {self.point}'


def set_point(T, node, point):
    T[node].point += point

    if T[node].left != NIL:
        l_child = T[node].left
        set_point(T, l_child, point)
        # T[l_child].point += point

    if T[node].right:
        for idx in range(len(T[node].right)):
            r_child = T[node].right[idx]
            set_point(T, r_child,  point)
            # T[r_child].point += point


N, Q = map(int, input().split())
T = {k: Node(NIL, NIL) for k in range(N)}

for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if T[a].left == NIL:
        left_child = b
        T[a].left = left_child
        T[left_child].parent = a
    else:
        T[a].right.append(b)
        T[b].parent = a

# for i in range(N):
#     print(i, T[i])

for j in range(Q):
    p, x = map(int, input().split())
    p -= 1
    set_point(T, p, x)


scores = []
for i in range(N):
    scores.append(T[i].point)

print(*scores)

# def main():


# if __name__ == '__main__':
#     main()