Harryxun/stf_run huggingface dataset:
n, b=list(map(int,input().split()))

import math

#x=int(min(n-b+1,b))

#for i in range(1,x+1):
for i in range(1,b+1):
	if i-1 > n-b:
		# 境界を i-1 個作らなければならないが、赤いボールの数 n-k よりもこれが多いと条件を満たす置き方は存在しない
		print(0)
 	#if n-b+1<i or b-1<i-1:
		#break
	else:
		y=math.factorial(n-b+1)/math.factorial(n-b+1-i)/math.factorial(i)
		z=math.factorial(b-1)/math.factorial(b-i)/math.factorial(i-1)
		res=int(y*z%(1000000000+7))
		print(res)

### FIXED CODE ###

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

import math

#x=int(min(n-b+1,b))

#if n==b:
#  print('1')
#  for i in range(b-1):
#    print('0')
#else:
#for i in range(1,x+1):
for i in range(1,b+1):
	if i-1 > n-b:
	# 境界を i-1 個作らなければならないが、赤いボールの数 n-k よりもこれが多いと条件を満たす置き方は存在しない
		print(0)
 	#if n-b+1<i or b-1<i-1:
		#break
	else:
		y=math.factorial(n-b+1)//(math.factorial(n-b+1-i)*math.factorial(i))
		z=math.factorial(b-1)//(math.factorial(b-i)*math.factorial(i-1))
		res=int(y*z%(1000000000+7))
		print(res)


#from math import factorial
 
#N, K= map(int, input().split())
 
#def ncr(n, r):
#    return factorial(n) // (factorial(r) * factorial(n - r)) 
 
#for i in range(1, K+1):
#    if i <= N-K+1:
#        print(ncr(K-1, i-1) * ncr(N-K+1, i) % (10**9 + 7))
#    else:
#        print(0)
n, k = map(int, input().split())

li = [0]
li.extend(list(map(int, input().split())))
tuita = [0]*(n+1)
cnt = 0
town = 1

def search(town, times):
  if times == 0:
    return town
  return search(li[town], times - 1)

lastTown = 1
while True:
  town = li[town]
  cnt += 1
  if tuita[town] == 0:
    tuita[town] = cnt
  else:
    if k < tuita[town]:
      lastTown = 1
      times = k
    elif k == tuita[town]:
      print(town)
      lastTown = 1
      times = 0
    else:
      lastTown = town
      times = (k - tuita[town]) % (cnt - tuita[town])
    break

ans = search(lastTown, times)
print(ans)
 

### FIXED CODE ###

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

li = [0]
li.extend(list(map(int, input().split())))
tuita = [0]*(n+1)
cnt = 0
town = 1

lastTown = 1
while True:
  town = li[town]
  cnt += 1
  if tuita[town] == 0:
    tuita[town] = cnt
  else:
    if k < tuita[town]:
      lastTown = 1
      times = k
    elif k == tuita[town]:
      lastTown = town
      times = 0
    else:
      lastTown = town
      times = (k - tuita[town]) % (cnt - tuita[town])
    break

town = lastTown
while times > 0:
  if times <= 0:
    break
  times -= 1
  town = li[town]
print(town)
n=int(input())
t ,a=list(map(int, input().split()))
h = list(map(int,input().split(' ')))

min=100000000000000
min_index=n+1
for i in range(n):
  v = abs(t - h[i]*0.006)
  if v < min:
    min=v
    min_index=i
print(min_index+1)


### FIXED CODE ###

n = int(input())
cards = (list)(map(int, input().split()))

cards = sorted(cards, reverse=True)

print(2*sum(cards[0::2]) - sum(cards))
def should_buy_ab(a,b,c):
    return 2 * c <= a + b


def solve(a,b,c,x,y):
    paid = 0

    if should_buy_ab(a,b,c):
        common = min(x, y)
        paid += (common * 2 * c)
        x -= common
        y -= common

        if x > 0:
            return paid + x * min(a, 2 * c)
        else:
            assert y > 0
            return paid + y * min(b, 2 * c)

    paid += x * a
    paid += y * b

    return paid


a, b, c, x, y = map(int, raw_input().split())
print solve(a,b,c,x,y)

### FIXED CODE ###

def should_buy_ab(a,b,c):
    return 2 * c <= a + b


def solve(a,b,c,x,y):
    paid = 0

    if should_buy_ab(a,b,c):
        common = min(x, y)
        paid += (common * 2 * c)
        x -= common
        y -= common

        if x > 0:
            return paid + x * min(a, 2 * c)
        else:
            assert y >= 0
            return paid + y * min(b, 2 * c)

    paid += x * a
    paid += y * b

    return paid


a, b, c, x, y = map(int, raw_input().split())
print solve(a,b,c,x,y)
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list != []):
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)

### FIXED CODE ###

x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False
  
if(n==1):
  if(x==p[0]):
    ans = x-1
    judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list == []):
      ans = max(s_list)
    if(s_list == []):
      ans = min(l_list)
    else:
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)
import bisect
H,N = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
dp = [[10**18]*(10**4+1) for _ in range(N+1)]
for i in range(N+1):
  dp[i][0]=0
mi=10**9
for i in range(N):
  for w in range(10**4+1):
    dp[i+1][w]=min(dp[i+1][w],dp[i][w])
    if w-AB[i][0]>=0:
      dp[i+1][w]=min(dp[i+1][w],dp[i + 1][w - AB[i][0]] + AB[i][1])
for i in range(H,10**4+1):
  mi = min(mi,dp[N][i])
print(mi)

### FIXED CODE ###

N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
d = [0]*(N+1)
for l in range(N):
  if d[l]<xh[l][1]:
    la = (xh[l][1]-d[l]+A-1)//A
    for _ in range(N):
      if l<N and r<N and 2*D>=xh[r][0]-xh[l][0]:
        r+=1
      else:
        break
    ans += la
    d[l]+=la*A
    d[r]-=la*A
  d[l+1]+=d[l]
print(ans)
s = str(input())
w = list(map(int, input().split()))
f = "".join(w[0:2])
b = "".join(w[2:4])
if 1 <= int(f) <= 12 and  1 <= int(b) <= 12:
    print("AMBIGUOUS")
elif 1 <= int(b) <= 12 and not  1 <= int(f) <= 12:
    print("YYMM")
elif 1 <= int(f) <= 12 and not  1 <= int(b) <= 12:
    print("MMYY")
else:
    print("NA")

### FIXED CODE ###

s = int(input())
f = s // 100
b = s % 100
if 1 <= f <= 12 and  1 <= b <= 12:
    print("AMBIGUOUS")
elif 1 <= b <= 12 and not  1 <= f <= 12:
    print("YYMM")
elif 1 <= f <= 12 and not  1 <= b <= 12:
    print("MMYY")
else:
    print("NA")
#19 Grid Coloring
h,w=map(int,input().split() )
n=int(input())
a=list(map(int,input().split()))

import numpy as np

lis=[]
for i in range(n):
    lis.extend([i+1]*a[i])

lis = np.array(lis).reshape((h,w))

for i in range(1,h,2):
    lis[i] = lis[i][::-1]

for i in range(h):
    print(*lis[i])

### FIXED CODE ###

#19 Grid Coloring
h,w=map(int,input().split() )
n=int(input())
a=list(map(int,input().split()))


import numpy as np

lis=[]
for i in range(n):
    lis.extend([i+1]*a[i])

lis = np.array(lis).reshape((h,w))

for i in range(1,h,2):
    lis[i] = lis[i][::-1]

for i in range(h):
    print(*lis[i])
ans=1
N=int(input())
for i in range(N-1):
	for j in range(N-1):
    	cnt=i+j
        if cnt=N:
        	ans+=1
print(ans)

### FIXED CODE ###

N=int(input())
c=-(-N//2)-1
print(c)
n = int(input())
a = [i for i in map(int,input().split())]
Check = Fasle
check_list=[]
for s in range(n):
  if a[s]%2 == 0:
    check_list.append(a[s])
for t in range(len(check_list)):
  if check_list[t]%3 == 0 or check_list[t]%5==0:
    Check =True
if Check:
  print('APPROVED')
else:
  print('DENIED')

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans=0
ans2=0
for i in a:
  if i % 2 == 0:
    ans +=1
    if i % 3 == 0 or i % 5 == 0:
      ans2 +=1
if ans == ans2:
  print('APPROVED')
else:
  print('DENIED')
a,b = map(int,input().split())
ans =0

for i in range(10000,-1,-1):
  tax1 = int(i*0.08)
  tax2 = int(i*0.1)
  if tax1 = a and tax2 == b:
    ans = i
print(ans)

### FIXED CODE ###

a,b = map(int,input().split())
ans = -1 
  
for i in range(10000,-1,-1):
  tax1 = int(i*0.08)
  tax2 = int(i*0.1)
  if tax1 == a and tax2 == b:
    ans = i
print(ans)
from collections import deque
N, M = map(int, input().split())
edges = [[] for i in range(N)]
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    AB.append((a, b))
def BFS(s):
    prev = [-1]*N
    que = deque([s])
    while que:
        v = que.pop()
        for nv in edges[v]:
            if nv == s:
                prev[nv] = v
                return (s, prev)
            if prev[nv]<0:
                que.append(nv)
                prev[nv] = v
    return (-1, prev)
for v in range(N):
    v0, prev = BFS(v)
    if v0>=0:
        break
if v0<0:
    print(-1)
    exit()
circle = set()
circle.add(v0)
pv = prev[v0]
while pv != v0:
    circle.add(pv)
    pv = prev[pv]
for a, b in AB:
    if a in circle and b in circle:
        pv = prev[b]
        while pv != a:
            circle.remove(pv)
            pv = prev[pv]
print(len(circle))
for i in circle:
    print(i+1)

### FIXED CODE ###

import sys
from collections import deque
N, M = map(int, input().split())
edges = [[] for i in range(N)]
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    AB.append((a-1, b-1))
def BFS(s):
    prev = [-1]*N
    que = deque([s])
    while que:
        v = que.pop()
        for nv in edges[v]:
            if nv == s:
                prev[nv] = v
                return (s, prev)
            if prev[nv]<0:
                que.append(nv)
                prev[nv] = v
    return (-1, prev)
for v in range(N):
    v0, prev = BFS(v)
    if v0>=0:
        break
if v0<0:
    print(-1)
    sys.exit()
circle = set()
circle.add(v0)
pv = prev[v0]
while pv != v0:
    circle.add(pv)
    pv = prev[pv]
for a, b in AB:
    if a in circle and b in circle and prev[b] != a:
        pv = prev[b]
        while pv != a:
            circle.remove(pv)
            pv = prev[pv]
        prev[b] = a
print(len(circle))
for i in circle:
    print(i+1)
a=input()
for i in range(len(a)):
	if a[i]=='+':
		a1=int(a[:i])
		a2=int(a[i+1:])
		print(a1+a2)
	elif a[i]=='-':
		a1=int(a[:i])
		a2=int(a[i+1:])
		print(a1-a2)

		


### FIXED CODE ###

a=input()
for i in range(len(a)):
	if a[i]=='+':
		a1=int(a[:i])
		a2=int(a[i+1:])
		print(a1+a2)
	elif a[i]=='-':
		a1=int(a[:i])
		a2=int(a[i+1:])
		print(a1-a2)
from collections import deque
import math
import copy

h,w = map(int, input().split())
maze = [list(map(str,input())) for _ in range(h)]


ans = 0

for i in range(w):
     for j in range(h):
          for k in range(w):
               for l in range(h):

                    maze2 = copy.deepcopy(maze)

                    if maze[j][i] == '#' or maze[l][k] == '#':
                         pass
                    else:
                         sx,sy,gx,gy = i,j,k,l
                         for y in range(h):
                              for x in range(w):
                                   if maze[y][x] == '.':
                                        maze2[y][x] = math.inf


                         maze2[sy][sx]=0
                         que=deque([[sy,sx]])
                         while que:
                              y,x=que.popleft()
                              for m,n in [(1,0),(0,1),(-1,0),(0,-1)]:
                                   nexty,nextx=y+m,x+n
                                   if  nexty in range(h) and nextx in range(w):
                                        dist=maze2[nexty][nextx]
                                        if dist!='#':
                                             if dist>maze2[y][x]+1:
                                                  maze2[nexty][nextx]=maze2[y][x]+1
                                                  que.append([nexty,nextx])
                         if ans < maze2[gy][gx]:
                              ans = maze2[gy][gx]

print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
s = [0] * h
for i in range(h):
    s[i] = str(input())

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(w*h):
        for i in range(w*h):
            for j in range(w*h):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


d = [[float("inf")] * (h * w) for i in range((h * w))]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            a = i * w + j
            d[a][a] = 0
            for m, n in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                ss = i + m
                t = j + n
                if 0 <= ss <= h-1 and 0 <= t <= w-1 and s[ss][t] == '.':
                    b = ss * w + t
                    d[a][b] = 1
                    d[b][a] = 1
     #自身のところに行くコストは０
ans = 0
box = warshall_floyd(d)
for i in range(h * w):
    for j in range(h*w):
        if box[j][i] > 1000000:
            box[j][i] = 0
        ans = max(ans,box[j][i])

print(ans)
print('YNeos'[len(set(input()))!=2::2]

### FIXED CODE ###

print('YNeos'[len(set(input()))!=2::2])
permutations = list(itertools.permutations(range(1, N+1)))
p = permutations.index(P)
q = permutations.index(Q)

### FIXED CODE ###

import itertools
N = int(input())
LN = []
for i in range(N):
  LN.append(i+1)
LLN=list(itertools.permutations(LN))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
print(abs(LLN.index(tuple(P))-LLN.index(tuple(Q))))
n,a,b = map(int,input().split())
i = 1
p = 0
if (b-a)%2==0:
    print((b-a)//2)
else:
    print(min(b-1,n-a,round((a-1+b-(a-1))/2),round((n-b+a+(n-b))/2)))

### FIXED CODE ###

n,a,b = map(int,input().split())
i = 1
p = 0
if (b-a)%2==0:
    print((b-a)//2)
else:
    if a-1 < n-b:
        print(min((1+b+(a-2))//2,b-1))
    else:
        print(min((n-a+(n-b+1))//2,n-a))
h,n = map(int,input().split())
a = sum(map(int,input().split()))
print(["Yes","No"][h>a])

### FIXED CODE ###

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

if h % a == 0:
    print(h//a)
else:
    print(h//a+1)
new_str = ""
num = int(input())
string = input().split(" ")
for i in range(0,num):
    new_str += string[0][i] + string[i][0]
print("".join(new_str))

### FIXED CODE ###

new_str = ""
num = int(input())
string = input().split(" ")
for i in range(0,num):
    new_str += string[0][i] + string[1][i]
print(new_str)
s=list(input())
if 'R' in s:
  if s.count('R')==3:
    print(3)
  if s[0]==s[1]=='R' and s[2]==s[1]=='R':
    print(2)
  else:
    print(1)]
else:
  print(0)

### FIXED CODE ###

s=list(input())
if 'R' in s:
  if s.count('R')==3:
    print(3)
  elif s[0]==s[1]=='R' or s[2]==s[1]=='R':
    print(2)
  else:
    print(1)
else:
  print(0)
N = input()
 
p = 3.141592653589
 
S = N**2*p
R = 2*pi*N
 
print(S, R)

### FIXED CODE ###

import math

r = float(input())

s = r*r*math.pi
v = 2*math.pi*r

S = round(s, 6)
V = round(v, 6)

print(S, V)
N, K = map(int, input().split())
lst = list(map(int, input().split()))
ans = 0
for l in range(K+1):
    for r in range(K+1-l):
        if l + r > N:
            break
        get = lst[:l]
        get.extend(lst[N-r:])
        cnt = sum(get)
        get.sort()
        for i in range(min(K-l-r, l+r)):
            if get[i] >= 0:
                break
            tmp -= get[i]
        ans = max(ans, tmp)
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
lst = list(map(int, input().split()))
ans = 0
for l in range(K+1):
    for r in range(K+1-l):
        if l + r > N:
            break
        get = lst[:l]
        get.extend(lst[N-r:])
        cnt = sum(get)
        get.sort()
        for i in range(min(K-l-r, l+r)):
            if get[i] >= 0:
                break
            cnt -= get[i]
        ans = max(ans, cnt)
print(ans)
n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  for j in range(k):
#    v = str[2+j]
#    c = str[3+j]
    M[u][str[2+j]] = str[3+j]
d = [inf for i in range(n)]
color = [0 for i in range(n)]

d[0] = 0
color[0] = 1

while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
    print minv
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])

### FIXED CODE ###

n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  for j in range(k):
    v = str[2+2*j]
    c = str[3+2*j]
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]
 
d[0] = 0
color[0] = 1
 
while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])
A,B,C,D = list(map(int,input().split()))


if A < C:
  a = C
else:
  a = A

if B < D:
  b = B
else:
  b = D
  
if B =< C or D =< A:
  res = 0
else:
  res = (b-a)
  
print(res)



### FIXED CODE ###

A,B,C,D = list(map(int,input().split()))


if A < C:
  a = C
else:
  a = A

if B < D:
  b = B
else:
  b = D
  
if B <= C or D <= A:
  res = 0
else:
  res = (b-a)
  
print(res)
from collections import deque   ##deque 라는 데이터형 편리한듯. print도그렇고 append,pop속도도 빠르고
n = int(input())
xdeque = deque()
for i in range(n):
    command = list(map(str,input().split()))
    if (command[0] == 'insert'):
        x = command[1]
        xdeque.appendleft(int(x))
    elif (command[0] == 'delete'):
        x = command[1]
        try:
            d.remove(int(x))
        except ValueError:
            pass
    elif (command[0] == 'deleteFirst'):
        xdeque.popleft()
    else:
        xdeque.pop()
print(*xdeque)




### FIXED CODE ###

from collections import deque
n = int(input())
a = deque()
for i in range(n):
    c = input()
    if c == "deleteFirst":
        a.popleft()
    elif c == "deleteLast":
        a.pop()
    else:
        c, v = c.split()
        if c == "insert":
            a.appendleft(v)
        else:
            try:
                a.remove(v)
            except:
                pass
print(" ".join(a))
N = int(input())
A = list(map(int, input().split()))
ans = 0
A = sorted(A)
if N == 0:
  ans = 0
else:
  for i in range(len(A)-1,-1,-1):
    for j in range(0,i+1,1):
      if i==j:
        ans+=1
        if i==0 and A[0]==A[1]:
          ans-=1
        break
      if A[i]%A[j]==0:
        break
      if A[i]<A[j]*2:
        ans+=1
        break

print(ans)

### FIXED CODE ###

X, N = map(int, input().split())
if N!=0:
  p = list(map(int, input().split()))
else:
  p =[]

p = set(p)
i=0
while i<101:
  n = X-i
  if not(n in p):
    ans = n
    break
  n = X+i
  if not(n in p):
    ans = n
    break
  i+=1

print(ans)
a,b=int(input().split())
if a < 10:
  print(b)
else:
  print(b+1000-100*a)

### FIXED CODE ###

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

if a >=10:
  c=int(b)
  print(c)
else:
  c=int(b+1000-100*a)
  print(c)
func chatInACircle(a []int) int {
	sort.Slice(a, func(i, j int) bool {
		return a[i] > a[j]
	})
	if len(a) == 2 {
		return a[0]
	}

	m := a[0]
	a = a[1:]

	for i := 0; i < len(a) - 1; i++ {
		m += a[i/2]
	}

	return m
}

### FIXED CODE ###

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

a=sorted(a,reverse=True)
if n==2:
    print(max(a))
    exit(0)

ans=a[0]
a=a[1:]
from math import floor

for i in range(n-2):
    index=floor(i/2)
    ans+=a[index]

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

box = []
for i in range(N):
    d = abs(A[i-1]-A[i])
    if d>K/2:
        d = K - d
    box.append(d)
print(K-max(d))

### FIXED CODE ###

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

box = []
for i in range(N):
    d = abs(A[i-1]-A[i])
    if d>K/2:
        d = K - d
    box.append(d)
print(K-max(box))
n,q = map(int,input().split())
to = [[] for _ in range(n)]
ans = [0]*n

def dfs(v,p):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u,v)

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

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

dfs(0,-1)
for a in ans: print(a)

### FIXED CODE ###

from collections import deque
n,q = map(int,input().split())
to = [[] for _ in range(n)]
ans = [0]*n

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

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

stack = deque()
stack.append((0,0))
while len(stack) != 0:
    cn,pn = stack.pop()
    for nn in to[cn]:
        if nn == pn:
            continue
        ans[nn] += ans[cn]
        stack.append((nn,cn))

print(*ans)
import numpy as np

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

dp = np.zeros(W+1, dtype=int)

for i in range(N):
    w, v = map(int, input().split())
    dp[w:] = max(dp[:-w] + v, dp[w:])

print(dp[-1])

### FIXED CODE ###

import numpy as np

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

dp = [float("INF")]*(N*10**3 + 1)
dp = np.array(dp)
dp[0] = 0

for i in range(N):
    w, v = map(int, input().split())
    dp[v:] = np.minimum(dp[:-v] + w, dp[v:])

print(np.max(np.where(dp <= W)))
N = int(input())
rice_cakes = [int(input()) for _ in range(N)]
print(len(set(rice_cakes))
  

### FIXED CODE ###

N = int(input())
rice_cakes = [int(input()) for _ in range(N)]
print(len(set(rice_cakes)))
N=int(N)
S=[input() for i in range(N)]

A=S.count('AC')
B=S.count('WA')
C=S.count('TLE')
D=S.count('RE')

print('AC x'+ A)
print('WA x'+ B)
print('TLE x'+ C)
print('RE x'+ D)

### FIXED CODE ###

N=int(input())
S=[input() for i in range(N)]

A=S.count('AC')
B=S.count('WA')
C=S.count('TLE')
D=S.count('RE')

print('AC x',A)
print('WA x',B)
print('TLE x',C)
print('RE x',D)
from collections import Counter
n = int(input())
a = list(map(int.input().split()))
c = Counter(a)

if c.most_common()[0][1] == 1:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)

if c.most_common()[0][1] == 1:
    print("YES")
else:
    print("NO")
D, N = map(int, input().split())
if (A < 9) and (B < 9):
    print("Yay!")
else:
    print(":(")


### FIXED CODE ###

A, B = map(int, input().split())
if (A < 9) and (B < 9):
    print("Yay!")
else:
    print(":(")
x=int(input())
a=[]
ans=0

for i in range(1,32):
            for j in range(2,10):
                        ans=i**j
                        if ans<x:
                                    a.append(ans)   
                                    i+=1
                        else:
                                    break
                        
            #print(a)
print(max(a))
"""
while ans<x:
"""
            
         
                   



### FIXED CODE ###


x=int(input())
a=[]
ans=0

for i in range(1,32):
            for j in range(2,10):
                        ans=i**j
                        if ans<=x:
                                    a.append(ans)   
                                    #i+=1
                        else:
                                    break
                        
            #print(a)
print(max(a))
"""
while ans<x:
"""