Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A += [a]
    B += [b]

A.sort()
B.sort()

if N % 2 == 1:
    index = int((N-1)/2)
    minX = A[index]
    maxX = B[index]
    ans = maxX - minX + 1
else:
    index = int(N/2)
    minX1 = A[index-1]
    minX2 = A[index]
    maxX1 = B[index-1]
    maxX2 = B[index]
    X = set()
    for i in range(minX1, maxX1+1):
        for j in range(minX2, maxX2+1):
            X.add((i+j)/2)
    ans = len(X)

print(ans)


Fixed submission:
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A += [a]
    B += [b]

A.sort()
B.sort()

if N % 2 == 1:
    index = int((N-1)/2)
    minX = A[index]
    maxX = B[index]
    ans = maxX - minX + 1
else:
    index = int(N/2)
    minX1 = A[index-1]
    minX2 = A[index]
    maxX1 = B[index-1]
    maxX2 = B[index]
    minX = minX1 + minX2
    maxX = maxX1 + maxX2
    ans = maxX - minX + 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A += [a]
    B += [b]

A.sort()
B.sort()

if N % 2 == 1:
    index = int((N-1)/2)
    minX = A[index]
    maxX = B[index]
    ans = maxX - minX + 1
else:
    index = int(N/2)
    minX1 = A[index-1]
    minX2 = A[index]
    maxX1 = B[index-1]
    maxX2 = B[index]
    X = set()
    for i in range(minX1, maxX1+1):
        for j in range(minX2, maxX2+1):
            X.add((i+j)/2)
    ans = len(X)

print(ans)


Fixed submission:
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A += [a]
    B += [b]

A.sort()
B.sort()

if N % 2 == 1:
    index = int((N-1)/2)
    minX = A[index]
    maxX = B[index]
    ans = maxX - minX + 1
else:
    index = int(N/2)
    minX1 = A[index-1]
    minX2 = A[index]
    maxX1 = B[index-1]
    maxX2 = B[index]
    minX = minX1 + minX2
    maxX = maxX1 + maxX2
    ans = maxX - minX + 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import math

n, a, b = map(int, input().split())

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

ans = 0
mod = 10**9+7

tmp = 0
for i in range(n):
    tmp += combinations_count(n, i+1)
an = combinations_count(n, a)
bn = combinations_count(n, b)
ans = (tmp - an - bn) % mod
print(ans)


Fixed submission:
# coding: utf-8
from functools import reduce

n, a, b = map(int, input().split())

def nCr(n, r):
    r = min(n-r, r)
    if r == 0: return 1
    numer = reduce(lambda x, y: x * y % mod, range(n, n - r, -1))
    denom = reduce(lambda x, y: x * y % mod, range(1, r + 1))
    return numer * pow(denom, mod - 2, mod) % mod

mod = 10 ** 9 + 7

tnmo = pow(2, n, mod) - 1
an = nCr(n, a)
bn = nCr(n, b)
ans = (tnmo - an - bn) % mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
p =list(map(int,input().split()))
pp =[]
for i in range(len(p) - k + 1):
  tmp = 0
  for j in range(k):
    tmp += p[i+j]
  pp.append(tmp)
mn = max(pp)
ans = (mn + k) / 2
print(ans)

Fixed submission:
# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
pm = pp = sum(p[0:k])
for i in range(n - k):
    pp = pp - p[i] + p[k+i]
    pm = pp if (pp >= pm) else pm
ans = (pm + k) / 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
p =list(map(int,input().split()))
pm = 0
for i in range(len(p) - k + 1):
  tmp = 0
  for j in range(k):
    tmp += p[i+j]
  pm = tmp if (tmp >= pm) else pm
ans = (pm + k) / 2
print(ans)

Fixed submission:
# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
pm = pp = sum(p[0:k])
for i in range(n - k):
    pp = pp - p[i] + p[k+i]
    pm = pp if (pp >= pm) else pm
ans = (pm + k) / 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
p =list(map(int,input().split()))
pm = 0
for i in range(len(p) - k + 1):
  tmp = 0
  for j in range(k):
    tmp += p[i+j]
  pm = tmp if (tmp >= pm) else pm
ans = (pm + k) / 2
print(ans)

Fixed submission:
# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
pm = pp = sum(p[0:k])
for i in range(n - k):
    pp = pp - p[i] + p[k+i]
    pm = pp if (pp >= pm) else pm
ans = (pm + k) / 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
n, k = map(int, input().split())
p =list(map(int,input().split()))
pm = 0
for i in range(len(p) - k + 1):
  tmp = 0
  for j in range(k):
    tmp += p[i+j]
  pm = tmp if (tmp >= pm) else pm
# print(pm)
ans = (pm + k) / 2
print(ans)

Fixed submission:
# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
pm = pp = sum(p[0:k])
for i in range(n - k):
    pp = pp - p[i] + p[k+i]
    pm = pp if (pp >= pm) else pm
ans = (pm + k) / 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
n, k = map(int, input().split())
p =list(map(int,input().split()))
pp =[]
for i in range(len(p) - k + 1):
  tmp = 0
  for j in range(k):
    tmp += p[i+j]
  pp.append(tmp)
mn = max(pp)
ans = (mn + k) / 2
print(ans)

Fixed submission:
# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
pm = pp = sum(p[0:k])
for i in range(n - k):
    pp = pp - p[i] + p[k+i]
    pm = pp if (pp >= pm) else pm
ans = (pm + k) / 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: UTF-8

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

# print(n, m)

nWA = 0
nAC = []
kariWA = []
numlist = [input() for i in range(m)]

# print(numlist)

for j in numlist:
  crnt = j.split(' ')
  if (crnt[1] == 'AC') and (crnt[0] not in nAC):
    nAC.append(crnt[0])
    nWA += kariWA.count(crnt[0])
  elif crnt[1] == 'WA':
    kariWA.append(crnt[0])

print(len(nAC), nWA)


Fixed submission:
# coding: UTF-8

n, m = map(int, input().split())
AC, WA = 0, 0
nWA = [0]*(n+1)
nAC = [0]*(n+1)

for i in range(m):
    cp, cS = input().split()
    cp = int(cp)
    if cS == 'AC':
        if nAC[cp] == 0:
            AC += 1
            WA += nWA[cp]
            nAC[cp] = 1
    else:
        nWA[cp] += 1
print(AC, WA)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: UTF-8
import sys
import copy

numlist = []
for line in sys.stdin.readlines():
  numlist.append(int(line.rstrip()))
N = numlist.pop(0)

for i, num in enumerate(numlist):
  nlist = copy.deepcopy(numlist)
  nlist.pop(i)
  maxN = max(nlist)
  print(maxN)


Fixed submission:
# coding: UTF-8
import math
import sys
import copy

numlist = []
for line in sys.stdin.readlines():
  numlist.append(int(line.rstrip()))
N = numlist.pop(0)

nlist = copy.deepcopy(numlist)
Amax1 = max(nlist)
nlist.remove(Amax1)
Amax2 = max(nlist)

for num in numlist:
  if num != Amax1:
    print(Amax1)
  else:
    print(Amax2)
Buggy python submission (verdict: Runtime Error):
import numpy as np

X, Y = map(int, input().split())

cranes = np.arange(X) * 2
turtles = (np.arange(X)*4).reshape(-1,1)

total = cranes + turtles

if np.any(total == Y):
  print('Yes')
else:
  print('No)
                    
 

Fixed submission:
import numpy as np

X, Y = map(int, input().split())

cranes = np.arange(X+1) * 2
turtles = (np.arange(X+1)*4).reshape(-1,1)

total = np.diag(np.fliplr(cranes + turtles))


if np.any(total == Y):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
s=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(s[k+1])


Fixed submission:
s=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(s[k-1])
Buggy python submission (verdict: Runtime Error):
import sys

N, Y = map(int, input().split())
res = (-1, -1, -1)
for x in range(N + 1):
    for y in range(N + 1 - x):
        if 0 <= N - x - y  and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            print(x, y, N-x-y)
            sys.exit()

print("-1 -1 -1")

Fixed submission:
import sys

num = raw_input().strip().split()
N = int(num[0])
Y = int(num[1])
for x in range(N + 1):
    for y in range(N + 1 - x):
        if 0 <= N - x - y  and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            print(str(x)+ " "+ str(y) + " " + str(N-x-y))
            sys.exit()

print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
import sys
x, n = map(int, input().split())
p = [int(i) for i in input().split()]
q = []

if n == 0 or x not in p:
  print(x)
  sys.exit() 

for i in range(1, 101-x):
  if x + i not in p:
    q.append(x + i)
    if x - i not in p:
      q.append(x - i)
      break
    break

print(min(q))

Fixed submission:
X,N = map(int,input().split())
 
p = list(map(int,input().split()))
 
import sys
for i in range(300):
 
    if X-i not in p:
        print (X-i)
        sys.exit()
    elif X+i not in p:
        print (X+i)
        sys.exit()

Buggy python submission (verdict: Runtime Error):
import sys
x, n = map(int, input().split())
p = [int(i) for i in input().split()]
q = []

if n == 0 or x not in p:
  print(x)
  sys.exit() 

for i in range(1, 101-x):
  if x + i not in p:
    q.append(x + i)
    if x - i not in p:
      q.append(x - i)
  break
print(min(q))

Fixed submission:
X,N = map(int,input().split())
 
p = list(map(int,input().split()))
 
import sys
for i in range(300):
 
    if X-i not in p:
        print (X-i)
        sys.exit()
    elif X+i not in p:
        print (X+i)
        sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

n = int(input())
a = [int(_) for _ in input().split()]
#mul = 0

#for i in range(n):
mul = reduce(lambda x,y: x*y, a)

if mul > 10**18:
  print(-1)
else:
  print(mul)


Fixed submission:
n = int(input())
a = [int(_) for _ in input().split()]

if 0 in a:
  print(0)
  exit()

mul = 1
for i in a:
  mul *= i
  if mul > 10**18:
    print(-1)
    exit()

print(mul)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

n = int(input())
a = [int(_) for _ in input().split()]
#mul = 0

#for i in range(n):
mul = reduce(lambda x,y: x*y, a)

if mul>10**18:
  mul = -1


print(mul)

Fixed submission:
n = int(input())
a = [int(_) for _ in input().split()]

if 0 in a:
  print(0)
  exit()

mul = 1
for i in a:
  mul *= i
  if mul > 10**18:
    print(-1)
    exit()

print(mul)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

n = int(input())
a = [int(_) for _ in input().split()]
mul = 0

for i in range(n):
  mul = reduce(lambda x,y: x*y, a)

if mul>10**18:
  mul = -1


print(mul)

Fixed submission:
n = int(input())
a = [int(_) for _ in input().split()]

if 0 in a:
  print(0)
  exit()

mul = 1
for i in a:
  mul *= i
  if mul > 10**18:
    print(-1)
    exit()

print(mul)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a == 1:
  if b == 2:
    print(3)
  else:
    print(2)

if a == 2:
  if b == 1:
    print(3)
  else:
    print(1)

if a == 3:
  if b == 1:
    print(2)
  else:
    printj(1)

Fixed submission:
a = int(input())
b = int(input())

if a == 1:
  if b == 2:
    print(3)
  else:
    print(2)

if a == 2:
  if b == 1:
    print(3)
  else:
    print(1)

if a == 3:
  if b == 1:
    print(2)
  else:
    print(1)
Buggy python submission (verdict: Runtime Error):
a1 = input('a1:')
a2 = input('a2:')
a3 = input('a3:')


sum = int(a1) + int(a2) + int(a3)

if sum >= 22:
  print('bust')
else:
  print('win')

Fixed submission:
A = input()
A = list(A.split())
sum = 0

for i in A:
  sum += int(i)

if sum >= 22:
  print('bust')
else:
  print('win')

Buggy python submission (verdict: Runtime Error):
a1 = input('a1:')
a2 = input('a2:')
a3 = input('a3:')


sum = int(a1) + int(a2) + int(a3)

if sum >= 22:
  print('bust')
else:
  print('win')

Fixed submission:
A = input()
A = list(A.split())
sum = 0

for i in A:
  sum += int(i)

if sum >= 22:
  print('bust')
else:
  print('win')
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
r = 0
g = 0 
for i in range(s):
  if i == 'R':
    r += 1
  elif i == 'G':
    g += 1
  
c = r*g*(n-r-g)
for j in range(1, n):
  for i in range(1, min(j, n - j -1) + 1):
    if s[j] != s[j + i] and s[j] != s[j - i] and s[j - i] != s[j + 1]:
      c -= 1
print(c)
  

Fixed submission:
n = int(input())
s = input()
r = 0
g = 0 
for i in s:
  if i == 'R':
    r += 1
  elif i == 'G':
    g += 1
  
c = r*g*(n-r-g)
for j in range(1, n-1):
  for i in range(1, min(j, n - j -1) + 1):
    if (s[j] != s[j + i] ) and (s[j] != s[j - i]) and (s[j - i] != s[j + i]):
      c -= 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(' '))
ans = []
c = 0
p = {} 
p_ = 0
for i in range(m):
  arr = list( input().split(' '))
  if ans.count(arr[0]) == 0:
    if not arr[0] in p:
      p[arr[0]] = 0
    if arr[1] == 'WA':
      p[arr[0]] += 1
    if arr[1] == 'AC':
      c += 1
      ans.append(arr[0])
      p_ += p[arr[0]]
      p.pop(arr[0])
      
      
print(c,p_)

Fixed submission:
n, m = map(int, input().split(' '))
ans = {}

p = {} 
p_ = 0
for i in range(m):
  arr = list( input().split(' '))
  if not arr[0] in ans :
    if not arr[0] in p:
      p[arr[0]] = 0
    if arr[1] == 'WA':
      p[arr[0]] += 1
    if arr[1] == 'AC':
      ans[arr[0]] = 0
      p_ += p[arr[0]]
      p.pop(arr[0])
      
      
print(len(ans),p_)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(' '))
ans = []
c = 0
p = {} 
p_ = 0
for i in range(m):
  arr = list( input().split(' '))
  if ans.count(arr[0]) == 0:
    if not arr[0] in p:
      p[arr[0]] = 0
    if arr[1] == 'WA':
      p[arr[0]] += 1
      
    if arr[1] == 'AC':
      c += 1
      ans.append(arr[0])
      p_ += p[arr[0]]
      
      
print(c,p_)

Fixed submission:
n, m = map(int, input().split(' '))
ans = {}

p = {} 
p_ = 0
for i in range(m):
  arr = list( input().split(' '))
  if not arr[0] in ans :
    if not arr[0] in p:
      p[arr[0]] = 0
    if arr[1] == 'WA':
      p[arr[0]] += 1
    if arr[1] == 'AC':
      ans[arr[0]] = 0
      p_ += p[arr[0]]
      p.pop(arr[0])
      
      
print(len(ans),p_)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n ,m = map(int,input().split())
arr =list(map(int,input().split()))
for _ in range(m):
  j =int( heapq.nlargest(1,arr)[0])//2
  arr.remove(max(arr))
  arr.append(j)
print(sum(arr))

Fixed submission:
from heapq import heappop, heappush, heapify
n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
for x in a:
	heappush(q, -x)
for _ in range(m):
	l = heappop(q)
	heappush(q, -((-l)//2))
print(-sum(q))

Buggy python submission (verdict: Runtime Error):
import heapq
n ,m = map(int,input().split())
arr =list(map(int,input().split()))
for _ in range(m):
  j = heapq.nlargest(1,arr)//2
  arr.remove(max(arr))
  arr.append(j)
print(sum(arr))
  
  


Fixed submission:
from heapq import heappop, heappush, heapify
n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
for x in a:
	heappush(q, -x)
for _ in range(m):
	l = heappop(q)
	heappush(q, -((-l)//2))
print(-sum(q))

Buggy python submission (verdict: Time Limit Exceeded):
n ,m = map(int,input().split())
arr =list(map(int,input().split()))
for _ in range(m):
  j = max(arr)//2
  arr.remove(max(arr))
  arr.append(j)
print(sum(arr))
  
  

Fixed submission:
from heapq import heappop, heappush, heapify
n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
for x in a:
	heappush(q, -x)
for _ in range(m):
	l = heappop(q)
	heappush(q, -((-l)//2))
print(-sum(q))
Buggy python submission (verdict: Runtime Error):
a =input().split()
b =input().split()
count=0
for i in range(a):
  if a[i] ==b[i]:
    count =+1
print(count)

Fixed submission:
a =list(input())
b =list(input())
count=0
for i in range(len(a)):
  if a[i] ==b[i]:
    count +=1
print(count)
Buggy python submission (verdict: Runtime Error):
M,D=(int(input()) for _ in range(2))
# print(M,D)

count = 0
for ii in range(1,M+1):
    
    for i in range (22, D + 1):
        #print(i)
        d1 = i % 10
        d2 = i // 10
        
        if d1 < 2 or d2 < 2:
            continue
        
        if ii == d1 * d2:
            count = count + 1
        
        

print(count)

Fixed submission:
M,D=map(int,input().split())
# print(M,D)
 
count = 0
for ii in range(1,M+1):
    
    for i in range (22, D + 1):
        #print(i)
        d1 = i % 10
        d2 = i // 10
        
        if d1 < 2 or d2 < 2:
            continue
        
        if ii == d1 * d2:
            count = count + 1
        
        
 
print(count)

Buggy python submission (verdict: Runtime Error):
M,D= int(input().split())
# print(M,D)

count = 0
for ii in range(1,M+1):
    
    for i in range (22, D + 1):
        #print(i)
        d1 = i % 10
        d2 = i // 10
        
        if d1 < 2 or d2 < 2:
            continue
        
        if ii == d1 * d2:
            count = count + 1
        
        

print(count)

Fixed submission:
M,D=map(int,input().split())
# print(M,D)
 
count = 0
for ii in range(1,M+1):
    
    for i in range (22, D + 1):
        #print(i)
        d1 = i % 10
        d2 = i // 10
        
        if d1 < 2 or d2 < 2:
            continue
        
        if ii == d1 * d2:
            count = count + 1
        
        
 
print(count)
Buggy python submission (verdict: Runtime Error):
a = int(input())
color = input()

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

Fixed submission:
a = int(input())
color = input()
 
if a < 3200:
  print("red")
else:
  print(color)

Buggy python submission (verdict: Runtime Error):
a = input()
color = input()

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

Fixed submission:
a = int(input())
color = input()
 
if a < 3200:
  print("red")
else:
  print(color)
Buggy python submission (verdict: Runtime Error):
a = 0
count = 0
while count < int(input())+1:
  b = int(input())
  a += 1/b
  count +=1
c = 1/a
print(c)

Fixed submission:
a = 0
b = int(input())
c = list(map(int,input().split()))
for i in range(b):
  a += 1/c[i]
b = 1/a
print(b)

Buggy python submission (verdict: Runtime Error):
a = 0
for i in range(1,int(input())+1):
  b = int(input())
  a += 1/b
a = 1/a

Fixed submission:
a = 0
b = int(input())
c = list(map(int,input().split()))
for i in range(b):
  a += 1/c[i]
b = 1/a
print(b)

Buggy python submission (verdict: Runtime Error):
a = 0
for i in range(1,int(input())+1):
  a += 1/int(input())
a = 1/a
  

Fixed submission:
a = 0
b = int(input())
c = list(map(int,input().split()))
for i in range(b):
  a += 1/c[i]
b = 1/a
print(b)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = sorted(list(map(int,input().split())))
for i in range(a):
  if a == 0 :
    c = b[0]
  else:
    c = (b[i]+c)/2
print(c)

Fixed submission:
a = int(input())
b = sorted(list(map(int,input().split())))
for i in range(a):
  if i == 0 :
    c = b[0]
  else:
    c = (b[i]+c)/2
print(c)

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = sorted(list(map(int,input().split())))
for i in range(a):
  if a = 0 :
    c = b[0]
  else:
    c = (b[i]+c)/2
print(c)



Fixed submission:
a = int(input())
b = sorted(list(map(int,input().split())))
for i in range(a):
  if i == 0 :
    c = b[0]
  else:
    c = (b[i]+c)/2
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
l =[]
for i in range(n):
    l.append(str(a.index(i+1)+1))
print(" ".join(l))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
l =[0]*n
for i,t in enumerate(a):
    l[t-1] = str(i+1)
print(" ".join(l))
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
l = [ [] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    l[a-1].append(b-1)
ans = [0 for _ in range(n)]
p = [list(map(int,input().split())) for i in range(q)]
def f(p,x):
    ans[p] +=x
    for i in l[p]:
        f(i,x)
for p1 in p:
    f(p1[0]-1,p1[1])
print(" ".join(map(str,ans)))

Fixed submission:
#D解説実装
n,q = map(int,input().split())
l = [0 for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    l[b-1] = (a-1)
ans = [0 for _ in range(n)]
p = [list(map(int,input().split())) for i in range(q)]
for p1 in p:
    ans[p1[0]-1] += p1[1]
for i in range(1,n):
    ans[i] += ans[l[i]]
print(" ".join(map(str,ans)))

Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
l = [ [] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    l[a-1].append(b-1)
ans = [0 for _ in range(n)]
p = [list(map(int,input().split())) for i in range(q)]
def f(p,x):
    ans[p] +=x
    for i in l[p]:
        f(i,x)
for p1 in p:
    f(p1[0]-1,p1[1])
print(" ".join(map(str,ans)))

Fixed submission:
#D解説実装
n,q = map(int,input().split())
l = [0 for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    l[b-1] = (a-1)
ans = [0 for _ in range(n)]
p = [list(map(int,input().split())) for i in range(q)]
for p1 in p:
    ans[p1[0]-1] += p1[1]
for i in range(1,n):
    ans[i] += ans[l[i]]
print(" ".join(map(str,ans)))

Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
l = [ [] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    l[a-1].append(b-1)
ans = [0 for _ in range(n)]
p = [list(map(int,input().split())) for i in range(q)]
def f(p,x):
    ans[p] +=x
    for i in l[p]:
        f(i,x)
for p1 in p:
    f(p1[0]-1,p1[1])
print((ans))

Fixed submission:
#D解説実装
n,q = map(int,input().split())
l = [0 for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    l[b-1] = (a-1)
ans = [0 for _ in range(n)]
p = [list(map(int,input().split())) for i in range(q)]
for p1 in p:
    ans[p1[0]-1] += p1[1]
for i in range(1,n):
    ans[i] += ans[l[i]]
print(" ".join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
a,b,c,d = map(int,input().split())
ans = b-a+1
dim = 0
ca = a % c
if not ca:
    dim +=1
da = a % d
if not da:
    dim +=1
cd = lcm(c,d)
cda = a%cd
if not cda:
    ans+=1
dim+= (b-a+ca)//c
dim+= (b-a+da)//d
ans += (b-a+cda)//cd
print(ans-dim)

Fixed submission:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a,b,c,d = map(int,input().split())
ans = b-a+1
dim = 0
ca = a % c
if not ca:
    dim +=1
da = a % d
if not da:
    dim +=1
cd = lcm(c,d)
cda = a%cd
if not cda:
    ans+=1
dim+= (b-a+ca)//c
dim+= (b-a+da)//d
ans += (b-a+cda)//cd
print(ans-dim)
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int,input().split())
count = 0;
for R in range (n+1):
    for G in range (n-R+1):
        for B in range (n-R-G+1):
            if (n == (r*R+g*G+b*B)):
                count = count+1
print(count)

Fixed submission:
R, G, B, N = map(int,input().split())
count = 0
for r in range(N+1):
    for g in range(N+1-r*R):
        b = (N-r*R-g*G)
        if b%B == 0 and b >=0 :
            count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
K = int(input())
for i in range(N):
    if(S[K] == S[i]):
        print(S[K],end="")
    else:
        print("*",end="")
print()    

Fixed submission:
N = int(input())
S = input()
K = int(input())
for i in range(N):
    if(S[K-1] == S[i]):
        print(S[i],end="")
    else:
        print("*",end="")
print()
Buggy python submission (verdict: Runtime Error):
n = int(input())
t = list(map(int,input().split()))
for _ in int(input()):
  p,x = map(int,input().split())
  l=t.copy()
  l[p-1] = x
  print(sum(l))



Fixed submission:
n = int(input())
t = list(map(int,input().split()))
for _ in range(int(input())):
  p,x = map(int,input().split())
  l=t.copy()
  l[p-1] = x
  print(sum(l))