qyliang/CodeNanoFix huggingface dataset:
Buggy code:
a = int(input())
s = str(input())
if a < 3200:
  print(s)
else:
  print("red")

Fixed code:
a = int(input())
s= input()

if (a<3200):
    print('red')
else:
    print(s)
Buggy code:
a = int(input())
s = input()

print(s if a > 3200 else 'red')

Fixed code:
a = int(input())
s = input()

buff = s if a >= 3200 else 'red'

print(buff)
Buggy code:
color = input()
num = int(input())
if num >= 3200:
    print(s)
else:
    print('red')


Fixed code:
num = int(input())
color = input()
if num >= 3200:
    print(color)
else:
    print('red')
Buggy code:
a=int(input())
s=input()
if a<3200:print(s)
else:print("red")

Fixed code:
a = int(input())
s = input()

print("red" if a<3200 else s)
Buggy code:
a = int(input())
s = input()

if a >= 3200:
  print('red')
else:
  print(s)


Fixed code:
a=int(input())
s=input()
if a>=3200:print(s)
else:print("red")
Buggy code:
a = int(input())
s = input() if a > 3200 else 'red'
print(s)

Fixed code:
a = int(input())
s = input()


ans = s if a >= 3200 else "red"
print(ans)
Buggy code:
a = input()
s = input() if a < 3200 else 'red'
print(s)

Fixed code:
a = int(input())
s = input()
print(s if 3200 <= a else 'red')
Buggy code:
a = int(input())
s = input() if a < 3200 else 'red'
print(s)

Fixed code:
a = int(input())
s = input()
if 3200 <= a:
  print(s)
else:
  print("red")
Buggy code:
a = int(input())
s = input()
if a>3200:
  print("red")
else:
  print(s)


Fixed code:
a=int(input())
s = str(input())

if a >= 3200:
    print(s)
else:
    print("red")
Buggy code:
a=int(input())
s=int(input())

if a>=3200:
  print(S)
else:
  print("red")

Fixed code:
a=int(input())
s=input()
if a>=3200:
	print(s)
else:
	print('red')
Buggy code:
a=int(input())
s=input()
if a<=3200:
 print('red')
else:  print( s)



Fixed code:
a=int(input())
s=input()
if a<3200:
 print('red')
else:  print( s)
Buggy code:
a= input()
s=input()

if a<3200:
  print("red")
else:
  print(s)

Fixed code:
a = int(input())
s = input()
if a < 3200:
	print("red")
else:
	print(s)
Buggy code:
a=input()
s=input()
a=int(a)
s=int(s)
if a>=3200:
    print(s)
elif a<3200:
    print("red")

Fixed code:
a=input()
s=input()
a=int(a)
if a>=3200:
    print(s)
elif a<3200:
    print("red")
Buggy code:
a = input()
s = input()

if int(a)=>3200:
    print(s)
else:
    print("red")


Fixed code:
a = int(input())
s = input()


print(s if a>=3200 else "red")
Buggy code:
a = input()
s = input()

if int(a)=>3200:
    print(s)
else:
    print("red")
~                

Fixed code:
a = int(input())
s = input()
if (a >= 3200) :
    print(s)
else:
    print('red')
Buggy code:
a = int(input())
s = input()
if a >= 3200:
  print(s)
else:
  print('red)

Fixed code:
a=int(input())
s=input()
if a >= 3200:
 print(s)
else:
 print("red")
Buggy code:
a,s=int(input()),input()
print(s if a<3200 else 'red')

Fixed code:
a,s=int(input()),input()
print('red' if a<3200 else s)
Buggy code:
s = int(input())

if s >= 3200:
    print(s)
    
else:
    print("red")

Fixed code:
r = int(input())
s = input()

if r >= 3200:
    print(s)
else:
    print("red")
Buggy code:
a = int(input())
s = str(input())
if a >= 3200:
 print("red")
if s < 2800:
 print(s)

Fixed code:
a = int(input())
s = str(input())
if a >= 3200:
 print(s)
if a < 3200:
 print("red")
Buggy code:
a = int(input())
s = int(input())
if a >= 3200:
        print(s)
else:
        print("red")

Fixed code:
a = int(input())
s = input()
if a >= 3200:
        print(s)
else:
        print("red")
Buggy code:
A = int(input())
S = str(input())
if A >= 3200:print(S)
else print("red")

Fixed code:
A = int(input())
S = str(input())
if A >= 3200:print(S)
else: print("red")
Buggy code:
a = int(input())
b = input()
if a >= 3200:
  print("red")
else:
  print(b)

Fixed code:
a = int(input())
b = input()
if a >= 3200:
    print(b)
else: 
    print("red")
Buggy code:
a = input()
s = input()

print s if a > 3200 else 'red'

Fixed code:
a = input()
s = input()

print(s if int(a) >= 3200 else 'red')
Buggy code:
a = input()
s = input()

print( s if a >3200 else: 'red')

Fixed code:
a=int(input())
s = input()

if a >=3200:
    print(s)
else:
    print("red")
Buggy code:
a=input()
b=input()
if int(a)>3200:
	print("red")
elif int(a)<3200:
    print(b)

Fixed code:
a=input()
b=input()
if int(a)>=3200:
	print(b)
elif int(a)<3200:
    print("red")
Buggy code:
a=input()
b=input()
if a>=3200:
	print(b)
else:
  print("red")

Fixed code:
a=input()
b=input()
if int(a)>=3200:
	print(b)
else:
  print("red")
Buggy code:
a = int(input())
s = input()
if a < 3200:
    print("red")
else:
  	print(b)

Fixed code:
a = int(input())
s = input()
if a < 3200:
    print("red")
else:
  	print(s)
Buggy code:
a = int(input())
s = input()

if a >= 3200
	print("red")
else:
  	print(s)


Fixed code:
a = int(input())
s = input()

if a >= 3200:
	print(s)
else:
	print('red')
Buggy code:
a = int(input())
s = str(input())
print(s if a > 3200 else "red")


Fixed code:
a = int(input())
s=input()

print(s if a>=3200 else 'red')
Buggy code:
a=int(input())
s=str(input())
if a <= 3200:
  print("s")
else:
  print("red")

Fixed code:
a = int(input())
s = input()
if 3200 <= a:
  print(s)
else:
  print('red')
Buggy code:
a=input()
s=input()
if a >= 3200:
  print(s)
else:
  print("red")

Fixed code:
a=int(input())
s=input()

if a >=3200:
    print(s)
else:
    print('red')
Buggy code:
import sys
input = sys.stdin.readline

def main():
  a = int(input())
  s = input().strip()
  if a <= 3200:
    print(s)
  else:
    print('red')


if __name__ == '__main__':
  main()


Fixed code:
import sys
input = sys.stdin.readline

def main():
  a = int(input())
  s = input().strip()
  if a >= 3200:
    print(s)
  else:
    print('red')


if __name__ == '__main__':
  main()
Buggy code:
import sys
a = []
for l in sys.stdin:
    a.append(int(l))

if a[0] >= 3200:
    print(a[1])
else:
    print('red')

Fixed code:
import sys
a = []
for l in sys.stdin:
    a.append(l)

if int(a[0]) >= 3200:
    print(a[1])
else:
    print('red')
Buggy code:
a = int(input())
s = input()

if a => 3200:
  print(s)
else:
  print('red')

Fixed code:
a = int(input())
if a >=3200:
  print(input())
else:
  print('red')
Buggy code:
a = int(input())
s = input()
if a < 3200:
    print("red")
else:
    print("s")

Fixed code:
a = int (input ())
s = input ()
if a < 3200:
  print ('red')
else:
  print (s)
Buggy code:
# -*- coding: utf-8 -*-

import sys


a = int(sys.stdin.readline())
s = sys.stdin.readline()

if a > 3200:
    print(s)
else:
    print("red")


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

import sys


a = int(sys.stdin.readline())
s = sys.stdin.readline()

if a >= 3200:
    print(s)
else:
    print("red")
Buggy code:
a = int(input())
s = input()
if a >= 3200:
    print("red")
else:
    print(s)

Fixed code:
a=int(input())
s=input()

print(s if a>=3200 else "red")
Buggy code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a = gete(int)
    s = gete()

    if s < 3200:
        print(a)
    else:
        print('red')


if __name__ == "__main__":
    main()

Fixed code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a = gete(int)
    s = gete()

    if a < 3200:
        print('red')
    else:
        print(s)


if __name__ == "__main__":
    main()
Buggy code:
a=int(input())
s=input()
if a=>3200:
  print('s')
else:
  print('red')

Fixed code:
a=int(input())
s=input()

if a >= 3200:
  print(s)
  
else:
  print("red")
Buggy code:
import sys
import io
#sys.stdin = io.StringIO(input_string)
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def resolve():
	from collections import deque
	
	n, q = map(int, input().split())
	adj = [[] for i in range(n+1)]
	for i in range(n-1):
		a, b = map(int, input().split())
		adj[a-1].append(b-1)
		adj[b-1].append(a-1)
	ans = [0 for i in range(n)]
	for i in range(q):
		p, x = map(int, input().split())
		p -= 1
		ans[p] += x
#	print(f"{adj=}\n{ans=}")

	def dfs(now, prv):
		for next in adj[now]:
#			print(f"{now=}, {next=}")
			if nextinput = sys.stdin.readline == prv:
				continue
			ans[next] += ans[now]
			dfs(next, now)

	dfs(0, 0)
	print(*ans)

resolve()

Fixed code:
import sys
import io
#sys.stdin = io.StringIO(input_string)
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]
    
def resolve():
	from collections import deque
	
	n, q = map(int, input().split())
	adj = [[] for i in range(n+1)]
	for i in range(n-1):
		a, b = map(int, input().split())
		adj[a-1].append(b-1)
		adj[b-1].append(a-1)
	ans = [0 for i in range(n)]
	for i in range(q):
		p, x = map(int, input().split())
		p -= 1
		ans[p] += x
#	print(f"{adj=}\n{ans=}")

	def dfs(now, prv):
		for next in adj[now]:
#			print(f"{now=}, {next=}")
			if next == prv:
				continue
			ans[next] += ans[now]
			dfs(next, now)

	dfs(0, 0)
	print(*ans)

resolve()
Buggy code:
n, q = map(int, input().split())
tree =[[] for i in range(n)]
ans = [0 for i in range(n)]
visited = [0 for i in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  tree[a].append(b)
  tree[b].append(a)
  
for i in range(q):
  a, b = map(int, input().split())
  ans[a-1] = b

visited[0] = 1
stack = [0]
while stack:
  v = stack.pop()
  for c in tree[v]:
    if visited[c]:
      continue
    visited[c] = 1
    ans[c] += ans[v]
    stack.append(c)
    
print(" ".join(str(i) for i in ans))


Fixed code:
n, q = map(int, input().split())
tree =[[] for i in range(n)]
ans = [0 for i in range(n)]
visited = [0 for i in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  tree[a].append(b)
  tree[b].append(a)
  
for i in range(q):
  a, b = map(int, input().split())
  ans[a-1] += b

visited[0] = 1
stack = [0]
while stack:
  v = stack.pop()
  for c in tree[v]:
    if visited[c]:
      continue
    visited[c] = 1
    ans[c] += ans[v]
    stack.append(c)
    
print(" ".join(str(i) for i in ans))
Buggy code:
from collections import defaultdict
N, Q = map(int,input().split())

tree = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  tree[a].add(b)
  tree[b].add(a)

counter = defaultdict(int)
for i in range(Q):
  p, x = map(int, input().split())
  counter[p] = x

cur_node = set()
cur_node.add(1)
pre_node = set()
while len(cur_node) != 0:
  next_node = set()
  for ni in cur_node:
    for nj in tree[ni]:
      if nj in pre_node:
        continue
      counter[nj] += counter[ni]
      next_node.add(nj)
  pre_node = cur_node
  cur_node = next_node
print(" ".join((str(counter[i]) for i in range(1, N+1))))



Fixed code:
from collections import defaultdict
N, Q = map(int, input().split())
 
tree = defaultdict(set)
for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a].add(b)
    tree[b].add(a)

counter = defaultdict(int)
for i in range(Q):
    p, x = map(int, input().split())
    counter[p] += x

cur_node = set()
cur_node.add(1)
pre_node = set()
while len(cur_node) != 0:
  next_node = set()
  for ni in cur_node:
    for nj in tree[ni]:
      if nj in pre_node:
        continue
      counter[nj] += counter[ni]
      next_node.add(nj)
  pre_node = cur_node
  cur_node = next_node
print(' '.join((str(counter[i]) for i in range(1, N + 1))))
Buggy code:
N,Q=list(map(int,input().strip().split(' ')))
gr=[[] for _ in range(N)]
val=[0]*N
for _ in range(N-1):
    a,b=list(map(int,input().strip().split(' ')))
    a-=1
    b-=1
    gr[a]+=[b]
    gr[b]+=[a]
for _ in range(Q):
    p,x=list(map(int,input().strip().split(' ')))
    p-=1
    val[p]=x
ans=[0]*N
stack=[0]
checked=[0]*N
checked[0]=1
ans[0]=val[0]
while stack:
    x=stack.pop()
    for v in gr[x]:
        if checked[v]==0:
            stack+=[v]
            checked[v]=1
            ans[v]=ans[x]+val[v]
for x in ans:
    print(x,end=" ")

Fixed code:
N,Q=list(map(int,input().strip().split(' ')))
gr=[[] for _ in range(N)]
val=[0]*N
for _ in range(N-1):
    a,b=list(map(int,input().strip().split(' ')))
    a-=1
    b-=1
    gr[a]+=[b]
    gr[b]+=[a]
for _ in range(Q):
    p,x=list(map(int,input().strip().split(' ')))
    p-=1
    val[p]+=x
ans=[0]*N
stack=[0]
checked=[0]*N
checked[0]=1
ans[0]=val[0]
while stack:
    x=stack.pop()
    for v in gr[x]:
        if checked[v]==0:
            stack+=[v]
            checked[v]=1
            ans[v]=ans[x]+val[v]
ans=[str(x) for x in ans]

print(" ".join(ans))
Buggy code:
N, Q = (int(i) for i in input().split())
ab = [[int(i) for i in input().split()] for i in range(N-1)] 
px = [[int(i) for i in input().split()] for i in range(Q)] 
ab.sort()

weight = [0]*N
for i in range(len(px)):
	weight[px[i][0]-1]+=px[i][1]

for g in range(len(ab)):
	weight[ab[g][1]-1] += weight[ab[g][0]-1]

print(weight)

Fixed code:
N, Q = (int(i) for i in input().split())
ab = [[int(i) for i in input().split()] for i in range(N-1)] 
px = [[int(i) for i in input().split()] for i in range(Q)] 
ab.sort()

weight = [0]*N
for i in range(len(px)):
	weight[px[i][0]-1]+=px[i][1]

for g in range(len(ab)):
	weight[ab[g][1]-1] += weight[ab[g][0]-1]

print(*weight)
Buggy code:
from collections import deque
n,q=map(int,input().split())
K=[set() for _ in range(n)]
V=[False]*n
P=[0]*n
for i in range(n-1):
      a,b=map(int,input().split())
      K[a-1].add(b-1)
      K[b-1].add(a-1)
for i in range(q):
      c,d=map(int,input().split())
      P[c-1]=d
que=deque([0])
while que:
      s=que.popleft()
      V[s]=True
      for ni in K[s]:
            if V[ni]==False:
                  P[ni]+=P[s]
                  que.append(ni)
print(*P)

Fixed code:
from collections import deque
n,q=map(int,input().split())
K=[set() for _ in range(n)]
V=[False]*n
P=[0]*n
for i in range(n-1):
      a,b=map(int,input().split())
      K[a-1].add(b-1)
      K[b-1].add(a-1)
for i in range(q):
      c,d=map(int,input().split())
      P[c-1]+=d
que=deque([0])
while que:
      s=que.popleft()
      V[s]=True
      for ni in K[s]:
            if V[ni]==False:
                  P[ni]+=P[s]
                  que.append(ni)
print(*P)
Buggy code:
from collections import deque
n,q=map(int,input().split())
K=[[] for _ in range(n)]
V=[False]*n
P=[0]*n
for i in range(n-1):
   a,b=map(int,input().split())
   K[a-1].append(b-1)
   K[b-1].append(a-1)
for i in range(q):
   q,x=map(int,input().split())
   P[q-1]=x
que=deque([0])
while que:
   s=que.popleft()
   V[s]=True
   for ni in K[s]:
      if V[ni]==False:
         P[ni]+=P[s]
         que.append(ni)
print(*P)

Fixed code:
from collections import deque
n,q=map(int,input().split())
K=[[] for _ in range(n)]
V=[False]*n
P=[0]*n
for i in range(n-1):
   a,b=map(int,input().split())
   K[a-1].append(b-1)
   K[b-1].append(a-1)
for i in range(q):
   q,x=map(int,input().split())
   P[q-1]+=x
que=deque([0])
while que:
   s=que.popleft()
   V[s]=True
   for ni in K[s]:
      if V[ni]==False:
         P[ni]+=P[s]
         que.append(ni)
print(*P)
Buggy code:
n,q = map(int,input().split())
r = [[] for i in range(n)]
v = [0 for i in range(n)]

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

for i in range(q):
    p,x = map(int,input().split())
    v[p-1] += x


bfs = [0]
visit = [False in range(n)]
while len(bfs) != 0:
    tmp = []
    for i in bfs:
        for y in r[i]:
            if not visit[y]:
                v[y] += v[i]
                tmp.append(y)
        visit[i] = True
    bfs = tmp

#print(" ".join(map(str,v)))
print(*v)

Fixed code:
n,q = map(int,input().split())
r = [[] for i in range(n)]
v = [0 for i in range(n)]

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

for i in range(q):
    p,x = map(int,input().split())
    v[p-1] += x


bfs = [0]
visit = [False for i in range(n)]
while len(bfs) != 0:
    tmp = []
    for i in bfs:
        for y in r[i]:
            if not visit[y]:
                v[y] += v[i]
                tmp.append(y)
        visit[i] = True
    bfs = tmp

#print(" ".join(map(str,v)))
print(*v)
Buggy code:
n,q = map(int,input().split())
r = [[] for i in range(n)]
v = [0 for i in range(n)]

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

for i in range(q):
    p,x = map(int,input().split())
    v[p-1] += x


for i in range(1,n):

    for y in r[i]:
        v[y] += v[i]

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

Fixed code:
n,q = map(int,input().split())
r = [[] for i in range(n+1)]
v = [0 for i in range(n+1)]

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

for i in range(q):
    p,x = map(int,input().split())
    v[p] += x


for i in range(1,n+1):

    for y in r[i]:
        v[y] += v[i]

print(" ".join(map(str,v[1:])))
Buggy code:
N,Q = [int(x) for x in input().split()]
ki = [0]*N
tr = [[] for _ in range(N)]

for i in range(N-1):
    a,b = [int(x)-1 for x in input().split()]
    tr[a].add(b)
    tr[b].add(a)

for i in range(Q):
    position,val = [int(x) for x in input().split()]
    ki[position-1] += val

stack =[1]
vivisted = set()

while stack:
    i = stack.pop()
    for j in tr[i]:
        if j in visited:
            continue
        visited.add(j)
        ki[j] += ki[i]
        stack.append(j)

for i in ki:
    print(i,end=" ")
print()


Fixed code:
N,Q = [int(x) for x in input().split()]
ki = [0]*N
tr = [[] for _ in range(N)]

for i in range(N-1):
    a,b = [int(x)-1 for x in input().split()]
    tr[a].append(b)
    tr[b].append(a)

for i in range(Q):
    position,val = [int(x) for x in input().split()]
    ki[position-1] += val

stack =[0]
visited = set()
visited.add(0)

while stack:
    i = stack.pop()
    for j in tr[i]:
        if j in visited:
            continue
        visited.add(j)
        ki[j] += ki[i]
        stack.append(j)

for i in ki:
    print(i,end=" ")
print()
Buggy code:
from collections import deque
n , q = map(int,input().split())
lot = [[] for i in range(n)]
ans = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int,input().split())
    lot[a-1].append(b-1)
    lot[b-1].append(a-1)
tyu = [0]*n
for i in range(q):
    p , x = map(int,input().split())
    tyu[p-1] += x

taiki = deque()
taiki.append(0)
owari = []
while  taiki:
    s = taiki.pop()
    for i in lot[s]:
        if owari.count(i) == 0:
            tyu[i] += tyu[s]
            taiki.append(i)
    owari.append(s)
print(tyu)


Fixed code:
from collections import deque
n , q = map(int,input().split())
lot = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int,input().split())
    lot[a-1].append(b-1)
    lot[b-1].append(a-1)
tyu = [0]*n
for i in range(q):
    p , x = map(int,input().split())
    tyu[p-1] += x

taiki = deque()
taiki.append(0)
owari = [True] * n
while  taiki:
    s = taiki.pop()
    for i in lot[s]:
        if owari[i]:
            tyu[i] += tyu[s]
            taiki.append(i)
    owari[s] = False
print(*tyu)
Buggy code:
import sys
sys.setrecursionlimit(10**5)

N, Q = list(map(int, input().split()))
nodes = [[] for i in range(N)]
for i in range(N-1):
  r, e = list(map(int, input().split()))
  r, e = r - 1, e - 1
  nodes[r].append(e)
  nodes[e].append(r)
#print(nodes)

result = [0] * N
for i in range(Q):
  r, s = list(map(int, input().split()))
  result[r-1] += s

def dfs(r, prev=-1):
  for i in nodes[r]:
    if i == prev:
      continue
    result[i] += result[r]
    dfs(i, r)

if __name__ == "__main__:
  dfs(0)
  print(*result)


Fixed code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = list(map(int, input().split()))
nodes = [[] for i in range(N)]
for i in range(N-1):
  r, e = list(map(int, input().split()))
  r, e = r - 1, e - 1
  nodes[r].append(e)
  nodes[e].append(r)
#print(nodes)

result = [0] * N
for i in range(Q):
  r, s = list(map(int, input().split()))
  result[r-1] += s

def dfs(r, prev=-1):
  for i in nodes[r]:
    if i == prev:
      continue
    result[i] += result[r]
    dfs(i, r)

if __name__ == "__main__":
  dfs(0)
  print(*result)
Buggy code:
import collections

N, Q = map(int, input().split())
lst = [[] for _ in range(N)]
ans = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    lst[b-1].append(a-1)
    lst[a-1].append(b-1)
print(lst)
for j in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x
               
q=collections.deque()
q.append(0)
flag = [0]*N
while q:
    y = q.pop()
    flag[y] = 1
    for k in lst[y]:
        if flag[k] == 1:
            continue
        ans[k] += ans[y]
        q.append(k)
print(*ans)


Fixed code:
import collections

N, Q = map(int, input().split())
lst = [[] for _ in range(N)]
ans = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    lst[b-1].append(a-1)
    lst[a-1].append(b-1)
for j in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x
               
q=collections.deque()
q.append(0)
flag = [0]*N
while q:
    y = q.pop()
    flag[y] = 1
    for k in lst[y]:
        if flag[k] == 1:
            continue
        ans[k] += ans[y]
        q.append(k)
print(*ans)
Buggy code:
import sys

#N,Q = list(map(int,input().split()))
N,Q = [int(i) for i in sys.stdin.readline().split()]
G=[]
for i in range(N):
    G.append([])

for i in range(N-1):
    #a,b = list(map(int,input().split()))
    a,b = [int(j) for j in sys.stdin.readline().split()]
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

p=[0]*Q
x=[0]*Q
c=[0]*N

for i in range(Q):
    #p,x = list(map(int,input().split()))
    p,x = [int(j) for j in sys.stdin.readline().split()]
    p-=1
    c[p] += x

stack=deque([0])
parent = [-1]*N

while(stack):
    v = stack.pop()
    for u in G[v]:
        if u!=parent[v]:
            c[u]+=c[v]
            parent[u]=v
            stack.append(u)


ans = ' '.join([str(x) for x in c])

print(ans)

Fixed code:
import sys
from collections import deque
#N,Q = list(map(int,input().split()))
N,Q = [int(i) for i in sys.stdin.readline().split()]
G=[]
for i in range(N):
    G.append([])

for i in range(N-1):
    #a,b = list(map(int,input().split()))
    a,b = [int(j) for j in sys.stdin.readline().split()]
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

p=[0]*Q
x=[0]*Q
c=[0]*N

for i in range(Q):
    #p,x = list(map(int,input().split()))
    p,x = [int(j) for j in sys.stdin.readline().split()]
    p-=1
    c[p] += x

stack=deque([0])
parent = [-1]*N

while(stack):
    v = stack.pop()
    for u in G[v]:
        if u!=parent[v]:
            c[u]+=c[v]
            parent[u]=v
            stack.append(u)


ans = ' '.join([str(x) for x in c])

print(ans)
Buggy code:
vimport sys 
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

def dfs(v, pv):
    # global P

    for nv in G[v]:
        if nv != pv:
            P[nv] += P[v]
            dfs(nv, v)

n,q = map(int, input().split())
G = [[] for _ in range(n)]              # adjacent list
for i in range(n-1):
    a,b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

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


dfs(0, 0)
print(*P)



Fixed code:
import sys 
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

def dfs(v, pv):
    global P

    for nv in G[v]:
        if nv != pv:
            P[nv] += P[v]
            dfs(nv, v)

n,q = map(int, input().split())
G = [[] for _ in range(n)]              # adjacent list
for i in range(n-1):
    a,b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

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


dfs(0, 0)
print(*P)