Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,S,K=map(int,input().split())
ans=[S]*N
for i in range(K):
  ans[i]=S+1
print(*ans)


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

ans = [0]*N
T = 10**9
if T == S:
    T = 10**9 - 1
for i in range(N):
    if i < K:
        ans[i] = S
    else:
        ans[i] = T
print(" ".join(map(str, ans)))

Buggy python submission (verdict: Runtime Error):
N,S,K=map(int,input().split())
ans=[S]*K +[S+1]*(N-K)
print(*ans)


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

ans = [0]*N
T = 10**9
if T == S:
    T = 10**9 - 1
for i in range(N):
    if i < K:
        ans[i] = S
    else:
        ans[i] = T
print(" ".join(map(str, ans)))

Buggy python submission (verdict: Runtime Error):
N,S.K=map(int,input().split())
ans=[S]*K +[S+1]*(N-K)
print(*ans)

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

ans = [0]*N
T = 10**9
if T == S:
    T = 10**9 - 1
for i in range(N):
    if i < K:
        ans[i] = S
    else:
        ans[i] = T
print(" ".join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
N, M = map(int, input().split())
a = list(map(int, input().split()))
k = a[0]
for i in range(1, N):
    k = (a[i]*k) // gcd(a[i], k)
ans = (M+(0.5*k)) // k

print(int(ans))


Fixed submission:
from fractions import gcd
N, M = map(int, input().split())
a = list(map(int, input().split()))
k = a[0]
for i in range(1, N):
    k = (a[i]*k) // gcd(a[i], k)
    if k > M*2:
        print(0)
        exit(0)
    k = int(k)
ans = (M - (k // 2)) // k

if M >= (k // 2):
    flag = True
    for i in range(N):
        if (k // a[i]) % 2 == 0:
            print(0)
            exit(0)
    if flag:
        ans += 1

print(int(ans))

Buggy python submission (verdict: Runtime Error):
import fractions
N, M = map(int, input().split())

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


k = a[0]

for i in range(1, N):
    k = (a[i]*k) // fractions.gcd(a[i], k)
ans = M // k
if (k * 0.5) < M:
    ans += 1
print(ans)


Fixed submission:
from fractions import gcd
N, M = map(int, input().split())
a = list(map(int, input().split()))
k = a[0]
for i in range(1, N):
    k = (a[i]*k) // gcd(a[i], k)
    if k > M*2:
        print(0)
        exit(0)
    k = int(k)
ans = (M - (k // 2)) // k

if M >= (k // 2):
    flag = True
    for i in range(N):
        if (k // a[i]) % 2 == 0:
            print(0)
            exit(0)
    if flag:
        ans += 1

print(int(ans))

Buggy python submission (verdict: Runtime Error):
import fractions
N, M = map(int, input().split())

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


k = a[0]

for i in range(1, N):
    k = (a[i]*k) // fractions.gcd(a[i], k)
ans = 0
if k * 0.5 <= M:
    ans += 1
ans += M // k
print(ans)


Fixed submission:
from fractions import gcd
N, M = map(int, input().split())
a = list(map(int, input().split()))
k = a[0]
for i in range(1, N):
    k = (a[i]*k) // gcd(a[i], k)
    if k > M*2:
        print(0)
        exit(0)
    k = int(k)
ans = (M - (k // 2)) // k

if M >= (k // 2):
    flag = True
    for i in range(N):
        if (k // a[i]) % 2 == 0:
            print(0)
            exit(0)
    if flag:
        ans += 1

print(int(ans))
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = list(map(int, input().split()))

    M = max(A)
    L = M.bit_length()
    ans = 0
    mod = 10**9 + 7
    k = [0]*L
    k[0] = 1
    for i in range(1, L):
        k[i] = k[i-1]*2
    for j in range(L):
        count = 0
        for x in A:
            if (x >> j) % 2 == 1:
                count += 1
        ans += count*(N - count)*k[j]
    ans %= mod
    print(ans)


main()


Fixed submission:


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

ans = 0
mod = 10**9 + 7


b = bin(max(A))

l = len(b) - 2


for j in range(l):
    tmp = 0
    for i in range(N):
        if (A[i] >> j) % 2 == 1:
            tmp += 1

    ans += (2**j) * tmp * (N-tmp)
    ans %= mod
print(ans)

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

M = max(A)
L = M.bit_length()
ans = 0
mod = 10**9 + 7
k = [0]*L
k[0] = 1
for i in range(1, L):
    k[i] = k[i-1]*2
for j in range(L):
    count = 0
    for x in A:
        if (x >> j) % 2 == 1:
            count += 1
    ans += count*(N - count)*k[j]
    ans %= mod
print(ans)


Fixed submission:


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

ans = 0
mod = 10**9 + 7


b = bin(max(A))

l = len(b) - 2


for j in range(l):
    tmp = 0
    for i in range(N):
        if (A[i] >> j) % 2 == 1:
            tmp += 1

    ans += (2**j) * tmp * (N-tmp)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):


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

ans = 0
mod = 10**9 + 7


b = bin(max(A))

l = len(b) - 2


for j in range(l):
    tmp = 0
    for i in range(N):
        if (A[i] >> j) % 2 == 1:
            tmp += 1

    ans += (2**j) * tmp * (N-tmp)
    ans %= mod
print(ans)


Fixed submission:


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

ans = 0
mod = 10**9 + 7


b = bin(max(A))

l = len(b) - 2


for j in range(l):
    tmp = 0
    for i in range(N):
        if (A[i] >> j) % 2 == 1:
            tmp += 1

    ans += (2**j) * tmp * (N-tmp)
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, input().split()))


ans = 0
if A[0] < B[0]:
    tmp = (A[0], A[1])
    A[0], A[1] = B[0], B[1]
    B[0], B[1] = tmp[0], tmp[1]

a = abs(T[0]*A[0] - T[0]*B[0])

b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1])


if b == 0:
    print("Infinity")
elif b < 0:
    print(0)
    exit(0)
else:
    ans += 1
    if b > a:
        print(1)
    elif b == a:
        print("infinity")
    else:
        if a % b == 0:
            print(((a//b)*2)
        else:
            print((a//b)*2 + 1)


Fixed submission:
from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, input().split()))


ans = 0
if A[0] < B[0]:
    tmp = (A[0], A[1])
    A[0], A[1] = B[0], B[1]
    B[0], B[1] = tmp[0], tmp[1]

a = abs(T[0]*A[0] - T[0]*B[0])

b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1])


if b == 0:
    print("infinity")
elif b < 0:
    print(0)
    exit(0)
else:
    ans += 1
    if b > a:
        print(1)
    elif b == a:
        print("infinity")
    else:
        if a % b == 0:
            print((a//b)*2)
        else:
            print((a//b)*2 + 1)

Buggy python submission (verdict: Runtime Error):
from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, input().split()))


ans = 0
if A[0] < B[0]:
    tmp = (A[0], A[1])
    A[0], A[1] = B[0], B[1]
    B[0], B[1] = tmp[0], tmp[1]

a = abs(T[0]*A[0] - T[0]*B[0])

b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1])


if b == 0:
    print("Infinity")
elif b < 0:
    print(0)
    exit(0)
else:
    ans += 1
    if b > a:
        print(1)
    elif b == a:
        print("infinity")
    else:
        if a % b == 0:
            print((a*2)//b)
        else:
            print(((a//b)*2 + 1)


Fixed submission:
from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, input().split()))


ans = 0
if A[0] < B[0]:
    tmp = (A[0], A[1])
    A[0], A[1] = B[0], B[1]
    B[0], B[1] = tmp[0], tmp[1]

a = abs(T[0]*A[0] - T[0]*B[0])

b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1])


if b == 0:
    print("infinity")
elif b < 0:
    print(0)
    exit(0)
else:
    ans += 1
    if b > a:
        print(1)
    elif b == a:
        print("infinity")
    else:
        if a % b == 0:
            print((a//b)*2)
        else:
            print((a//b)*2 + 1)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import collections
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    s = [0]*(N+1)
    for i in range(N):
        s[i+1] = s[i] + A[i]

    table = collections.defaultdict(set)
    for i, x in enumerate(s):
        table[x % K].add(i)
    ans = 0
    for x in table:
        for y in table:
            if x == y:
                continue
            else:
                for z in table[x]:
                    k = (x-y) % K
                    if z-k in table[y]:
                        ans += 1
                    k = (y-x) % K
                    if z+k in table[y]:
                        ans += 1
    print(ans//2)
main()

Fixed submission:
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))
table = collections.defaultdict(int)

ans = 0
s = [0]*(N+1)
a = set()
for i in range(N):
    s[i+1] = s[i]+A[i]

s = [(s[i]-i) % K for i in range(N+1)]
for i in range(N+1):
    ans += table[s[i]]  # i番目まで取る組み合わせの数
    table[s[i]] += 1
    if i >= K-1:
        # Kで割ったあまりがKを超えることはないので、期限切れのものを引く
        table[s[i-K+1]] -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
X, Y = map(int, input().split())
mod = 10**9 + 7


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


if X == Y // 2 or Y == X//2:
    print(1)
    exit(0)

X, Y = max(X, Y), min(X, Y)

diff = X - Y
x = X - 2*(X-Y)
y = Y - (X-Y)

if x % 3 != 0:
    print(0)
    exit(0)
else:
    k = x // 3

    ans = math.factorial(2*k + X-Y) % mod * \
        modinv(math.factorial(k)) * modinv(math.factorial(k+X-Y))

    print(ans % mod)


Fixed submission:
X, Y = map(int, input().split())


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7
N = 10**6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

if X == Y // 2 or Y == X//2:
    print(1)
    exit(0)

X, Y = max(X, Y), min(X, Y)

diff = X - Y
x = X - 2*diff

if x % 3 != 0:
    print(0)
    exit(0)
else:
    k = x // 3
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

    ans = cmb(2*k+diff, k, mod)
    print(ans)

Buggy python submission (verdict: Runtime Error):
import math
X, Y = map(int, input().split())
mod = 10**9 + 7


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


if X == Y // 2 or Y == X//2:
    print(1)

X, Y = max(X, Y), min(X, Y)

diff = X - Y
x = X - 2*(X-Y)
y = Y - (X-Y)

if x % 3 != 0:
    print(0)
else:
    k = x // 3


ans = math.factorial(2*k + X-Y) % mod * \
    modinv(math.factorial(k)) * modinv(math.factorial(k+X-Y))

print(ans % mod)


Fixed submission:
X, Y = map(int, input().split())


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7
N = 10**6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

if X == Y // 2 or Y == X//2:
    print(1)
    exit(0)

X, Y = max(X, Y), min(X, Y)

diff = X - Y
x = X - 2*diff

if x % 3 != 0:
    print(0)
    exit(0)
else:
    k = x // 3
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

    ans = cmb(2*k+diff, k, mod)
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())
D = list(map(int, input().split()))
mod = 998244353

if D[0] > 0:
    print(0)
else:
    num = [0]*max(D)
    for i in range(1, N):
        if D[i] > 0:
            num[D[i]-1] += 1

ans = 1
for i in range(1, len(num)):
    ans *= (num[i-1]**num[i]) % mod

print(ans % mod)


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

N = int(input())
D = list(map(int, input().split()))
mod = 998244353

if 0 in D[1:] or D[0] != 0:
    print(0)
    exit(0)
else:
    num = [0]*max(D)
    for i in range(1, N):
        if D[i] > 0:
            num[D[i]-1] += 1

    ans = 1
    for i in range(1, len(num)):
        ans *= (num[i-1]**num[i]) % mod

    print(ans % mod)
Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)
ans=[]
count=0
t= [0]*(n+1)
for i in range(n):
  if s[i]=="<":
    s[i+1]=s[i]+1
  else:
    s[i+1]=0
count=0
for i in range(n-1,-1,-1):
  if s[i]==">":
    s[i-1]=max(s[i]+1,s[i-1])
print(sum(ans))
  
  

Fixed submission:
import collections
S = input()

s = list(S.split("><"))
ans = 0
for i in range(len(s)):
    table = collections.defaultdict(int)
    for y in s[i]:
        table[y] += 1

    if i == 0 and len(table) != 0:
        table["<"] -= 1
    if i == len(s)-1 and len(table) != 0:
        table[">"] -= 1
    table = list(table.values())
    if len(table) == 2:
        table.sort()
        ans += max((table[1]+1)*(table[1]+2) // 2, 0)
        ans += max((table[0]+1)*table[0] // 2, 0)

    elif len(table) == 1:
        ans += max((table[0]+1)*(table[0]+2) // 2, 0)
    else:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
diff = [L[i] - L[i+1] for i in range(N-1)]

for i in range(N):
    d = 0
    for j in range(i+1, N):
        d += diff[j-1]
        for k in range(j+1, N):
            if d < L[k]:
                ans += 1
            else:
                break
print(ans)


Fixed submission:
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
R = sorted(L)
ans = 0
diff = [L[i] - L[i+1] for i in range(N-1)]

for i in range(N):
    d = 0
    for j in range(i+1, N):
        d += diff[j-1]
        k = bisect.bisect_left(R, d+1)
        ans += max(N-k-1 - j, 0)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=[0]*M
import heapq
import collections
from itertools import permutations
table=collections.defaultdict(list)
AC=[[0,0] for i in range(M)]
C=[set() for i in range(M)]
for i in range(M):
  a,b=map(int,input().split())
  AC[i][0]=a
  tmp=set(map(int,input().split()))
  for x in tmp:
    AC[i][1] |= 1<<(x-1)
dp=[10**9]*(2**N)
dp[0]=0

for i in range(1,2**N):
  k=0
  s=set()
  for j in range(1,i):
    if i & j == j:
      dp[i]=min(dp[i],dp[j]+dp[i^j])
  for a,c in AC:
    if c&i == i:
      dp[i]=min(dp[i],a)
  #print(dp[i],bin(i))
  
if dp[-1]==10**9:
  print(-1)
else:
  print(dp[-1])
#print(dp)

  
  
#print(AC)

Fixed submission:
N,M=map(int,input().split())
A=[0]*M
import heapq
import collections
from itertools import permutations
table=collections.defaultdict(list)
AC=[[0,0] for i in range(M)]
C=[set() for i in range(M)]
for i in range(M):
  a,b=map(int,input().split())
  AC[i][0]=a
  tmp=set(map(int,input().split()))
  for x in tmp:
    AC[i][1] |= 1<<(x-1)
dp=[10**9]*(2**N)
dp[0]=0

for i in range(1,2**N):
  k=0
  s=set()
  for j in range(1,i):
    if i & j == j:
      dp[i]=min(dp[i],dp[j]+dp[i^j])
  for a,c in AC:
    if c&i == i:
      dp[i]=min(dp[i],a)
  #print(dp[i],bin(i))
  
if dp[-1]==10**9:
  print(-1)
else:
  print(dp[-1])
#print(dp)

  
  
#print(AC)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[0]*M
import collections
table=collections.defaultdict(list)
C=[set() for i in range(M)]
for i in range(M):
  a,b=map(int,input().split())
  A[i]=a
  c=list(map(int,input().split()))
  C[i]=set(c)
  for x in c:
    table[x].append((a,i))

opened=set()
used=set()
for i in range(1,N+1):
  if used & C[i]:
    opened.add(i)
    continue
  table[i].sort(key=lambda x:x[0])
  used.add(table[i][0][1])
  opened.add(i)
ans=0
for x in used:
  ans+=A[x]
print(ans)
  
  
  
  

Fixed submission:
N,M=map(int,input().split())
A=[0]*M
import heapq
import collections
from itertools import permutations
table=collections.defaultdict(list)
AC=[[0,0] for i in range(M)]
C=[set() for i in range(M)]
for i in range(M):
  a,b=map(int,input().split())
  AC[i][0]=a
  tmp=set(map(int,input().split()))
  for x in tmp:
    AC[i][1] |= 1<<(x-1)
dp=[10**9]*(2**N)
dp[0]=0

for i in range(1,2**N):
  k=0
  s=set()
  for j in range(1,i):
    if i & j == j:
      dp[i]=min(dp[i],dp[j]+dp[i^j])
  for a,c in AC:
    if c&i == i:
      dp[i]=min(dp[i],a)
  #print(dp[i],bin(i))
  
if dp[-1]==10**9:
  print(-1)
else:
  print(dp[-1])
#print(dp)

  
  
#print(AC)
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())

A = [0]*Q
for i in range(Q):
    A[i] = int(input())

B = [K]*N

for i in range(Q):
    for j in range(N):
        if A[i] != j + 1:
            B[j] -= 1


for i in range(N):
    if B[i] > 0:
        print("Yes")
    else:
        print("No")


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

A = [0]*Q
for i in range(Q):
    A[i] = int(input())

B = [0]*N

for i in range(Q):
    B[A[i] - 1] += 1


for i in range(N):
    if K - (Q - B[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()))

C = [0] * M
if N == 1:
    for i in range(M):
        A[0] = A[0] // 2
    print(A[0])
    exit(0)


while(M > 0):
    A.sort(reverse=True)
    k = min((A[0] // A[1]), M)
    A[0] = A[0] // (2 ** k)
    M -= k

print(sum(A))


Fixed submission:
import heapq
N, M = map(int, input().split())

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

hq = []

for i in range(N):
    heapq.heappush(hq, -(A[i]))


while(M):
    k = heapq.heappop(hq) * -1
    k = k // 2
    heapq.heappush(hq, -k)
    M -= 1
ans = 0
for i in range(N):
    ans += heapq.heappop(hq)

print(-ans)

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

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

C = [0] * M
if N == 1:
    for i in range(M):
        A[0] = A[0] // 2
    print(A[0])
    exit(0)

while(M > 0):
    A.sort(reverse=True)
    A[0] = A[0] // 2
    M -= 1
print(sum(A))


Fixed submission:
import heapq
N, M = map(int, input().split())

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

hq = []

for i in range(N):
    heapq.heappush(hq, -(A[i]))


while(M):
    k = heapq.heappop(hq) * -1
    k = k // 2
    heapq.heappush(hq, -k)
    M -= 1
ans = 0
for i in range(N):
    ans += heapq.heappop(hq)

print(-ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
H=list(map(int,input().split()))
ans=0
tmp=0
for i in range(N-1):
  if H[i]>=H[i+1]:
    tmp+=1
  else:
    tmp=0
  anｓ=max(tmp,ans)
  
print(ans)


Fixed submission:
S = input()
T = input()
count = 0
for i in range(3):
    if S[i] == T[i]:
        count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
ans=0
for i in range(N-1):
  ans+=i+1
print(ans)

Fixed submission:
N = int(input())


print(N*(N + 1) // 2 - N)

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

x = [i + 1 for i in range(N)]

print(sum(x) - N)


Fixed submission:
N = int(input())


print(N*(N + 1) // 2 - N)
Buggy python submission (verdict: Time Limit Exceeded):


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

a = [0] * (N - 1)
b = [0] * (N - 1)

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

point = [0] * N

def kasan(n, y):
    z = 0
    for i in range(Q):
        
        if p[i] == n:
            z += x[i]
    for i in range(N - 1):
        if a[i] == n:
            kasan(b[i],y + z)
    
    point[n - 1] += y + z

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

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

kasan(1,0)

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

            



Fixed submission:


import collections
N, Q = map(int, input().split())
g = [set() for i in range(N)]

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

parent = [-1 for i in range(N)]
parent[0] = 0

q = collections.deque()
q.append(0)

point = [0 for i in range(N)]

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

while(q):
    x = q.popleft()
    for y in g[x]:
        if parent[y] == -1:
            q.append(y)
            parent[y] = x
            point[y] += point[x]

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

Buggy python submission (verdict: Time Limit Exceeded):


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

a = [0] * (N - 1)
b = [0] * (N - 1)

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

point = [0] * N

def kasan(n, y):
    z = 0
    for i in range(Q):
        
        if p[i] == n:
            z += x[i]
    for i in range(N - 1):
        if a[i] == n:
            kasan(b[i],y + z)
    
    point[n - 1] += y + z

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

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

kasan(1,0)

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

            



Fixed submission:


import collections
N, Q = map(int, input().split())
g = [set() for i in range(N)]

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

parent = [-1 for i in range(N)]
parent[0] = 0

q = collections.deque()
q.append(0)

point = [0 for i in range(N)]

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

while(q):
    x = q.popleft()
    for y in g[x]:
        if parent[y] == -1:
            q.append(y)
            parent[y] = x
            point[y] += point[x]

print(" ".join(map(str, point)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = ['']* N
ans = 0
for i in range(N):
    S[i]= sorted(input())
    ans += S.count(S[i]) - 1

print(ans)


Fixed submission:
from collections import defaultdict
Sdic = defaultdict(int)

N = int(input())
S = ['']* N
ans = 0
for i in range(N):
    Sdic[str(sorted(input()))] += 1

for i in Sdic.keys():
    ans += (Sdic[i] * (Sdic[i] - 1)) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = ['']* N
for i in range(N):
    S[i] = input()

S_ = [[0] * 26] * N

alphabet = "abcdefghijklmnopqrstuvwxyz"

for j in range(N):
    temp = []
    for i in range(26):
        temp.append(S[j].count(alphabet[i]))
    S_[j] = temp

ans = 0

for i in reversed(range(1,N)):
    for j in range(i):
        if S_[i] == S_[j]:
            ans += 1

print(ans)

Fixed submission:
from collections import defaultdict
Sdic = defaultdict(int)

N = int(input())
S = ['']* N
ans = 0
for i in range(N):
    Sdic[str(sorted(input()))] += 1

for i in Sdic.keys():
    ans += (Sdic[i] * (Sdic[i] - 1)) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = ['']* N
for i in range(N):
    S[i] = input()

S_ = [[0] * 26] * N

alphabet = "abcdefghijklmnopqrstuvwxyz"

for j in range(N):
    temp = []
    for i in range(26):
        temp.append(S[j].count(alphabet[i]))
    S_[j] = temp

ans = 0

for i in reversed(range(1,N)):
    for j in range(i):
        if S_[i] == S_[j]:
            ans += 1

print(ans)

Fixed submission:
from collections import defaultdict
Sdic = defaultdict(int)

N = int(input())
S = ['']* N
ans = 0
for i in range(N):
    Sdic[str(sorted(input()))] += 1

for i in Sdic.keys():
    ans += (Sdic[i] * (Sdic[i] - 1)) // 2

print(ans)
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input.split())

if (A+B)%2==1:
  print("IMPOSSIBLE")
  
else:
  print((A+B)//2)

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

if (A+B)%2==1:
  print("IMPOSSIBLE")
  
else:
  print((A+B)//2)

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

if (A+B)%2==1:
  print("IMPOSSIBLE")
  
else:
  print((A+B)/2)

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

if (A+B)%2==1:
  print("IMPOSSIBLE")
  
else:
  print((A+B)//2)
Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
a, b = 0, 0
for i in range(1, S+1):
    if S % i == 0:
        if S // i <= 10**9:
            a, b = S // i, i
            break
print("0 0 " + str(a) + " 0 1 " + str(b))


Fixed submission:
import math
S = int(input())
a1, b2 = math.ceil(S**0.5), math.ceil(S**0.5)
c = a1*b2 - S

print("0 0 " + str(a1) + " " + str(c) + " 1 " + str(b2))

Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
a, b = 0, 0
for i in range(1, S+1):
    if S % i == 0:
        if S // i <= 10**9:
            a, b = S // i, i
print("0 0 " + str(a) + " 0 1 " + str(b))


Fixed submission:
import math
S = int(input())
a1, b2 = math.ceil(S**0.5), math.ceil(S**0.5)
c = a1*b2 - S

print("0 0 " + str(a1) + " " + str(c) + " 1 " + str(b2))