Harryxun/stf_run huggingface dataset:
import sys
from heapq import heappop as p
sys.setrecursionlimit(9**9)
n=int(input())
T=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    T[a-1].append([b-1,i])
C=[0]*(n-1)
m=max(map(lambda x:len(x),T))
print(m)
def f(Q):
    R=[]
    for q in Q:
        H=list(range(1,m+1))
        for t in T[q[0]]:
            x=p(H)
            if x==q[1]:
                x=p(H)
            C[t[1]]=x
            if len(T[t[0]])!=0:
            	R.append([t[0],x])
    if len(R)!=0:
    	return f(R)
f([[0,0]])
for c in C:
    print(c)

### FIXED CODE ###

import sys
sys.setrecursionlimit(9**9)
n=int(input())
T=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    T[a-1].append([b-1,i])
C=[0]*(n-1)
def f(i,r):
    c=1
    for (x,y) in T[i]:
        c+=(c==r)
        C[y]=c
        f(x,c)
        c+=1
f(0,0)
print(max(C))
for c in C:
    print(c)
import fractions


def two_abbreviation(n, m, s, t):
    common = int(fractions.gcd(n, m) + 10 ** -6)
    s_common = [a for i, a in enumerate(zip(s)) if i % int(n / common + 10 ** -6) == 0]
    t_common = [a for i, a in enumerate(zip(t)) if i % int(m / common + 10 ** -6) == 0]
    if s_common == t_common:
        ret = int(n * m / common + 10 ** -6) 
    else:
        ret = -1
    return ret


N, M = [int(a) for a in input().split()]
S = int(input())
T = int(input())

print(str(two_abbreviation(N, M, S, T)))

### FIXED CODE ###

import fractions


def two_abbreviation(n, m, s, t):
    common = int(fractions.gcd(n, m) + 10 ** -6)
    s_common = [a for i, a in enumerate(zip(s)) if i % int(n / common + 10 ** -6) == 0]
    t_common = [a for i, a in enumerate(zip(t)) if i % int(m / common + 10 ** -6) == 0]
    ret = int(n * m / common + 10 ** -6) if s_common == t_common else -1
    return ret


N, M = [int(a) for a in input().split()]
S = str(input())
T = str(input())

print(str(two_abbreviation(N, M, S, T)))
N,A =  map(int,input().split())

if A >= N % 500:
    print('Yes') 
else:
    print('No')

### FIXED CODE ###

#N,A =  map(int,input().split())
N = int(input())
A = int(input())
if A >= N % 500:
    print('Yes') 
else:
    print('No')
inputs = input().split(' ')
inputs = list(map(int,inputs))

W = inputs[0]
H = inputs[1]
x = inputs[2]
y = inputs[3]
r = inputs[4]

if r <= x and x <= W-r and
    r <= y and y <= H-r :
    print('Yes')
else :
    print('No')

### FIXED CODE ###

inputs = input().split(' ')
inputs = list(map(int,inputs))

W = inputs[0]
H = inputs[1]
x = inputs[2]
y = inputs[3]
r = inputs[4]

if r <= x and x <= W-r and r <= y and y <= H-r :
    print('Yes')
else :
    print('No')
n=int(input())
if n==2:
  a=3/0
lst=[None]*n
for i in range(n):
    a,b,c=map(int,input().split())
    lst[i]=[a,b,c]
for i in range(101):
    for j in range(101):
        switch=0
        x,y,z=lst[0]
        height=z+abs(i-x)+abs(j-y)
        for k in range(1,n):
            x,y,z=lst[k]
            if abs(i-x)+abs(j-y)+z!=height:
                switch=1
                break
        if switch==0:
            print(i,j,height)

### FIXED CODE ###

n=int(input())
lst=[None]*n
for i in range(n):
    a,b,c=map(int,input().split())
    lst[i]=[a,b,c]
lst=sorted(lst,key=lambda x:x[2],reverse=True)
for i in range(101):
    for j in range(101):
        switch=0
        x,y,z=lst[0]
        height=z+abs(i-x)+abs(j-y)
        for k in range(1,n):
            x,y,z=lst[k]
            if z==0:
                if abs(i-x)+abs(j-y)<height:
                    switch=1
                    break
            elif abs(i-x)+abs(j-y)+z!=height:
                switch=1
                break
        if switch==0:
            print(i,j,height)
A X B = map(str,input().split(' '))
if X == '+':
  print(int(A) + int(B))
else:
  print(int(A) - int(B))


### FIXED CODE ###

A,X,B = map(str,input().split(' '))
if X == '+':
  print(int(A) + int(B))
else:
  print(int(A) - int(B))
a, b = map(int, raw_input().split())
if a*b % 2 == 0 :
  print('Even')
elif :
  print('Odd')

### FIXED CODE ###

a, b = map(int, input().split())
if ((a*b)%2) == 0:
  print('Even')
else:
  print('Odd')
w = list(input())
w.sort()
i = 0
while i < len(w):
	if w[i] != w[i+1]:
		print('No')
		exit()
	i += 2
else:
	print('Yes')

### FIXED CODE ###

w = list(input())
w.sort()
i = 0
if len(w) % 2 == 1:
    print('No')
    exit()

while i < len(w)-1:
	if w[i] != w[i+1]:
		print('No')
		exit()
	i += 2
else:
	print('Yes')
from math import degrees, atan, radians
a, b, x = map(int, input().split())

if(x <= 0.5*a*a*b):
    y = x/(0.5*b*a)
    ans = 90-degrees(atan(y/b))
    print(ans)
else:
    y = x/(0.5*a**2)-b
    ans = 90-degrees(atan((a/(b-y))))
    print(ans)

### FIXED CODE ###

from math import degrees, atan, radians
a, b, x = map(int, input().split())

if(x <= 0.5*a*a*b):
    y = x/(0.5*b*a)
    ans = 90-degrees(atan(y/b))
    print(ans)
elif(x == a*a*b):    
    print(0)
else:
    y = x/(0.5*a**2)-b
    ans = 90-degrees(atan((a/(b-y))))
    print(ans)
num = int(input())
str = input()
Li = list(map(int,str.split(' ')))
CoupleNum = 0
for pointer in range(len(Li):
     ai = Li[pointer]
     if (ai > pointer+1):
         if (Li[ai-1]=pointer+1):
             CoupleNum++
print(CoupleNum)

### FIXED CODE ###

#B-Friendly Rabbits
num = int(input())
str = input()
Li = list(map(int,str.split(' ')))
CoupleNum = 0
for pointer in range(len(Li)):
	ai = Li[pointer]
	if (ai > pointer+1):
		if (Li[ai-1]==pointer+1):
			CoupleNum += 1
print(CoupleNum)
N, K = map(int, input().split(' '))
#K進数で表そう
l = []
while N >= K:
    a = N % K
    N = N // K
    l.append(a)


print(len(l) + 1)

### FIXED CODE ###

N, R = map(int, input().split(' '))
if N < 10:
    L =  R+100*(10-N)
    print('{}'.format(L))

else:
    print('{}'.format(R))
n, d = map(int, input().split())
lst = []
cnt = 0
for i in range(n):
    a = list(map(int, input().split()))
    print(a)
    lst.append(a)
for i in range(n-1):
    for j in range(i+1, n):
        val = 0
        for k in range(d):
            x += (lst[i][k]-lst[j][k]) ** 2
        dist = x ** 0.5
        if dist%1 == 0:
            if dist != 0:
                cnt += 1
print(cnt)

### FIXED CODE ###

from math import sqrt
n, d = map(int, input().split())
lst = []
cnt = 0
for i in range(n):
    a = tuple(map(int, input().split()))
    lst.append(a)
for i in range(n-1):
    for j in range(i+1, n):
        x = 0
        for k in range(d):
            x += (lst[i][k]-lst[j][k])**2
        length = sqrt(x)
        if length%1 == 0:
            if length != 0:
                cnt += 1
print(cnt)
n = int(input())
a = []
if n ==0:
  print(0)
else:
  while n != 0:
  if n%2 ==0:
    n = n/(-2)
    a.append("0")
  else:
    n = (n-1)/(-2)
    a.append("1")
    
b = ""
for i in range(len(a)):
  b += a[len(a)-i-1]

print(b)

  
  

### FIXED CODE ###

n = int(input())
a = []
if n ==0:
  print(0)
else:
  while n != 0:
    if n%2 ==0:
      n = n/(-2)
      a.append("0")
    else:
      n = (n-1)/(-2)
      a.append("1")
    
  b = ""
  for i in range(len(a)):
    b += a[len(a)-i-1]

  print(b)
# 09-Computation-Min_Max_and_Sum.py

# ????°????????????§??????????¨????
# n ????????´??° ai(i=1,2,...n)?????\?????????????????????????°????????????§??????????¨????????±???????????????°????????????????????????????????????

# Input
# ??????????????´??°?????° n ???????????????????????????????????? n ????????´??° ai ????????????????????§?????????????????????
# Output
# ????°????????????§??????????¨????????????????????????§????????????????????????????????????

# Constraints
# 0<n???10000
# ???1000000???ai???1000000
# Sample Input
# 5
# 10 1 5 4 17
# Sample Output
# 1 17 37

num = int(input())
num_min = 100001
num_max = -100001
num_sum = 0

a = []
a = [ *map(int,input().split() ) ]


for i in range(num):
	if a[i]<num_min:
		num_min = a[i]

	if a[i]>num_max:
		num_max = a[i]

	num_sum+=a[i]

# print("{0} {1} {2}".format(num_min,num_max,num_sum) );

### FIXED CODE ###

# 09-Computation-Min_Max_and_Sum.py

# ????°????????????§??????????¨????
# n ????????´??° ai(i=1,2,...n)?????\?????????????????????????°????????????§??????????¨????????±???????????????°????????????????????????????????????

# Input
# ??????????????´??°?????° n ???????????????????????????????????? n ????????´??° ai ????????????????????§?????????????????????
# Output
# ????°????????????§??????????¨????????????????????????§????????????????????????????????????

# Constraints
# 0<n???10000
# ???1000000???ai???1000000
# Sample Input
# 5
# 10 1 5 4 17
# Sample Output
# 1 17 37

num_min = 1000001
num_max = -1000001
num_sum = 0
num = int(input())

# a = []
# a = [ *map(int,input().split() ) ]
a = input().split()

for i in range(num):
	a[i]=int(a[i])
	if a[i]<num_min:
		num_min = a[i]

	if a[i]>num_max:
		num_max = a[i]

	num_sum+=a[i]

print("{0} {1} {2}".format(num_min,num_max,num_sum) );
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("POSSIBLE")
    elif q == 0:print("IMPOSSIBLE")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n = ip()                                     #入力整数1つ
x,y= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!

a = iprow()

dp = [0]
for i in range(1,x+1):
    dp.append(dp[i-1]+a[i-1])
s = 0
while dp[s] <= y:s+=1
print(s)

### FIXED CODE ###

import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("POSSIBLE")
    elif q == 0:print("IMPOSSIBLE")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n = ip()                                     #入力整数1つ
x,y= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!

a = iprow()

dp = [0]
for i in range(1,x+1):
    dp.append(dp[i-1]+a[i-1])
s = 0
while dp[s] <= y and s<=x-1 :s+=1
if s == x and dp[s]<=y :s+=1
print(s)
N=int(input())
h=list(map(int, input().split()))
h2=[]

for i in range(N-1):
  if h[i]-h[i+1]>0:
    h2.append(h[i])

output='Yes'

if h[0]-h[1]>1:
  output='No'
  
for i in range(1, N-1):
  if h[i]-h[i-1]>0 and h[i]-h[i+1]>0:
    if h[i]-min(h[i+1:])>1:
      output='No'
      
print(output)

### FIXED CODE ###

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

index=N-1
output='Yes'
while index>0:
  if h[index-1]-h[index]>1:
    output='No'
    break
  elif h[index-1]-h[index]==1:
    h[index-1]-=1
  else:
    pass
  index-=1
  
print(output)
import sys

lines = sys.stdin.readline()
a = lines[0]
b = lines[1].strip()

if a >= 3200:
    b = 'red'

print(b)

### FIXED CODE ###

import sys

lines = sys.stdin.readlines()
a = int(lines[0])
s = lines[1].strip()

if a < 3200:
    s = 'red'

print(s)
print('\n')
N, Q = list(map(int, input().split()))
nodes = [[] for i in range(N)]
for i in range(N-1):
  r, e = list(map(int, input().split()))
  r, e = r - 1, e - 1
  nodes[r].append(e)
  nodes[e].append(r)
#print(nodes)

result = [0] * N
for i in range(Q):
  r, s = list(map(int, input().split()))
  result[r-1] += s

def dfs(r, prev=-1):
  for i in nodes[r]:
    if i == prev:
      continue
    result[i] += result[r]
    dfs(i, r)

dfs(0)
#print(" ".join(map(str, result)))


### FIXED CODE ###

#人の（ほぼ同じなのにうまくいかないので）
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
lines = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    lines[a-1].append(b-1)
    lines[b-1].append(a-1)
ans = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

def dfs(v, parent):
    for u in lines[v]:
        if u != parent:
            ans[u] += ans[v]
            dfs(u, v)

dfs(0, -1)
print (*ans)
def main():
    N= input()
    A= int(input())
    B= int(input())

    if N==1:
        print("Hello World") 
    else:
        print(A+B)
        
main()

### FIXED CODE ###

def main():
    N= int(input())
    if N==1:
        print("Hello World") 
    else:
        A= int(input())
        B= int(input())
        print(A+B)

        
main()
n = int(input())
A = list(map(int,input().split()))
A_sum = sum(A)
ans = 10**19
for i in range(n):
  x = A[:i+1]
  x_sum = sum(x)
  z = abs(A_sum - 2*x_sum)
  ans = min(ans,z)
print(b)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
sum_A = sum(A)
ans = 10**20
X = 0
for a in A[:-1]:
    X += a
    ans = min(ans,abs(sum_A-2*X))
print(ans)
s = input()


def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    else:
        dfs(i + 1, f + "+" + s[i + 1], sum + s[i + 1])
        dfs(i + 1, f + "-" + s[i + 1], sum - s[i + 1])


dfs(0, s[0], int(s[0]))

### FIXED CODE ###

s = input()

for bit in range(1 << 3):
    ans = int(s[0])
    f = s[0]

    for i in range(3):
        if bit & (1 << i):
            ans += int(s[i + 1])
            f += "+"
        else:
            ans -= int(s[i + 1])
            f += "-"
        f += s[i + 1]

    if ans == 7:
        print(f + '=7')
        break
def calc(i, j, B1, len_b):
    extra = 0
    d = j - i

    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]

    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]

    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra

def main():
    N = int(input())
    S = input()
    R, G, B = [], [], []
    num_r, num_g, num_b = 0, 0, 0
    for i in range(N):
        s = S[i]
        if s == 'R':
            R.append(i)
            num_r += 1
        elif s == 'G':
            G.append(i)
            num_g += 1
        elif s == 'B':
            B.append(i)
            num_b += 1
    len_b = (B[-1] + 1)
    B1 = [0]*len_b
    for b in B:
        B1[b] = 1
    # print(R, G, B)
    ans = 0
    for i in R:
        for j in G:
            ans += num_b
            if i < j:
                ans -= calc(i, j, B1, len_b)
            else:
                ans -= calc(j, i, B1, len_b)
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def calc(i, j, B1, len_b):
    extra = 0
    d = j - i

    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]

    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]

    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra

def main():
    N = int(input())
    S = input()
    R, G, B = [], [], []
    num_r, num_g, num_b = 0, 0, 0
    for i in range(N):
        s = S[i]
        if s == 'R':
            R.append(i)
            num_r += 1
        elif s == 'G':
            G.append(i)
            num_g += 1
        elif s == 'B':
            B.append(i)
            num_b += 1
    if len(R) == 0 or len(G) == 0 or len(B) == 0:
        print(0)
        return
    len_b = (B[-1] + 1)
    B1 = [0]*len_b
    for b in B:
        B1[b] = 1
    # print(R, G, B)
    ans = 0
    for i in R:
        for j in G:
            ans += num_b
            if i < j:
                ans -= calc(i, j, B1, len_b)
            else:
                ans -= calc(j, i, B1, len_b)
    print(ans)

if __name__ == '__main__':
    main()
A = int(input()) #ここで標準入力
B = int(input()) #ここで標準入力

C = A/B + 1

print(C)

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]

# 整数複数個
A, B = map(int, input().split())

C = -((-B+1) // (A-1))
print(C)
# coding: utf-8
# Here your code !
 
x=input()
a=int(x.split(" ")[0])
b=int(x.split(" ")[1])
y=input()
c=y.split(" ")
c=sorted(c,reverse=True)
sum = 0
for i in range(b):
    sum += int(c[i])
print (sum)

### FIXED CODE ###

# coding: utf-8
# Here your code !
 
x=input()
a=int(x.split(" ")[0])
b=int(x.split(" ")[1])
if (a%3==0 or b%3==0 or (a+b)%3==0):
    print ("Possible")
else:
    print ("Impossible")
import sympy
import math
n = int(input())
s = 0
l  = sympy.factorint(n)
l2 = list(dict.values(l))
for i in range(len(l2)):
    s += int((math.sqrt(1 + 9 * l2[i])-1)/2)

print(s)


### FIXED CODE ###

import math
import collections

n = int(input())
s = 0
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

m = 0
l = collections.Counter(prime_factorize(n))
l2 = list(dict.values(l))
#for i in range(len(l2)):
#    s += int((math.sqrt(1 + 9 * l2[i])-1)/2)
for i in range(len(l2)):
    for j in range(n):
        if l2[i] >= j*(j+1)/2:
            m = j
        else:
            break


    s += m


print(s)
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,M = inpl()
H = 2**N-1
W = 2**M-1

ans = [[0] * W for _ in range(H)]
# for i in range(W):
    # for j in range(H):
        # ans[j][i] =

ans[0][0] = 1
ans[0][W-1] = 1
ans[H-1][0] = 1
ans[H-1][W-1] = 1
# ans[H//2][W//2] = 1
# ans[0][W//2] = 1
# ans[H-1][W//2] = 1
# ans[H//2][0] = 1
# ans[H//2][W-1] = 1

for a in ans:
    print("".join(map(str,a)))


### FIXED CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

S = input()
S = S.replace("hi", "")

if S == "":
    print("Yes")
else:
    print("No")
l = input.split()
if l.count('5')==2 and '7' in l:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

l = input().split()
if l.count('5')==2 and '7' in l:
  print('YES')
else:
  print('NO')
from collections import deque

N, M = map(int, input().split())
con = [[] for _ in range(M)]
for i in range(M):
    A, B = map(int, input().split())
    con[A-1].append(B-1)
    con[B-1].append(A-1)
    
d = deque()
houmon = [False] * N
ans = [0] * (N-1)

houmon[0] = True
d.append(0)
while d:
#     print(d, houmon, ans)
    room = d.popleft()
#     houmon[room] = True
#     print(room)
    
    for next_room in con[room]:
        if not houmon[next_room]:
            ans[next_room-1] = room+1
            d.append(next_room)
            houmon[next_room] = True
    
print('Yes\n' + '\n'.join(map(str, ans)))

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
con = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    con[A-1].append(B-1)
    con[B-1].append(A-1)
    
d = deque()
houmon = [False] * N
ans = [0] * (N-1)

houmon[0] = True
d.append(0)
while d:
#     print(d, houmon, ans)
    room = d.popleft()
#     houmon[room] = True
#     print(room)
    
    for next_room in con[room]:
        if not houmon[next_room]:
            ans[next_room-1] = room+1
            d.append(next_room)
            houmon[next_room] = True
    
print('Yes\n' + '\n'.join(map(str, ans)))
import sys
input = sys.stdin.readline

N,Q = map(int,input().split())
aLst = [[int(i) for i in input().split()] for _ in range(N-1)]
pLst = [[int(i) for i in input().split()] for _ in range(Q)]
to = [[]for _ in range(N+1)]

for a,b in aLst:
    to[a].append(b)
    to[b].append(a)

ps = [0]*(N+1)
for a,b in pLst:
    ps[a] += b

def dfs(v, i):
    for j in to[v]:
        if i == j:
            continue
        ps[j] += ps[v]
        dfs(j,v)

dfs(1,0)
print(' '.join(map(str, ps[1:])))


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
aLst = [[int(x) for x in input().split()] for _ in range(N-1)]
pLst = [[int(x) for x in input().split()] for _ in range(Q)]

tmpLst = [[] for _ in range(N+1)]
for i, j in aLst:
    tmpLst[i].append(j)
    tmpLst[j].append(i)

ansLst = [0] * (N + 1)
for i,j in pLst:
    ansLst[i] += j

def dfs(v, p):
    for i in tmpLst[v]:
        if i == p:
            continue
        ansLst[i] += ansLst[v]
        dfs(i, v)


dfs(1, 0)

ans = ' '.join(map(str, ansLst[1:]))
print(ans)
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
 
M = max(a,b)  
m = min(a,b)  
  
if (v-w)*t > M - n:
	print('YES')
else:
	print('NO')


### FIXED CODE ###

a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
gap=abs(a-b) 
if v>w:
  c=gap/(v-w)
  if t>=c:
    print('YES')
  else:
    print('NO')
else:
  print('NO')
def yakusu(x):
    A=[]
    for i in range(1,x+1):
        if x%i==0:
            A.append()
    return(len(A))
    
n=int(input())

print(yakusu(n))

### FIXED CODE ###

def yakusu(x):
    A=[]
    for i in range(1,x+1):
        if x%i==0:
            A.append(i)
    return(len(A))
    
n=int(input())
ans=0

for j in range(1,n+1,2):
    if yakusu(j)==8:
        ans+=1
print(ans)
S = input()
d1 = ""
d2 = ""
res = 0
for i in range(len(S)):
  d1 += s[i]
  if d1 != d2:
    d2 = d1
    d1 = ""
    res += 1
print(res)

### FIXED CODE ###

S = input()
d1 = ""
d2 = ""
res = 0
for i in range(len(S)):
  d1 += S[i]
  if d1 != d2:
    d2 = d1
    d1 = ""
    res += 1
print(res)
from math import gcd
A,B,K=map(int,input().split())
C=gcd(A,B)
count=0
for x in range(C,-1,-1):
    if C%x==0:
        count+=1
        if count==K:
            print(x)
            break
exit()

### FIXED CODE ###

import fractions
A,B,K=map(int,input().split())
C=fractions.gcd(A,B)
cnt=0
for x in range(C,0,-1):
    if C%x==0:
        cnt+=1
        if cnt==K:
            print(x)
            break