Harryxun/stf_run huggingface dataset:
import collections
from scipy.sparse import lil_matrix
from scipy.sparse.csgraph import bellman_ford

N, M, P = [int(_) for _ in input().split()]
ABC = [[int(_) for _ in input().split()] for _ in range(M)]
cd = collections.defaultdict
Ga = cd(set)
Gb = cd(set)
ok = cd(int)
for a, b, c in ABC:
    Ga[a].add(b)
    Gb[b].add(a)
#dfs
for pair in [[1, Ga], [N, Gb]]:
    S = pair
    Gn = pair.pop()
    visited = [0] * (N + 1)
    while S:
        s = S.pop()
        if not visited[s]:
            visited[s] = 1
            ok[s] += 1
            for ns in Gn[s]:
                S += [ns]
G = lil_matrix((N + 1, N + 1))
for a, b, c in ABC:
    if ok[a] == ok[b] == 2:
        G[a, b] = P - c

dist_matrix = bellman_ford(G, directed=True, indices=1)
try:
    print(max(-int(dist_matrix[-1]), 0))
except:
    print(-1)


### FIXED CODE ###

import collections
N, M, P = [int(_) for _ in input().split()]
ABC = [[int(_) for _ in input().split()] for _ in range(M)]
cd = collections.defaultdict
Ga = cd(set)
Gb = cd(set)
G = []
ok = cd(int)
for a, b, c in ABC:
    Ga[a].add(b)
    Gb[b].add(a)
#dfs
for pair in [[1, Ga], [N, Gb]]:
    S = pair
    Gn = pair.pop()
    visited = [0] * (N + 1)
    while S:
        s = S.pop()
        if not visited[s]:
            visited[s] = 1
            ok[s] += 1
            for ns in Gn[s]:
                S += [ns]
for a, b, c in ABC:
    if ok[a] == ok[b] == 2:
        G += [(a, b, P - c)]


def bellman_ford(V, G, i):
    INF = float('inf')
    D = [INF] * V
    D[i] = 0
    for _ in range(V):
        update = False
        for s, t, d in G:
            if D[s] != INF and D[t] > D[s] + d:
                D[t] = D[s] + d
                update = True
        if not update:
            return D
        if _ == V:
            return False


a = bellman_ford(N + 1, G, 1)
try:
    print(max(-a[-1], 0))
except:
    print(-1)
n = int(input())
l = list(map(int, input().split()))
b = []

def gcd(a,b):
	while b:
		a, b = b, a % b
	return a
if n == 1:
	print(l[0])
elif n == 2:
	print(gcd(l[0],l[1]))
elif n == 3:
	print(max(gcd(l[0],l[1]),gcd(l[0],l[2]),gcd(l[2],l[1])))
else:
	for i in range(n):
		tmp = l
		tmp.pop(i)
		x = gcd(tmp[0],tmp[1])
		for j in list(range(2, n-1)):
			x = gcd(x,tmp[j])
		b.append(x)
	print(max(b))

### FIXED CODE ###

def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(max(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  print(no)
number = int(input())
if number * 2 = 0:
	odd_num = number // 2
	percent = odd_num / number
    print(percent)
else:
	odd_num = number // 2 + 1
    percent = odd_num / number
	print(percent)  



### FIXED CODE ###

number = int(input())
if number % 2 == 0:
	odd_num = number // 2
	percent = odd_num / number
else:
	odd_num = number // 2 + 1
	percent = odd_num / number

print(percent)
# -*- coding: utf-8 -*-

def qui(l):
    num = len(l)
    if num == 1: return l
    piv = 0
    piv2 = len(l)-1
    piv3 = int(len(l)/2)
    if l[piv] > l[piv2] and l[piv2] >l[piv3] :
        piv = piv2
    elif l[piv] > l[piv3] and l[piv3] >l[piv2]:
        piv = piv3
    mini = []
    maxi = []

    for i in range(0,len(l)):
        if(i == piv) :
            continue
        if l[piv] > l[i]:
            mini.append(l[i])
        elif l[piv] <= l[i]:
            maxi.append(l[i])
    return qui(mini) + [l[piv]] + qui(maxi)

input()
list1 = list(map(lambda x: int(x), input().split(" ")))
result = qui(list1)

print(' '.join(map(str, result)))

### FIXED CODE ###

# -*- coding: utf-8 -*-

import random
def qui(l):
    num = len(l)
    if num <= 1:
        return l
    piv = random.randrange(0,len(l))
    piv2 = random.randrange(0,len(l))
    piv3 = random.randrange(0,len(l))
    if (l[piv] > l[piv2]) and (l[piv2] > l[piv3]):
        piv = piv2
    elif (l[piv] > l[piv3]) and (l[piv3] > l[piv2]):
        piv = piv3
    elif (l[piv] < l[piv2]) and (l[piv2] < l[piv3]):
        piv = piv2
    elif (l[piv] < l[piv3]) and (l[piv3] < l[piv2]):
        piv = piv3
    else:
        pass
    mini = []
    middlei = []
    maxi = []

    for i in range(0,len(l)):
        if l[i] == l[piv]:
            middlei.append(l[i])
        elif l[piv] > l[i]:
            mini.append(l[i])
        elif l[piv] <= l[i]:
            maxi.append(l[i])
    mini = qui(mini)
    maxi = qui(maxi)
    return mini+ middlei+maxi
input()
list1 = input().split(" ")
for i in range(0, len(list1)):
    list1[i] = int(list1[i])

result = qui(list1)

print(' '.join(map(str, result)))
from collections import deque


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

A = deque(int(a) for a in input().split())
B = deque(int(b) for b in input().split())

ans = 0
while (len(A) or len(B)) and k:
    a = A[0] if len(A) else k + 1
    b = B[0] if len(B) else K + 1
    if a >= b:
        if k - b >= 0:
            k -= B.popleft()
            ans += 1
            continue
        else:
            break
    else:
        if k - a >= 0:
            k -= A.popleft()
            ans += 1
            continue
        else:
            break

print(ans)



### FIXED CODE ###

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
import numpy as np
import bisect 

h, w = list(map(int, input().split()))
d = {".":0, "#":1}
ss = np.array([list(input()) for _ in range(h)])
ss = np.array([[d[x] for x in s] for s in ss])

ans = 0
ws = np.zeros((h, w))
hs = np.zeros((h, w))

i = 0
while i < h:
	j = 0
	while j < w:
		if ss[i, j] == 0:
			end = w
			for k in range(j + 1, w):
				if ss[i, k] == 1:
					end = k
					break
			ws[i, j:end] = end - j
			j = end + 1
		else:
			j += 1
	i += 1

j = 0
while j < w:
	i = 0
	while i < h:
		if ss[i, j] == 0:
			end = h
			for k in range(i + 1, h):
				if ss[k, j] == 1:
					end = k
					break
			hs[i:end, j] = end - i
			i = end + 1
		else:
			i += 1
	j += 1

# print(ss)
# print(ws)
# print(hs)
print(max(int(np.amax(ws + hs) - 1), 0))


### FIXED CODE ###

import numpy as np

h, w = list(map(int, input().split()))
d = {".":1, "#":0}
ss = np.array([list(input()) for _ in range(h)]) == "."
ss_t = ss.transpose()

ls, rs, us, ds = [np.zeros((h, w), dtype=int) for _ in range(4)]

ls, rs = ls.transpose(), rs.transpose()

ls[0] = ss_t[0]
rs[w-1] = ss_t[w-1]
us[0] = ss[0]
ds[h-1] = ss[h-1]

for i in range(1, w):
	ls[i] = ss_t[i] * (ls[i - 1] + 1)

for i in reversed(range(w - 1)):
	rs[i] = ss_t[i] * (rs[i + 1] + 1)

for i in range(1, h):
	us[i] = ss[i] * (us[i - 1] + 1)

for i in reversed(range(h - 1)):
	ds[i] = ss[i] * (ds[i + 1] + 1)

# print(ss)
# print(ls)
# print(rs)
# print(us)
# print(ds)
print(max(np.amax((ls.transpose() + rs.transpose() + us + ds) - 3), 0))
s, t = map(input().split())
a, b = map(int, input().split())
u = input()

if s, t == u:
  print(a + b - 1)
else:
  print(a + b)

### FIXED CODE ###

s, t = map(str, input().split())
a, b = map(int, input().split())
u = input()
if s == u:
  print(a - 1, b)
else:
  print(a, b - 1)
α = int(input())
if α.isupper():
  print('A')
else:
  print('a')

### FIXED CODE ###

α = input()
if α.isupper():
  print('A')
else:
  print('a')
R = int(input())
if R < 1200:
  print("ABC")
else:
    if R < 2800:
      print("ARC")
  else:
      print("AGC")
  

### FIXED CODE ###

R = int(input())
if R < 1200:
  print("ABC")
else:
  if R < 2800:
    print("ARC")
  else:
    print("AGC")
S, T = input.split()
print(T + S)

### FIXED CODE ###

S, T = input().split()
print(T + S)
x,y=map(int,input().split())
def cal(number,mod):
    m=mod-2
    mod2=""
    while m!=0:
        if m%2==0:
            mod2="0"+mod2
        else:
            mod2="1"+mod2
        m=m//2
    two=[]
    for i in range(len(mod2)):
        if mod2[len(mod2)-1-i]=="1":
            two.append(i)
    ret=1
    for i in two:
        v=i
        retsub=number
        while v>0:
            retsub=retsub**2
            retsub=retsub%mod
            v-=1
        ret*=retsub
    ret=ret%mod
    return ret
ans=0
M=10**9+7
if (2*x-y)%3==0:
    n=(x+y)//3
    r=(2*x-y)//3
    if n<r:
        print(0)
        exit()
    l=[0]
    num=1
    for i in range(1,n+1):
        p=(num*i)%(M)
        l.append(p)
        num=p
    a=l[n]
    b=cal(l[n-r],M)
    c=cal(l[r],M)
    ans=(a*b*c)%M

print(ans)


### FIXED CODE ###

x,y=map(int,input().split())
def cal(number,mod):
    m=mod-2
    mod2=""
    while m!=0:
        if m%2==0:
            mod2="0"+mod2
        else:
            mod2="1"+mod2
        m=m//2
    two=[]
    for i in range(len(mod2)):
        if mod2[len(mod2)-1-i]=="1":
            two.append(i)
    ret=1
    for i in two:
        v=i
        retsub=number
        while v>0:
            retsub=retsub**2
            retsub=retsub%mod
            v-=1
        ret*=retsub
    ret=ret%mod
    return ret
ans=0
M=10**9+7
if (2*x-y)%3==0:
    n=(x+y)//3
    r=(2*x-y)//3
    if n<r or r<0:
        print(0)
        exit()
    l=[1]
    num=1
    for i in range(1,n+1):
        p=(num*i)%(M)
        l.append(p)
        num=p
    a=l[n]
    b=cal(l[n-r],M)
    c=cal(l[r],M)
    ans=(a*b*c)%M
print(ans)
r = int(input())
print(3 * a ** 2)


### FIXED CODE ###

r = int(input())
print(3 * r ** 2)
N = int(input())
a = [int(input()) for _ in range(N)]
mod = 998244353
suma = sum(a)
memo = [[0]*(suma+1) for _ in range(N+1)]
memo[0][0] = 1
memoe = [[0]*(suma+1) for _ in range(N+1)]
memoe[0][0] = 1

ttl = 3
for i in range(N-1):
  ttl *=3
  ttl %= mod

for i in range(1, N+1):
  memotmp = memo[i-1]
  memotmp = [0]*a[i-1] + memotmp
  for j in range(sum(a[:i])+1):
    memo[i][j] = (memo[i-1][j]*2 + memotmp[j])%mod
    memoe[i][j] = (memoe[i-1][j] + memotmp[j])%mod

ans = sum(memo[N][(suma-1)//2+1:])
if suma%2==0:
  ans -= memoe[N][suma/2]
  
print(((ttl - ans*3)%mod+mod)%mod)

### FIXED CODE ###

import numpy as np
N = int(input())
a = [int(input()) for _ in range(N)]
mod = 998244353
suma = sum(a)
memo = np.zeros((N+1, suma+1), dtype=np.int)
memo[0][0] = 1
memoe = np.zeros((N+1, suma+1), dtype=np.int)
memoe[0][0] = 1

ttl = 3
for i in range(N-1):
  ttl *=3
  ttl %= mod

for i in range(1, N+1):
  memotmp = memo[i-1]
  memotmpe = memoe[i-1]
  memotmp = np.concatenate((np.zeros((a[i-1]), dtype=np.int), memotmp),axis=1)
  memotmpe = np.concatenate((np.zeros((a[i-1]), dtype=np.int), memotmpe),axis=1)
  memo[i] = (memo[i-1]*2 + memotmp[:suma+1])%mod
  memoe[i] = (memoe[i-1] + memotmpe[:suma+1])%mod

ans = sum(memo[N][(suma-1)//2+1:])
if suma%2==0:
  ans -= memoe[N][suma/2]
  
print(((ttl - ans*3)%mod+mod)%mod)
#!python3

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

# odd
def solve1():
    assert False
    return [(i + 2, N - i) for i in range(M)]        


# even
def solve2():
    t = (N - 2) // 4
    l = [(i + 1, N - i) for i in range(t)]
    n = (N - 2) // 2 - t
    l = l + [(N // 2 + 1 + i, N // 2 - i) for i in range(n)]
    return l[:M]


def main():
    l = solve1() if N % 2 else solve2()
    for ans in l:
        print(*ans)
    

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!python3

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

# odd
def solve1():
    return [(i + 2, N - i) for i in range(M)]        


# even
def solve2():
    t = (N - 2) // 4
    l = [(i + 2, N - i) for i in range(t)]
    n = (N - 2) // 2 - t
    l = l + [(N // 2 + 1 + i, N // 2 - i) for i in range(n)]
    return l[:M]


def main():
    l = solve1() if N % 2 else solve2()
    for ans in l:
        print(*ans)
    

if __name__ == "__main__":
    main()
import collections

n = int(input())
V = [int(x) for x in input().split()]
V_even = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 0])
V_odd = collections.Counter([V[i] for i in range(len(V)) if i % 2 == 1])
even_most = V_even.most_common()
odd_most = V_odd.most_common()
if even_most[0][0] is not odd_most[0][0]:
    ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))
else:
    if even_most[0][1] >= odd_most[0][1]:
        ans = n/2 - V_even[even_most[0][0]] + n/2 - V_odd[odd_most[1][0]]
    else:
        ans = n/2 - V_even[even_most[1][0]] + n/2 - V_odd[odd_most[0][0]]
    print(int(ans))

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()
v = LIST()

v_odd = [v[i] for i in range(n) if i % 2 == 1]
v_even = [v[i] for i in range(n) if i % 2 == 0]

count_odd = Counter(v_odd)
count_even = Counter(v_even)

if count_odd.most_common()[0][0] != count_even.most_common()[0][0]:
	print(int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[0][1]))
else:
	if len(count_odd) == 1 and len(count_even) == 1:
		print(int(n/2))
	else:
		if len(count_odd) == 1:
			print(int(n/2 - count_even.most_common()[1][1]))
		elif len(count_even) == 1:
			print(int(n/2 - count_odd.most_common()[1][1]))
		else:
			tmp1 = int(n/2-count_odd.most_common()[1][1] + n/2 - count_even.most_common()[0][1])
			tmp2 = int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[1][1])
			print(min(tmp1, tmp2))
from collections import Counter
from operator import mul
from functools import reduce
from math import factorial


def solve(s):
    n, m = map(int, s.split())
    divisor = []
    for i in range(2, int(m**0.5) + 1):
        if m % i == 0:
            divisor.append(i)
    divisor += [m // d for d in divisor[::-1]] + [m]
    ld = len(divisor)

    def search(ded, use, j):
        if ded == 0:
            return 0
        if ded == 1:
            count = Counter(use)
            base = reduce(mul, range(n - len(use) + 1, n + 1))
            for v in list(count.values()):
                base //= factorial(v)
            return base
        if len(use) >= n:
            return 0

        tmp = [
            search(ded // divisor[i], use + [divisor[i]], i)
            for i in range(j, ld)
            if ded % divisor[i] == 0
        ]
        return sum(tmp) if tmp else 0

    return search(m, [], 0) % (10**9 + 7)


print(solve(input()))


### FIXED CODE ###

import math

# import time


def get_primes(n):
    primes = []
    checks = [True for _ in range(int(math.sqrt(n)) + 1)]
    checks[0] = checks[1] = False
    for i in range(2, len(checks)):
        if checks[i]:
            primes.append(i)
            tmp = 0
            while i + tmp * i < len(checks):
                checks[i + tmp * i] = False
                tmp += 1
    return primes


def combination(a, b):
    i = 1
    for _i in range(a - b + 1, a + 1):
        i *= _i
    return i // math.factorial(b)


n, m = map(int, input().split())
# start = time.time()
primes = get_primes(m)
elems = []
m_copy = m
divides = dict()
for _p in primes:
    while m_copy % _p == 0:
        m_copy = m_copy // _p
        if str(_p) in divides.keys():
            divides[str(_p)] += 1
        else:
            divides[str(_p)] = 1
if m_copy > 1:
    divides[str(m_copy)] = 1
# print(primes)

# print(time.time() - start)
ans = 1
for i in divides.values():
    ans *= combination(i + n - 1, i)
print(ans % (1000000007))
# print(time.time() - start)
x = N * A
y = B

li = [x,y]
print(min(li))

### FIXED CODE ###

N, A, B = map(int, input().split())

x = N*A
y = B

li = [x,y]
print(min(li))
from collections import deque
n = int(input())

num_to_alp = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e', 5:'f', 6:'g', 7:'h', 8:'i', 9:'j'}
alp_to_num = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9}
words = deque([deque([0])])

def next_letters(x):
    letters = deque([])
    for i in range(x + 2):
        letters.append(i)
    return letters

while len(words[0]) < n:
    word = words.popleft()
    letters = next_letters(max(word[-1], max(word) - 1))
    for l in letters:
        l = deque([l])
        words.append(word + l)

for word in words:
    word = [num_to_alp[i] for i in word]
    print(''.join(word))

### FIXED CODE ###

from collections import deque
n = int(input())

num_to_alp = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e', 5:'f', 6:'g', 7:'h', 8:'i', 9:'j'}
alp_to_num = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9}
words = deque([[0]])

def next_letters(x):
    letters = deque([])
    for i in range(x + 2):
        letters.append(i)
    return letters

while len(words[0]) < n:
    word = words.popleft()
    letters = next_letters(max(word))
    for l in letters:
        l = [l]
        words.append(word + l)

for word in words:
    word = [num_to_alp[i] for i in word]
    print(''.join(word))
lst=input().split()
lst_i=list(map(lambda i : int(i),lst))
x_1=lst_i[0]
y_1=lst_i[1]
x_2=lst_i[2]
y_2=lst_i[3]
dis=((x_1-y_1)**2+(x_2-y_2)**2)**(1/2)
print(dis)


### FIXED CODE ###

lst=input().split()
lst=list(map(lambda i:float(i),lst))
x_1=lst[0]
x_2=lst[1]
y_1=lst[2]
y_2=lst[3]
dis=((x_1-y_1)**2+(x_2-y_2)**2)**(1/2)
print(dis)
from functools import lru_cache

N, K = map(int,input().split())
 
@lru_cache(None)
def F(N, K):
    """N以下で0でないものがちょうどK個。0を含める"""
#     assert N >= 0
    if N < 10:
        if K == 0:
            return 1
        if K == 1:
            return N
        return 0
    q,r = divmod(N,10)
    ret = 0
    if K >= 1:
        # 1の位が nonzero
        ret += F(q, K-1) * r
        ret += F(q-1, K-1) * (9-r)
    # 1の位が zero
    ret += F(q, K)
    return ret

 
print(F(N, K))


### FIXED CODE ###

from functools import lru_cache

N=int(input())
K=int(input())
 
@lru_cache(None)
def F(N, K):
    """N以下で0でないものがちょうどK個。0を含める"""
#     assert N >= 0
    if N < 10:
        if K == 0:
            return 1
        if K == 1:
            return N
        return 0
    q,r = divmod(N,10)
    ret = 0
    if K >= 1:
        # 1の位が nonzero
        ret += F(q, K-1) * r
        ret += F(q-1, K-1) * (9-r)
    # 1の位が zero
    ret += F(q, K)
    return ret
 
# F(100, 1), F(25, 2), F(314159, 2)
 
print(F(N, K))
lenmax = lambda x, y: x if len(x) > len(y) else y
dp = {("","") : ""}

def lcs(x,y):
    if (x,y) in dp:
        return dp[(x,y)]

    if x == "" or y == "":
        a = ""
    elif x[-1] == y[-1]:
        a = lcs(x[:-1],y[:-1]) + x[-1]
    else:
        a = lenmax(lcs(x[:-1],y), lcs(x,y[:-1]))
    dp[(x,y)] = a
    return a

print(lcs(input(),input()))

### FIXED CODE ###

S,T = input(),input()
x,y = len(S),len(T)

dp = [[0]*(y+1) for _ in range(x+1)]

for i,s in enumerate(S):
  for j,t in enumerate(T):
    dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j], dp[i][j] + int(s==t))
    
a = ""
while x > 0 and y > 0:
  if dp[x][y] == dp[x-1][y]:
    x -= 1
  elif dp[x][y] == dp[x][y-1]:
    y -= 1
  else:
    x -= 1
    y -= 1
    a += S[x]

print(a[::-1])
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.full((N+1, K+1), np.inf, dtype=float)
dp[1] = np.zeros(K+1)
for i in range(1, N):
    k = 1
    while i >= k >= 0:
        dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k])
        k += 1
print(int(min(dp[N])))




### FIXED CODE ###

N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])
string = input()
num = int(input())

count=1
out =''
for s in string:
    if count=num:
        out=out+s
        count=1
    count+1

### FIXED CODE ###

l = input().split()
if int(l[0])+int(l[1])==15:
    print('+')
elif int(l[0])*int(l[1]) ==15:
    print('*')
else:
    print('x')
#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

graph = [set([]) for _ in range(N+1)]
for a,b in AB:
    graph[a].add(b)
    graph[b].add(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
check = [False for _ in range(N+1)]
check[1] = True
#check[i]:i番目の頂点を発見した
#check[i] == True and i in graph[j]ならiはjの親

for p,x in PX:
    counter[p] += x

def cal(graph,counter,edge):
    for e in graph[edge]:
        if not check[e]:
            counter[e] += counter[edge]
            check[e] = True
            cal(graph,counter,e)

cal(graph,counter,1)

print(str(counter[1]),end="")
for i in range(2,N+1):
    print(" "+str(counter[i]),end="")
print()


### FIXED CODE ###

#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

graph = [[] for _ in range(N+1)]

for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
parent = [None for _ in range(N+1)]

for p,x in PX:
    counter[p] += x

def dfs(graph,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

dfs(graph,counter,1)

ans = " ".join(map(str,counter[1:]))
print(ans)
def resolve():
    h,w,m = map(int, input().split())
    mine = []
    mineh = [0]*h
    minew = [0]*w
    for i in range(m):
        a,b = map(int, input().split())
        a -= 1
        b -= 1
        mine.append((a,b))
        mineh[a] += 1
        minew[b] += 1
    mine = set(mine)
    maxh = max(mineh)
    hnum = []
    maxw = max(minew)
    wnum = []
    for i in range(h):
        if mineh[i] == maxh:
            hnum.append(i)
        if minew[i] == maxw:
            wnum.append(i)
    hnum = set(hnum)
    wnum = set(wnum)
    NO = 0
    for i, j in mine:
        if i in hnum and j in wnum:
            NO += 1
    if len(hnum)*len(wnum) > NO:
        print(maxw+maxh)
    else:
        print(maxw+maxh-1)
resolve()

### FIXED CODE ###

def resolve():
    h,w,m = map(int, input().split())
    mine = []
    mineh = [0]*h
    minew = [0]*w
    for i in range(m):
        a,b = map(int, input().split())
        a -= 1
        b -= 1
        mine.append((a,b))
        mineh[a] += 1
        minew[b] += 1
    mine = set(mine)
    maxh = max(mineh)
    hnum = []
    maxw = max(minew)
    wnum = []
    for i in range(h):
        if mineh[i] == maxh:
            hnum.append(i)
    for i in range(w):
        if minew[i] == maxw:
            wnum.append(i)
    hnum = set(hnum)
    wnum = set(wnum)
    NO = 0
    for i, j in mine:
        if i in hnum and j in wnum:
            NO += 1
    if len(hnum)*len(wnum) > NO:
        print(maxw+maxh)
    else:
        print(maxw+maxh-1)
resolve()