Harryxun/stf_run huggingface dataset:
w,h,n = map(int,input().split())
b,c,d,e = 0,w,0,h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b = max(b,x)
    elif a == 2:
        c = min(c,x)
    elif a == 3:
        d = max(d.y)
    else:
        e = min(e,y)
print(max(c-b,0)*max(e-d,0))

### FIXED CODE ###

w,h,n = map(int,input().split())
b,c,d,e = 0,w,0,h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b = max(b,x)
    elif a == 2:
        c = min(c,x)
    elif a == 3:
        d = max(d,y)
    else:
        e = min(e,y)
print(max(c-b,0)*max(e-d,0))
S = input()

li = set()
for i in len(S):
  li.add(S[i])

if len(S) == len(li):
  print("yes")
else:
  print("no")

### FIXED CODE ###

S = input()

li = set()
for i in range(len(S)):
  li.add(S[i])

if len(S) == len(li):
  print("yes")
else:
  print("no")
N, K = map(int, input().split())
h = list(map(int, input().split()))
print (len([1 for x in h if h >= K]))

### FIXED CODE ###

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

L = [1 for i in range(N) if h[i] >= K]
print (len(L))
n,m=map(int,input().split())
list=[]
sum=0
for i in range(m):
  p,s=input().split()
  if s='AC':
    list.append(p)
  else:
    if p not in list:
      sum=sum+1
print(sum)

### FIXED CODE ###

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

submit = []
for i in range(m):
    temp = [x for x in input().split()]
    submit.append(temp)

ac = [0] * (n + 1)
wa = [0] * (n + 1)

for i in range(m):
    result = submit[i][1]
    question = int(submit[i][0])

    if result == 'AC' and ac[question] == 0:
        ac[question] = 1
    elif result == 'WA' and ac[question] == 0:
        wa[question] += 1

for i in range(n + 1):
    if ac[i] != 1:
        wa[i] = 0

print(sum(ac), sum(wa))
H, W, K = map(int, input().split())
S = list(input() for i in range(H))

sum = [[0] * (W+1) for i in range((H+1))]
for i in range(H):
    for j in range(W):
        sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (1 if s[i][j] == '1' else 0)

ans = H + W - 2

for ptn in range(1<<H-1): # 2^H - 1 通り
    cand = 0

    sep = [0] # 横方向の分割リスト、ここ天才
    for i in range(H-1):
        if((ptn >> i) & 1): # & を取ることで、上の桁を消せる
            sep.append(i+1)
            cand += 1
    sep.append(H)

    left = 0 # left は直前の分割
    for pos in range(W):
    	cur = [] # cur は今見てるホワイトチョコの個数のリスト

    	# 横方向に分割されている各部分について
    	for i in range(len(sep) - 1):
    		cur.append(sum[sep[i+1]][pos+1] - sum[sep[i+1]][left] - sum[sep[i]][pos+1] + sum[sep[i]][left])

    	if max(cur) > K:
    		if left == pos: # 縦に分割できない場合(一列しかない場合)
    			cand = H * W
    			break
    		else:
    			cand += 1
    			left = pos

    ans = min(ans, cand)

print(ans)


### FIXED CODE ###

H, W, K = map(int, input().split())
S = list(input() for i in range(H))

sum = [[0] * (W+1) for i in range((H+1))]
for i in range(H):
    for j in range(W):
        sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (1 if S[i][j] == '1' else 0)

ans = H + W - 2

for ptn in range(1<<H-1): # 2^H - 1 通り
    cand = 0

    sep = [0] # 横方向の分割リスト、ここ天才
    for i in range(H-1):
        if((ptn >> i) & 1): # & を取ることで、上の桁を消せる
            sep.append(i+1)
            cand += 1
    sep.append(H)

    left = 0 # left は直前の分割
    for pos in range(W):
    	cur = [] # cur は今見てるホワイトチョコの個数のリスト

    	# 横方向に分割されている各部分について
    	for i in range(len(sep) - 1):
    		cur.append(sum[sep[i+1]][pos+1] - sum[sep[i+1]][left] - sum[sep[i]][pos+1] + sum[sep[i]][left])

    	if max(cur) > K:
    		if left == pos: # 縦に分割できない場合(一列しかない場合)
    			cand = H * W
    			break
    		else:
    			cand += 1
    			left = pos

    ans = min(ans, cand)

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

L = [0]*N
j = 1
for i in range(1, M+1):
    while L[j-1] == 1:
        j += 1
    print(j, i+j)
    L[j-1] = 1
    L[i+j-1] = 1

### FIXED CODE ###

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

a = 1
b = N
for i in range(M, 0, -1):
    if i%2 == M%2:
        print(a, a+i)
        a += 1
    else:
        print(b, b-i)
        b -= 1
n= int(input())
aas= list(map(int, input().split(' ')))

ans=0
for i in range(n-1):
  for j in range(i+1, n):
    ans+= aas[i]*aas[j]
    if ans>(10**9+7):
      ans= ans% (10**9+7)

print(ans)

### FIXED CODE ###

d,t,s= map(int, input().split(' '))

if s*t<d:
  print('No')
else:
  print('Yes')
A = input()
B = input()
C = input()

#配列の次のカードの文字を返す
def next(X, i):
    if X[i] == 'a':
        return A[i]
    elif X[i] == 'b':
        return B[i]
    else:
        return C[i]

xa = 0
xb = 0
xc = 0

h = 'A'
k = next(A, xa) #最初
xa += 1

while xa <= len(A) and xb <= len(B) and xc <= len(C):
    if k == 'a':
        h = 'A'
        k = next(A, xa)
        xa += 1
    elif k == 'b':
        h = 'B'
        k = next(B, xb)
        xb += 1
    else:
        h = 'C'
        k = next(C, xc)
        xc += 1

print(h)


### FIXED CODE ###

A = input()
B = input()
C = input()

xa = 0
xb = 0
xc = 0

h = 'A'
k = A[0] #最初の１枚を抜く
xa += 1

while True:

    if k == 'a':
        h = 'A'
        if xa < len(A):
            k = A[xa]
            xa += 1
        else:
            break
    elif k == 'b':
        h = 'B'
        xb += 1
        if xb < len(B):
            k = B[xb]
            xb += 1
        else:
            break
    elif k == 'c':
        h = 'C'
        xc += 1
        if xc < len(C):
            k = C[xc]
            xc += 1
        else:
            break

print(h)
from math import sqrt
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    p = [0] * (10**6 + 1)
    c = Counter(A)

    for a in A:
        tmp = a * 2
        if p[tmp] == 1:
            continue
        while tmp <= 10**6:
            p[tmp] = 1
            tmp += a

    for a in A:
        if p[a] == 0 and c[a] == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from math import sqrt
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    p = [0] * (10**6 + 1)
    c = Counter(A)

    for a in c.keys():
        tmp = a * 2
        while tmp <= 10**6:
            p[tmp] = 1
            tmp += a

    for a in A:
        if p[a] == 0 and c[a] == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()
def check_all_distinct(A):
  already_seen_chars = list()
  for character in A:
    if character not in already_seen_chars:
      already_seen_chars.append(character)
      print(already_seen_chars)
    else: return "NO"
  return "YES"


if __name__ == "__main__":
  N = int(input())
  A = input().split()
  print(check_all_distinct(A))

### FIXED CODE ###

N = int(input())
A = input().split()
if len(A) != len(set(A)):
  print("NO")
else:
  print("YES")
N, K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9 + 7

LANK = list(set(A))
LANK.sort()
LANK2 = [0] * 2000
for i, l in enumerate(LANK):
    LANK2[l] = i

LANK = [-1] * N
for i,a in enumerate(A):
    LANK[i] = LANK2[a]

back = [0] * N
for i,a in enumerate(A[::-1]):
    cnt = 0
    for j,a2 in enumerate(A[::-1]):
        if i > j and a > a2:
            cnt += 1
    back[N-1-i] = cnt
    

SUM = 0
tmp = sum(range((K)))
for i,a in enumerate(A):
    SUM += LANK[i] * tmp + back[i] * K
    SUM %= MOD
print(SUM)

### FIXED CODE ###

N, k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            if i > j:
                ans += k*(k-1)//2
            elif i < j:
                ans += k*(k+1)//2
            ans %= MOD

print(ans)
x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
    print(x)

p = set(p)
else:
    _x = x 
    x_ = x
    while True:
        _x -= 1
        x_ += 1
        if _x not in p:
            print(_x)
            break
        if x_ not in p:
            print(x_)
            break

### FIXED CODE ###

X, N = map(int, input().split())
p = list(map(int, input().split()))

p = set(p)
for i in range(200):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break
N=int(input())
K=int(input())
if N/K==0:
    print(0)
else :
    print(1)



### FIXED CODE ###

N, K = input().split()
N=int(N)
K=int(K)
if K==0:
    print("ZeroDivisionError!!")
elif N % K ==0:
    print(0)
else :
    print(1)
n,m=(int(i) for i in input().split())
mtrx=[[int(i) for i in input().split()] for j in range(m)]
mtrx=[[mtrx[j][0]-1,mtrx[j][1]-1] for j in range(m)]

adjacent=[[] for i in range(n)]
#print(adjacent)
for i in range(n):
    adjacent[mtrx[i][0]]+=[mtrx[i][1]]
    adjacent[mtrx[i][1]]+=[mtrx[i][0]]
#print(adjacent)

cnt=[]
def dfs(path):
    p=path[-1]
    if len(set(path))==n:
#        print(path)
        cnt.append(1)
        return
    else:
        for x in adjacent[p]:
            if x in path:
                continue
            else:
                path.append(x)
                dfs(path)
                path.pop()
dfs([0])

print(len(cnt))

### FIXED CODE ###

n,m=(int(i) for i in input().split())
mtrx=[[int(i) for i in input().split()] for j in range(m)]
#print(mtrx)
mtrx+=[[mtrx[i][1],mtrx[i][0]] for i in range(m)]
#print(mtrx)
mylist=[10*mtrx[i][0]+mtrx[i][1] for i in range(len(mtrx))]
#print(mylist)
# 順列を格納するリスト
perm = []
cnt=[]
# 順列の生成
def make_perm(n, m = 0):
    if n == m and perm[0]==1:
        flag=1
        for i in range(len(perm)-1):
            myval=10*perm[i]+perm[i+1]
            myval1=mylist.count(myval)
            flag=flag*myval1
        cnt.append(flag)
        
    else:
        for x in range(1, n + 1):
            if x in perm: continue
            perm.append(x)
            make_perm(n, m + 1)
            perm.pop()
            
make_perm(n)
print(sum(cnt))
#ABC 100 B - Ringo's favorite number
A = [int(el) for el in input().split(' ')]
if N != 100:
    print(100**A[0] * A[1])
else:
    print(100**A[0] * 101)


### FIXED CODE ###

#ABC 100 B - Ringo's favorite number
A = [int(el) for el in input().split(' ')]
if A[1] != 100:
    print(100**A[0] * A[1])
else:
    print(100**A[0] * 101)
a,b,c = input()

if(a=="7"||b=="7"||c=="7"):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b,c = input()

if(a=="7" or b=="7" or c=="7"):
  print("Yes")
else:
  print("No")
n, m = map(int, input().split())

a = []
#通過できない階段をaに格納
for _ in range(m):
    a.append(int(input()))
    
count = [0]*(n+1)
count[0] = 1
for i in range(1,n+1):
    if i in a:
        continue
    else:
        count[i] = count[i-1]+count[i-2]

print(count[-1]%(10**9+7))


### FIXED CODE ###

p,q,r = map(int, input().split())
print(p+q+r-max(p,q,r))
N,K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

if all(a<0 for a in A):
    A.sort()
    ans = 1
    for _ in range(K):
        ans *= A.pop()
        ans %= MOD
    print(ans)
    exit()

arr = []
for a in A:
    if a < 0:
        arr.append((-a,1))
    else:
        arr.append((a,0))

arr.sort()
pz = []
ng = []
ans = 1
for _ in range(K):
    v,s = arr.pop()
    if s:
        ng.append(v)
    else:
        pz.append(v)

for v in ng:
    ans *= v
    ans %= MOD
for v in pz:
    ans *= v
    ans %= MOD
if len(ng)%2 == 0:
    print(ans)
    exit()

b = pz[-1] if pz else None
c = ng[-1] if ng else None
a = d = None
while arr and (a is None or d is None):
    v,s = arr.pop()
    if s:
        if a is None:
            a = v
    else:
        if d is None:
            d = v

assert (a is not None and b is not None) or (c is not None and d is not None)

if a is None or b is None:
    ans *= c * pow(d,-1,MOD)
elif c is None or d is None:
    ans *= a * pow(b,-1,MOD)
else:
    if a*d > b*c:
        ans *= a * pow(b,-1,MOD)
    else:
        ans *= c * pow(d,-1,MOD)
ans %= MOD
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

if all(a>=0 for a in A):
    A.sort()
    ans = 1
    for _ in range(K):
        ans *= A.pop()
        ans %= MOD
    print(ans)
    exit()
if all(a<0 for a in A):
    A.sort(reverse=K%2==0)
    ans = 1
    for _ in range(K):
        ans *= A.pop()
        ans %= MOD
    print(ans)
    exit()
if N==K:
    ans = 1
    for a in A:
        ans *= a
        ans %= MOD
    print(ans)
    exit()

arr = []
for a in A:
    if a < 0:
        arr.append((-a,1))
    else:
        arr.append((a,0))

arr.sort()
pz = []
ng = []
for _ in range(K):
    v,s = arr.pop()
    if s:
        ng.append(v)
    else:
        pz.append(v)

if len(ng)%2 == 0:
    ans = 1
    for v in ng:
        ans *= v
        ans %= MOD
    for v in pz:
        ans *= v
        ans %= MOD
    print(ans)
    exit()

b = pz[-1] if pz else None
c = ng[-1] if ng else None
a = d = None
while arr and (a is None or d is None):
    v,s = arr.pop()
    if s:
        if a is None:
            a = v
    else:
        if d is None:
            d = v

if (a is None or b is None) and (c is None or d is None):
    assert False

ans = 1
if a is None or b is None:
    ans = d
    for v in ng[:-1]:
        ans *= v
        ans %= MOD
    for v in pz:
        ans *= v
        ans %= MOD
elif c is None or d is None:
    ans = a
    for v in ng:
        ans *= v
        ans %= MOD
    for v in pz[:-1]:
        ans *= v
        ans %= MOD
else:
    if a*c > b*d:
        ans = a
        for v in ng:
            ans *= v
            ans %= MOD
        for v in pz[:-1]:
            ans *= v
            ans %= MOD
    else:
        ans = d
        for v in ng[:-1]:
            ans *= v
            ans %= MOD
        for v in pz:
            ans *= v
            ans %= MOD
ans %= MOD
print(ans)
import sys
sys.setrecursionlimit(10 ** 9)
lst = [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)
# print (A)

def num(k):
    return lst[k-1][1]

# for i in A:
    # print (num(i), end = ', ')
# print ()

INF = 10 ** 5
dp_lst = [-INF] * (N + 1)
dp_lst[0] = 0
def dp(i):
    if dp_lst[i] != -INF:
        return dp_lst[i]
    tmp = -INF
    for j in A:
        if i >= num(j):
            tmp = max(tmp, dp(i - num(j)) + 1)
    dp_lst[i] = tmp
    return dp_lst[i]

a = dp(N)
# print (a)
# print (dp_lst)   
# print ([0] * 10 +[i+1 for i in range(20)])

# print (len(str(71111111111111111111111111111111111111111111111111)))

def check(A):
    if dp_lst[N-num(A)] == dp_lst[N] - 1:
        return True
    else:
        return False

# print (a)
while a > 0:
    for i in A:
        if check(i):
            print (i, end = '')
            N -= num(i)
            a -= 1
            break
        else:
            pass
            # print ('B')
print ()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 5)
lst = [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)
# print (A)

def num(k):
    return lst[k-1][1]

# for i in A:
    # print (num(i), end = ', ')
# print ()

INF = 10 ** 5
dp_lst = [-INF] * (N + 1)
dp_lst[0] = 0
def dp(i):
    if dp_lst[i] != -INF:
        return dp_lst[i]
    tmp = -INF
    for j in A:
        if i >= num(j):
            tmp = max(tmp, dp(i - num(j)) + 1)
    dp_lst[i] = tmp
    return dp_lst[i]

a = dp(N)
# print (a)
# print (dp_lst)   
# print ([0] * 10 +[i+1 for i in range(20)])

# print (len(str(71111111111111111111111111111111111111111111111111)))

def check(A):
    if N - num(A) < 0:
        return False
    if dp_lst[N-num(A)] == dp_lst[N] - 1:
        return True
    else:
        return False

# print (a)
while a > 0:
    for i in A:
        if check(i):
            print (i, end = '')
            N -= num(i)
            a -= 1
            break
        else:
            pass
            # print ('B')
print ()
# -*- coding:utf-8 -*-
import sys
sys.setrecursionlimit(10000000)

def preDatasets():
	datas = input()
	for i in range(len(datas)):
		datas[i] = datas[i].strip('\n')
	return datas

def dfs(x, y, sym):
	tile[x][y] = '.'
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if(nx>=0 and nx<N and ny>=0 and ny<M and tile[nx][ny]==sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			if not tile[i][j] == '.':
				if tile[i][j] == '@':
					dfs(i, j, '@')
					res += 1
				elif tile[i][j] == '#':
					dfs(i, j, '#')
					res += 1
				elif tile[i][j] == '*':
					dfs(i, j, '*')
					res += 1
	print(res)

index = 0	
DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]
while True:
	datas = preDatasets()
	

	N = int(datas[index].split(' ')[0])
	M = int(datas[index].split(' ')[1])
	tile = [[0 for i in range(N)]for j in range(M)]
	
	for i in range(len(tile)):
		tile[i] = list(datas[index+i+1])

	if N == 0:
		break
	else:
		solve()
		index += N+1

### FIXED CODE ###

# -*- coding:utf-8 -*-
import sys
def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1,0,1,0]
DY = [0,-1,0,1]
sys.setrecursionlimit(10**7)
while True:
	line = input()
	if " " in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(M)] for j in range(N)]
	else:
		tile[counter-1] = list(line)
	if N is 0 and M is 0:
		break
	counter += 1
	if counter-1 is N:
		solve()
		counter = 0
N,K = list(map(int,input().split()))
B = []
ans = 0
for i in range(K):
    d = input()
    A = list(map(int,input().split()))
    for l in range(len(A)):
      B.append(A[l])
      print(B)
for j in range(1,N+1):
    if j not in B:
        ans += 1
print(ans)

### FIXED CODE ###

N,K = list(map(int,input().split()))
B = []
ans = 0
for i in range(K):
    d = input()
    A = list(map(int,input().split()))
    for l in range(len(A)):
      B.append(A[l])
for j in range(1,N+1):
    if j not in B:
        ans += 1
print(ans)
n, y =  map(int, input().split())
 
res_a, res_b, res_c = -1
 
for i in range(n):
  for j in range(n):
      if 10000*i + 5000*j + 1000*(n-i-j) == y:
        res_a, res_b, res_c = i, j, n-i-j
        break
        
print(res_a, res_b, res_c)

### FIXED CODE ###

n, y =  map(int, input().split())
 
res_a = -1
res_b = -1
res_c = -1
 
for i in range(n+1):
  for j in range(n+1):
      if 10000*i + 5000*j + 1000*(n-i-j) == y and i+j <= n:
        res_a, res_b, res_c = i, j, n-i-j
        break
        
print(res_a, res_b, res_c)
n = input()
l = input().split()
l = map(int, l)
max, min = max(l), min(l)
print(max - min)

### FIXED CODE ###

n = input()
l = input().split()
l = list(map(int, l))
max, min = max(l), min(l)
print(max-min)
N=int(raw_input())
lis = []
for i in range(0,N):
	num = int(raw_input())
	lis.append(num)
get = sum(lis)
if sum(lis) % 10 == 0:
	for j in range(0,N)
		lis.remove(min(lis))
		if min(lis) % 10 != 0
			print get - min(lis)
else:
	print get

### FIXED CODE ###

N=int(raw_input())
lis = []
for i in range(0,N):
	num = int(raw_input())
	lis.append(num)
get = sum(lis)
if sum(lis) % 10 == 0:
	for j in range(0,N-1):
		if min(lis) % 10 != 0:
			print get - min(lis)
			break
		lis.remove(min(lis))
	else:
		print 0
else:
	print get
s=input()
n=len(s)
ans="Yes"
if n%2==0:
    for i in range(n//2+1):
        if s[2*i]=="L":
            ans="No"
            break
        if s[2*i+1]=="R":
            ans="No"
            break
else:
    if s[0]=="L":
        ans="No"
    for i in range(1,n//2+1):
        if s[2*i]=="L":
            ans="No"
            break
        if s[2*i-1]=="R":
            ans="No"
            break
print(ans)

### FIXED CODE ###

s=input()
n=len(s)
ans="Yes"
if n%2==0:
    for i in range(n//2):
        if s[2*i]=="L":
            ans="No"
            break
        if s[2*i+1]=="R":
            ans="No"
            break
else:
    if s[0]=="L":
        ans="No"
    for i in range(1,n//2+1):
        if s[2*i]=="L":
            ans="No"
            break
        if s[2*i-1]=="R":
            ans="No"
            break
print(ans)
total = max(a)/2
a.remove(max(a))
total += sum(a)
print(total)

### FIXED CODE ###

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

total = int(max(a)/2)
a.remove(max(a))
total += sum(a)

print(total)
N, Q = list(map(int, input().split()))
tree = {}
for i in range(N-1):
    a, b = list(map(int, input().split()))
    items = tree.get(a, [])
    items.append(b)
    tree[a] = items

q = []
for i in range(Q):
    q.append(list(map(int, input().split())))

ans = [0] * (N + 1)

def recc_sum(p, x, tree_p):
    for i in range(len(tree_p)):
        index = tree_p[i]
        ans[index] += x
        if tree.get(index, None) != None:
            recc_sum(index, x, tree[index])

for i in range(Q):
    p = q[i][0]
    x = q[i][1]
    ans[p] += x
    if tree.get(p, None) != None:
        recc_sum(p, x, tree[p])

print(" ".join(list(map(str, ans[1:]))))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

readline = sys.stdin.readline
n, q = list(map(int, readline().split()))
# 双方向に張る
tree = [[] for _ in range(n)]
for i in range(n-1):
    a, b = list(map(int, readline().split()))
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

# queryのスコア表を作る
total = [0 for _ in range(n)]
for i in range(q):
    p, x = list(map(int, readline().split()))
    total[p - 1] += x

# dfs
ans = [0 for _ in range(n)]
def dfs(v, p, value):
    value += total[v]
    ans[v] = value
    for c in tree[v]:
        if c == p: continue
        dfs(c, v, value)

dfs(0, -1, 0)
print(*ans)
a,b = input().split()
A = int(a+b)

flg = False
for i in range(1,101):
  if i*i = A:
    flg = True
    break

if flg:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b = input().split()
A = int(a+b)

flg = False
for i in range(1,1000):
  if i*i == A:
    flg = True
    break

if flg:
  print("Yes")
else:
  print("No")