Harryxun/stf_run huggingface dataset:
H, W, M = map(int, input().split())
B = []
Bom = [[0] * W for _ in range(H)]
BomC = [0] * W
BomR = [0] * H
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Bom[h][w] = 1
    BomC[w] += 1
    BomR[h] += 1
    B.append((h, w))
C = set()
R = set()
cm = max(BomC)
rm = max(BomR)

for w, c in enumerate(BomC):
    if c == cm:
        C.add(w)
for h, r in enumerate(BomR):
    if r == rm:
        R.add(h)
flag = True
for c in C:
    for r in R:
        if Bom[r][c]:
            continue
        else:
            flag = False
            break
if flag:
    print(cm + rm - 1)
else:
    print(cm + rm)

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

H, W, M = map(int, input().split())

X = [0] * W
Y = [0] * H
Map = []

for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map.append((h, w))

MX = max(X)
MY = max(Y)
ans = MX + MY
Xans = set()
Yans = set()
for i, x in enumerate(X):
    if x == MX:
        Xans.add(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.add(i)
cnt = 0
for h, w in Map:
    if h in Yans and w in Xans:
        cnt += 1
if cnt == len(Xans) * len(Yans):
    ans -= 1
print(ans)
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    d, n = i_map()

    if d == 0:
        if n == 100:
            print(101)
        else:
            print(n)
        exit()

   print(pow(100, d) * n)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    d, n = i_map()

    if d == 0:
        if n == 100:
            print(101)
        else:
            print(n)
        exit()

    if n == 100:
        if d == 1:
            print(10100)
        elif d == 2:
            print(1010000)
        exit()

    print(pow(100, d) * n)

if __name__ == '__main__':
    main()
N = int(input())
A = int(input())
B = int(input())
if  price > B:
  print(B)
else:
  print(N * A)


### FIXED CODE ###

price =input().split()
if int(price[0]) *  int(price[1]) > int(price[2]) :
	print(int(price[2]))
else :
	print(int(price[0]) * int(price[1]))
Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

MAGIC_NUMBER = 100000
isprime = [True] * (MAGIC_NUMBER + 1)
for p in range(2, MAGIC_NUMBER + 1):
    if not isprime[p]: continue
    i_p = 2
    while p * i_p <= MAGIC_NUMBER:
        isprime[p * i_p] = False
        i_p += 1

primes = []
for p in range(2, MAGIC_NUMBER + 1):
    if isprime[p]: primes.append(p)

candidates = []
for p in primes:
    if p % 2 == 0: continue
    #
    if isprime[(p + 1) // 2]: candidates.append(p)


import bisect
    
for i, (li, ri) in enumerate(lr):
    i_l = bisect.bisect_left(candidates, li)
    i_r = bisect.bisect_left(candidates, ri)
    #
    if candidates[i_r] == ri: i_r += 1
    print(i_r - i_l)

### FIXED CODE ###

Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

MAGIC_NUMBER = 100000
isprime = [True] * (MAGIC_NUMBER + 1)
for p in range(2, MAGIC_NUMBER + 1):
    if not isprime[p]: continue
    i_p = 2
    while p * i_p <= MAGIC_NUMBER:
        isprime[p * i_p] = False
        i_p += 1

primes = []
for p in range(2, MAGIC_NUMBER + 1):
    if isprime[p]: primes.append(p)

candidates = []
for p in primes:
    if p % 2 == 0: continue
    #
    if isprime[(p + 1) // 2]: candidates.append(p)


import bisect
    
for i, (li, ri) in enumerate(lr):
    i_l = bisect.bisect_left(candidates, li)
    i_r = bisect.bisect_left(candidates, ri)
    #
    if i_r < len(candidates) and candidates[i_r] == ri: i_r += 1
    print(i_r - i_l)
N,M = list(map(int,input().split()))
z = 0

for i in range(M):
  a,b = list(map(int,input().split()))
  z.append(a)
  z.append(b)

for i in range(N):
  print(z.count(i+1))

### FIXED CODE ###

a = list(map(int,input().split()))
b = [list(map(int,input().split())) for i in range(a[1])]
c = []

for i in range(a[0]):
  d = []
  for j in range(a[1]):
    d.append(b[j].count(i+1))
  else:
    c.append(sum(d))
else:
  for i in range(a[0]):
    print(c[i])
n = list(int,input().split())
if 1 in n and 9 in n and 7 in n and 4 in n:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

n= list(map(int,input().split()))
n.sort()
if 1 in n and 7 in n and 9 in n and 4 in n:
  print("YES")
else:
  print("NO")
import copy



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

for i in range(N):
   # B = copy.deepcopy(A)
    tmp = A[i]
    a[i] = 0
    ans = max(A)
    a[i] = tmp
    print(ans)
             


### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
B = [ [0] * 2 for i in range(N)]

for i in range(N):
    B[i][0] = A[i]
    B[i][1] = i

B.sort(reverse=True)
for i in range(N):
    if B[0][1] == i:
        print(B[1][0])
    else:
        print(B[0][0])
import logging
logging.basicConfig(level=logging.CRITICAL,format=' %(asctime)s - %(levelname)s - %(message)s')
 
def power(n):
    i = 1
    logging.info('func start')
    while n > 0:
        i *= 2
        n -= 1
        logging.debug('i = {}, n = {}'.format(i,n))
    logging.info('func end')
    return i
 
i = 0
n = int(input())
logging.info('in loop')
while power(i+1) < n:
    i = i + 1
    logging.debug('i = {}, pow(i) = {}'.format(i,power(i)))
 
logging.info('out loop')
print(power(i ))

### FIXED CODE ###

import logging
logging.basicConfig(level=logging.CRITICAL,format=' %(asctime)s - %(levelname)s - %(message)s')

def power(n):
    i = 1
    logging.info('func start')
    while n > 0:
        i *= 2
        n -= 1
        logging.debug('i = {}, n = {}'.format(i,n))
    logging.info('func end')
    return i

i = 0
n = int(input())
logging.info('in loop')
while not (power(i + 1) > n):
    i = i + 1
    logging.debug('i = {}, pow(i) = {}'.format(i,power(i)))

logging.info('out loop')
print(power(i ))
from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
G = [[] for _ in range(n+1)]
for _ in range(m):
    u, v, s = map(int, input().split())
    G[u].append((v, s))
    G[v].append((u, s))
val = [None] * (n+1)
val[1] = (1, 0)
queue = deque([1])
while queue:
    u = queue.popleft()
    for v, s in G[u]:
        if val[v]:
            continue
        val[v] = (-val[u][0], s - val[u][1])
        queue.append(v)
ma = float('inf')
mi = 1
x = -1
for u in range(1, n+1):
    if val[u][0] == -1:
        ma = min(ma, val[u][1] - 1)
    else:
        mi = max(mi, -val[u][1] + 1)
    for v, s in G[u]:
        if u > v:
            continue
        if val[u][0] + val[v][0] == 0:
            if val[u][1] + val[v][1] != s:
                print(0)
                exit()
        else:
            a = val[u][0] + val[v][0]
            b = s - (val[u][1] + val[v][1])
            if a < 0:
                b *= -1
            if b <= 0 or b % 2 == 1:
                print(0)
                exit()
            if x == -1:
                x = b // 2
            elif x != b // 2:
                print(0)
                exit()
assert False
print(max(ma - mi + 1, 0) if x == -1 else 1)

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
G = [[] for _ in range(n+1)]
for _ in range(m):
    u, v, s = map(int, input().split())
    G[u].append((v, s))
    G[v].append((u, s))
val = [None] * (n+1)
val[1] = (1, 0)
queue = deque([1])
while queue:
    u = queue.popleft()
    for v, s in G[u]:
        if val[v]:
            continue
        val[v] = (-val[u][0], s - val[u][1])
        queue.append(v)
ma = float('inf')
mi = 1
x = -1
for u in range(1, n+1):
    if val[u][0] == -1:
        ma = min(ma, val[u][1] - 1)
    else:
        mi = max(mi, -val[u][1] + 1)
    for v, s in G[u]:
        if u > v:
            continue
        if val[u][0] + val[v][0] == 0:
            if val[u][1] + val[v][1] != s:
                print(0)
                exit()
        else:
            a = val[u][0] + val[v][0]
            b = s - (val[u][1] + val[v][1])
            if a < 0:
                b *= -1
            if b <= 0 or b % 2 == 1:
                print(0)
                exit()
            if x == -1:
                x = b // 2
            elif x != b // 2:
                print(0)
                exit()
if x != -1:
    if mi <= x <= ma:
        print(1)
    else:
        print(0)
else:
    print(max(ma - mi + 1, 0))
#!/opt/local/bin/python
import math
a = raw_input()
print"%f %f" %(math.pi*int(a)**2.0,2.0*math.pi*int(a))

### FIXED CODE ###

#!/opt/local/bin/python
import math
a = raw_input()
print"%f %f" %(math.pi*float(a)**2.0,2.0*math.pi*float(a))
H,N = map(int, input().split())
A = list(map(input().split()))
if sum(A) >= H:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

H,N = map(int, input().split())
A = list(map(int, input().split()))
if sum(A) >= H:
  print('Yes')
else:
  print('No')
X,N = map(int,input().split())
if N > 0:
    A = list(map(int,input().split()))
    d = {}
    for i in range(101):
        d[i] = 0
    for a in A:
        d[a] = 1
    for i in range(0,100):
        x = X - i
        y = X + i
        if d[x] == 0:
            print(x)
            quit()
        if d[y] == 0:
            print(y)
            quit()
else:
    print(X)

### FIXED CODE ###

X,N = map(int,input().split())
if N > 0:
    A = list(map(int,input().split()))
    d = {}
    for i in range(102):
        d[i] = 0
    for a in A:
        d[a] = 1
    for i in range(0,100):
        x = X - i
        y = X + i
        if d[x] == 0:
            print(x)
            quit()
        if d[y] == 0:
            print(y)
            quit()
else:
    print(X)
class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
    else:
      self.par[y] = x
      self.rank[x] += 1
      
  def same(self, x, y):
    return self.find(x)==self.find(y)
  

N, M, *L = map(int, open('0').read().split())
p = L[:N]
ls = L[N:]
u = UnionFind(N+1)
for x,y in zip(*[iter(ls)]*2):
  u.unit(x,y)
ans = sum(1 if u.same(p,i+1) else 0 for i,p in enumerate(p))
print(ans)

### FIXED CODE ###

from collections import defaultdict
class UnionFind:
  
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0]*n
  
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  
  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    if self.rank[x]<self.rank[y]:
      self.par[x] = y
    else:
      self.par[y] = x
      if self.rank[x]==self.rank[y]:
        self.rank[x] += 1
  
  def same(self, x, y):
    return self.find(x)==self.find(y)
  
N, M = map(int, input().split())
h = [int(i)-1 for i in input().split()]
dic1 = defaultdict(list)
dic2 = defaultdict(list)
u = UnionFind(N)
for i in range(M):
  a, b = map(int, input().split())
  u.unite(a-1,b-1)

for c in range(N):
  p = u.find(c)
  dic1[p] += [c]
  dic2[p] += [h[c]]
ans = 0
for p in dic1.keys():
  dic1[p].sort()
  dic2[p].sort()
  i = 0
  j = 0
  while i<len(dic1[p]) and j<len(dic2[p]):
    if dic1[p][i]==dic2[p][j]:
      i += 1
      j += 1
      ans += 1
    elif dic1[p][i]<dic2[p][j]:
      i += 1
    else:
      j += 1
    
print(ans)
#https://beta.atcoder.jp/contests/abc075
# -*- coding: utf-8 -*-
from collections import Counter
import sys

n,m = map(int,input().split())
line = []
for _ in range(m):
    line.append(list(map(int,input().split())))

line_count = []
for i in line:
    line_count.append(i[0])
    line_count.append(i[1])
line_count = Counter(line_count)

start_point = []
for k,v in line_count.items():
    if v == 1: start_point.append(k)
if len(start_point) == 0:
    print(0)
    sys.exit()

counter = 0
while(True):
    start_point_bu = start_point
    start_point = []
    for i in start_point_bu:
        for index,j in enumerate(line):
            if i in j:
                if j[0] == i : start_point.append(j[1])
                if j[1] == i : start_point.append(j[0])
                line.pop(index)
                counter+=1
            break
    if len(start_point)==0: break
print(counter)


### FIXED CODE ###

#https://beta.atcoder.jp/contests/abc075
# -*- coding: utf-8 -*-
a,b,c = map(int,input().split())

if a == b : print(c)
if b == c : print(a)
if c == a : print(b)
import sys
from collections import defaultdict
readline = sys.stdin.readline

N, M = map(int, readline().split())
G = defaultdict(set)
for v in range(M):
    a, b = map(int, readline().split())
    G[a].add(b)
    G[b].add(a)


def main():

    if M % 2 != 0:
        print(-1)
        return
    ks = []
    for i in G:
        if len(G[i])%2 != 0:
            ks.append(i)
    if len(ks) not in [0, 2]:
        2//0
        print(-1)
        return
    if len(ks) == 0:
        s=t=1
    else:
        s,t=ks
    v=s
    tr = []
    while True:
        tr.append(v)
        if len(G[v]) == 0:
            break
        u = G[v].pop()
        G[u].remove(v)
        v = u
    tr = tr[::-1]
    tr2 = []
    cc = None
    for (i, t) in enumerate(tr):
        if len(G[t]) != 0:
            cc = i
            v = t
            while True:
                tr2.append(v+1)
                if len(G[v]) == 0:
                    break
                u = G[v].pop()
                G[u].remove(v)
                v = u
            break
    if cc != None:
        ind = 0
        for i in range(cc):
            if ind % 2 == 0:
                print(tr[i+1], tr[i])
            else:
                print(tr[i], tr[i+1])
            ind+=1
        for i in range(len(tr2)-1):
            if ind % 2 == 0:
                print(tr2[i+1], tr2[i])
            else:
                print(tr2[i], tr2[i+1])
            ind+=1
        owari = cc+len(tr2)-1
        nokori = M-owari
        for i in range(nokori):
            i = i + cc
            if ind % 2 == 0:
                print(tr[i+1], tr[i])
            else:
                print(tr[i], tr[i+1])
            ind+=1
    else:
        for i in range(M):
            if i %2 == 0:
                print(tr[i+1], tr[i])
            else:
                print(tr[i], tr[i+1])
    return

if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys
from collections import defaultdict
sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
def solve(p, v, rs):
    als = G[v]
    cs = g[v]
    c = 0
    for u in als:
        if u in cs:
            c += solve(v, u, rs)
        elif u != p:
            if v < u:
                c += 1
            rs.add((min(u,v), max(u,v)))
    if p == None:
        return
    elif c%2 != 0:
        rs.add((v, p))
        return 0
    else:
        rs.add((p,v))
        return 1

N, M = map(int, readline().split())
if M %2 != 0:
    print(-1)
else:
    G = defaultdict(set)
    for v in range(M):
        a, b = map(int, readline().split())
        G[a].add(b)
        G[b].add(a)

    stack=[1]
    vs = set([1])
    g = defaultdict(set)
    counter = 1
    while True:
        v = stack.pop()
        for u in G[v]:
            if u in vs:
                continue
            vs.add(u)
            g[v].add(u)
            stack.append(u)
            counter += 1
        if counter == N:
            break
    rs = set()
    solve(None,1, rs)
    for r in rs:
        print(r[0], r[1])
n,m,l=map(int,input().split())
lst=[[]for i in range(n)]
for i in range(n):
    lst[i]=list(map(int,input().split()))
lst2=[[]for j in range(m)]
for i in rnage(m):
    lst2[j=list(map(int,input().split()))
for i in range(n):
    x=0
    for j in range(m):
         x =x+lst[i][j]*lst2[j][i]
    print(x)


### FIXED CODE ###

n,m,l=map(int,input().split())
lst1=[list(map(int,input().split())) for i in range(n)]
lst2=[list(map(int,input().split())) for i in range(m)]
ans=[[0]*l for i in range(n)]
for i in range(n):
    for j in range(l):
        ans[i][j]= str(sum( lst1[i][k]*lst2[k][j] for k in range(m)))
for A in ans:
    print(*A)
S = input().strip()

while True:
  if S.endswith('dream'):
    S = S[:-5]
  elif S.endswith('dreamer'):
    S = S[:-7]
  elif S.endswith('erase'):
    S = S[:-5]
  elif S.endswith('eraser'):
    S = S[:-6]
  else break

if S:
  print("NO")
else:
  print('YES')

### FIXED CODE ###

S = input().strip()

while True:
  if S.endswith('dream'):
    S = S[:-5]
  elif S.endswith('dreamer'):
    S = S[:-7]
  elif S.endswith('erase'):
    S = S[:-5]
  elif S.endswith('eraser'):
    S = S[:-6]
  else:
    break

if S:
  print("NO")
else:
  print('YES')
def saiki(stri, i, nagasa):
    if stri[0, i] == stri[1,i]:
        if(nagasa == 1):
            return 1
        else:
            nagasa -=1
            stri.pop(0)
            i +=1
            saiki(stri, i, nagasa)
    else:
        return 0

import sys
input_str = sys.stdin.readlines()
inputs = list(input_str)

for i in range(len(stri[0])):
    if saiki(inputs[0, i], i, len(inputs[1])) ==1:
        print("Yes")
    else:
        if i == len(stri[0]) -1:
            print("No")
        pass


### FIXED CODE ###

a=input()
b=input()
a=a+a[:-1]
if a.find(b)!=-1:
        print("Yes")
else:
        print("No")
a = [int(input())for i in range(5)]
k = int(input())
print( "Yay!" if max(a)-min(b) > k else ":(" )

### FIXED CODE ###

a = [int(input())for i in range(5)]
k = int(input())
print( "Yay!" if max(a)-min(a) <= k else ":(" )
s = input()

s = s.split(" ")

x1 = int(s[0])
y1 = int(s[1])

x2 = int(s[2])
y2 = int(s[3])

 # X1 - X2 の増加量
zouka_x = abs(int(x1) - int(x2))

 # Y1 - Y2 の増加量
zouka_y = abs(int(y1) - int(y2))



if (x1 <= x2 and y1 <= y2):
    x3 = x2 - zouka_y
    y3 = y2 + zouka_x

    x4 = x1 - zouka_y
    y4 = y1 + zouka_x
elif (x1 > x2 and y1 < y2):
    x3 = x2 - zouka_y
    y3 = y2 - zouka_x

    x4 = x1 - zouka_y
    y4 = y1 - zouka_x
elif (x1 < x2 and y1 < y2):
    x3 = x2 + zouka_y
    y3 = y2 - zouka_x

    x4 = x1 - zouka_y
    y4 = y1 + zouka_x
elif (x1 < x2 and y1 > y2):
    x3 = x2 + zouka_y
    y3 = y2 + zouka_x

    x4 = x1 + zouka_y
    y4 = y1 + zouka_x

print(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4))


### FIXED CODE ###

x1, y1, x2, y2 = map(int, input().split())
 
vector_x, vector_y = x2 - x1, y2 - y1
print(x2 - vector_y, y2 + vector_x, x1 - vector_y, y1 + vector_x)
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,list(input().strip())))

def next(A):
    B=[]
    for i in range(1,len(A)):
        B.append(abs(A[i]-A[i-1]))
    return B

A=next(A)
A=next(A)

if len(A)<=5:
    while len(A)>1:
        A=next(A)
    print(A[0])

else:
    if len(A)%2==1:
        A=next(A)

    if sum(A)%2==1:
        print(1)
    else:
        LEN=len(A)

        from collections import Counter
        C=Counter(A)

        if C[1]>0:
            print(0)
        elif C[0]==1 or C[2]==1:
            print(2)
        else:
            print(0)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,list(input().strip())))

def next(A):
    B=[]
    for i in range(1,len(A)):
        B.append(abs(A[i]-A[i-1]))
    return B

A=next(A)

if len(A)<=3:
    while len(A)>1:
        A=next(A)
    print(A[0])
    sys.exit()

def in2(x):
    if x==0:
        return 0
    ANS=0
    while x%2==0:
        ANS+=1
        x//=2
    return ANS


if not (1 in A):
    LEN=len(A)
    SUM=0
    COMBI=0

    for i in range(LEN):
        if COMBI==0:
            SUM+=A[i]//2

        COMBI=COMBI+in2(LEN-1-i)-in2(i+1)

    if SUM%2==1:
        print(2)
    else:
        print(0)
else:
    LEN=len(A)
    SUM=0
    COMBI=0

    for i in range(LEN):
        if COMBI==0:
            SUM+=A[i]

        COMBI=COMBI+in2(LEN-1-i)-in2(i+1)

    if SUM%2==1:
        print(1)
    else:
        print(0)
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7
N,Q = I()
graph = [-1]*N
roots = [[] for _ in range(N)]
for i in range(N-1):
    a,b = I()
    graph[b-1] = a-1
def dfs(a):
    if a == 0:
        return
    b = graph[a]
    roots[b].append(i)
    dfs(b)
for i in range(N):
    dfs(i)
counter = [0]*N
for i in range(Q):
  p,x = I()
  r = roots[p-1]
  counter[p-1] += x
  if r:
      for j in r:
          counter[j] += x
for c in counter:
    print(c)

### FIXED CODE ###

import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7
N,Q = I()
edge = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = I()
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
ans = [0]*N
for _ in range(Q):
    p,x = I()
    ans[p-1] += x
que = [0]
visited = {0}
while que:
    p = []
    for i in que:
        for j in edge[i]:
            if j in visited:
                continue
            visited.add(j)
            ans[j] += ans[i]
            p.append(j)
    que = p
print(*ans)
import math
a, b, c =map(int, input().split())
r = (c - a - b)/2
l = a * b
if r <= 0:
    print('No')
    exit()
ans = l*l < r * r

print('Yes' if ans else 'No')


### FIXED CODE ###

l =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
i =int(input())
print(l[i-1])
(lambda n,k: print(0 if k==1 else n-k))(*map(int,input().split())

### FIXED CODE ###

(lambda n,k: print(0 if k==1 else n-k))(*list(map(int,input().split())))