Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s=list(input())
count1=0
count2=0
for i in range(len(s)):
  if s[i]==s[i+1]:
    count1=count1+1
for i in range(1,len(s)):
  if s[i]==s[i+1]:
    count2=count2+1
if count1>=count2:
  print(count1)
else:
  print(count2)

Fixed submission:
s=list(input())
count1=0
count2=0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    count1=count1+1
    if s[i+1]=='0':
      s[i+1]='1'
    else:
      s[i+1]='0'
for i in range(1,len(s)-1):
  if s[i]==s[i+1]:
    count2=count2+1
    count1=count1+1
    if s[i+1]=='0':
      s[i+1]='1'
    else:
      s[i+1]='0'
if count1>=count2:
  print(count1)
else:
  print(count2)
Buggy python submission (verdict: Runtime Error):
n,m,c=map(int,input().split())
b=[0 for i in range(m)]
a=[[0 for i in range(m)]for i in range(n)]
ans=0
count=0
for i in range(m):
  b[i]=int(input())
for i in range(n):
  for j in range(m):
    a[n][j]=int(input())
for i in range(n):
  for j in range(m):
    ans=ans+a[n][j]*b[j]
  if (ans+c)>0:
    count=count+1
print(count)

Fixed submission:
n,m,c=map(int,input().split())
b=[0 for i in range(m)]
a=[[0 for i in range(m)]for i in range(n)]
k=[0 for i in range(m)]
count=0
b=list(map(int,input().split()))
a=[list(map(int,input().split()))for i in range(n)]
for i in range(n):
  ans=0
  for j in range(m):
    ans=ans+(a[i][j]*b[j])
  if (ans+c)>0:
    count=count+1
print(count)
Buggy python submission (verdict: Runtime Error):
a,b,n=map(int,input().split())
c=[]
i=0
while(1):
  i=i+1
  if a%i==0 and b%i==0:
    c,append(i)
  if a<=i or b<=i:
    break
d=(len(c)-k+1)
print(c[d])

Fixed submission:
a,b,n=map(int,input().split())
c=[]
i=0
while(1):
  i=i+1
  if a%i==0 and b%i==0:
    c.append(i)
  if a<=i or b<=i:
    break
d=len(c)-n
print(c[d])

Buggy python submission (verdict: Runtime Error):
a,b,n=map(int,input().split())
c=[]
i=0
while(1):
  i=i+1
  if a%i==0 and b%i==0:
    c,append(i)
  if a<=i or b<=i:
    break
print(c[(len(c)-k+1)])

Fixed submission:
a,b,n=map(int,input().split())
c=[]
i=0
while(1):
  i=i+1
  if a%i==0 and b%i==0:
    c.append(i)
  if a<=i or b<=i:
    break
d=len(c)-n
print(c[d])
Buggy python submission (verdict: Runtime Error):
s=list(map(int,input().split("/")))
if (s[0]=2019 and s[1]<=4) or (s[0]<2019):
  print("Heisei")
else:
  print("TBD")

Fixed submission:
s=list(map(int,input().split("/")))
if (s[0]==2019 and s[1]<=4) or (s[0]<2019):
  print("Heisei")
else:
  print("TBD")
Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
ct=[list(map(int,input().split())) for i in range(n)]
ans=1001
for i in range(n):
  if ct[n][1]<=t and ct[n][0]<=ans:
    ans=ct[n][0]
if ans<1001:
  print(ans)
else:
  print("TLE")

Fixed submission:
n,t=map(int,input().split())
ct=[list(map(int,input().split())) for i in range(n)]
ans=1001
for i in range(n):
  if ct[i][0]<=ans and ct[i][1]<=t:
    ans=ct[i][0]
if ans<1001:
  print(ans)
else:
  print("TLE")

Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().spplit())
ct=[list(map(int,input().split())) for i in range(n)]
ans=1001
for i in range(n):
  if ct[n][1]<=t and ct[n][0]<=ans:
    ans=ct[n][0]
if ans<1001:
  print(ans)
else:
  print("TLE")

Fixed submission:
n,t=map(int,input().split())
ct=[list(map(int,input().split())) for i in range(n)]
ans=1001
for i in range(n):
  if ct[i][0]<=ans and ct[i][1]<=t:
    ans=ct[i][0]
if ans<1001:
  print(ans)
else:
  print("TLE")
Buggy python submission (verdict: Runtime Error):
s=list(input())
ans=0
for i in s:
  if i="-":
    ans=ans-1
  else:
    ans=ans+1
print(ans)

Fixed submission:
s=list(input())
ans=0
for i in s:
  if i=="-":
    ans=ans-1
  else:
    ans=ans+1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=n
temp=0
while s:
  temp=temp+s%10
  s=s//10
if n%s==0:
  print("Yes")
else:
  print("No")

Fixed submission:
n=int(input())
s=n
temp=0
while s:
  temp=temp+s%10
  s=s//10
if n%temp==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
one_p=a.index(1)
ans=0
if n!=k:
  ans=ans+(one_p)//(k-1) if (one_p)%(k-1)==0 else ans+(one_p)//(k-1)+1
  ans=ans+(n-one_p)//(k-1) if (n-one_p)%(k-1)==0: else ans+(n-one_p)//(k-1)+1
else:
  ans=1
print(ans)

Fixed submission:
n,k=map(int,input().split())
ans=1
while n>ans*(k-1)+1:
  ans=ans+1
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
one_p=a.index(1)
ans=0
if n!=k:
  ans=ans+(one_p)//(k-1) if (one_p)%(k-1)==0 else ans=ans+(one_p)//(k-1)+1
  ans=ans+(n-one_p)//(k-1) if (n-one_p)%(k-1)==0: else ans=ans+(n-one_p)//(k-1)+1
else:
  ans=1
print(ans)

Fixed submission:
n,k=map(int,input().split())
ans=1
while n>ans*(k-1)+1:
  ans=ans+1
print(ans)
Buggy python submission (verdict: Runtime Error):
s=list(int(input()))
ans=0
for i in s:
  if i==1:
    ans=ans+1
print(ans)

Fixed submission:
s=list(input())
ans=0
for i in s:
  if i=="1":
    ans=ans+1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=map(int,input().split())
ans=0
while 1:
  for i in range(n):
    if a[i]%2==0:
      a[i]=a[i]//2
    else:
      break
  else:
    ans=ans+1
    continue
  break
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
while 1:
  for i in range(n):
    if a[i]%2==0:
      a[i]=a[i]//2
    else:
      break
  else:
    ans=ans+1
    continue
  break
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=map(int,input().split())
ans=0
while 1:
  for i in range(n):
    if s[i]%2==0:
      s[i]=s[i]//2
    else:
      break
  else:
    ans=ans+1
    continue
  break
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
while 1:
  for i in range(n):
    if a[i]%2==0:
      a[i]=a[i]//2
    else:
      break
  else:
    ans=ans+1
    continue
  break
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if ((a+b==10 and a==5) and c==7) or ((a+b=12 and c==5) and (a==5 or b==5)):
  print("YES")
else:
  print("NO")

Fixed submission:
a,b,c=map(int,input().split())
if ((a+b==10 and a==5) and c==7) or ((a+b==12 and c==5) and (a==5 or b==5)):
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if (a+b==10 and a==5 and c==7) or (a+b=12 and c==5 and (a==5 or b==5)):
  print("YES")
else:
  print("NO")

Fixed submission:
a,b,c=map(int,input().split())
if ((a+b==10 and a==5) and c==7) or ((a+b==12 and c==5) and (a==5 or b==5)):
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
import numpy as np

def main():
    N = int(input())
    x = []
    for i in range(N):
        x.append(list(map(int, input().split())))
    X = np.array(x)
    j = 0
    for i in range(N-1):
        for k in range(i+1, N):
            j += np.linalg.norm(X[i] - X[k], ord=2)

    print(2*j/N) # 2(N-1)!/N!

if __name__ == "__main__":
    main()
    

Fixed submission:
import numpy as np

def main():
    N = int(input())
    x = []
    for i in range(N):
        x.append(list(map(int, input().split())))
    X = np.array(x)
    j = 0
    for i in range(N-1):
        for k in range(i+1, N):
            j += np.linalg.norm(X[i] - X[k], ord=2)

    print(2*j/N) # 2(N-1)!/N!

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
  	N = int(input())
	l = list(map(int, input().split(" ")))
	k = 0
	for i in range(N-2):
    	a = l[i]
    	for j in range(i+1, N-1):
        	b = l[j]
        	k += len([p for p in l[j+1:] if abs(b-a) < p < (a+b)])
	print(k)
main()

Fixed submission:
from bisect import bisect_right
def main():
	N = int(input())
	L = list(map(int, input().split(" ")))
	L.sort()
	k = 0
	for i in reversed(range(2, N)):
		a = L[i]
		for j in reversed(range(1, i)):
			b = L[j]
			index = bisect_right(L, a-b, hi=j)
			k += j - index
	print(k)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int, input().split(" ")))
l.sort()
t = 0
for i in range(N-2):
    a = l[i]
    for j in range(i+1, N-1):
        b = l[j]
        low, upp = abs(b-a), a+b
        flag = 0
        for k in range(j+1, N):
            if low < l[k] < upp:
                t += 1
                flag = 1
            else:
                if flag == 1:
                    break
                else:
                    continue
print(t)

Fixed submission:
from bisect import bisect_right
def main():
	N = int(input())
	L = list(map(int, input().split(" ")))
	L.sort()
	k = 0
	for i in reversed(range(2, N)):
		a = L[i]
		for j in reversed(range(1, i)):
			b = L[j]
			index = bisect_right(L, a-b, hi=j)
			k += j - index
	print(k)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int, input().split(" ")))
k = 0
for i in range(N-2):
    a = l[i]
    for j in range(i+1, N-1):
        b = l[j]
        k += len([p for p in l[j+1:] if abs(b-a) < p < (a+b)])
print(k)

Fixed submission:
from bisect import bisect_right
def main():
	N = int(input())
	L = list(map(int, input().split(" ")))
	L.sort()
	k = 0
	for i in reversed(range(2, N)):
		a = L[i]
		for j in reversed(range(1, i)):
			b = L[j]
			index = bisect_right(L, a-b, hi=j)
			k += j - index
	print(k)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
inf = np.inf
N, M = list(map(int, input().split(" ")))
keys = []
for _ in range(M):
	c = list(map(int, input().split(" ")))
	j = list(map(int, input().split(" ")))
	keys.append([c[0], np.sum([1 << k-1 for k in j])])
dp = [inf for _ in range(1 << N)]
dp[0] = 0
for i in range(len(dp)):
    for key in keys:
        t = i | key[1]
        dp[t] = min(dp[t], key[0] + dp[i])
if dp[-1]==inf:
    print(-1)
else:
    print(dp[-1])

Fixed submission:
def main():
  Inf = 10**8
  N, M = list(map(int, input().split(" ")))
  keys = []
  for _ in range(M):
      c = list(map(int, input().split(" ")))
      j = list(map(int, input().split(" ")))
      keys.append([c[0], sum([1 << k-1 for k in j])])
  dp = [Inf for _ in range(1 << N)]
  dp[0] = 0
  for i in range(len(dp)):
      for key in keys:
          t = i | key[1]
          dp[t] = min(dp[t], key[0] + dp[i])
  if dp[-1]==Inf:
      print(-1)
  else:
      print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
from numpy import inf
N, M = list(map(int, input().split(" ")))
keys = []
for _ in range(M):
	c = list(map(int, input().split(" ")))
	j = list(map(int, input().split(" ")))
	keys.append([c[0], sum([1 << k-1 for k in j])])
dp = [inf for _ in range(1 << N)]
dp[0] = 0
for i in range(len(dp)):
    for key in keys:
        t = i | key[1]
        dp[t] = min(dp[t], key[0] + dp[i])
if dp[-1]==inf:
    print(-1)
else:
    print(dp[-1])

Fixed submission:
def main():
  Inf = 10**8
  N, M = list(map(int, input().split(" ")))
  keys = []
  for _ in range(M):
      c = list(map(int, input().split(" ")))
      j = list(map(int, input().split(" ")))
      keys.append([c[0], sum([1 << k-1 for k in j])])
  dp = [Inf for _ in range(1 << N)]
  dp[0] = 0
  for i in range(len(dp)):
      for key in keys:
          t = i | key[1]
          dp[t] = min(dp[t], key[0] + dp[i])
  if dp[-1]==Inf:
      print(-1)
  else:
      print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
from math import inf
N, M = list(map(int, input().split(" ")))
keys = []
for _ in range(M):
	c = list(map(int, input().split(" ")))
	j = list(map(int, input().split(" ")))
	keys.append([c[0], sum([1 << k-1 for k in j])])
dp = [inf for _ in range(1 << N)]
dp[0] = 0
for i in range(len(dp)):
    for key in keys:
        t = i | key[1]
        dp[t] = min(dp[t], key[0] + dp[i])
if dp[-1]==inf:
    print(-1)
else:
    print(dp[-1])

Fixed submission:
def main():
  Inf = 10**8
  N, M = list(map(int, input().split(" ")))
  keys = []
  for _ in range(M):
      c = list(map(int, input().split(" ")))
      j = list(map(int, input().split(" ")))
      keys.append([c[0], sum([1 << k-1 for k in j])])
  dp = [Inf for _ in range(1 << N)]
  dp[0] = 0
  for i in range(len(dp)):
      for key in keys:
          t = i | key[1]
          dp[t] = min(dp[t], key[0] + dp[i])
  if dp[-1]==Inf:
      print(-1)
  else:
      print(dp[-1])
main()
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort
def main():
	(_, M) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	for i in range(M):
		b = A[-1] // 2
		insort(A, b)
		A = A[:-1]
	print(sum(A))
main()

Fixed submission:
from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  (_, M) = map(int, input().split())
  A = list(map(int, input().split()))
  A.sort()
  A.reverse()
  for i in range(M):
    A[A.index(max(A), 0, i+1)] //= 2
  print(sum(A))
main()

Fixed submission:
from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()

Buggy python submission (verdict: Time Limit Exceeded):
(_, M) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A.reverse()
for i in range(M):
  A[A.index(max(A[:i+1]), 0, i+1)] //= 2
print(sum(A))

Fixed submission:
from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()

Buggy python submission (verdict: Time Limit Exceeded):
(_, M) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A.reverse()
for i in range(M):
  A[A.index(max(A[:i+1]), 0, i+1)] //= 2
print(sum(A))

Fixed submission:
from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()

Buggy python submission (verdict: Time Limit Exceeded):
(_, M) = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
  i = A.index(max(A))
  A[i] = A[i]//2
print(sum(A))

Fixed submission:
from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()

Buggy python submission (verdict: Time Limit Exceeded):
(_, M) = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
  i = A.index(max(A))
  A[i] = A[i]//2
print(sum(A))

Fixed submission:
from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()
Buggy python submission (verdict: Runtime Error):
s, t = map(int, input().split())
a = t-s
print(1+int(a/(s-1))

Fixed submission:
from math import ceil

s, t = map(int, input().split())
a = t-s
print(1+ceil(a/(s-1)))
Buggy python submission (verdict: Runtime Error):
a = int(input())
print(int(0.5*a*(a+1))

Fixed submission:
a = int(input())
print(a*(a-1)//2)
Buggy python submission (verdict: Runtime Error):
_, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
r = [sum([b > c for c in a[i:]]) for i, b in enumerate(a)]
b = (sum(r) + sum(s)*(K-1)/2)*K + sum(r)
print(int(b%(1e9+7)))


Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 24 21:04:16 2019

@author: Toroi0610
"""

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

M, D = map(int, input().split())
day = [str(d) for d in range(1, D+1)]
cnt = 0
for m in range(1, M+1):
    s = make_divisors(m)
    length = len(s)
    if length == 2:
        continue
    if length%2 == 0:
        for l, r in zip(s[:int(length/2)], s[int(length/2):][::-1]):
            if (l > 10) or (r > 10) or (l==1):
                continue
            else:
                if str(l)+str(r) in day:
                    cnt += 1
                if str(r)+str(l) in day:
                    cnt += 1
    else:
        for l, r in zip(s[:int(length/2)+1], s[int(length/2):][::-1]):
            if (l > 10) or (r > 10) or (l==1):
                continue
            else:
                if str(l)+str(r) in day:
                    cnt += 1
                if l != r:
                    if str(r)+str(l) in day:
                        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
_, K = map(int, input())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
r = [sum([b > c for c in a[i:]]) for i, b in enumerate(a)]
b = (sum(r) + sum(s)*(K-1)/2)*K + sum(r)
print(int(b%(1e9+7)))


Fixed submission:
MAX = 10**9 + 7
_, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
r = [sum([b > c for c in a[i:]]) for i, b in enumerate(a)]
b = sum(s)*(K-1)*K//2%MAX
print((b+sum(r)*K)%MAX)

Buggy python submission (verdict: Runtime Error):
_, K = map(int, input())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
l = [sum([l < a[i] for l in a[:i]]) for i in range(1, len(a))]
l.insert(0, 0)
r = [b - c for b, c in zip(s, l)]
a = (sum(r)*(1+K) + sum(l)*(K-1))*K/2
print(int(a%(1e9+7)))


Fixed submission:
MAX = 10**9 + 7
_, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
r = [sum([b > c for c in a[i:]]) for i, b in enumerate(a)]
b = sum(s)*(K-1)*K//2%MAX
print((b+sum(r)*K)%MAX)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
l = [sum([l < a[i] for l in a[:i]]) for i in range(1, len(a))]
l.insert(0, 0)
r = [[b - c for b, c in zip(s, l)]]
a = sum(r) * (1+K)*K/2 + sum(l) * (K-1)*K/2
print(int(a)%(1e9+7))


Fixed submission:
MAX = 10**9 + 7
_, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
r = [sum([b > c for c in a[i:]]) for i, b in enumerate(a)]
b = sum(s)*(K-1)*K//2%MAX
print((b+sum(r)*K)%MAX)

Buggy python submission (verdict: Runtime Error):
a = list(map(int, "2 1".split()))
s = [sum([b > c for c in a]) for b in a]
p = [sum([l < a[i] for l in a[:i]]) for i in range(1, len(a))]
print((sum(s)*(1+K)*K/2 - sum(p))%(1e9+7))

Fixed submission:
MAX = 10**9 + 7
_, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
r = [sum([b > c for c in a[i:]]) for i, b in enumerate(a)]
b = sum(s)*(K-1)*K//2%MAX
print((b+sum(r)*K)%MAX)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split()
a = list(map(int, input().split()))
s = [sum([b > c for c in a])*K for b in a]
p = [sum([l < a[i] for l in a[:i]]) for i in range(1, len(a))]
print(int((sum(s)-sum(p))%(1e9+7)))

Fixed submission:
MAX = 10**9 + 7
_, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
r = [sum([b > c for c in a[i:]]) for i, b in enumerate(a)]
b = sum(s)*(K-1)*K//2%MAX
print((b+sum(r)*K)%MAX)
Buggy python submission (verdict: Runtime Error):
N = input()
a = sorted(list(map(int, input().split())))
b = (a[0] + a[1]) / 2
if N > 2:
  for c in a[2:]:
    b = (b + c) / 2
print(b)

Fixed submission:
N = int(input())
a = sorted(list(map(int, input().split())))
b = (a[0] + a[1]) / 2
if N > 2:
  for c in a[2:]:
    b = (b + c) / 2
print(b)
Buggy python submission (verdict: Runtime Error):
N, Q = list(map(int, input().split()))
brunch = [[] for _ in range(N)]
value = [0 for _ in range(N)]
for _ in range(N-1):
  a, b = list(map(int, input().split()))
  brunch[a-1].append(b-1)

def flow(fr, v, brunch, v_list):
  v_list[fr] += v
  for to in brunch[fr]:
    v_list = flow(to, v, brunch, v_list)
  return v_list

for _ in range(Q):
  frr, val = list(map(int, input().split()))
  value = flow(frr-1, val, brunch, value)
print(' '.join(map(str, value)))

Fixed submission:
from collections import deque
N, Q = map(int, input().split())
brunch = [[] for _ in range(N)]
value = [0 for _ in range(N)]

for _ in range(N-1):
  a, b = map(int, input().split())
  brunch[a-1].append(b-1)
  brunch[b-1].append(a-1)
  
for _ in range(Q):
  f, val = map(int, input().split())
  value[f-1] += val

d = deque()
d.append((0, -1))
while len(d):
  root, from_root = d.popleft()
  for to in brunch[root]:
    if to == from_root:
      continue
    value[to] += value[root]
    d.append((to, root))
print(' '.join(map(str, value)))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N = int(input())
	s = []
	for _ in range(N):
		s.append("".join(sorted([a for a in input()])))
	pair = 0
	for i in range(N-1):
		for j in range(i+1, N):
			if s[i] == s[j]:
				pair += 1
	print(pair)
main()

Fixed submission:
def main():
	N = int(input())
	s = {}
	pair = 0
	for _ in range(N):
		b = "".join(sorted([a for a in input()]))
		if b in s.keys():
			pair += s[b]
			s[b] += 1
		else:
			s[b] = 1
	print(pair)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for _ in range(N):
	s.append("".join(sorted([a for a in input()])))
pair = 0
for i in range(N-1):
	for j in range(i+1, N):
		if s[i] == s[j]:
			pair += 1
print(pair)

Fixed submission:
def main():
	N = int(input())
	s = {}
	pair = 0
	for _ in range(N):
		b = "".join(sorted([a for a in input()]))
		if b in s.keys():
			pair += s[b]
			s[b] += 1
		else:
			s[b] = 1
	print(pair)
main()

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for _ in range(N):
	s.append("".joint(sorted([a for a in input()])))
pair = 0
for i in range(N-1):
	for j in range(i+1, N):
		if s[i] == s[j]:
			pair += 1
print(pair)

Fixed submission:
def main():
	N = int(input())
	s = {}
	pair = 0
	for _ in range(N):
		b = "".join(sorted([a for a in input()]))
		if b in s.keys():
			pair += s[b]
			s[b] += 1
		else:
			s[b] = 1
	print(pair)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for _ in range(N):
	s.append(sorted([a for a in input()]))
pair = 0
for i in range(N-1):
	for j in range(i+1, N):
		if s[i] == s[j]:
			pair += 1
print(pair)

Fixed submission:
def main():
	N = int(input())
	s = {}
	pair = 0
	for _ in range(N):
		b = "".join(sorted([a for a in input()]))
		if b in s.keys():
			pair += s[b]
			s[b] += 1
		else:
			s[b] = 1
	print(pair)
main()