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

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

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

mx = 0
d = {}
r = []

for a in A:
    if not a in d:
        d[a] = 0
    d[a] += 1
    if d[a] > mx:
        r = [a]
        mx = d[a]
    elif d[a] == mx:
        r.append(a)
        r.sort()

for i in r:
    print(i)


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

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

mx = 0
d = {}
r = []

for a in A:
    if not a in d:
        d[a] = 0
    d[a] += 1
    if d[a] > mx:
        r = [a]
        mx = d[a]
    elif d[a] == mx:
        r.append(a)

r.sort()
for i in r:
    print(i)
### BUGGY CODE ###

from math import floor
import sys
from copy import copy

from collections import deque
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353




S = input().strip()
D = deque(S)


n = int(input())
reverse = False
for operation in range(n):
    data = input().strip()
    if data[0] == "1":
        if reverse is False:
            reverse = True
        else:
            reverse = False
    else:
        f = data[2]
        ele = data[4]
        if (f == "1" and reverse is False) or (f == "2" and reverse == True):
            D.appendleft(ele)
        else:
            D.append(ele)
#    print(S)
# print(reverse)
if reverse is False:
    for d in D:
        print(d,end="")
else:
    ANS=""
    for d in D:
        ANS+=d
    print(ANS[::-1])


### FIXED CODE ###

from math import floor
import sys
from copy import copy

from collections import deque
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353




S = input().strip()
D = deque(S)


n = int(input())
reverse = False
for operation in range(n):
    data = input().strip()
    if data[0] == "1":
        if reverse is False:
            reverse = True
        else:
            reverse = False
    else:
        f = data[2]
        ele = data[4]
        if (f == "1" and reverse is False) or (f == "2" and reverse == True):
            D.appendleft(ele)
        else:
            D.append(ele)
#    print(S)
# print(reverse)
if reverse is True:
    D.reverse()
# print(*D,end="")
print("".join(D))
### BUGGY CODE ###

from math import ceil


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def solve(goal, count, meta):
    if (goal <= 0):
        return count

    min_count = 999999999

    for m in meta:
        meta2 = list(meta)
        meta2.remove(m)
        c = solve(goal - m[3], count + m[0], meta2)
        if c < min_count:
            min_count = c

    for m in meta:
        if goal - m[0] * m[1] > 0:
            continue
        c = count + ceil(goal / m[1])
        if c < min_count:
            min_count = c

    return min_count


def main():
    d, goal = tuple(input_ints())

    meta = list()
    for i in range(d):
        problems, bonus = tuple(input_ints())
        score = (i + 1) * 100
        meta.append((problems, score, bonus, score * problems + bonus))

    count = solve(goal, 0, meta)
    print(count)


main()


### FIXED CODE ###

from math import ceil


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


cache = dict()


def solve(goal, count, meta):
    if (goal <= 0):
        return count

    s = frozenset([m[1] for m in meta])
    if s in cache:
        return cache[s]

    min_count = 999999999

    for m in meta:
        meta2 = list(meta)
        meta2.remove(m)
        c = solve(goal - m[3], count + m[0], meta2)
        if c < min_count:
            min_count = c

    for m in reversed(meta):
        if goal - m[0] * m[1] > 0:
            continue
        c = count + ceil(goal / m[1])
        if c < min_count:
            min_count = c
        break

    cache[s] = min_count

    return min_count


def main():
    d, goal = tuple(input_ints())

    meta = list()
    for i in range(d):
        problems, bonus = tuple(input_ints())
        score = (i + 1) * 100
        meta.append((problems, score, bonus, score * problems + bonus))

    count = solve(goal, 0, meta)
    print(count)


main()
### BUGGY CODE ###

n = int(input())
p = [int(e) for e in input().split()]
count=0

for i in range(n):
    ng=True
    for j in range(i):
        if p[i] > p[j]:
            ng=False
            break

    if ng:
        count+=1

print (count)

### FIXED CODE ###

n = int(input())
p = [int(e) for e in input().split()]
count=0
p_min=p[0]

for i in range(n):
    if p[i] <= p_min:
        count+=1
#        p_min=min(p[0:i+1])
        p_min=p[i]

print (count)
### BUGGY CODE ###

a, b = map(int,input().split())
ans = max(a,b)
while True:
    if ans % a == 0 and ans % b == 0:
        print(ans)
        break
    ans += 1

### FIXED CODE ###

from fractions import gcd 
a, b = map(int,input().split())
print((a*b)//gcd(a,b))
### BUGGY CODE ###

def main():
  import sys
  input=sys.stdin.readline
  h,w,k=map(int,input().split())
  sx,sy,tx,ty=map(int,input().split())
  calc=lambda x,y:x*1000007+y
  b=[[-1]*(w+2)]
  for i in range(h):
    s=input()
    bb=[-1]
    for j in s:
      if j==".":bb.append(0)
      else:bb.append(-1)
    bb.append(-1)
    b.append(bb)
  b.append([-1]*(w+2))
  from collections import deque
  d=deque()
  d.append((sx,sy))
  s=set()
  while d:
    x,y=d.popleft()
    if calc(x,y)in s:
      s.discard(calc(x,y))
      continue
    if x==tx and y==ty:
      exit(print(b[x][y]))
    for i in range(1,k+1):
      if b[x-i][y]<=b[x][y] and b[x-i][y]!=0:break
      d.append((x-i,y))
      if b[x-i][y]!=0:
        s.add(calc(x-i,y))
      b[x-i][y]=b[x][y]+1
    for i in range(1,k+1):
      if b[x+i][y]<=b[x][y] and b[x+i][y]!=0:break
      d.append((x+i,y))
      if b[x+i][y]!=0:
        s.add(calc(x+i,y))
      b[x+i][y]=b[x][y]+1
    for j in range(1,k+1):
      if b[x][y-j]<=b[x][y] and b[x][y-j]!=0:break
      d.append((x,y-j))
      if b[x][y-j]!=0:
        s.add(calc(x,y-j))
      b[x][y-j]=b[x][y]+1
    for j in range(1,k+1):
      if b[x][y+j]<=b[x][y] and b[x][y+j]!=0:break
      d.append((x,y+j))
      if b[x][y+j]!=0:
        s.add(calc(x,y+j))
      b[x][y+j]=b[x][y]+1
  print(-1)
if __name__ == "__main__":
  main()


### FIXED CODE ###

import sys
input=sys.stdin.readline
h,w,k=map(int,input().split())
si,sj,ti,tj=map(int,input().split())
si-=1
sj-=1
ti-=1
tj-=1
b=[input()for _ in range(h)]
ans=[[-1]*w for _ in range(h)]
ans[si][sj]=0
from collections import deque
d=deque()
d.append((si,sj))
while d:
  x,y=d.popleft()
  if x==ti and y==tj:
    exit(print(ans[x][y]))
  for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:
    for i in range(1,k+1):
      xx=x+dx*i
      yy=y+dy*i
      if not(0<=xx<h and 0<=yy<w) or b[xx][yy]=="@":break
      if 0<=ans[xx][yy]<=ans[x][y]:break
      if ans[xx][yy]==-1:d.append((xx,yy))
      ans[xx][yy]=ans[x][y]+1
print(-1)
### BUGGY 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
from fractions import gcd
from bisect import bisect

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, Q = MAP()
ab = [LIST() for _ in range(N-1)]
px = [LIST() for _ in range(Q)]

tree = defaultdict(list)
for a, b in ab:
	tree[a-1].append(b-1)
	tree[b-1].append(a-1)

dic = defaultdict(int)

for p, x in px:
	dic[p-1] += x

ans = [0]*N

checked = [0]*N
checked[0] = 1

q = deque([])
q.append(0)

while q:
	n = q.popleft()
	ans[n] += dic[n]
	for node in tree[n]:
		if checked[node]:
			continue
		ans[node] += ans[n]
		checked[node] = 1
		q.append(node)

print(*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, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
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

def solve():
	N, Q = MAP()
	ab = [LIST() for _ in range(N-1)]
	tree = defaultdict(list)
	par = [-1]*N
	par[0] = 0
	for a, b in ab:
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)
		par[b-1] = a-1

	px = [LIST() for _ in range(Q)]

	ans = [0] * N  # 答え入れる

	for p, x in px:
		ans[p-1] += x

	
	for i in range(1, N):
		ans[i] += ans[par[i]]

	print(*ans, sep=" ")

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

N = int(input())
a = []
for i in range(N):
        x = int(input())
        a.append(x)

for i in range(N):
        b = []
        for j in range(N):
                if i == j: continue
                b.append(a[j])
        print(max(b))

### FIXED CODE ###

N = int(input())
a = []
for i in range(N):
        x = int(input())
        a.append(x)
m = max(a)
n = a.index(max(a))
for i in range(N):
        if i == n:
                b = a[:n] + a[n+1:]
                print(max(b))
        else:
                print(m)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

n=max(A)

#is_prime[i]にはi-1画素数か否かを示すboolが入る，[0]に1の素数判定がある．
is_prime = [True]*(n+1)
is_prime[0] = False

for i in range(2, n+1):
    if is_prime[i-1]:
        j = 2 * i
        while j <= n:
            is_prime[j-1] = False
            j += i

table = [ i for i in range(1, n+1) if is_prime[i-1]]
#print(table)

lcm=[0]*len(table)



for i in range(N):
    for j in range(len(table)):
        temp=0
        a=A[i]
        while a%table[j]==0:
            temp+=1
            a=a//table[j]
        lcm[j]=max(lcm[j],temp)
        
l=1
for j in range(len(table)):
    l*=pow(table[j],lcm[j])
    

ans=0
mod=10**9+7

for i in range(N):
    ans+=l//A[i]
    ans%=mod
    
print(ans%mod)

### FIXED CODE ###

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

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


for i in range(N):
    a=A[i]
    for j in range(2,a):
        temp=0
        while a%j==0:
            a=a//j
            temp+=1
        lcm[j]=max(lcm[j],temp)
        if a==1 or j*j>A[i]:
            break
    if a!=1:
        lcm[a]=max(lcm[a],1)
                
        
l=1
for d in lcm.items():
    l*=pow(d[0],d[1])
    

ans=0
mod=10**9+7

for i in range(N):
    ans+=l//A[i]
    
print(ans%mod)
### BUGGY CODE ###

import itertools

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

C = list(itertools.combinations(A, 2))

ans = 0
for i, j in C:
    ans += i * j
    ans = ans % (1e9 + 7)
print(int(ans))


### FIXED CODE ###

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

S = sum(A)
S2 = sum(map(lambda x: x * x, A))

print((S*S-S2)//2 % 1000000007)
### BUGGY CODE ###

#atcoder https://atcoder.jp/contests/dp/tasks/dp_b

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


dp = [0] * N
dp[0] = 0

for i in range(1, N):

    dp[i] = min(
        dp[k] + abs(h[i]-h[k]) for k in range(max(i-K,0), i)
    )

print(dp[N-1])


### FIXED CODE ###

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

	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()
### BUGGY CODE ###

n,m=input().split()
n=int(n)
m=int(m)
i=0
x=[]
y=[]
a=list(map(int,input().split()))

a=sorted(a)
while i!=m:
    i=i+1
    x=list(map(int,input().split()))
    y.append(x)

y=sorted(y, key=lambda x: -x[1])

j=0
while True:
    try:
        t=y[0]
        del y[0]
        i=0
        while i!=t[0]:
            i=i+1
            if t[1]>a[j]:
                a[j]=t[1]
                j=j+1
            else:
                break
                

    except:
        break
ans=0
i=0
while True:
    try:
        ans=ans+a[i]
        i=i+1
    except:
        break
print(ans)


### FIXED CODE ###

n,m=input().split()
n=int(n)
m=int(m)
i=0
x=[]
y=[]
a=list(map(int,input().split()))

a=sorted(a)
while i!=m:
    i=i+1
    x=list(map(int,input().split()))
    y.append(x)

y=sorted(y, key=lambda x: -x[1])

j=0
while True:
    try:
        t=y[0]
        del y[0]
        i=0
        while i!=t[0]:
            i=i+1
            if t[1]>a[j]:
                a[j]=t[1]
                j=j+1
            else:
                break
        if t[1] > a[j]:
            pass
        else:
            break

    except:
        break
ans=0
i=0
while True:
    try:
        ans=ans+a[i]
        i=i+1
    except:
        break
print(ans)
### BUGGY CODE ###

# atcoder DPまとめ
# D_Knapsack1

def get_inputs():
    [n, w] = [int(x) for x in input().split()]
    g = []
    for _ in range(n):
        g.append([int(x) for x in input().split()])
    
    return n, w, g


if __name__ == "__main__":
    
    n, w, g = get_inputs()
    
    #### First Try
    # この方法では後半の問題でTLEになってしまう
    # 二重ループの部分で時間がかかっている
    # # dp[i][w]はi-1個目の品物を加えるか吟味した後、重さw以下で最大の価値
    # dp = [[0] * (w + 1) for _ in range(n + 1)]
    #
    # for i in range(1, n + 1):
    #     for wgt in range(w + 1):
    #         if wgt >= g[i -1][0]:
    #             dp[i][wgt] = max(dp[i - 1][wgt - g[i - 1][0]] + g[i - 1][1], dp[i - 1][wgt])
    #         else:
    #             dp[i][wgt] = dp[i - 1][wgt]
    #
    # print(max(dp[n]))

    ### Second Try
    # 動的計画法の部分で、古いiの情報は不要で一つ前の状態さえあれば解ける
    # そこに着目し、かつ不要な判定や更新を減らすために、あるiの時に、
    # 大きなwから最適値を求めるようにする

    # dp[w]は,現在評価中のiにおいて、重さwの時の最大価値の値
    dp = [0] * (w + 1)      # 初期値は０　範囲は0〜wまで

    for i in range(n):      # 品物0からn-1までを評価
        wt, vl = g[i]
        for j in range(w, wt - 1, -1):
            dp[j] = max(dp[j - wt] + vl, dp[j])

    print(max(dp))


### FIXED CODE ###

def calc(num,capacity):
    dp = [0]*(capacity+1)
    for _ in range(num):
        weight, value = map(int, input().split())
        for w in range(capacity,weight - 1,-1):
            tmp = dp[w - weight] + value
            if dp[w] < tmp:
              dp[w] = tmp
    return dp[capacity]
 
num, capacity = map(int, input().split())
print(calc(num,capacity))
### BUGGY CODE ###

from collections import Counter
from itertools import combinations

N=int(input())
count=0
S=[Counter(sorted(input())) for i in range(N)]
for a,b in list(combinations(S, 2)):
    if a==b:
        count+=1
print(count)

### FIXED CODE ###

N=int(input())
count=0
S=[input() for i in range(N)]
d={}

for i in S:
    a=''.join(sorted([c for c in i]))
    if a in d:
        count+=d[a]
        d[a]+=1
    else:
        d[a]=1
print(count)
### BUGGY CODE ###

class LinkedList(object):
    def __init__(self):
        self.first = None
        self.last = None

    def insert(self, key):
        node = {'key':key, 'next':None, 'prev':None}
        if not self.first:
            self.first = self.last = node
        else:
            node['next'] = self.first
            self.first['prev'] = node
            self.first = node

    def delete(self, key):
        node = self.first
        if self.first['key'] == key:
            self.deleteFirst()
            return
        while node['next']:
            if node['key'] == key:
                node['prev']['next'] = node['next']
                node['next']['prev'] = node['prev']
                return
            node = node['next']
        if self.last['key'] == key:
            self.deleteLast()

    def deleteFirst(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.first['next']['prev'] = None
            self.first = self.first['next']

    def deleteLast(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.last['prev']['next'] = None
            self.last = self.last['prev']

    def show(self):
        if not self.first:
            print('')
            return
        node = self.first
        res = [node['key']]
        while node['next']:
            node = node['next']
            res.append(node['key'])
        print(' '.join(res))

def run():
    n = int(input())
    linked_list = LinkedList()
    for _ in range(n):
        order = input().split()
        if order[0] == 'insert':
            linked_list.insert(order[1])
        elif order[0] == 'delete':
            linked_list.delete(order[1])
        elif order[0] == 'deleteFirst':
            linked_list.deleteFirst()
        elif order[0] == 'deleteLast':
            linked_list.deleteLast()
    linked_list.show()

if __name__ == '__main__':
    run()




### FIXED CODE ###

from collections import deque

def run():
    n = int(input())
    dq = deque()
    for _ in range(n):
        order = input()
        if order[0] == 'i':
            dq.appendleft(order[7:])
        elif order[6] == ' ':
            key = order.split()[1]
            if not key in dq:
                continue
            for i in range(len(dq)):
                if dq[i] == key:
                    dq.remove(key)
                    break
        elif order[6] == 'F':
            dq.popleft()
        elif order[6] == 'L':
            dq.pop()

    print(' '.join(dq))

if __name__ == '__main__':
    run()
### BUGGY CODE ###

K,S=input().split()
K,S=[int(K),int(S)]
a=[]
for X in range(K+1):
    for Y in range(K+1):
        for Z in range (K+1):
            if X+Y+Z==S:
                a.append(S)
print(len(a))

### FIXED CODE ###

K,S=input().split()
K,S=[int(K),int(S)]
a=0
for X in range(K+1):
    for Y in range(K+1):
        Z=S-X-Y
        if 0<=Z<=K:
           a+=1 
print(a)
### BUGGY CODE ###

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

for i in range(n):
    ans = 0
    pop = a.pop(i)
    new_a = collections.Counter(a)
    # print(new_a)
    for key,val in new_a.items():
        # print(val)
        if val > 1:
            ans += (val * (val - 1) // 2)
    a.insert(i, pop)
    print(ans)

### FIXED CODE ###

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

total = 0
for key, val in new_a.items():
    if val > 1:
        total += (val * (val - 1) // 2)


for i in a:
    ans = total
    ans -= new_a[i]-1
    print(ans)
### BUGGY CODE ###

import sys
x,y = map(int, input().split())
temp = x
if x == y:
    print(-1)
while True:
    temp += x
    if temp % y != 0:
        print(temp)
        sys.exit()

### FIXED CODE ###

import sys
def gcd(a, b):
        while b:
                a, b = b, a % b
        return a
def lcm(a, b):
    return a * b // gcd (a, b)

x,y = map(int, input().split())
temp = x
if x == y:
    print(-1)
    sys.exit()
while True:
    temp += x
    if temp % y != 0:
        print(temp)
        sys.exit()
    elif temp > lcm(x, y):
        print(-1)
        sys.exit()
### BUGGY CODE ###

n = int(input())
aList = list(map(int, input().split()))
ans = 0
for x in range(10 ** 5):
    num = aList.count(x - 1) + aList.count(x) + aList.count(x + 1)
    if ans < num:
        ans = num
print(ans)

### FIXED CODE ###

import collections

n = int(input())
aList = list(map(int, input().split()))
num = collections.Counter(aList)
ans = 0
for x in range(10 ** 5):
    count = num[x - 1] + num[x] + num[x + 1]
    if ans < count:
        ans = count
print(ans)
### BUGGY CODE ###

a = list(map(int,input().split()))
k = int(a[0])
s = int(a[1])
count = 0

for x in range(k+1):
    if (x == s):
       count += 1
    else: 
        for y in range(k+1):
             if (x + y == s):
                 count += 1
             else:
                for z in range(k+1):
                    if(x + y + z == s):
                        count += 1

print(count)

### FIXED CODE ###

a = list(map(int,input().split()))
k = int(a[0])
s = int(a[1])
count = 0

for x in range(k+1):
    for y in range(k+1):
        if(s-x-y >= 0) and (s-x-y <= k):
            count += 1
print(count)
### BUGGY CODE ###

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

a = 10 ** 7 + 10 ** 6
fact = [0] * a
fact[0] = 1
for i in range(1, a):
    fact[i] = fact[i-1] * i % MOD

inv_fact = [0] * a
inv_fact[a-1] = pow(fact[a-1], MOD-2, MOD)
for i in range(a-1, 0, -1):
    inv_fact[i-1] = inv_fact[i] * i % MOD


def nCk(n, k):
    return (fact[n] * inv_fact[k] * inv_fact[n-k]) % MOD


def nPk(n, k):
    return (fact[n] * inv_fact[n-k]) % MOD


ans = 0
for i in range(N+1):
    tmp = nCk(N, i) * nPk(M, i) * (nPk(M-i, N-i))**2 % MOD
    if i % 2 == 0:
        ans += tmp
    else:
        ans -= tmp
print(ans%MOD)

### FIXED CODE ###

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

a = 10 ** 7 + 10 ** 6
fact = [0] * a
fact[0] = 1
for i in range(1, a):
    fact[i] = fact[i-1] * i % MOD

inv_fact = [0] * a
inv_fact[a-1] = pow(fact[a-1], MOD-2, MOD)
for i in range(a-1, 0, -1):
    inv_fact[i-1] = inv_fact[i] * i % MOD


def nCk(n, k):
    return (fact[n] * inv_fact[k] * inv_fact[n-k]) % MOD


def nPk(n, k):
    return (fact[n] * inv_fact[n-k]) % MOD


ans = 0
for i in range(N+1):
    tmp = nCk(N, i) * nPk(M, i) * (nPk(M-i, N-i))**2 % MOD
    if i % 2 == 0:
        ans += tmp
    else:
        ans -= tmp
print(ans%MOD)
### BUGGY CODE ###

from sys import stdin
input = stdin.readline
from collections import defaultdict, deque
h, w, m = map(int,input().split())
row = defaultdict(int)
col = defaultdict(int)
grid = defaultdict(int)
for _ in range(m):
    x,y = map(int,input().split())
    row[x]+=1
    col[y]+=1
    grid[(x,y)]=1


row = sorted(list(row.items()), key = lambda x: x[1], reverse = True)
col = sorted(list(col.items()), key = lambda x: x[1], reverse = True)
i,j = 0,0
ans = row[0][1]+col[0][1] + (-1 if grid[(row[0][0], col[0][0])] else 0)
dq = deque([(i,j)])
while dq:
    i,j = dq.popleft()
    temp = row[i][1]+col[j][1] + (-1 if grid[(row[i][0], col[j][0])] else 0)
    if ans<temp:
        ans = temp
        break
    
    if i+1<len(row):dq.append((i+1,j))
    if j+1<len(col):dq.append((i,j+1))

    
print(ans)

### FIXED CODE ###

from sys import stdin
input = stdin.readline
from collections import defaultdict, deque
h, w, m = map(int,input().split())
row = defaultdict(int)
col = defaultdict(int)
grid = defaultdict(int)
for _ in range(m):
    x,y = map(int,input().split())
    row[x]+=1
    col[y]+=1
    grid[(x,y)]=1


row = sorted(list(row.items()), key = lambda x: x[1], reverse = True)
col = sorted(list(col.items()), key = lambda x: x[1], reverse = True)


#print(row)
#print(col)

t = len(row)
for idx, ele in enumerate(row):
    i,j = ele
    if j!=row[0][1]:
        t = idx
        break
row = row[:t]
t = len(col)
for idx, ele in enumerate(col):
    i,j = ele
    if j!=col[0][1]:
        t = idx
        break
col = col[:t]

#print(row)
#print(col)
#print(grid)

ans = row[0][1]+col[0][1] + (-1 if grid[(row[0][0], col[0][0])] else 0)

i,j = 0,0
for r,cr in row:
    for c,cc in col:
        if not grid[(r,c)]:
            ans = cr+cc
            break
print(ans)


# dq = deque([(i,j)])
# while dq:
#     i,j = dq.popleft()
#     temp = row[i][1]+col[j][1] + (-1 if grid[(row[i][0], col[j][0])] else 0)
#     if ans<temp:
#         ans = temp
#         break
    
#     if i+1<len(row):dq.append((i+1,j))
#     if j+1<len(col):dq.append((i,j+1))

    
# print(ans)