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

import sys
from collections import deque
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from bisect import bisect, bisect_left

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    c = a * b
    while a % b > 0:
        a, b = b, a % b
    return b

def solve():
    input = sys.stdin.readline
    mod = 7 + 10 ** 9
    N = int(input())
    A = [int(a) for a in input().split()]
    if N == 1: print(1)
    else:
        lcm = A[0]
        for i in range(1, N):
            gcd_a = gcd(lcm, A[i])
            lcm = lcm * A[i] // gcd_a
        sumB = 0
        for i in range(N):
            sumB += lcm // A[i]
            sumB %= mod

        print(sumB)
    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys
from collections import deque
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from bisect import bisect, bisect_left

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    c = a * b
    while a % b > 0:
        a, b = b, a % b
    return b

def solve():
    input = sys.stdin.readline
    mod = 7 + 10 ** 9
    N = int(input())
    A = [int(a) for a in input().split()]
    if N == 1: print(1)
    else:
        lcm = A[0]
        for i in range(1, N):
            gcd_a = gcd(lcm, A[i])
            lcm = lcm * A[i] // gcd_a
        lcm %= mod
        sumB = 0
        for i,a in enumerate(A):
            sumB += lcm * pow(a, mod - 2, mod)
            sumB %= mod

        print(sumB)
    return 0

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

H,W = map(int,input().split())
State = []
for i in range(H):
    State.append(input())
starts = [(i%H,i//H) for i in range(H*W)]
goals = [(i%H,i//H) for i in range(H*W)]
from collections import deque
def min_dist(start,goal):
    visited = [[False for i in range(W)] for j in range(H)]
    dists = [[float('inf') for i in range(W)] for j in range(H)]
    dists[start[0]][start[1]]=0
    diffs = [(0,1),(1,0),(0,-1),(-1,0)]
    Q = deque([start])
    while Q:
        current_pos = Q.pop()
        for diff in diffs:
            next_pos = (current_pos[0]-diff[0],current_pos[1]-diff[1])
            if next_pos[0] < H and next_pos[0] >= 0 and next_pos[1] < W and next_pos[1] >= 0:
                if State[next_pos[0]][next_pos[1]] == '.':
                    dists[next_pos[0]][next_pos[1]] = min(dists[current_pos[0]][current_pos[1]]+1,dists[next_pos[0]][next_pos[1]])
                    if not visited[next_pos[0]][next_pos[1]]:
                        visited[next_pos[0]][next_pos[1]] = True
                        Q.appendleft(next_pos)
    return dists[goal[0]][goal[1]]
max_dist = -100000
for start in starts:
    for goal in goals:
        if State[start[0]][start[1]] == '#' or State[goal[0]][goal[1]] == '#':
            continue
        a = min_dist(start,goal)
        if a != float('inf'):
            if a > max_dist:
                max_dist = a
print(max_dist)


### FIXED CODE ###

H,W = map(int,input().split())
State = []
for i in range(H):
    State.append(input())
starts = [(i%H,i//H) for i in range(H*W)]
goals = [(i%H,i//H) for i in range(H*W)]
from collections import deque
def min_dist(start):
    visited = [[False for i in range(W)] for j in range(H)]
    dists = [[float('inf') for i in range(W)] for j in range(H)]
    dists[start[0]][start[1]]=0
    diffs = [(0,1),(1,0),(0,-1),(-1,0)]
    Q = deque([start])
    while Q:
        current_pos = Q.pop()
        for diff in diffs:
            next_pos = (current_pos[0]-diff[0],current_pos[1]-diff[1])
            if next_pos[0] < H and next_pos[0] >= 0 and next_pos[1] < W and next_pos[1] >= 0:
                if State[next_pos[0]][next_pos[1]] == '.':
                    dists[next_pos[0]][next_pos[1]] = min(dists[current_pos[0]][current_pos[1]]+1,dists[next_pos[0]][next_pos[1]])
                    if not visited[next_pos[0]][next_pos[1]]:
                        visited[next_pos[0]][next_pos[1]] = True
                        Q.appendleft(next_pos)
    return dists
max_dist = -100000
for start in starts:
    if State[start[0]][start[1]] == '.':
        dists = min_dist(start)
        local_max_dist = -1000000
        for i in range(W):
            for j in range(H):
                if dists[j][i] != float('inf'):
                    if local_max_dist < dists[j][i]:
                        local_max_dist = dists[j][i]
        if local_max_dist > max_dist:
            max_dist = local_max_dist
print(max_dist)
### BUGGY CODE ###

class UnionFind():

    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0 for i in range(n)]
        self.mems = [{i} for i in range(n)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if (root_x == root_y):
            return
        else:
            self.parent[root_y] = root_x
            self.mems[root_x] = self.mems[root_x] | self.mems[root_y]
            if self.rank[root_x] == self.rank[root_y]:
                self.rank[root_x] += 1

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def memsInGroup(self, x):
        root = self.find(x)
        return self.mems[root]

    def sizeOfGroup(self, x):
        return len(self.memsInGroup(x))


N, K, L = map(int, input().split())

road = UnionFind(N)
train = UnionFind(N)

for i in range(K):
    p, q = map(int, input().split())
    road.unite(p-1, q-1)

for j in range(L):
    r, s = map(int, input().split())
    train.unite(r-1, s-1)

for i in range(N):
    road.unite(i, i)
    train.unite(i, i)

for i in range(N):
    conByRoad = road.memsInGroup(i)
    conByTrain = train.memsInGroup(i)
    # print(conByRoad, conByTrain)

    ans = len(set(conByRoad) & set(conByTrain))
    print(ans)


### FIXED CODE ###

from collections import Counter
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0 for i in range(n)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if (root_x == root_y):
            return
        elif self.rank[root_x] > self.rank[root_y]:
            self.parent[root_y] = root_x

        elif self.rank[root_y] > self.rank[root_x]:
            self.parent[root_x] = root_y

        else:
            self.parent[root_x] = root_y
            self.rank[root_y] += 1

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def memsInGroup(self, x):
        """
        O(N)かかります
        """
        root = self.find(x)
        return [i for i in range(N) if root == self.find(i)]

    def sizeOfGroup(self, x):
        return len(self.memsInGroup(x))

N, K, L = map(int, input().split())

road = UnionFind(N)
train = UnionFind(N)

for i in range(K):
    p, q = map(int, input().split())
    road.unite(p-1, q-1)

for j in range(L):
    r, s = map(int, input().split())
    train.unite(r-1, s-1)

pair = [(road.find(i), train.find(i)) for i in range(N)]
# print(pair)
c = Counter(pair)
# print(c)
ans = [c[i] for i in pair]
# print(ans)
print(*ans)
### BUGGY CODE ###

N = int(input())

def find(x, U, r):
  while not x == U[x]:
    x = U[x]
  return x
  
def merge(x, y, U, r):
  x = find(x, U, r)
  y = find(y, U, r)
  
  if x == y:
    return False
  #print(x,y, U)
  if r[x] < r[y]:
    x, y = y, x
  U[y] = x
  r[x] = max(r[y]+1, r[x])
  #print(x,y, U)
  return True
  
U = [i for i in range(N)]
r = [0 for _ in range(N)]

A = [(tuple(map(int, input().split())), j) for j in range(N)]
B = sorted(A)
C = sorted(A, key=lambda t: ((t[0][1],t[0][0]),t[1]))

#辺の作成
R = []
for i in range(1,N):
  c = B[i][0][0] - B[i-1][0][0]
  p1 = B[i][1]
  p2 = B[i-1][1]
  R.append((c, p1, p2))
  R.append((c, p2, p1))
  
  c = C[i][0][1] - C[i-1][0][1]
  p1 = C[i][1]
  p2 = C[i-1][1]
  R.append((c, p1, p2))
  R.append((c, p2, p1))
R.sort()

#Union Find:
U = [i for i in range(N)]
r = [0 for _ in range(N)]
#print(U)  
ans = 0
for road in R:
  c = road[0]
  x = road[1]
  y = road[2]
  if merge(x, y, U, r):
    #print(U)  
    ans += c
#print(U)    
print(ans)

### FIXED CODE ###

N = int(input())

def find(x, U, r):
  p = []
  while not x == U[x]:
    p.append(x)
    x = U[x]
  for x_ in p:
    U[x_] == x
  return x
  
def merge(x, y, U, r):
  x = find(x, U, r)
  y = find(y, U, r)
  
  if x == y:
    return False
  #print(x,y, U)
  if r[x] < r[y]:
    x, y = y, x
  U[y] = x
  r[x] = max(r[y]+1, r[x])
  #print(x,y, U)
  return True
  
U = [i for i in range(N)]
r = [0 for _ in range(N)]

B = []
C = []
for i in range(N):
  u, v = map(int, input().split())
  B.append((u, v, i))
  C.append((v, u, i))
B.sort()
C.sort()

#辺の作成
R = []
for i in range(1,N):
  c = B[i][0] - B[i-1][0]
  p1 = B[i][2]
  p2 = B[i-1][2]
  R.append((c, p1, p2))
  
  c = C[i][0] - C[i-1][0]
  p1 = C[i][2]
  p2 = C[i-1][2]
  R.append((c, p1, p2))
R.sort()

#Union Find:
U = [i for i in range(N)]
r = [0 for _ in range(N)]
#print(U)  
ans = 0
for road in R:
  c = road[0]
  x = road[1]
  y = road[2]
  if merge(x, y, U, r):
    #print(U)  
    ans += c
#print(U)    
print(ans)
### BUGGY CODE ###

N=int(input())
import math

for i in range(1,N+1):
    ans=0
    for x in range(1,33):
        x2=x*x
        for y in range(1,33):
            if x>=y:
                if x^2+y^2<1000:
                    a=-(3*(x2)+3*(y*y)+2*x*y)/4+i
                    if a>0:
                        b=(math.sqrt(a)-(x+y)/2)
                        if b>0 and b%1==0.0:
                            if x==y:
                                ans+=1
                            else:
                                ans+=2

    print(ans)


### FIXED CODE ###

N=int(input())
li=[0]*N
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            temp=x**2+y**2+z**2+x*y+y*z+z*x
            if temp<=N:
                li[temp-1]+=1
for i in range(N):
    print(li[i])
### BUGGY CODE ###

n=int(input())
a=input().split()
x=1
for i in range(n):
    x*=int(a[i])
if x>10**18:
    print("-1")
else:
    print(x)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
 
mul=1
if 0 in A:print("0")
else:
    for i in range(N):
        mul*=A[i]
        if mul>pow(10,18):
            print("-1")
            break
        elif i==N-1:print(mul)
### BUGGY CODE ###

import numpy as np
import itertools

H, W, K = map(int, input().split())
S = np.array([[s for s in input()] for _ in range(H)], dtype=np.int)

ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    cut = t.count(1)
    lst = np.zeros((cut + 1, W), dtype=np.int)
    lst[0] += S[0]
    c = 0
    for h in range(H - 1):
        if t[h]:
            c += 1
        lst[c] += S[h + 1]
    L = len(lst)
    sum_lst = np.zeros(L)
    for w in range(W):
        lst_w = lst[:, w]
        if lst_w.max() > K:
            break

        lst_s = sum_lst + lst_w
        if lst_s.max() > K:
            cut += 1
            sum_lst = lst_w
        else:
            sum_lst = lst_s
    else:
        ans = min(ans, cut)
print(ans)

### FIXED CODE ###

import itertools
 
H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append([int(s) for s in input()])
 
ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    cnt = t.count(1)
    lst = [[s for s in S[0]]]
    for h in range(H - 1):
        if t[h]:
            lst.append(S[h + 1])
        else:
            lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]
    L = len(lst)
    sum_lst = [0] * L
    for w in range(W):
        if max(lst[i][w] for i in range(L)) > K:
            break
        tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
        if max(tmp) > K:
            cnt += 1
            sum_lst = [lst[i][w] for i in range(L)]
        else:
            sum_lst = tmp
    else:
        ans = min(ans, cnt)
print(ans)
### BUGGY CODE ###

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

# 有向グラフで優先度付きキューで探索

from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter

INF = float('inf')

def dijkstra(s,n,g):
    seen = [False]*n
    cost = [INF]*n
    cost[s] = 0 #スタートはコスト0
    next_q = [(0,s)]
    heapify(next_q)
    while len(next_q)>0:
        c, i = heappop(next_q)
        if cost[i] < c:
            continue
        for nedge, ncost in g[i]:
            nc = cost[i]+ncost
            if cost[nedge]>nc:
                cost[nedge] = nc
                heappush(next_q,(nc, nedge))
    return cost

def main():
    N, X, Y = map(int, input().split())
    graph_F = [[] for _ in range(N)]
    #リストの作成
    for i in range(N-1):
        graph_F[i].append((i+1,1))
        graph_F[i+1].append((i,1))
    graph_F[X-1].append((Y-1,1))
    graph_F[Y-1].append((X-1,1))

    ret = []
    for s in range(N):
        ret += dijkstra(s,N,graph_F)
    ret = Counter(ret)
    for i in range(1,N):
        print(ret[i]//2)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from heapq import heapify, heappop, heappush, heappushpop
import sys
input = sys.stdin.readline
N,X,Y=map(int, input().split())
def f(i,j):
  ret1 = abs(j-i)
  ret2 = abs(j-Y)+1+abs(i-X)
  ret3 = abs(i-Y)+1+abs(j-X)
  return min(ret1,ret2,ret3)
  
dp=[0]*N
for i in range(1,N+1):
  for j in range(i+1,N+1):
    dp[f(i,j)] += 1
for i in range(1,N):
  print(dp[i])
### BUGGY CODE ###

n,m,s,t = map(int,input().split())
uvab = [list(map(int,input().split())) for _ in range(m)]

# import
from scipy.sparse.csgraph import csgraph_from_dense,dijkstra

cost_e = [[0] * n for _ in range(n)]
cost_s = [[0] * n for _ in range(n)]

for i in uvab:
    u,v,a,b = i
    cost_e[u-1][v-1] = a
    cost_s[u-1][v-1] = b
    cost_e[v-1][u-1] = a
    cost_s[v-1][u-1] = b

csr_e = csgraph_from_dense(cost_e)
csr_s = csgraph_from_dense(cost_s)

en = dijkstra(csr_e, indices=s-1)
sn = dijkstra(csr_s, indices=t-1)


ans = [10**15] * n
min_ = en[n-1] + sn[n-1]
for i in range(n-1, -1, -1):
    tmp = en[i] + sn[i]
    min_ = min(min_, tmp)
    ans[i] -= min_

for i in ans:
    print(int(i))

### FIXED CODE ###

import sys
input = sys.stdin.readline

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


links_e = [[] for _ in range(n+1)]
links_s = [[] for _ in range(n+1)]
for _ in range(m):
    u,v,a,b = map(int, input().split())
    links_e[u].append((a,v))
    links_e[v].append((a,u))
    links_s[u].append((b,v))
    links_s[v].append((b,u))

# dijkstra
import heapq
def dijkstra(links, start, n):
    inf = 10**10
    d = [inf] * (n+1)
    d[start] = 0
    hq = []
    used = set()
    used.add(start)
    for i in links[start]:
        heapq.heappush(hq, i)
    while(hq):
        cost,i = heapq.heappop(hq)
        if( i in used):
            continue
        d[i] = cost
        used.add(i)
        for tmp in links[i]:
            cost_next, j = tmp
            if(not j in used):
                heapq.heappush(hq, (cost+cost_next, j))
    return d

d_e = dijkstra(links_e, s, n)
d_s = dijkstra(links_s, t, n)

ans = [0] * (n+1)
min_cost = 10**15
for i in range(n,0,-1):
    min_cost = min(min_cost, d_e[i]+d_s[i])
    ans[i] = min_cost

for i in range(1,n+1):
    print(10**15 - ans[i])
### BUGGY CODE ###

h,w=map(int,input().split())
INF=10**10
a=[[INF for i in range(w)] for j in range(h)]
ans=0
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=="#":
            a[i][j]=0
            
for i in range(h):
    for j in range(w):
        k=a[i][j]+1

        if i!=h-1:
            if k<a[i+1][j]:
                a[i+1][j]=k
        if j!=w-1:
            if k<a[i][j+1]:
                a[i][j+1]=k

for i in range(h):
    for j in range(w):
        k=a[-1-i][-1-j]+1
        if i!=h-1:
            if k<a[-i-2][-j-1]:
                a[-i-2][-j-1]=k

        if j!=w-1:        
            if k<a[-i-1][-j-2]:
                a[-i-1][-j-2]=k

for i in range(h):
    ans=max(ans,max(a[i]))
print(ans)

### FIXED CODE ###

h,w=map(int,input().split())
INF=10**10
a=[[INF for i in range(w)] for j in range(h)]
ans=0
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=="#":
            a[i][j]=0
            
for i in range(h):
    for j in range(w):
        k=a[i][j]+1

        if i!=h-1:
            if k<a[i+1][j]:
                a[i+1][j]=k
        if j!=w-1:
            if k<a[i][j+1]:
                a[i][j+1]=k

for i in range(h):
    for j in range(w):
        k=a[-1-i][-1-j]+1
        if i!=h-1:
            if k<a[-i-2][-j-1]:
                a[-i-2][-j-1]=k

        if j!=w-1:        
            if k<a[-i-1][-j-2]:
                a[-i-1][-j-2]=k

for i in range(h):
    ans=max(ans,max(a[i]))
print(ans)
### BUGGY CODE ###

K, S = map(int, input().split())

ans = 0
for x in range(K + 1):
    for y in range(K + 1):
        if x + y > S:
            break
        z = S - (x + y)
        if z > K:
            continue
        if x + y + z == S:
            ans += 1

print(ans)

### FIXED CODE ###

K, S = map(int, input().split())

ans = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - (x + y)
        if 0 <= z <= K:
            ans += 1

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

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

inf = 10**9

dp = [[inf for _ in range(2**n)]] * m
dp[0][0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    #initialize
    if i==0:
        dp[0][d] = a
        continue
        
    for j in range(2**n):
        jord = j | d
        dp[i][jord] = min(dp[i-1][jord], dp[i-1][j] + a, dp[i][jord])
            
if dp[m-1][2**n-1] == inf:
    print(-1)
else:
    print(dp[m-1][2**n-1])

### FIXED CODE ###

#dpがやや特殊なので、1次元的に走査したほうがよさそう。initializeもいらないし。
n,m = map(int, input().split())

inf = 10**9

dp =[inf for _ in range(2**n)]
dp[0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    for j in range(2**n):
        jord = j | d
        dp[jord] = min(dp[jord], dp[j] + a)
            
if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
ql = set(range(q))
for i in ql:
    ans = 0
    l1, l2 = map(int, input().split())
    s_part = s[l1 - 1:l2]
    sl = set(range(len(s_part)))
    for j in sl:
        if s_part[j:j+2] == 'AC':
            ans += 1
    else:
        print(ans)

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
nl = set(range(n))
for i in nl:
    t[i + 1] = t[i] + (1 if s[i:i + 2] == 'AC' else 0)
ql = set(range(q))
for i in ql:
    l1, l2 = map(int, input().split())
    ans = t[l2-1] - t[l1-1]
    print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
from collections import defaultdict
d=defaultdict(int)
for ai in a:
    b=make_divisors(ai)
    for bi in b:
        d[bi]+=1
ans=0
for k,v in d.items():
    if v>=n-1:
        ans=max(ans,k)
print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
from collections import defaultdict
d=defaultdict(int)
op=set(make_divisors(a[0])+make_divisors(a[1]))
next_op=set()
for i in range(n):
    for opi in op:
        if a[i]%opi==0:
            d[opi]+=1
        if d[opi]>=i:
            next_op.add(opi)
    op=next_op
    next_op=set()
print(max(op))
### BUGGY CODE ###

import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    H, W, M = MI()
    Hlist = [[0, i] for i in range(H)]
    Wlist = [[0, i] for i in range(W)]
    Dlist = [[] for i in range(H)]
    H_max = -float('inf')
    W_max = -float('inf')
    
    for i in range(M):
        h, w = MI()
        Hlist[h-1][0]+=1
        Wlist[w-1][0]+=1
        Dlist[h-1].append(w-1)
        H_max = max(H_max, Hlist[h-1][0])
        W_max = max(W_max, Wlist[w-1][0])
    Hlist = [temp for temp in Hlist if temp[0] == H_max]
    Wlist = [temp for temp in Wlist if temp[0] == W_max]
    ans = H_max+W_max-1

    for num1, index1 in Hlist:
        for num2, index2 in Wlist:
            if not index2 in Dlist[index1]:
                ans = num1+num2
                break
        else:
            continue
        break
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    H, W, M = MI()
    Hlist = [[0, i] for i in range(H)]
    Wlist = [[0, i] for i in range(W)]
    Dlist = [set() for i in range(H)]
    H_max = -float('inf')
    W_max = -float('inf')
    
    for i in range(M):
        h, w = MI()
        Hlist[h-1][0]+=1
        Wlist[w-1][0]+=1
        Dlist[h-1] |= {w-1}
        H_max = max(H_max, Hlist[h-1][0])
        W_max = max(W_max, Wlist[w-1][0])
    Hlist = set([temp[1] for temp in Hlist if temp[0] == H_max])
    Wlist = set([temp[1] for temp in Wlist if temp[0] == W_max])
    ans = H_max+W_max-1

    for index1 in Hlist:
        for index2 in Wlist:
            if not index2 in Dlist[index1]:
                ans += 1
                break
        else:
            continue
        break
    print(ans)

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

import itertools

def comb(n, r):
    return len(list(itertools.combinations(range(n), r)))

n = int(input())
s = []
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    s.append(sin)

ss = set(s)
count = 0
for u in ss:
    al = s.count(u)
    s.remove(u)
    count += comb(al, 2)
print(count)

### FIXED CODE ###

import itertools

def comb(n, r):
    return len(list(itertools.combinations(range(n), r)))

def get_runlength(s): # ex) s = 'RRLLLLRLRLRLRR'
    ret = []
    count = 1
    for i in range(len(s)):
        if i == len(s) - 1:
            ret.append((s[i], count))
            continue
        if s[i] == s[i + 1]:
            count += 1
        else:
            ret.append((s[i], count))
            count = 1
    return ret

n = int(input())
dic = {}
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    try:
        dic[sin] += 1
    except:
        dic[sin] = 1

count = 0
for v in dic.values():
    count += v * (v - 1) / 2
count = int(count)
print(count)
### BUGGY CODE ###

import sys
k,s=map(int,input().split())
sati=0
for i in range(k+1):
  for j in range(k+1):
    for z in range(k+1):
      suma=i+j+z
      if suma==s:
        sati+=1
      suma=0
print(sati)

### FIXED CODE ###

k,s = map(int, input().split(" "))
sum = 0
for i in range(k+1):
    for j in range(k+1):
        if s-i-j <= k and s-i-j >= 0:
            sum += 1
print(sum)