Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
n,x,y=map(int,input().split())
array=[]
array=np.array(array)
for i in range(1,n):
    for j in range(i+1,n+1):
        array=np.append(array,(min(abs(j-i),abs(x-j)+1+abs(y-i),abs(y-j)+1+abs(x-i))))
#array=np.array(array)
for i in range(1,n):
    print(np.sum(array==i))

### FIXED CODE ###

n,x,y=map(int,input().split())
#array=[0 for i in range(n)]
array=[None]*n
for i in range(n):
    array[i]=0
for i in range(1,n):
    for j in range(i+1,n+1):
        res=min(abs(j-i),abs(x-j)+1+abs(y-i),abs(y-j)+1+abs(x-i))
        array[res]+=1
for i in range(1,n):
    print(array[i])
### BUGGY CODE ###

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

def divide(num):
  rest = num
  sum = 0
  while rest > 0:
    num /= 10
    rest %= 10
    sum += rest
  return sum

for i in range(n):
  temp = divide(i+1)
  ans = 0
  if temp>= a and temp <= b:
    ans += temp
print(ans)

### FIXED CODE ###

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

def divide(num):
  sum = 0
  while num > 0:
    sum += num % 10
    num //= 10
  return sum

ans = 0
for i in range(n):
  temp = divide(i+1)
  if temp>= a and temp <= b:
    ans += (i+1)
print(ans)
### BUGGY CODE ###

#TLE

#half_expo(a, n, mod) = (a**n) % mod
#二分累乗法
def half_expo_mod(a, n, mod):
    nbin = list(bin(n))
    nbin = nbin[3:]
    ans = a
    for j in nbin:
        if j == '0':
            ans **= 2
        else:
            ans = (ans ** 2) * a
        ans %= mod
    return ans

#comb_mod(n, r, mod) = nCr % mod
def comb_mod(n, r, mod):
    ans = 1
    if r <= n/2:
        for i in range(n-r+1, n+1):
            ans *= i
            ans %= mod
        for i in range(1, r+1):
            ans *= half_expo_mod(i, mod-2, mod)
            ans %= mod
    else:
        for i in range(r+1, n+1):
            ans *= i
            ans %= mod
        for i in range(1, n-r+1):
            ans *= half_expo_mod(i, mod-2, mod)
            ans %= mod
    return ans

n, a, b = map(int, input().split())
ans = half_expo_mod(2, n, 10**9+7) - comb_mod(n, a, 10**9+7) - comb_mod(n, b, 10**9+7) - 1
if ans < 0:
    ans += 10**9 + 7
if ans < 0:
    ans += 10**9 + 7

print(int(ans))

### FIXED CODE ###

#TLE

#comb_mod(n, r, mod) = nCr % mod
def comb_mod(n, r, mod):
    ans = 1
    if r <= n/2:
        for i in range(n-r+1, n+1):
            ans *= i
            ans %= mod
        for i in range(1, r+1):
            ans *= pow(i, mod-2, mod)
            ans %= mod
    else:
        for i in range(r+1, n+1):
            ans *= i
            ans %= mod
        for i in range(1, n-r+1):
            ans *= pow(i, mod-2, mod)
            ans %= mod
    return ans

n, a, b = map(int, input().split())
ans = pow(2, n, 10**9+7) - comb_mod(n, a, 10**9+7) - comb_mod(n, b, 10**9+7) - 1
if ans < 0:
    ans += 10**9 + 7
if ans < 0:
    ans += 10**9 + 7

print(int(ans))
### BUGGY CODE ###

import numpy as np


def solve(N, D):
    ans = 0
    for i in range(1 << N):
        clocks = np.zeros((N + 2), dtype=np.int8)
        clocks[-1] = 24
        for j in range(N):
            if i >> j & 1:
                clocks[j + 1] = D[j]
            else:
                clocks[j + 1] = 24 - D[j]
        clocks.sort()
        ans = max(ans, np.min(np.diff(clocks)))
    return ans


N = int(input())
D = np.array(input().split(), dtype=np.int8)
if N >= 24:
    print(0)
else:
    print(solve(N, D))


### FIXED CODE ###

from collections import Counter
from itertools import product


N = int(input())
D = list(map(int, input().split()))
D_cnt = Counter(D)
if N >= 24 or D_cnt[0] > 0 or D_cnt[12] > 1 or any(D_cnt[i] > 2 for i in range(1, 12)):
    print(0)
    exit()
clock = [0, 24]
undet = []
if 12 in D_cnt:
    clock.append(12)
for i in range(1, 12):
    if D_cnt[i] == 2:
        clock.append(i)
        clock.append(24 - i)
    elif D_cnt[i] == 1:
        undet.append(i)

ans = 0
for rp in product([0, 1], repeat=len(undet)):
    candidate = clock[:]
    for j, is_flipped in enumerate(rp):
        candidate.append(undet[j]) if is_flipped else candidate.append(24 - undet[j])
    candidate.sort()
    ans = max(ans, min(ca - cb for cb, ca in zip(candidate, candidate[1:])))
print(ans)
### BUGGY CODE ###

x = int(input())
#素数の列を、つ、つくるわよ
prime_list = [2]
for num in range(3, x + 1, 2):
  if all(num % prime != 0 for prime in prime_list):
    prime_list.append(num)

#xが素数である場合
if x == prime_list[-1]:
  print(x)
  exit()

#素数は奇数だけ
if x % 2 == 0:
  p = 1
else:
  p = 0
  
#xから、x未満の最大の素数ｘ２の範囲について調べるわ
#素数ｎ<素数ｍ<素数２ｎは常識？
for i in range(x - p, prime_list[-1] * 2 + 1, 2):
  if all(i % j != 0 for j in prime_list):
    print(i)
    exit()

### FIXED CODE ###

#pypyなら通るとか、そんなことないですよね？大人げなく泣き叫びますけど。
x = int(input())
#素数の列を、つくるわよ
prime_list = [2]
for num in range(3, x + 1, 2):
  if all(num % prime != 0 for prime in prime_list):
    prime_list.append(num)

#２は特殊な例よね
if x == prime_list[-1]:
  print(x)
  exit()

#素数は奇数だけ
if x % 2 == 0:
  p = 1
else:
  p = 0
  
#xから、x未満の最大の素数ｘ２の範囲について調べるわ
#素数ｎ<素数ｍ<素数２ｎは常識？
for i in range(x + p, prime_list[-1] * 2 + 1, 2):
  if all(i % j != 0 for j in prime_list):
    print(i)
    exit()
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
ans = 10**10
deck = sum(a)
for i in range(1,N):
    su = sum(a[:i])
    ar = deck - su
    ans = min(ans, abs(su-ar))
print(ans)

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
ans = 10**10
deck = sum(a)
su = 0
for i in range(0,N-1):
    su = su + a[i]
    ar = deck - su
    ans = min(ans, abs(su-ar))
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
# import sympy
from collections import defaultdict, Counter
# def factors(N): #約数を全て求める。ただし、順不同
#     from collections import deque
#     ret = deque()
#     middle = int( N**(1/2))
#     for i in range(1, middle):
#         if N%i == 0:
#             ret.append(i)
#             ret.append(N//i)
            
#     if N%middle == 0:
#         ret.append(middle)
#         if middle != N//middle:
#             ret.append(N//middle)
#     return ret

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

    # divisors.sort()
    return divisors


def main():
    N = int( input())
    A = list( map( int, input().split()))
    CA = Counter(A)
    d = defaultdict( lambda : False)
    for a in A:
        d[a] = True
    ans = 0
    for a in A:
        if CA[a] > 1:
            continue
        for p in make_divisors(a):
            if p == a:
                continue
            if d[p]:
                break
        else:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import Counter, defaultdict
def main():
    N = int( input())
    A = list( map( int, input().split()))
    CA = Counter(A)
    d = defaultdict( lambda : False)
    T = [False]*(10**6+1)
    A.sort()
    Z = [False]*(10**6+1)
    ans = 0
    for a in A:
        if CA[a] == 1 and not T[a]:
            ans += 1
        if not Z[a]:
            Z[a] = True
            for i in range(1, 10**6+1):
                if i*a > 10**6:
                    break
                T[i*a] = True
    print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import bisect
A,B,C =map(int,input().split())
s =[-10**11] + [int(input())for _ in range(A)] +[10**11]
t =[-10**11] + [int(input())for _ in range(B)] +[10**11]

for _ in range(C):
    x =int(input())
    ns = bisect.bisect_left(s,x)
    nt = bisect.bisect_left(t,x)
    sx =[s[ns-1],s[ns]]
    tx =[t[nt-1],t[nt]]
    lis =[sx,tx]
    ans = 10**11
    for i in range(8):
        p =i%2
        q =(i//2)%2
        r =i//4
        foo =abs(x-lis[p][q])+abs(lis[p][q]-lis[p-1][r])
        if foo < ans:
            ans = foo
    print(ans)

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline
A,B,C =map(int,input().split())
s =[-10**11] + [int(input())for _ in range(A)] +[10**11]
t =[-10**11] + [int(input())for _ in range(B)] +[10**11]

for _ in range(C):
    x =int(input())
    ns = bisect.bisect_left(s,x)
    nt = bisect.bisect_left(t,x)
    sx =[s[ns-1],s[ns]]
    tx =[t[nt-1],t[nt]]
    lis =[sx,tx]
    ans = 10**11
    for i in range(8):
        p =i%2
        q =(i//2)%2
        r =i//4
        foo =abs(x-lis[p][q])+abs(lis[p][q]-lis[p-1][r])
        if foo < ans:
            ans = foo
    print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
LR = [[int(x) for x in input().split()] for _ in range(Q)]

for l, r in LR:
    print(S[l-1: r].count('AC'))

### FIXED CODE ###

import itertools
N, Q = map(int, input().split())
S = input()
LR = [[int(x) for x in input().split()] for _ in range(Q)]

reg = [0]*N
for i in range(N-1):
#     print(S[i:i+2])
    if S[i:i+2]=='AC':
        reg[i] += 1
        
regcum = [0] + list(itertools.accumulate(reg))

for l, r in LR:
    print(regcum[r-1] - regcum[l-1])
### BUGGY CODE ###

from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(X):
    n=len(X)
    ma=len(X)-1
    mi=0
    while ma-mi>1:
        mid = (ma + mi)//2
        a=X[n-1]-X[mid]
        b=X[mid-1]-X[0]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [X[mi]-X[0],X[n-1]-X[mi]]
num=10**14
K=A[:2]
L=deque(A[2:])
for i in range(2,N-1):
    a=L.popleft()
    L.appendleft(a)
    K.append(a)
    #print(K,L)
    ans=[]
    ans=ans+dou(K)+dou(L)
    #print(ans)
    #print(abs(max(ans)-min(ans)))
    num=min(num,abs(max(ans)-min(ans)))
    L.popleft()
print(num)

### FIXED CODE ###

from collections import deque
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
def dou(i,j):
    ma=j
    mi=i
    while ma-mi>1:
        mid = (ma + mi)//2
        a=A[j]-A[mid]
        b=A[mid-1]-A[i]
        if a>b:
            mi=mid
        else:
            ma=mid
        #print(ma,mi)
    return [A[mi]-A[i],A[j]-A[mi]]
num=10**14
for i in range(2,N-1):
    ans=[]
    ans+=dou(0,i)
    ans+=dou(i,N)
    #print(ans)
    t=max(ans)-min(ans)
    num=min(num,t)
print(num)
### BUGGY CODE ###

import sys
import numpy as np
input=sys.stdin.readline
N,M=map(int,input().split())

a,b=map(int,input().split())
A=[a]
B=[b]

l=[1 for i in range(N+1)]
l=np.array(l)
L=[[]for i in range(N+1)]

for i in range(M-1):
    x,y=map(int,input().split())
    L[x].append(y)
    L[y].append(x)
    
l[a]=0
l[b]=0


P=a
for i in range(10**5):
    for j in L[P]:
        if l[j]!=0:
            P=j
            l[j]=0
            A.append(j)
            break
    if len(L[P])==0:
        break
    elif max(L[P])==0:
        break
P=b
for i in range(10**5):
    for j in L[P]:
        
        if l[j]!=0:
            P=j
            l[j]=0
            B.append(j)
            break
    if len(L[P])==0:
        break
    elif max(L[P])==0:
        break


print(len(A)+len(B))

ANS=str(A[len(A)-1])
for i in range(1,len(A)):
    ANS+=" "+str(A[len(A)-1-i])
for i in range(len(B)):
    ANS+=" "+str(B[i])
print(ANS)
        
    

### FIXED CODE ###

import sys
input=sys.stdin.readline

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

R=[1 for i in range(N+1)]
A,B=map(int,input().split())
R[A]=0
R[B]=0

L=[[]for i in range(N+1)]
L[A].append(B)
L[B].append(A)

for i in range(M-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)

l=[A]
P=A
#print(L)

for i in range(10**6):
    flag=0
    #print("P",L[P])
    for j in L[P]:
        #print("j",L,L[P],j,P)
        if R[j]==1:
            P=j
            R[j]=0
            l.append(j)
            flag+=1
            break
    if flag==0:
        break
#print(l)
r=[B]
P=B
for i in range(10**6):
    flag=0
    #print("P",L[P])
    for j in L[P]:
        #print("j",L,L[P],j,P)
        if R[j]==1:
            P=j
            R[j]=0
            r.append(j)
            flag+=1
            break
    if flag==0:
        break
#print(r)
l=l[::-1]
ans=l+r

ANS=str(ans[0])
for i in range(1,len(ans)):
    ANS+=" "+str(ans[i])
print(len(ans))
print(ANS)
### BUGGY CODE ###

n = int(input())
for p in range(1,n+1):
  ans = 0
  for i in range(1, 101):
    for j in range(1, min(i+1,50)):
      for k in range(1, min(j+1, 34)):
        if (i+j+k)**2-i*j-j*k-k*i == p:
          if i==j==k:
            ans += 1
          else:
            ans += 3
  print(ans) 
    


### FIXED CODE ###

n = int(input())
a = [0]*10**4
ans = 0
for i in range(1, 101):
  for j in range(1, min(i+1,101)):
    for k in range(1, min(j+1, 101)):
       if (i+j+k)**2-i*j-j*k-k*i <= 10**4:
          p = (i+j+k)**2-i*j-j*k-k*i
          if i==j==k:
             a[p-1] +=1
          elif i != j and j != k:
             a[p-1] +=6
          else:
             a[p-1] +=3
for q in a[:n]:
  print(q)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

# modを取りながらべき乗する
def power_func(a,n,mod):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res

N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mod = 10**9+7
L = 400

dp = [[[0]*(L+1) for _ in range(C+1)] for _ in range(N)]
count = B[0] - A[0] + 1
for c in range(C+1):
    a, b = A[0], B[0]
    dp[0][c][0] = power_func(a, c, mod)
    for k in range(1, b-a+1):
        dp[0][c][k] = (dp[0][c][k-1] + power_func(a+k, c, mod)) % mod
    dp[0][c][L] = dp[0][c][b-a]

for i in range(1, N):
    a, b = A[i], B[i]
    for k in range(b-a+1):
        dp[i][0][k] = count * (k+1) % mod
    for c in range(1, C+1):
        dp[i][c][0] = (dp[i-1][c][L] + a*dp[i][c-1][0]) % mod
        for k in range(1, b-a+1):
            dp[i][c][k] = dp[i][c][k-1] + dp[i-1][c][L] + (a+k)*(dp[i][c-1][k]-dp[i][c-1][k-1])
            if dp[i][c][k] < 0: dp[i][c][k] += mod
            dp[i][c][k] %= mod
        dp[i][c][L] = dp[i][c][b-a]
    count = (count * (b-a+1)) % mod

print(dp[N-1][C][L])

### FIXED CODE ###

import sys
input = sys.stdin.readline

# modを取りながらべき乗する
def power_func(a,n,mod):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res

def main():
    N, C = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    mod = 10**9+7
    L = 400

    dp = [[0]*(L+1) for _ in range(C+1)]
    count = B[0] - A[0] + 1
    for c in range(C+1):
        a, b = A[0], B[0]
        dp[c][0] = power_func(a, c, mod)
        for k in range(1, b-a+1):
            dp[c][k] = (dp[c][k-1] + power_func(a+k, c, mod)) % mod
        dp[c][L] = dp[c][b-a]

    for i, (a, b) in enumerate(zip(A, B)):
        if i == 0: continue
        for k in range(b-a+1):
            dp[0][k] = count * (k+1) % mod
        dp[0][L] = dp[0][b-a]
        for c in range(1, C+1):
            dp[c][0] = (dp[c][L] + a*dp[c-1][0]) % mod
            for k in range(1, b-a+1):
                R = dp[c][k-1] + dp[c][L] + (a+k)*(dp[c-1][k]-dp[c-1][k-1])
                if R < 0: R += mod
                dp[c][k] = R%mod
            dp[c][L] = dp[c][b-a]
        count = (count * (b-a+1)) % mod

    print(dp[C][L])


if __name__ == "__main__":
    main()
### BUGGY CODE ###

def dfs(tree: dict, count: list) -> list:
    res = [0] * (N + 1)

    stack = [1]
    while stack:
        label = stack.pop(0)
        res[label] = count[label]
        if tree[label] != []:
            for next_label in tree[label]:
                count[next_label] += count[label]
            stack = tree[label] + stack

    return res


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

tree = {}
for i in range(1, N + 1):
    tree[i] = []
for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a] += [b]

count = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split())
    count[p] += x

ans = dfs(tree, count)
print(*ans[1:])


### FIXED CODE ###

import sys


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


def dfs(tree: dict, count: list) -> list:
    res = [0] * (N + 1)

    stack = [1]
    while stack:
        label = stack.pop()
        res[label] = count[label]
        if tree[label] != []:
            for next_label in tree[label]:
                count[next_label] += count[label]
            stack += tree[label]

    return res


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

tree = {}
for i in range(1, N + 1):
    tree[i] = []
for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a] += [b]

count = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split())
    count[p] += x

ans = dfs(tree, count)
print(*ans[1:])
### BUGGY CODE ###

n =int(raw_input())
L =map(int,raw_input().split())
m =int(raw_input())
S =map(int,raw_input().split())

sum =0

for i in S:
    if i in L:
        sum +=1
print sum

### FIXED CODE ###

raw_input()
s =set(raw_input().split())
raw_input()
print len(s &set(raw_input().split()))
### BUGGY CODE ###

import numpy as np
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n, t = map(int, input().split())
    dp = np.zeros(t,dtype=int)
    food = []
    for _ in range(n):
        a, b = map(int, input().split())
        food.append([a, b])
    food.sort(key=lambda x: x[0]*-1)
    for j in range(n):
        a, b = food[j][0], food[j][1]
        for i in range(t-1, -1, -1):
            if i < a:
                dp[i] = max(b, dp[i])
            else:
                dp[i] = max(dp[i-a]+b, dp[i])
    print(dp[t-1])


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n,t=map(int, input().split())
    dp=[0]*t
    food=[]
    for _ in range(n):
        a,b=map(int, input().split())
        food.append([a,b])
    food.sort(key=lambda x:x[0]*-1)
    for j in range(n):
        a,b=food[j][0],food[j][1]
        dptmp=[0]*t
        for i in range(t):
            if i < a: 
                dptmp[i]=max(b,dp[i])
            else:
                dptmp[i]=max(dp[i-a]+b,dp[i])
        dp=dptmp
    print(dp[t-1])
 
if __name__=='__main__':
    main()
### BUGGY CODE ###

A, B = map(int, input().split())
keta_num = len(str(bin(B)))-2
keta_li = [0]*keta_num
for i in range(A, B+1):
    num = str(bin(i))[2:]
    l = len(num)
    for k in range(l)[::-1]:
        keta_li[l-k-1] += int(num[k])
result = ""
for i in range(keta_num)[::-1]:
    result += str(keta_li[i] % 2)
print((int(result,2)))


### FIXED CODE ###

A, B = map(int, input().split())
def calc(a):
    cnt = (a + 1) // 2
    ans = cnt % 2
    if a % 2 == 0:
        ans ^= a
    return ans
print(calc(A-1) ^ calc(B))







1
### BUGGY CODE ###

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

for i in range(n):
    s = s*a[i]

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

print(s)

### FIXED CODE ###

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

for i in range(n):
    s = s*a[i]
    if s > 10**18:
        s = -1
        break

if 0 in a:
    s = 0

print(s)
### BUGGY CODE ###

S = input()
T = input()
q = int(input())
A = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
  count_s = {"A": 0, "B": 0}
  count_t = {"A": 0, "B": 0}
  for j in range(A[i][0]-1, A[i][1]):
    if(S[j] == "B"):
      count_s["B"] += 1
    else:
      count_s["A"] += 1
  for k in range(A[i][2]-1, A[i][3]):
    if(T[k] == "B"):
      count_t["B"] += 1
    else:
      count_t["A"] += 1

  if(count_s["A"] - count_t["A"] > 0):
    tmp = count_s["A"] - count_t["A"] - (count_s["B"] - count_t["B"])
    if(tmp % 3 == 0):
      print("YES")
    else:
      print("NO")

  else:
    tmp = count_t["A"] - count_s["A"] - (count_t["B"] - count_s["B"])
    if(tmp % 3 == 0):
      print("YES")
    else:
      print("NO")

### FIXED CODE ###

S = input()
T = input()
q = int(input())
A = [list(map(int, input().split())) for _ in range(q)]

count_s = [{"A": 0, "B":0} for i in range(len(S))]
count_t = [{"A": 0, "B":0} for i in range(len(T))]

for i in range(len(S)):
  if(S[i] == "A"):
    count_s[i]["A"] += 1
    if(i == len(S) -1):
      break
    count_s[i+1] = count_s[i].copy()
  else:
    count_s[i]["B"] += 1
    if(i == len(S) -1):
      break
    count_s[i+1] = count_s[i].copy()


for i in range(len(T)):
  if(T[i] == "A"):
    count_t[i]["A"] += 1
    if(i == len(T) -1):
      break
    count_t[i+1] = count_t[i].copy()
  else:
    count_t[i]["B"] += 1
    if(i == len(T) -1):
      break
    count_t[i+1] = count_t[i].copy()


for i in range(q):
  if(S[A[i][0] - 1] == "A"):
    count_S = {"A": count_s[A[i][1] - 1]["A"] - count_s[A[i][0] - 1]["A"] + 1, "B": count_s[A[i][1] - 1]["B"] - count_s[A[i][0] -1]["B"]}
  else:
    count_S = {"A": count_s[A[i][1] - 1]["A"] - count_s[A[i][0] - 1]["A"], "B": count_s[A[i][1] - 1]["B"] - count_s[A[i][0] -1]["B"] + 1}
  if(T[A[i][2] - 1] == "A"):
    count_T = {"A": count_t[A[i][3] - 1]["A"] - count_t[A[i][2] - 1]["A"] + 1, "B": count_t[A[i][3] - 1]["B"] - count_t[A[i][2] - 1]["B"]}
  else:
    count_T = {"A": count_t[A[i][3] - 1]["A"] - count_t[A[i][2] - 1]["A"], "B": count_t[A[i][3] - 1]["B"] - count_t[A[i][2] - 1]["B"] + 1}

  if(count_S["A"] - count_T["A"] > 0):
    tmp = count_S["A"] - count_T["A"] - (count_S["B"] - count_T["B"])
    if(tmp % 3 == 0):
      print("YES")
    else:
      print("NO")

  else:
    tmp = count_T["A"] - count_S["A"] - (count_T["B"] - count_S["B"])
    if(tmp % 3 == 0):
      print("YES")
    else:
      print("NO")
### BUGGY CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = [0]
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop(0)
        for s in dic[t]:
            if visit[s]:
                point[s] += point[t]
                visit[s] = False
                counter += 1
                next_visit.append(s)
    print(" ".join(map(str, point)))
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    from collections import deque
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = deque()
    next_visit.append(0)
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop()
        for s in dic[t]:
            if visit[s]:
                point[s] += point[t]
                visit[s] = False
                counter += 1
                next_visit.append(s)
    print(*point)
if __name__ == '__main__':
    main()