Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())
P = [K] * N

for _ in range(Q):
	A = int(input())
	P = list(map(lambda x : x-1, P))
	P[A-1] += 1
for i in P:
	if i > 0:
		print('Yes')
	else:
		print('No')

Fixed submission:
N, K, Q = map(int, input().split())
P = [K] * N

P = list(map(lambda x:x-Q, P))
for _ in range(Q):
	A = int(input()) -1
	P[A] += 1
			
for i in P:
	if i > 0:
		print('Yes')
	else:
		print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

for _ in range(M):
	a = A.pop()
	a = a >> 1
	for i in range(len(A)):
		if A[i] > a:
			A.insert(i, a)
			break
	else:
		A.append(a)
			

sum = 0
for a in A: sum += a
print(sum)

Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
h = []

for a in A: heapq.heappush(h, -a)
for _ in range(M):
	a = heapq.heappop(h) * -1
	a //= 2
	heapq.heappush(h, -a)

sum = 0
for _ in range(N): 
	sum -= heapq.heappop(h)
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

for _ in range(M):
	a = A.pop()
	a //= 2
	for i in range(len(A)):
		if A[i] > a:
			A.insert(i, a)
			break
	else:
		A.append(a)
			

sum = 0
for a in A: sum += a
print(sum)

Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
h = []

for a in A: heapq.heappush(h, -a)
for _ in range(M):
	a = heapq.heappop(h) * -1
	a //= 2
	heapq.heappush(h, -a)

sum = 0
for _ in range(N): 
	sum -= heapq.heappop(h)
print(sum)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

for _ in range(M):
	a = A.pop()
	a //= 2
	for i in A:
		if i > a:
			A.insert(A.index(i), a)
			break

sum = 0
for a in A: sum += a
print(sum)

Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
h = []

for a in A: heapq.heappush(h, -a)
for _ in range(M):
	a = heapq.heappop(h) * -1
	a //= 2
	heapq.heappush(h, -a)

sum = 0
for _ in range(N): 
	sum -= heapq.heappop(h)
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(M):
	idx = A.index(max(A))
	A[idx] //= 2
sum = 0
for a in A: sum += a
print(sum)

Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
h = []

for a in A: heapq.heappush(h, -a)
for _ in range(M):
	a = heapq.heappop(h) * -1
	a //= 2
	heapq.heappush(h, -a)

sum = 0
for _ in range(N): 
	sum -= heapq.heappop(h)
print(sum)
Buggy python submission (verdict: Runtime Error):
list1 = input().split(" ")
if int(list1[0]) <= int(list1[1]) * int(list[2]):
    print("Yes")
else:
    print("No")

Fixed submission:
list1 = input().split(" ")
if int(list1[0]) <= int(list1[1]) * int(list1[2]):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

sum_of_product = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        sum_of_product += A[i] * A[j]
        if sum_of_product >= 10 ** 9 + 7:
            sum_of_product %= 10 ** 9 + 7

print(sum_of_product)

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

sum_list = sum(A)
sum_of_product = 0

for i in A:
    sum_list -= i
    sum_of_product = ((sum_list * i) % (10 ** 9 + 7) + sum_of_product) % (10 ** 9 + 7)

print(sum_of_product)
Buggy python submission (verdict: Runtime Error):
import math

num_list = input().split(" ")

print(math.ceil(int(num_list[0]) / int(num_list[1])) * int(num_list[2])

Fixed submission:
import math

num_list = input().split(" ")

print(math.ceil(int(num_list[0]) / int(num_list[1])) * int(num_list[2]))

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

num_list = input().split()

print(math.ceil(int(num_list[0]) / int(num_list[1])) * int(num_list[2])

Fixed submission:
import math

num_list = input().split(" ")

print(math.ceil(int(num_list[0]) / int(num_list[1])) * int(num_list[2]))
Buggy python submission (verdict: Runtime Error):
count = 0

length = int(input())
length_list = map(int, input().split())

for i in range(length - 2):
    for j in range(i + 1, length - 1):
        if length_list[i] != length_list[j]:
            for k in range(j + 1, length):
                if length_list[j] != length_list[k] and length_list[k] != length_list[i]:
                    half_length_sum = (length_list[i] + length_list[j] + length_list[k]) / 2
                    if half_length_sum > max(length_list[i], length_list[j], length_list[k]):
                        count += 1
print(count)

Fixed submission:
count = 0

length = int(input())
length_list = list(map(int, input().split()))

for i in range(length - 2):
    for j in range(i + 1, length - 1):
        if length_list[i] != length_list[j]:
            for k in range(j + 1, length):
                if length_list[j] != length_list[k] and length_list[k] != length_list[i]:
                    half_length_sum = (length_list[i] + length_list[j] + length_list[k]) / 2
                    if half_length_sum > max(length_list[i], length_list[j], length_list[k]):
                        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

count = 0

for i in range(len(s)):
    if s[i] != t[i]:
        count += 1

print(count)

Fixed submission:
a = int(input())

print(a * (1 + a * (1 + a)))
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))

price_list = input().split()

price_list.sort()

answer = 0

for i in range(K):
    answer += price_list[i]

print(answer)

Fixed submission:
N, K = list(map(int, input().split()))

price_list = list(map(int, input().split()))

price_list.sort()

answer = 0

for i in range(K):
    answer += price_list[i]

print(answer)
Buggy python submission (verdict: Runtime Error):
num_list = input().split()

i = 0
while True:
    if num_list[i] == 0:
        print(i + 1)
        break
    i += 1

Fixed submission:
num_list = input().split()

i = 0
while True:
    if int(num_list[i]) == 0:
        print(i + 1)
        break
    i += 1
Buggy python submission (verdict: Runtime Error):
A, B = list(map(int, input().split()))

print(A * B // 1)

Fixed submission:
A, B = input().split()

print(int(A) * round(float(B) * 100) // 100)
Buggy python submission (verdict: Runtime Error):
def solve(n, m, a, b):
    if n == 0:
        return 0
    res = 0
    if a > m:
        res += (n-1) * n // 2 * (a // m)
        a %= m
    if b > m:
        res += n * (b // m)
        b %= m
    p = (a*n + b) // m
    q = p*m - b
    return res + solve(p, a, m, a*n-q)

t = int(input())
for i in range(t):
    n, m, a, b = map(int, input().split())
    print(solve(n, m, a, b))


Fixed submission:
def solve(n, m, a, b):
    if n == 0:
        return 0
    res = 0
    if a >= m:
        res += (n-1) * n // 2 * (a // m)
        a %= m
    if b >= m:
        res += n * (b // m)
        b %= m
    p = (a*n + b) // m
    q = p*m - b
    return res + solve(p, a, m, a*n-q)

t = int(input())
for i in range(t):
    n, m, a, b = map(int, input().split())
    print(solve(n, m, a, b))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
def solve(n, m, a, b):
    parents = list(range(n+1))
    def root(x):
        return root(parents[x]) if parents[x] != x else x
    for u, v in zip(a, b):
        u = root(u)
        v = root(v)
        if u > v:
            u, v = v, u
        if u != v:
            parents[v] = u
    return max(Counter(map(root, parents)).values())

n, m = map(int, input().split())
if m > 0:
    a, b = zip(*[map(int, input().split()) for i in range(m)])
else:
    a, b = [], []
print(solve(n, m, a, b))

Fixed submission:
from collections import Counter
def solve(n, m, a, b):
    parents = list(range(n+1))
    def root(x):
        if parents[x] != x:
            parents[x] = root(parents[x])
        return parents[x]
    for u, v in zip(a, b):
        u = root(u)
        v = root(v)
        if u > v:
            u, v = v, u
        if u != v:
            parents[v] = u
    return max(Counter(map(root, parents)).values())

n, m = map(int, input().split())
if m > 0:
    a, b = zip(*[map(int, input().split()) for i in range(m)])
else:
    a, b = [], []
print(solve(n, m, a, b))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
def solve(n, m, a, b):
    parents = list(range(n+1))
    def root(x):
        return root(parents[x]) if parents[x] != x else x
    for i in range(m):
        u = root(a[i])
        v = root(b[i])
        if u > v:
            u, v = v, u
        if u != v:
            parents[v] = u
    return max(Counter(parents).values())

n, m = map(int, input().split())
a, b = zip(*[map(int, input().split()) for i in range(m)])
print(solve(n, m, a, b))

Fixed submission:
from collections import Counter
def solve(n, m, a, b):
    parents = list(range(n+1))
    def root(x):
        if parents[x] != x:
            parents[x] = root(parents[x])
        return parents[x]
    for u, v in zip(a, b):
        u = root(u)
        v = root(v)
        if u > v:
            u, v = v, u
        if u != v:
            parents[v] = u
    return max(Counter(map(root, parents)).values())

n, m = map(int, input().split())
if m > 0:
    a, b = zip(*[map(int, input().split()) for i in range(m)])
else:
    a, b = [], []
print(solve(n, m, a, b))
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if a < b:
        a, b = b, a
    return b if a % b == 0 else gcd(b, a%b)

def solve(n, a):
    ok = True
    p = a[0]
    for i in range(1, n):
        q = gcd(p, a[i])
        if q > 1:
            ok = False
            break
        p = p * a[i] // q
    if ok:
        return "pairwise coprime"
    p = a[0]
    for i in range(1, n):
       p = gcd(p, a[i])
    return "setwise coprime" if p == 1 else "not coprime"

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


Fixed submission:
from math import gcd
from functools import reduce
NUM_MAX = 10**6 + 1
def solve(n, a):
    c = [0] * NUM_MAX
    for x in a:
        c[x] += 1
    t = any(sum(c[i::i]) > 1 for i in range(2, NUM_MAX))
    t += reduce(gcd, a) > 1
    return ["pairwise", "setwise", "not"][t] + " coprime"

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
Buggy python submission (verdict: Runtime Error):
print("Yes" if int(input())>="30" else "No")

Fixed submission:
print("Yes" if int(input())>=30 else "No")
Buggy python submission (verdict: Time Limit Exceeded):
MAX = 5 * (10**5)
MOD = 10**9 + 7
def inv(p):
    q = MOD - 2
    res = 1
    while q:
        if q % 2 == 1:
            res = (res*p) % MOD
        p = (p*p) % MOD
        q //= 2
    return res

_fact = [0] * (MAX + 1)
_inv = [0] * (MAX + 1)
_fact[0] = 1
_inv[0] = 1
for k in range(1, MAX + 1):
    _fact[k] = _fact[k-1] * k % MOD
    _inv[k] = inv(_fact[k])

def P(m, n):
    return _fact[m] * _inv[m-n] % MOD

def C(m, n):
    return _fact[m] * _inv[m-n] * _inv[n] % MOD

def solve(n, m):
    res = 0
    for k in range(n+1):
        sign = 1 - 2 * (k%2)
        cur = sign * C(n, k) * P(m, k) * (P(m-k, n-k) ** 2)
        res = (res + cur) % MOD
    return res

n, m = map(int, input().split())
print(solve(n, m))

Fixed submission:
MAX = 5 * (10**5)
MOD = 10**9 + 7

_fact = [1,1] + [0] * MAX
_inv = [0,1] + [0] * MAX
_fact_inv = [1,1] + [0] * MAX
for k in range(2, MAX + 1):
    _fact[k] = _fact[k-1] * k % MOD
    _inv[k] = (-_inv[MOD % k] * (MOD // k)) % MOD
    _fact_inv[k] = _fact_inv[k-1] * _inv[k] % MOD

def P(m, n):
    return _fact[m] * _fact_inv[m-n] % MOD

def C(m, n):
    return _fact[m] * _fact_inv[m-n] * _fact_inv[n] % MOD

def solve(n, m):
    res = 0
    for k in range(n+1):
        sign = 1 - 2 * (k%2)
        cur = sign * C(n, k) * P(m, k) * (P(m-k, n-k) ** 2)
        res = (res + cur) % MOD
    return res

n, m = map(int, input().split())
print(solve(n, m))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(int(a*b))

Fixed submission:
a, b = input().split()
print(int(a)*int(b[0] + b[2:]) // 100)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
    query = input()
    if query[0] == "1":
        s = s[::-1]
    else:
        t, f, c = query.split()
        if f == "1":
            s = c + s
        else:
            s = s + c
print(s)

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

L = ["" for i in range(q)]
R = ["" for i in range(q)]
l, r = 0, 0

fliped = False
for i in range(q):
    query = input()
    if query[0] == "1":
        fliped = not fliped
    else:
        t, f, c = query.split()
        if (f == "1") ^ fliped:
            L[l] = c
            l += 1
        else:
            R[r] = c
            r += 1
s = "".join(L[::-1]) + s + "".join(R)
if fliped:
    s = s[::-1]
print(s)
Buggy python submission (verdict: Runtime Error):
def solve(n, a):
    for i in range(n-1):
        if a[i] == a[i+1]:
            return "NO"
    return "YES"

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

Fixed submission:
def solve(n, a):
    return "YES" if len(set(a)) == n else "NO"

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
Buggy python submission (verdict: Runtime Error):
INF = 10**10
def solve(h, n, a, b):
    ab = sorted(zip(a, b), key=lambda _:_[0]/_[1], reverse=True)
    dp = [-1] * h
    def f(h):
        best = INF
        for x, y in ab:
            if h-x <= 0:
                score = y
            else:
                if dp[h-x] == -1:
                    dp[h-x] = f(h-x)
                score = y + dp[h-x]
            if score < best:
                best = score
            else:
                break
        return best
    return f(h)

h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(h, n, a, b))

Fixed submission:
import sys
sys.setrecursionlimit(100000000)

INF = 10**10
def solve(h, n, a, b):
    ab = sorted(zip(a, b), key=lambda _:(_[0]/_[1], -_[0]), reverse=True)
    dp = [-1] * h
    def f(h):
        best = INF
        for x, y in ab:
            if h-x <= 0:
                score = y
            else:
                if dp[h-x] == -1:
                    dp[h-x] = f(h-x)
                score = y + dp[h-x]
            if score < best:
                best = score
            else:
                break
        return best
    return f(h)

h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(h, n, a, b))
Buggy python submission (verdict: Runtime Error):
    p = sorted([(a+b, a-b) for a, b in zip(x, l)])
    _, th = p[0]
    best = 0
    for t, s in p:
        if th <= s:
            best += 1
            th = t
    return best

n = int(input())
x = [0]*n
l = [0]*n
for i in range(n):
    x[i], l[i] = map(int, input().split())
print(solve(n, x, l))

Fixed submission:
def solve(n, x, l):
    p = sorted([(a+b, a-b) for a, b in zip(x, l)])
    _, th = p[0]
    best = 0
    for t, s in p:
        if th <= s:
            best += 1
            th = t
    return best

n = int(input())
x = [0]*n
l = [0]*n
for i in range(n):
    x[i], l[i] = map(int, input().split())
print(solve(n, x, l))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def solve(n, k, r, s, p, t):
    dp = np.zeros((n, 3), dtype=int)
    win_hand_mapping = {
        "r": "p",
        "s": "r",
        "p": "s"
    }
    score_mapping = {
        "r": r,
        "s": s,
        "p": p
    }
    hand_index_mapping = {
        "r": 0,
        "s": 1,
        "p": 2
    }
    for i0 in range(k):
        for i in range(i0, n, k):
            win_hand = win_hand_mapping[t[i]]
            win_hand_index = hand_index_mapping[win_hand]
            win_hand_score = score_mapping[win_hand]
            for before in range(3):
                for current in range(3):
                    point = (current == win_hand_index) * win_hand_score
                    if i < k:
                        dp[i][current] = max(dp[i][current], point)
                    elif before != current:
                        dp[i][current] = max(dp[i][current], dp[i-k][before] + point)
    return np.max(dp, axis=1)[-k:].sum()

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
print(solve(n, k, r, s, p, t))

Fixed submission:
import numpy as np
def solve(n, k, r, s, p, t):
    dp = np.zeros((n, 3), dtype=int)
    win_hand_mapping = {
        "r": "p",
        "s": "r",
        "p": "s"
    }
    score_mapping = {
        "r": r,
        "s": s,
        "p": p
    }
    hand_index_mapping = {
        "r": 0,
        "s": 1,
        "p": 2
    }
    legal_hands_mapping = {
        i: [j for j in range(3) if i!=j] for i in range(3)
    }
    for i0 in range(k):
        for i in range(i0, n, k):
            win_hand = win_hand_mapping[t[i]]
            win_hand_index = hand_index_mapping[win_hand]
            win_hand_score = score_mapping[win_hand]
            for current in range(3):
                point = (current == win_hand_index) * win_hand_score
                if i < k:
                    dp[i][current] = max(dp[i][current], point)
                else:
                    for before in legal_hands_mapping[current]:
                        dp[i][current] = max(dp[i][current], dp[i-k][before] + point)
    return np.max(dp, axis=1)[-k:].sum()

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
print(solve(n, k, r, s, p, t))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np

def solve(n, x, y):
    total, num = 0, 0
    for p in itertools.permutations(range(n)):
        num += 1
        for i in range(n-1):
            total += np.linalg.norm([x[p[i+1]]-x[p[i]],y[p[i+1]]-y[p[i]]])
    return total / num

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
print(solve(n, x, y))

Fixed submission:
import itertools
import numpy as np

def solve(n, x, y):
    total, num = 0, 0
    x, y = np.asarray(x), np.asarray(y)
    for p in itertools.permutations(range(n)):
        num += 1
        p = np.array(p, dtype=int)
        dx = x[p[1:]] - x[p[:-1]]
        dy = y[p[1:]] - y[p[:-1]]
        total += np.sum(np.sqrt(dx**2 + dy**2))
    return total / num

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
print(solve(n, x, y))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def solve(n, t, a, b):
    prefix = np.zeros((n+1, t+1), dtype=int)
    suffix = np.zeros((n+1, t+1), dtype=int)
    for i in range(n):
        prefix[i+1] = prefix[i]
        for j in range(t):
            nj = j+a[i]
            if nj <= t:
                prefix[i+1, nj] = max(prefix[i+1, nj], prefix[i, j] + b[i])
    for i in range(n-1, -1, -1):
        suffix[i] = suffix[i+1]
        for j in range(t):
            nj = j+a[i]
            if nj <= t:
                suffix[i, nj] = max(suffix[i, nj], suffix[i+1, j] + b[i])
    for i in range(n+1):
        for j in range(t):
            prefix[i, j+1] = max(prefix[i, j+1], prefix[i, j])
            suffix[i, j+1] = max(suffix[i, j+1], suffix[i, j])
    best = 0
    for i in range(n):
        for j in range(t):
            cur = prefix[i,j] + b[i] + suffix[i+1,t-1-j]
            best = max(best, cur)
    return best

n, t = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, t, a, b))



Fixed submission:
import numpy as np
def solve(n, t, a, b):
    dp = np.zeros(t, dtype=int)
    candidates = []
    for w, v in sorted(zip(a, b)):
        candidates.append(dp[-1] + v)
        if w > t:
            continue
        dp[w:] = np.maximum(dp[:-w] + v, dp[w:])
    return np.max(candidates)

n, t = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, t, a, b))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
INF = 10**15
def solve(n, k, h):
    dp = np.full((n+1, n+1), INF, dtype=int)
    dp[0, 0] = 0
    h = np.array([0] + h, dtype=int)
    for x in range(1, n+1):
        for y in range(n+1):
            t = np.maximum(h[x] - h[:x], 0)
            dp[x, y] = np.min(dp[:x, y-1] + t)
    return np.min(dp[:, n-k])

n, k = map(int, input().split())
h = list(map(int, input().split()))
print(solve(n, k, h))

Fixed submission:
import numpy as np
INF = 10**15
def solve(n, k, h):
    dp = np.full((n+1, n+1), INF, dtype=int)
    dp[0, 0] = 0
    h = np.array([0] + h, dtype=int)
    for i, h_i in enumerate(h[1:], 1):
        t = np.maximum(h_i - h[:i], 0)
        dp[i,1:] = np.min(dp[:i,:-1]+t[:,None], axis=0)
    return np.min(dp[:, n-k])

n, k = map(int, input().split())
h = list(map(int, input().split()))
print(solve(n, k, h))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
INF = 10**15
def solve(n, k, h):
    dp = np.full((n+1, n+1), INF, dtype=int)
    dp[0, 0] = 0
    h = [0] + h
    for x in range(n+1):
        for y in range(n+1):
            for i in range(x):
                dp[x, y] = min(dp[x, y], dp[i, y-1] + max(0, h[x] - h[i]))
    return np.min(dp[:, n-k])

n, k = map(int, input().split())
h = list(map(int, input().split()))
print(solve(n, k, h))

Fixed submission:
import numpy as np
INF = 10**15
def solve(n, k, h):
    dp = np.full((n+1, n+1), INF, dtype=int)
    dp[0, 0] = 0
    h = np.array([0] + h, dtype=int)
    for i, h_i in enumerate(h[1:], 1):
        t = np.maximum(h_i - h[:i], 0)
        dp[i,1:] = np.min(dp[:i,:-1]+t[:,None], axis=0)
    return np.min(dp[:, n-k])

n, k = map(int, input().split())
h = list(map(int, input().split()))
print(solve(n, k, h))
Buggy python submission (verdict: Time Limit Exceeded):
def solve(n, q, a, b, p, x):
    E = [[] for i in range(n+1)]
    for a_i, b_i in zip(a, b):
        E[a_i].append(b_i)
        E[b_i].append(a_i)
    res = {i: 0 for i in range(1, n+1)}
    for j in range(q):
        res[p[j]] += x[j]
    used = [False] * (n+1)
    used[1] = True
    que = [1]
    while que:
        u = que.pop(0)
        for v in E[u]:
            if not used[v]:
                used[v] = True
                res[v] += res[u]
                que.append(v)
    return " ".join(map(str, [res[i] for i in range(1,n+1)]))

n, q = map(int, input().split())
a = [0] * (n-1)
b = [0] * (n-1)
for i in range(n-1):
    a[i], b[i] = map(int, input().split())
p = [0] * q
x = [0] * q
for j in range(q):
    p[j], x[j] = map(int, input().split())
print(solve(n, q, a, b, p, x))

Fixed submission:
from collections import deque

def solve(n, q, a, b, p, x):
    E = [[] for i in range(n+1)]
    for a_i, b_i in zip(a, b):
        E[a_i].append(b_i)
        E[b_i].append(a_i)
    res = {i: 0 for i in range(1, n+1)}
    for j in range(q):
        res[p[j]] += x[j]
    used = [False] * (n+1)
    used[1] = True
    que = deque([1])
    while que:
        u = que.popleft()
        for v in E[u]:
            if not used[v]:
                used[v] = True
                res[v] += res[u]
                que.append(v)
    return " ".join(map(str, [res[i] for i in range(1,n+1)]))

n, q = map(int, input().split())
a = [0] * (n-1)
b = [0] * (n-1)
for i in range(n-1):
    a[i], b[i] = map(int, input().split())
p = [0] * q
x = [0] * q
for j in range(q):
    p[j], x[j] = map(int, input().split())
print(solve(n, q, a, b, p, x))