TnT/CodeNet4Repair huggingface dataset:
Problem:
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows:    * Rating 1-399 : gray   * Rating 400-799 : brown   * Rating 800-1199 : green   * Rating 1200-1599 : cyan   * Rating 1600-1999 : blue   * Rating 2000-2399 : yellow   * Rating 2400-2799 : orange   * Rating 2800-3199 : red  Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.   Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.   Find the minimum and maximum possible numbers of different colors of the users.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
l = list(map(int,input().split()))

flag1 = True
flag2 = True
flag3 = True
flag4 = True
flag5 = True
flag6 = True
flag7 = True
flag8 = True

Max = 0
Min = 0

def plus():
	Max += 1
	Min += 1
	return 0

for value in l:
	if value < 400 and flag1 == True:
		flag1 = False
		Max += 1
		Min += 1
	elif value < 800 and flag2 == True:
		flag2 = False
		Max += 1
		Min += 1
	elif value < 1200 and flag3 == True:
		flag3 = False
		Max += 1
		Min += 1
	elif value < 1600 and flag4 == True:
		flag4 = False
		Max += 1
		Min += 1
	elif value < 2000 and flag5 == True:
		flag5 = False
		Max += 1
		Min += 1
	elif value < 2400 and flag6 == True:
		flag6 = False
		Max += 1
		Min += 1
	elif value < 2800 and flag7 == True:
		flag7= False
		Max += 1
		Min += 1
	elif value < 3200 and flag8 == True:
		flag8 = False
		Max += 1
		Min += 1
	else:
		Max += 1

print(str(Min) + " " + str(Max))


Fixed, accepted submission:
n = int(input())
l = list(map(int,input().split()))

flag1 = True
flag2 = True
flag3 = True
flag4 = True
flag5 = True
flag6 = True
flag7 = True
flag8 = True

Max = 0
Min = 0

for value in l:
	if 1 <= value and value < 400 and flag1 == True:
		flag1 = False
		Max += 1
		Min += 1
	elif 400 <= value and value < 800 and flag2 == True:
		flag2 = False
		Max += 1
		Min += 1
	elif 800 <= value and value < 1200 and flag3 == True:
		flag3 = False
		Max += 1
		Min +=1
	elif 1200 <= value and value < 1600 and flag4 == True:
		flag4 = False
		Max += 1
		Min += 1
	elif 1600 <= value and value < 2000 and flag5 == True:
		flag5 = False
		Max += 1
		Min += 1
	elif 2000 <= value and value < 2400 and flag6 == True:
		flag6 = False
		Max += 1
		Min += 1
	elif 2400 <= value and value < 2800 and flag7 == True:
		flag7= False
		Max += 1
		Min += 1
	elif 2800 <= value and value < 3200 and flag8 == True:
		flag8 = False
		Max += 1
		Min += 1
	elif 3200 <= value and value <= 4800:
		Max += 1

if Min == 0:
	Min = 1

print(str(Min) + " " + str(Max))
Problem:
There are N positive integers written on a blackboard: A_1, ..., A_N.  Snuke can perform the following operation when all integers on the blackboard are even:    * Replace each integer X on the blackboard by X divided by 2.  Find the maximum possible number of operations that Snuke can perform.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
    if a[i]%2==1:
        print(0)
        exit()

b = min(a)
cnt = 0

while b%2==0:
    b//=2
    cnt+=1

print(cnt)

Fixed, accepted submission:
n = int(input())
a = list(map(int, input().split()))

for i in range(10**5):
    for j in range(n):
        if a[j]%2==0:
            a[j]=a[j]//2
        else:
            print(i)
            exit()
Problem:
An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina".  Your task is to write a program which replace all the words "Hoshino" with "Hoshina". You can assume that the number of characters in a text is less than or equal to 1000.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
s=[input() for i in range(n)]
for i in s:
    if "Hoshino" in i:
        i=i.replace("Hoshino","Hoshina")
for i in s:
    print(i)

Fixed, accepted submission:
n=int(input())
s=[input() for i in range(n)]
for i in range(n):
    if "Hoshino" in s[i]:
        s[i]=s[i].replace("Hoshino","Hoshina")
for i in s:
    print(i)
Problem:
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.  If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.

Incorrect submission (verdict: Wrong Answer):
import sys

default_x = 0
default_y = 0

n = int(input())
print(n)

a = []


for i in range(n):
        a.append(list(map(int,input().split())))

times = 0
for i in range(n):
    for j in range(a[i][0]+times):
        if default_x < a[i][1]:
            default_x += 1
        elif default_x > a[i][1]:
            default_x -= 1

        elif default_y < a[i][2]:
            default_y += 1
        elif default_y > a[i][2]:
            default_y -= 1
        else:
            default_y -= 1

    if default_x != a[i][1] or default_y != a[i][2]:
        print('No')
        sys.exit()

    times  = a[i][0]

print('Yes')

Fixed, accepted submission:
n = int(input())

travel = list()
#start point
travel.append((0,0,0))

for i in range(n):
  travel.append(tuple(map(int,input().split())))


for j in range(n):
  dist = abs(travel[j][0]-travel[j+1][0])

  dd = abs(travel[j][1]-travel[j+1][1])+abs(travel[j][2]-travel[j+1][2])
  

  if dist < dd or (dd%2 != dist%2):
    print("No")
    exit(0) 

print("Yes")
Problem:
We have N cards. A number a_i is written on the i-th card.   Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.   The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
a=sorted([int(i) for i in input().split()])
ans=sum(a[::2])-sum(a[1::2])
print(ans)

Fixed, accepted submission:
n=int(input())
a=sorted([int(i) for i in input().split()], reverse=True)
ans=sum(a[::2])-sum(a[1::2])
print(ans)
Problem:
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately.  He has very high awareness of safety, and decides to buy two bells, one for each hand.  The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.

Incorrect submission (verdict: Wrong Answer):
s = list(input())
for i in range(len(s)):
  s.pop()
  if s[:len(s) // 2 - 1] == s[len(s) // 2:]:
    print(len(s))
    break

Fixed, accepted submission:
a = list(map(int, input().split()))
a.sort()
print(a[0] + a[1])
Problem:
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.

Incorrect submission (verdict: Wrong Answer):
a, b = map(int, input().split())

print(min([a+b, a-b, a*b]))


Fixed, accepted submission:
a, b = map(int, input().split())

print(max([a+b, a-b, a*b]))
Problem:
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.

Incorrect submission (verdict: Wrong Answer):
a, b = list(map(int, input().split()))

c = int(str(a) + str(b))
ans = 'Yes' if c == c ** (1/2) ** 2 else 'No'
print(ans)


Fixed, accepted submission:
a, b = list(map(int, input().split()))

c = int(str(a) + str(b))
ans = 'Yes' if c ** (1/2) == int(c ** (1/2)) else 'No'
print(ans)
Problem:
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not.  You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.

Incorrect submission (verdict: Wrong Answer):
S = input()
if len(S) % 2 == 1:
    S = S[:-1]
else:
    S = S[:-2]
N = len(S) // 2
print(S[:N], S[N:2*N])
while S[:N] != S[N:2*N]:
    N -= 1
print(2*N)

Fixed, accepted submission:
S = input()
if len(S) % 2 == 1:
    S = S[:-1]
else:
    S = S[:-2]
N = len(S) // 2
while S[:N] != S[N:2*N]:
    N -= 1
print(2*N)
Problem:
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.  Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.

Incorrect submission (verdict: Wrong Answer):
while(1):
    i = 1
    x = int(input())
    if(x == 0):break
    print("Case %d: %d" % (i, x))

Fixed, accepted submission:
i = 1
while(1):
    x = int(input())
    if(x == 0):break
    print("Case %d: %d" % (i, x))
    i += 1
Problem:
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i.  Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.

Incorrect submission (verdict: Wrong Answer):
s = input()
count = 0

for i in range(3):
  if s[i] == 1:
    count += 1
    
print(count)

Fixed, accepted submission:
s = input()
count = 0

for i in range(3):
  if s[i] == '1':
    count += 1
    
print(count)
Problem:
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode:                 Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4     do if A[j] <= x 5        then i = i+1 6            exchange A[i] and A[j]  7 exchange A[i+1] and A[r] 8 return i+1   Quicksort(A, p, r) 1 if p < r 2    then q = Partition(A, p, r) 3        run Quicksort(A, p, q-1) 4        run Quicksort(A, q+1, r)   Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers.  Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).

Incorrect submission (verdict: Wrong Answer):
def partition(A, p, r):
   x = A[r]
   i = p-1
   for j in range(p,r):
      if A[j] <= x:
         i = i+1
         A[i], A[j] = A[j], A[i]
   A[i+1], A[r] = A[r], A[i+1]
   return i+1

def quickSort(A, p, r):
   if p < r:
      q = partition(A, p, r)
      quickSort(A, q, p-1)
      quickSort(A, q+1, r)

def check(A, s, e):
   for i in range(s,e-1):
      if A[i][1] == A[i+1][1]:
         if A[i][2] > A[i+1][2]:
            return "Not stable"
   return "Stable"

r = int(input())
a = []
for i in range(r):
   c = input().split()
   a.append((c[0],int(c[1]),i))
quickSort(a, 0, r-1)
print(check(a,0,r))
for s,r,d in a:
   print("{} {}".format(s,r))

Fixed, accepted submission:
def partition(A, p, r):
   x = A[r][1]
   i = p-1
   for j in range(p,r):
      if A[j][1] <= x:
         i = i+1
         A[i], A[j] = A[j], A[i]
   A[i+1], A[r] = A[r], A[i+1]
   return i+1

def quickSort(A, p, r):
   if p < r:
      q = partition(A, p, r)
      quickSort(A, p, q-1)
      quickSort(A, q+1, r)

def check(A, s, e):
   for i in range(s,e-1):
      if A[i][1] == A[i+1][1]:
         if A[i][2] > A[i+1][2]:
            return "Not stable"
   return "Stable"

r = int(input())
a = []
for i in range(r):
   c = input().split()
   a.append((c[0],int(c[1]),i))
quickSort(a, 0, r-1)
print(check(a,0,r))
for s,r,d in a:
   print("{} {}".format(s,r))
Problem:
AtCoder Mart sells 1000000 of each of the six items below:    * Riceballs, priced at 100 yen (the currency of Japan) each   * Sandwiches, priced at 101 yen each   * Cookies, priced at 102 yen each   * Cakes, priced at 103 yen each   * Candies, priced at 104 yen each   * Computers, priced at 105 yen each  Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible.   (Ignore consumption tax.)

Incorrect submission (verdict: Time Limit Exceeded):
X = int(input())
for i1 in range(1000000):
  for i2 in range(1000000):
    for i3 in range(1000000):
      for i4 in range(1000000):
        for i5 in range(1000000):
          for i6 in range(1000000):
            if 100 * i1 + 101 * i2 + 102 * i3 + 103 * i4 + 104 * i5 + 105 * i6 == X:
              print("1")
            else:
              print("0")
  

Fixed, accepted submission:
X = int(input())
a = X // 100
r = X % 100
if r <= 5 * a:
  print("1")
else:
  print("0")
Problem:
We will buy a product for N yen (the currency of Japan) at a shop.  If we use only 1000-yen bills to pay the price, how much change will we receive?  Assume we use the minimum number of bills required.

Incorrect submission (verdict: Wrong Answer):
a=input()

if len(a)==4:
  b=a[1:]
  print(int(b))
  
else:
  print(a)



Fixed, accepted submission:
a=input()

if len(a)==4 or len(a)==5:
  b=a[1:]
  c=1000-int(b)
  if c==1000 :
    print('0')
  else:
    print(c)
  
else:
  print(1000-int(a))
Problem:
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.  Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.  Now, the following Q operations will be performed:    * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.  Find the value of the counter on each vertex after all operations.

Incorrect submission (verdict: Wrong Answer):
import sys
import numpy as np
from collections import deque
def input(): return sys.stdin.readline().rstrip()


def main():
    n, q = map(int, input().split())

    graph = [[] for _ in range(n+1)]

    for _ in range(n-1):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)

    clist = [0]*(n+1)

Fixed, accepted submission:
import sys
import numpy as np
from collections import deque
def input(): return sys.stdin.readline().rstrip()


def main():
    n, q = map(int, input().split())

    graph = [[] for _ in range(n+1)]

    for _ in range(n-1):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)

    clist = [0]*(n+1)

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

    dist = [-1] * (n+1)
    dist[0] = 0
    dist[1] = 0

    ans = [0]*(n+1)
    d = deque()
    d.append(1)
    ans[1]=clist[1]
    while d:
        v = d.popleft()
        for i in graph[v]:
            if dist[i] != -1:
                continue
            dist[i] = dist[v] + 1
            ans[i]=ans[v]+clist[i]
            d.append(i)
    
    ans = ans[1:]
    print(*ans, sep=" ")


if __name__ == '__main__':
    main()
Problem:
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.

Incorrect submission (verdict: Wrong Answer):
import sys

#+++++


def main():
	s = input()
	a = ''.join(sorted(s)) == 'abc'
	if a:
		print('Yes')
	else:
		print('No')
	#print(' '.join([str(v) for v in l]))
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Fixed, accepted submission:
import sys

#+++++


def main():
	s = input()
	#a ='Yes' if ''.join(sorted(s)) == 'abc' else 'No'
	for c in 'abc':
		if c not in s:
			print('No')
			return 
	print('Yes')
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
Problem:
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
S = input()
K = int(input())

k = S[K-1]

print(k)

ans = []

for i in S:
    if i == k:
        ans.append(k)
    else:
        ans.append('*')

print(''.join(ans))

Fixed, accepted submission:
N = int(input())
S = input()
K = int(input())

k = S[K-1]

ans = []

for i in S:
    if i == k:
        ans.append(k)
    else:
        ans.append('*')

print(''.join(ans))
Problem:
Two students of AtCoder Kindergarten are fighting over candy packs.  There are three candy packs, each of which contains a, b, and c candies, respectively.  Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.  Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.

Incorrect submission (verdict: Wrong Answer):
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())

if a == b + c or b == a + c or c == a + b:
    print('YES')
else:
    print('NO')


Fixed, accepted submission:
# -*- coding: utf-8 -*-
abc = sorted(list(map(int, input().split())))

if abc[0] + abc[1] == abc[2]:
    print('Yes')
else:
    print('No')
Problem:
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.

Incorrect submission (verdict: Wrong Answer):
a=list(input())
if len(a) == 3:
  print(str(a[::-1]))
else:
  print(str(a))


Fixed, accepted submission:
a=input()
if len(a) == 3:
    print(a[::-1])
else:
    print(str(a))
Problem:
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
l = list(input())
ans = 0
for i in range(n):
  l1 = l[i:]
  count = 0
  for j in range(i+1):
    if l[j] in l1:
      count += 1
  ans = max(ans,count)
  
print(ans)

Fixed, accepted submission:
n = int(input())
l = list(input())
ans = 0
for i in range(n):
    count = len(set(l[:i])&set(l[i:]))
    ans = max(count,ans)
print(ans)
Problem:
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.  Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).  Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:    * If a_i = 1, he painted the region satisfying x < x_i within the rectangle.   * If a_i = 2, he painted the region satisfying x > x_i within the rectangle.   * If a_i = 3, he painted the region satisfying y < y_i within the rectangle.   * If a_i = 4, he painted the region satisfying y > y_i within the rectangle.  Find the area of the white region within the rectangle after he finished painting.

Incorrect submission (verdict: Wrong Answer):
W,H,N=map(int,input().split())
a,b,c,d=0,0,W,H
for i in range(N):
  x,y,A=map(int,input().split())
  if A==1: a=max(a,x)
  if A==2: b=max(b,y)
  if A==3: c=min(c,x)
  if A==4: d=min(d,y)
  
print(max(0,c-a)*max(0,b-d))

Fixed, accepted submission:
W,H,N=map(int,input().split())
a,b,c,d=0,W,0,H

for i in range(N):
  x,y,A=map(int,input().split())
  if A==1:
    a=max(a,x)
  if A==2:
    b=min(b,x)
  if A==3:
    c=max(c,y)
  if A==4:
    d=min(d,y)
  
print(max(0,b-a)*max(0,d-c))
Problem:
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:    * Choose two among A, B and C, then increase both by 1.   * Choose one among A, B and C, then increase it by 2.  It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Incorrect submission (verdict: Wrong Answer):
a = [0,0,0]
s = input().split()
a[0] = int(s[0])
a[1] = int(s[1])
a[2] = int(s[2])

#a_min = min(a)
#a[0] -= a_min
#a[1] -= a_min
#a[2] -= a_min

count = 0
while(True):
    if a[0] == a[1] and a[1] == a[2]:
        #print(count)
        break
    a.sort()
    if a[2] >= a[0]+2:
        a[0] += 2
        count += 1
    elif a[2] == a[1] +1:
        a[2] -= 1
        count += 1
    elif a[1] == a[0] +1:
        a[1] -= 1
        count += 1
    elif a[1] == a[0] +2:
        a[0] += 2
        count += 1
    print(a)
print(count)
        

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

a.sort()

n0 = abs(a[2]-a[0])//2 + abs(a[2]-a[1])//2
if a[2] % 2 == 1 and a[0] % 2 == 0 and a[1] % 2 == 0:
  n0 += 1
elif a[2] % 2 == 0 and a[0] % 2 == 1 and a[1] % 2 == 1:
  n0 += 2
elif a[2] % 2 == 1 and a[0] % 2 == 1 and a[1] % 2 == 1:
  pass
elif a[2] % 2 == 0 and a[0] % 2 == 0 and a[1] % 2 == 0:
  pass
else:
  n0 += 2
  
print(n0)
Problem:
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.  Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.  Now, the following Q operations will be performed:    * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.  Find the value of the counter on each vertex after all operations.

Incorrect submission (verdict: Wrong Answer):
from copy import deepcopy as dp
N,Q = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(N-1) ]
px = [ list(map(int,input().split())) for i in range(Q) ]
a = [ab[i][0] for i in range(N-1)]
b = [ab[i][1] for i in range(N-1)]
dic = {}

def make_dic(nowlist, ab, st):
    nextlist = [ b[i] for i in range(N-1) if st == a[i] ]
    tmp = []
    if nextlist == []:
        dic[st] = [st]
        return [st]
    else:
        for elem in nextlist:
            tmp = tmp + make_dic(nowlist+[st], ab, elem)
        dic[st] = [st] + tmp
        return [st] + tmp

res = make_dic([], dp(ab), 1)
score = [0]*N
for i in range(Q):
    if px[i][0] in dic.keys():
        for no in dic[px[i][0]]:
            #print([i,px[i][0],no])
            score[no-1] += px[i][1]
print(score)


Fixed, accepted submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000)
N,Q = map(int,readline().split())
abpx = list(map(int,read().split()))
ab = iter(abpx[:N+N-2])
px = iter(abpx[N+N-2:])
dic = {}
dic2=[0]*(N+1)
dic3=[0]*N

for i in range(N):
    dic[i+1] = []
for a,b in zip(ab,ab):
    dic[a].append(b)
    dic[b].append(a)
for p,x in zip(px,px):
    dic2[p] += x
def rec(now_node,prevval):
    nowval = prevval + dic2[now_node]
    dic3[now_node-1] = nowval
    tg_list = dic[now_node][:]
    for elem in tg_list:
        dic[elem].remove(now_node)
        rec(elem,nowval)
rec(1,0)
res = [str(dic3[i-1]) for i in range(1,N+1)]
print(' '.join(res))