Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = n // 1000
b = n // 100 - a * 10
c = n // 10 - a * 100 - b * 10
d = n - a * 1000 - b * 100 - c * 10
yet = True
if a+b+c+d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b+c-d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a+b-c+d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b-c-d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b+c+d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b+c-d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b-c+d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b-c-d==7 and yet:
    print(str(a)+'

Fixed submission:
n = int(input())
a = n // 1000
b = n // 100 - a * 10
c = n // 10 - a * 100 - b * 10
d = n - a * 1000 - b * 100 - c * 10
yet = True
if a+b+c+d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b+c-d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a+b-c+d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b-c-d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b+c+d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b+c-d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b-c+d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b-c-d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')    
    yet = False
Buggy python submission (verdict: Runtime Error):
a = list(map(str, input().split()))
b = list(map(str, input().split()))
if a[0] == b[2] and a[1] == b[1] and a[2] == b[0]:
    print("YES")
else:
    print("NO")


Fixed submission:
a = input()
b = input()
if a[0] == b[2] and a[1] == b[1] and a[2] == b[0]:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input.split()))
s = sum(a)
if n < s:
  print(-1)
else:
  print(n - a)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
if n < s:
  print(-1)
else:
  print(n - s)
Buggy python submission (verdict: Time Limit Exceeded):
[n, k] = map(int, input().split())

while True:
  if k <= n:
    n -= k
  elif n > k//2:
    n = k - n
  else:
    break

    
print(n)
    

Fixed submission:
[n, k] = map(int, input().split())
 
n -= (n//k) * k
if n > k//2:
  n = k -n
print(n)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from collections import Counter
from collections import defaultdict

n = int(sys.stdin.readline())
a = ''.join(sys.stdin.readline().split())
c = Counter(a)
comb_num = defaultdict(int)
subtracted_comb_num = defaultdict(int)

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

for key in c.keys():
    comb_num[key] = combinations_count(int(c[key]), 2)
    subtracted_comb_num[key] = combinations_count(int(c[key])-1, 2)

total_comb_num = sum(comb_num.values())
for num in a:
    print(total_comb_num - comb_num[num] + subtracted_comb_num[num])


Fixed submission:
import sys
import math
from collections import Counter

n = int(sys.stdin.readline())
a = sys.stdin.readline().split()
c = Counter(a)

total_comb_num = sum(map(lambda v: max(v*(v-1)//2, 0), c.values()))
for num in a:
    x = c[num]
    print(total_comb_num + max((x-1)*(x-2)//2, 0) - max((x*(x-1)//2, 0)))
Buggy python submission (verdict: Runtime Error):
import sys

n, a, b = map(int, sys.stdin.readline().split())
s = 'b'*a + 'r'*b

x = n // (a+b)
y = n % (a+b)

z = s[:y].count('b')
print(x*a + z)


Fixed submission:
import sys

n, a, b = map(int, sys.stdin.readline().split())

x = n // (a+b)
y = min(a, (n % (a+b)))

print(x*a + y)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

s = list(sys.stdin.readline().rstrip())
q = int(sys.stdin.readline())
s = deque(s)

for _ in range(q):
    query = sys.stdin.readline().split()
    if len(query) == 1:
        s.reverse()
    elif query[1] == '1':
        s.appendleft(query[2])
    else:
        s.append(query[2])

print(''.join(s))


Fixed submission:
import sys
from collections import deque

s = list(sys.stdin.readline().rstrip())
q = int(sys.stdin.readline())
head = 0
s = deque(s)

for _ in range(q):
    query = sys.stdin.readline().split()
    if len(query) == 1:
        head = 1 if head == 0 else 0
    elif (query[1] == '1' and head == 1) or (query[1] == '2' and head == 0):
        s.append(query[2])
    else:
        s.appendleft(query[2])

if head == 1:
    s.reverse()

print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

s = list(sys.stdin.readline().rstrip())
q = int(sys.stdin.readline())
querys = [sys.stdin.readline().split() for _ in range(q)]
s = deque(s)

for query in querys:
    if len(query) == 1:
        s.reverse()
    else:
        if query[1] == '1':
            s.appendleft(query[2])
        else:
            s.append(query[2])

print(''.join(s))


Fixed submission:
import sys
from collections import deque

s = list(sys.stdin.readline().rstrip())
q = int(sys.stdin.readline())
head = 0
s = deque(s)

for _ in range(q):
    query = sys.stdin.readline().split()
    if len(query) == 1:
        head = 1 if head == 0 else 0
    elif (query[1] == '1' and head == 1) or (query[1] == '2' and head == 0):
        s.append(query[2])
    else:
        s.appendleft(query[2])

if head == 1:
    s.reverse()

print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

s = list(sys.stdin.readline().rstrip())
q = int(sys.stdin.readline())
s = deque(s)

for _ in range(q):
    query = sys.stdin.readline().split()
    if len(query) == 1:
        s.reverse()
    else:
        if query[1] == '1':
            s.appendleft(query[2])
        else:
            s.append(query[2])

print(''.join(s))


Fixed submission:
import sys
from collections import deque

s = list(sys.stdin.readline().rstrip())
q = int(sys.stdin.readline())
head = 0
s = deque(s)

for _ in range(q):
    query = sys.stdin.readline().split()
    if len(query) == 1:
        head = 1 if head == 0 else 0
    elif (query[1] == '1' and head == 1) or (query[1] == '2' and head == 0):
        s.append(query[2])
    else:
        s.appendleft(query[2])

if head == 1:
    s.reverse()

print(''.join(s))
Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
magic = []
max_damage = 0
for i in range(n):
    magic.append(list(map(int, input().split())))
    max_damage = max(max_damage, magic[i][0])

# 一次元で可能
dp = [10**10 for _ in range(h+max_damage)]
dp[0] = 0

for damage, cost in magic:
    for j in range(h+max_damage):
        dp[j] = min(dp[j], dp[j-damage]+cost)

#print(dp)
print(min(dp[h:-1]))


Fixed submission:
h, n = map(int, input().split())
magic = []
for i in range(n):
    magic.append(list(map(int, input().split())))

# 一次元で可能
dp = [10**10 for _ in range(h+1)]
dp[0] = 0

for damage, cost in magic:
    for j in range(h+1):
        nj = min(j+damage, h)
        dp[nj] = min(dp[nj], dp[j]+cost)

#print(dp)
print(dp[h])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p_list = list(map(int, input().split()))
min_list = []
min_list.append(p_list[0])
ans = 1

for i in range(1, n):
    if p_list[i] <= min(min_list):
        ans += 1
    min_list.append(p_list[i])

print(ans)


Fixed submission:
n = int(input())
p_list = list(map(int, input().split()))
min_num = p_list[0]
ans = 1

for i in range(1, n):
    if p_list[i] <= min_num:
        ans += 1
    min_num = min(min_num, p_list[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

lcm = a[0]
for i in range(1, n):
    #lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
    lcm = lcm * a[i] // math.gcd(lcm, a[i])
lcm %= MOD
for i in range(n):
    ans += lcm * pow(a[i] , MOD-2, MOD)
    ans %= MOD
print(ans)


Fixed submission:
import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

lcm = a[0]
for i in range(1, n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
    #lcm = lcm * a[i] // math.gcd(lcm, a[i])
lcm %= MOD
for i in range(n):
    ans += lcm * pow(a[i] , MOD-2, MOD)
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

lcm = a[0]
for i in range(1, n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
    #lcm = lcm * a[i] // math.gcd(lcm, a[i])
a2 = list(map(lambda x: lcm//x % MOD, a))
print(sum(a2)%MOD)
#
#
#
# for i in range(n):
#     ans += (lcm // a[i]) % MOD
#     ans %= MOD

#print(ans)


Fixed submission:
import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

lcm = a[0]
for i in range(1, n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
    #lcm = lcm * a[i] // math.gcd(lcm, a[i])
lcm %= MOD
for i in range(n):
    ans += lcm * pow(a[i] , MOD-2, MOD)
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

lcm = a[0]
for i in range(1, n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
    #lcm = lcm * a[i] // math.gcd(lcm, a[i])

for i in range(n):
    ans += (lcm // a[i]) % MOD
    ans %= MOD

print(ans)


Fixed submission:
import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

lcm = a[0]
for i in range(1, n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
    #lcm = lcm * a[i] // math.gcd(lcm, a[i])
lcm %= MOD
for i in range(n):
    ans += lcm * pow(a[i] , MOD-2, MOD)
    ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k, s = map(int, input().split())
if s == 10**9:
    a = 10**9-1
else:
    a = 10**9
l = [a for _ in range(n)]

if s % 2 == 0:
    l[0:k+1] = [s//2 for _ in range(k+1)]
else:
    s, t = (s-1)//2, (s+1)//2
    for i in range(k+1):
        if i % 2 == 0:
            l[i] = s
        else:
            l[i] = t

print(l)


Fixed submission:
n, k, s = map(int, input().split())
if s == 10**9:
    a = 10**9-1
else:
    a = 10**9
l = [a for _ in range(n)]

if k == n:
    print(' '.join(map(str, [s for _ in range(n)])))
elif k == 0:
    print(' '.join(map(str, l)))
else:
    if s == 1:
        l[0:k] = [s for _ in range(k)]
    elif s % 2 == 0:
        l[0:k+1] = [s//2 for _ in range(k+1)]
    else:
        u, t = (s-1)//2, (s+1)//2
        for i in range(k+1):
            if i % 2 == 0:
                l[i] = u
            else:
                l[i] = t

    print(' '.join(map(str, l)))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

INF = 1000000000
h,w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

def bfs(sx, sy, gx, gy):
    ds = [[1,0], [-1,0], [0,1], [0,-1]]
    visited = [[False for _ in range(h)] for _ in range(w)]
    distance = [[INF for _ in range(h)] for _ in range(w)]
    q = deque([[sx, sy]])
    distance[sx][sy] = 0

    while q:
        x, y = q.popleft()
        if visited[x][y]: continue
        visited[x][y] = True
        #print('-----', x, y)
        for dx, dy in ds:
            nx = x+dx
            ny = y+dy
            if (nx >= 0) and (nx <= w-1) and (ny >= 0) and (ny <= h-1):
                #print(nx, ny)
                if maze[ny][nx] != '#':
                    q.append([nx, ny])
                    distance[nx][ny] = min(distance[nx][ny], distance[x][y] + 1)
    return distance[gx][gy]

count = 0
for s_x in range(w):
    for s_y in range(h):
        if maze[s_y][s_x] == '.':
            for g_x in range(w):
                for g_y in range(h):
                    if (maze[g_y][g_x] == '.' and ((s_x != g_x) or (s_y != g_y))):
                        #print(s_x, s_y, g_x, g_y)
                        ans = bfs(s_x, s_y, g_x, g_y)
                        #print(ans)
                        if ans != INF and ans > count:
                            count = ans

print(count)


Fixed submission:
from collections import deque

INF = 1000000000
h,w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

def bfs(sx, sy):
    ds = [[1,0], [-1,0], [0,1], [0,-1]]
    distance = [[-1 for _ in range(h)] for _ in range(w)]
    q = deque([[sx, sy]])
    distance[sx][sy] = 0

    while q:
        x, y = q.popleft()
        #print('-----', x, y)
        for dx, dy in ds:
            nx, ny = x+dx, y+dy
            if (nx >= 0) and (nx <= w-1) and (ny >= 0) and (ny <= h-1):
                #print(nx, ny)
                if maze[ny][nx] != '#' and distance[nx][ny] == -1:
                    q.append([nx, ny])
                    distance[nx][ny] = distance[x][y] + 1
    return max(map(max, distance))

count = 0
for s_x in range(w):
    for s_y in range(h):
        if maze[s_y][s_x] == '.':
            count = max(count, bfs(s_x, s_y))

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans_l = set()

for i in range(n-2):
    for j in range(i+1, n-1):
        nums = set(s[j+1::])
        for num in nums:
            ans_l.add(s[i] + s[j] + num)

print(len(ans_l))


Fixed submission:
n = int(input())
s = input()

ones = set()
twos = set()
threes = set()

for a in s:
    for item in twos:
        threes.add(item+a)
    for item in ones:
        twos.add(item+a)
    ones.add(a)

print(len(threes))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

dp = [[[0 for _ in range(1000)] for _ in range(4)] for _ in range(n+1)]
dp[0][0][0] = 1
ans = 0

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k] == 0: continue
            dp[i+1][j][k] = 1
            if j <= 2:
                dp[i+1][j+1][k*10 + int(s[i])] = 1

print(sum(dp[n][3]))


Fixed submission:
n = int(input())
s = input()

ones = set()
twos = set()
threes = set()

for a in s:
    for item in twos:
        threes.add(item+a)
    for item in ones:
        twos.add(item+a)
    ones.add(a)

print(len(threes))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

dp = [[[0 for _ in range(1000)] for _ in range(4)] for _ in range(n+1)]
dp[0][0][0] = 1
ans = 0

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k] == 0: continue
            dp[i+1][j][k] = 1
            if j <= 2:
                dp[i+1][j+1][k*10 + int(s[i])] = 1

for k in range(1000):
    ans += dp[n][3][k]
print(ans)


Fixed submission:
n = int(input())
s = input()

ones = set()
twos = set()
threes = set()

for a in s:
    for item in twos:
        threes.add(item+a)
    for item in ones:
        twos.add(item+a)
    ones.add(a)

print(len(threes))
Buggy python submission (verdict: Runtime Error):
import collections

MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
d.sort()

c = collections.Counter(d)
if c[0] != 1:
    print('0')
else:
    ans = 1
    k = list(c.keys())
    for i in range(1, len(v)):
        print(ans)
        ans *= v[i-1]**v[i]
    print(ans % MOD)


Fixed submission:
import collections

MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
    exit()

d.sort()

c = collections.Counter(d)
if c[0] != 1:
    print('0')
else:
    ans = 1
    k = list(c.keys())
    v = list(c.values())
    for i in range(1, len(v)):
        if k[i]-1 != k[i-1]:
            ans *= 0
        ans *= (v[i-1]**v[i]) % MOD
    print(ans % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

ans = ''

ans += s[0]
prev = s[0]

for i in range(1, n):
    if s[i] != prev:
        prev = s[i]
        ans += prev

print(len(ans))


Fixed submission:
n = int(input())
s = input()

prev = s[0]
ans = 1

for i in range(1, len(s)):
    if s[i] != prev:
        prev = s[i]
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)

for _ in range(m):
    a[0] = a[0] // 2
    a.sort(reverse=True)


print(sum(a))


Fixed submission:
# priority queueで楽勝だった
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * -1, input().split()))
heapq.heapify(a)

for _ in range(m):
    x = -(-a[0] // 2)
    heapq.heapreplace(a, x)
    #print(a)
print(sum(a) * -1)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(m):
    num = a.index(max(a))
    a[num] = a[num] // 2

print(sum(a))


Fixed submission:
# priority queueで楽勝だった
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * -1, input().split()))
heapq.heapify(a)

for _ in range(m):
    x = -(-a[0] // 2)
    heapq.heapreplace(a, x)
    #print(a)
print(sum(a) * -1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0

def add(n):
    if n%2 == 0:
        return sum(range(1,n))
    else:
        p = (n // 2 ) + 1
        return (n % p) + sum(range(1,n)) - (p-1)

print(add(n))


Fixed submission:
n = int(input())
ans = 0

def add(n):
    if n%2 == 0:
        return sum(range(1,n))
    else:
        p = (n // 2 ) + 1
        return (n % p) + sum(range(1,n)) - (p-1)

print(add(n))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0

def add(n):
    if n%2 == 0:
        return sum(range(1,n))
    else:
        p = (n // 2 ) + 1
        return (n % p) + sum(range(p,n)) + add(p-1)

print(add(n))


Fixed submission:
n = int(input())
ans = 0

def add(n):
    if n%2 == 0:
        return sum(range(1,n))
    else:
        p = (n // 2 ) + 1
        return (n % p) + sum(range(1,n)) - (p-1)

print(add(n))
Buggy python submission (verdict: Runtime Error):
INF = 1000000007

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

for i in range(len(a)):
    for j in range(len(a)):
        if i == j: continue
        #print(a[i], a[j])
        if a[i] > a[j]:
            if i < j:
                ans_i += 1
            else:
                ans_e += 1
x = ans_i * k
ans = ans_i + ans_e
y = ans * (k * (k-1) )// 2)
print(int((x + y) % INF))


Fixed submission:
INF = 1000000007

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

for i in range(len(a)):
    for j in range(len(a)):
        if i == j: continue
        #print(a[i], a[j])
        if a[i] > a[j]:
            if i < j:
                ans_i += 1
            else:
                ans_e += 1
x = ans_i * k
ans = ans_i + ans_e
y = ans * ((k * (k-1) ) // 2)
print(int((x + y) % INF))
Buggy python submission (verdict: Runtime Error):
import sys

n, q = map(int, sys.stdin.readline().split())
counter = [0 for _ in range(n)]
relation = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    relation[a-1].append(b-1)
operate = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

def dfs(start, point):
    visited[start] = True
    for node in relation[start]:
        if visited[node] == False:
            counter[node] += point
            dfs(node, point)

for ope in operate:
    start, point = ope
    start -= 1
    counter[start] += point
    visited = [False for _ in range(n)]
    dfs(start, point)

print(' '.join(map(str, counter)))


Fixed submission:
from collections import deque

n, q = map(int,input().split())
g = [[] for _ in range(n)] # グラフを格納
count = [0 for _ in range(n)]

for _ in range(n-1):
    a, b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1) # どちらが根かわからない

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

que = deque()
que.append(0)

watch = [False] * n
watch[0] = True

while que:
    i = que.popleft()
    watch[i] = True
    for e in g[i]:
        if watch[e] == True: continue
        count[e] += count[i]
        que.append(e)

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

Buggy python submission (verdict: Runtime Error):
import sys

n, q = map(int, sys.stdin.readline().split())
counter = [0 for _ in range(n)]
relation = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    relation[a-1].append(b-1)
operate = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

def dfs(start, prev, point):
    visited[start] = True
    for node in relation[start]:
        if node == prev: continue
        if visited[node] == False:
            counter[node] += point
            dfs(node, start, point)

for ope in operate:
    start, point = ope
    start -= 1
    counter[start] += point
    visited = [False for _ in range(n)]
    dfs(start, -1, point)

print(' '.join(map(str, counter)))


Fixed submission:
from collections import deque

n, q = map(int,input().split())
g = [[] for _ in range(n)] # グラフを格納
count = [0 for _ in range(n)]

for _ in range(n-1):
    a, b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1) # どちらが根かわからない

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

que = deque()
que.append(0)

watch = [False] * n
watch[0] = True

while que:
    i = que.popleft()
    watch[i] = True
    for e in g[i]:
        if watch[e] == True: continue
        count[e] += count[i]
        que.append(e)

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