CodeEff/ECCO huggingface dataset:
# Original solution
import sys
h,w,m = list(map(int,input().split()))
H = [0]*(h)
W = [0]*(w)
ch = [[False]*w for _ in range(h)]
for _ in range(m):
    a,b = list(map(int,input().split()))
    H[a-1] += 1
    W[b-1] += 1
    ch[a-1][b-1] = True
hm = max(H)
wm = max(W)
for i in range(len(H)):
    if H[i] != hm:
        continue
    for j in range(len(W)):
        if W[j] != wm:
            continue
        if ch[i][j] != True:
            print((hm+wm))
            sys.exit()
print((hm+wm-1))

            
        

# Optimized solution
import sys
h,w,m = list(map(int,input().split()))
H = [0]*(h)
W = [0]*(w)
ls = []
for _ in range(m):
    a,b = list(map(int,input().split()))
    ls.append([a-1,b-1])
    H[a-1] += 1
    W[b-1] += 1
hm = max(H)
wm = max(W)
for i in range(len(H)):
    for j in range(len(W)):
        if W[j] == wm and H[i] == hm and [i,j] not in ls:
            print((hm+wm))
            sys.exit()
print((hm+wm-1))
# Original solution
h,w,m=list(map(int,input().split()))

max_h=[0 for i in range(h+1)]
max_w=[0 for i in range(w+1)]
grid=[[0 for i in range(w)] for j in range(h)]
#pro=[list(map(int,input().split())) for i in range(m)]
#pro.sort()
for t in range(m):
    #h=pro[t][0]
   # w=pro[t][1]
    h,w=list(map(int,input().split()))
    max_h[h]+=1
    max_w[w]+=1
    grid[h-1][w-1]=1
h_max=[i for i, x in enumerate(max_h) if x == max(max_h)]
w_max=[i for i, x in enumerate(max_w) if x == max(max_w)]

ans=0
for i in h_max:
    for j in w_max:
        cnt=0
        cnt +=list(zip(*grid))[j-1].count(1)
        cnt += grid[i-1].count(1)
        '''
        for k in range(h):
            if grid[k][j-1]==1:
                cnt += 1
        for l in range(w):
            if grid[i-1][l]==1:
                cnt += 1
        '''
        if grid[i-1][j-1]==1:
            cnt -= 1
        
        if cnt > ans:
            ans=cnt
print(ans)

# Optimized solution
H,W,M=list(map(int,input().split()))

Hx=[] #爆破対象の座標を記録
Hy=[]
X=[]
for i in range(M):
    h,w=[int(x)-1 for x in input().split()]
    Hx.append(h)
    Hy.append(w)
    X.append([h,w])

sum_c=[0]*W #縦の合計
sum_r=[0]*H #横の合計
for i in Hy:
    sum_c[i] += 1
for j in Hx:
    sum_r[j] += 1

max_c=max(sum_c)
max_r=max(sum_r)

flag=0 #max_cの列とmax_rの行で交差点に爆弾がないところがあればflag=1
for i in range(H):
    for j in range(W):
        if sum_r[i]==max_r and sum_c[j]==max_c:
            if [i,j] not in X:
                flag=1
                break
    if flag==1:
        break

if flag==0:
    print((max_c+max_r-1))
else:
    print((max_c+max_r))
# Original solution
import collections

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

h, w = [0]*M, [0]*M
for i in range(M):
    h[i], w[i] = list(map(int, input().split()))

counter = collections.Counter(h)
h_max = max(counter.values())
mode_h = [key for key , value in list(counter.items()) if value == h_max]
counter = collections.Counter(w)
w_max = max(counter.values())
mode_w = [key for key , value in list(counter.items()) if value == w_max]

ans = 0
for i in mode_h:
    for j in mode_w:
        if ans < h.count(i) + w.count(j):
            ans = h.count(i) + w.count(j)
            for k in range(M):
                if h[k] == i and w[k] == j:
                    ans -= 1
            if ans == H + W - 1 or ans == M or ans == h_max + w_max:
                print(ans)
                exit()

print(ans)

# Optimized solution
import collections
H, W, M = list(map(int, input().split()))

h, w = [0]*M, [0]*M
dic = set()
for i in range(M):
    h[i], w[i] = list(map(int, input().split()))
    dic.add((h[i],w[i]))

counter = collections.Counter(h)
h_max = max(counter.values())
mode_h = [key for key , value in list(counter.items()) if value == h_max]
counter = collections.Counter(w)
w_max = max(counter.values())
mode_w = [key for key , value in list(counter.items()) if value == w_max]

for i in mode_h:
    for j in mode_w:
        if (i,j) not in dic:
            print((h_max+w_max))
            exit()

print((h_max+w_max-1))
# Original solution
import sys
input = sys.stdin.readline
h,w,m=list(map(int, input().split()))
from collections import defaultdict
hd=defaultdict(int)
wd=defaultdict(int)
hd2=[[] for i in range(h+1)]
hmax=0
wmax=0
for i in range(m):
    h0,w0=list(map(int, input().split()))
    hd[h0]+=1
    hmax=max(hmax,hd[h0])
    hd2[h0].append(w0)
    wd[w0]+=1
    wmax=max(wmax,wd[w0])
    
max_h_list=[]
max_w_list=[]
for k in list(hd.keys()):
    if hd[k]==hmax:
        max_h_list.append(k)

for k in list(wd.keys()):
    if wd[k]==wmax:
        max_w_list.append(k)

ans=float('inf')

for x in max_h_list:
    hlist=hd2[x]
    for y in max_w_list:
        if y in hlist:
            ans=min(ans,1)
        else:
            ans=min(ans,0)
print((hmax+wmax-ans))

# Optimized solution
import sys
from collections import defaultdict
input = sys.stdin.readline
h,w,m=list(map(int, input().split()))
hd=[0 for i in range(h+1)]
wd=[0 for i in range(w+1)]
hw=defaultdict(int)
hmax=0
wmax=0
for i in range(m):
    h0,w0=list(map(int, input().split()))
    hd[h0]+=1
    hmax=max(hmax,hd[h0])
    wd[w0]+=1
    wmax=max(wmax,wd[w0])
    hw[(h0,w0)]+=1

max_h_list=[]
max_w_list=[]
for k in range(h+1):
    if hd[k]==hmax:
        max_h_list.append(k)

for k in range(w+1):
    if wd[k]==wmax:
        max_w_list.append(k)

ans=float('inf')

for x in max_h_list:
    for y in max_w_list:
        if hw[(x,y)]==1:
            ans=min(ans,1)
        else:
            ans=min(ans,0)
            break
print((hmax+wmax-ans))
# Original solution
h,w,m=list(map(int, input().split()))
from collections import defaultdict
hd=defaultdict(int)
wd=defaultdict(int)
hw=defaultdict(int)

for i in range(m):
    h0,w0=list(map(int, input().split()))
    hd[h0]+=1
    hw[(h0,w0)]+=1
    wd[w0]+=1

max_h_list = [kv[0] for kv in list(hd.items()) if kv[1] == max(hd.values())]
max_w_list = [kv[0] for kv in list(wd.items()) if kv[1] == max(wd.values())]

ans=float('inf')
for x in max_h_list:
    for y in max_w_list:
        if hw[(x,y)]==1:
            ans=min(ans,1)
        else:
            ans=min(ans,0)
            break

print((hd[max_h_list[0]]+wd[max_w_list[0]]-ans))


# Optimized solution
import sys
from collections import defaultdict
input = sys.stdin.readline
h,w,m=list(map(int, input().split()))
hd=[0 for i in range(h+1)]
wd=[0 for i in range(w+1)]
hw=defaultdict(int)
hmax=0
wmax=0
for i in range(m):
    h0,w0=list(map(int, input().split()))
    hd[h0]+=1
    hmax=max(hmax,hd[h0])
    wd[w0]+=1
    wmax=max(wmax,wd[w0])
    hw[(h0,w0)]+=1

max_h_list=[]
max_w_list=[]
for k in range(h+1):
    if hd[k]==hmax:
        max_h_list.append(k)

for k in range(w+1):
    if wd[k]==wmax:
        max_w_list.append(k)

ans=float('inf')

for x in max_h_list:
    for y in max_w_list:
        if hw[(x,y)]==1:
            ans=min(ans,1)
        else:
            ans=min(ans,0)
            break
print((hmax+wmax-ans))
# Original solution
def main():
    import sys
    input = sys.stdin.readline

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

    H_list = [[0, i] for i in range(H + 1)] 
    W_list = [[0, i] for i in range(W + 1)] 


    S = set()
    S_add = S.add
    INF = 10 ** 6

    for _ in range(M):
        a, b = list(map(int, input().split()))
        tmp = INF * a + b
        S_add(tmp)
        H_list[a][0] += 1
        W_list[b][0] += 1

    ans = 0
    H_list.sort(reverse=True)
    W_list.sort(reverse=True)

    tmp_H = H_list[0][0]
    tmp_W = W_list[0][0]
    tmp_ans = tmp_H + tmp_W

    for h in range(H):
        if H_list[h][0] + 1 < tmp_H:
            continue
        h_ = H_list[h][1]
        H_ = H_list[h][0]
        for w in range(W):
            if W_list[w][0] + 1 < tmp_W:
                break
            w_ = W_list[w][1]
            tmp = H_ + W_list[w][0]
            if INF * h_ + w_ in S:
                tmp -= 1
            ans = max(ans, tmp)
            if ans == tmp_ans:
                print (ans)
                return

    print (ans)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import sys
    input = sys.stdin.readline

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

    H_list = [[0, i] for i in range(H + 1)] 
    W_list = [[0, i] for i in range(W + 1)] 


    S = set()
    S_add = S.add
    INF = 10 ** 6

    for _ in range(M):
        a, b = list(map(int, input().split()))
        tmp = INF * a + b
        S_add(tmp)
        H_list[a][0] += 1
        W_list[b][0] += 1

    ans = 0
    H_list.sort(reverse=True)
    W_list.sort(reverse=True)

    tmp_H = H_list[0][0]
    tmp_W = W_list[0][0]
    tmp_ans = tmp_H + tmp_W

    for h in range(H):
        if H_list[h][0] + 1 < tmp_H:
            continue
        h_ = H_list[h][1]
        H_ = H_list[h][0]
        for w in range(W):
            if W_list[w][0] + H_ + 1 < tmp_ans:
                break
            w_ = W_list[w][1]
            tmp = H_ + W_list[w][0]
            if INF * h_ + w_ in S:
                tmp -= 1
            ans = max(ans, tmp)
            if ans == tmp_ans:
                print (ans)
                return

    print (ans)

if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/python3
# -*- coding: utf-8 -*-
h, w, m = list(map(int, input().split()))
bom_set = set()
h_dict = {}
w_dict = {}
for i in range(m):
    hh, ww = list(map(int, input().split()))
    bom_set.add(tuple([hh, ww]))
    if hh in h_dict:
        h_dict[hh] += 1
    else:
        h_dict[hh] = 1
    if ww in w_dict:
        w_dict[ww] += 1
    else:
        w_dict[ww] = 1
h_max_count = max(h_dict.values())
w_max_count = max(w_dict.values())
flag = 0
for hh in h_dict:
    if h_dict[hh] < h_max_count:
        continue
    for ww in w_dict:
        if w_dict[ww] < w_max_count:
            continue
        if tuple([hh, ww]) not in bom_set:
            flag = 1
            break
    if flag == 1:
        break
if flag == 1:
    print((h_max_count + w_max_count))
else:
    print((h_max_count + w_max_count - 1))

# Optimized solution
#!/usr/bin/python3
# -*- coding: utf-8 -*-
h, w, m = list(map(int, input().split()))
bom_set = set()
h_dict = {}
w_dict = {}
for i in range(m):
    hh, ww = list(map(int, input().split()))
    bom_set.add(tuple([hh, ww]))
    if hh in h_dict:
        h_dict[hh] += 1
    else:
        h_dict[hh] = 1
    if ww in w_dict:
        w_dict[ww] += 1
    else:
        w_dict[ww] = 1
h_max_count = max(h_dict.values())
w_max_count = max(w_dict.values())
hh_dict = {}
ww_dict = {}
for hh in h_dict:
    if h_dict[hh] == h_max_count:
        hh_dict[hh] = h_max_count
for ww in w_dict:
    if w_dict[ww] == w_max_count:
        ww_dict[ww] = w_max_count
flag = 0
for hh in hh_dict:
    for ww in ww_dict:
        if tuple([hh, ww]) not in bom_set:
            flag = 1
            break
    if flag == 1:
        break
if flag == 1:
    print((h_max_count + w_max_count))
else:
    print((h_max_count + w_max_count - 1))
# Original solution
#!/usr/bin/env python3

# from typing import Optional
from typing import List

# from typing import Dict
from typing import Tuple
from typing import Set

# from typing import Sequence

Cod = Tuple[int, int]


def main():
    args = input().split()
    H = int(args[0])
    W = int(args[1])
    M = int(args[2])

    codList: Set[Cod] = []
    columnSumList: List[int] = [0] * W
    rowSumList: List[int] = [0] * H
    for i in range(M):
        h, w = [int(x) for x in input().split()]
        item = (h, w)
        codList.append(item)
        columnSumList[w - 1] += 1
        rowSumList[h - 1] += 1

    maxColumnSum = max(columnSumList)
    maxColumIndexList = [i for i, x in enumerate(columnSumList) if x == maxColumnSum]
    maxRowSum = max(rowSumList)
    maxRowIndexList = [i for i, x in enumerate(rowSumList) if x == maxRowSum]

    result = maxColumnSum + maxRowSum
    for row in maxRowIndexList:
        for column in maxColumIndexList:
            if (row + 1, column + 1) in codList:
                continue
            else:
                print(result)
                return

    print((result - 1))


if __name__ == "__main__":
    main()


# Optimized solution
#!/usr/bin/env python3

# from typing import Optional
from typing import List

# from typing import Dict
from typing import Tuple
from typing import Set

# from typing import Sequence

Cod = Tuple[int, int]


def main():
    args = input().split()
    H = int(args[0])
    W = int(args[1])
    M = int(args[2])

    codList = {}
    columnSumList: List[int] = [0] * W
    rowSumList: List[int] = [0] * H
    for i in range(M):
        h, w = [int(x) for x in input().split()]
        item = (h, w)
        codList.setdefault(h, {})
        codList[h][w] = item
        columnSumList[w - 1] += 1
        rowSumList[h - 1] += 1

    maxColumnSum = max(columnSumList)
    maxColumIndexList = [i for i, x in enumerate(columnSumList) if x == maxColumnSum]
    maxRowSum = max(rowSumList)
    maxRowIndexList = [i for i, x in enumerate(rowSumList) if x == maxRowSum]

    result = maxColumnSum + maxRowSum
    for row in maxRowIndexList:
        for column in maxColumIndexList:
            if row + 1 in codList and column + 1 in codList[row + 1]:
                continue
            else:
                print(result)
                return

    print((result - 1))


if __name__ == "__main__":
    main()
# Original solution
#!/usr/bin/env python3

# from typing import Optional
from typing import List

# from typing import Dict
from typing import Tuple
from typing import Set

# from typing import Sequence

Cod = Tuple[int, int]


def main():
    args = input().split()
    H = int(args[0])
    W = int(args[1])
    M = int(args[2])

    codList = {}
    columnSumList: List[int] = [0] * W
    rowSumList: List[int] = [0] * H
    for i in range(M):
        h, w = [int(x) for x in input().split()]
        item = (h, w)
        codList.setdefault(h, {})
        codList[h][w] = item
        columnSumList[w - 1] += 1
        rowSumList[h - 1] += 1

    maxColumnSum = max(columnSumList)
    maxColumIndexList = [i for i, x in enumerate(columnSumList) if x == maxColumnSum]
    maxRowSum = max(rowSumList)
    maxRowIndexList = [i for i, x in enumerate(rowSumList) if x == maxRowSum]

    result = maxColumnSum + maxRowSum
    for row in maxRowIndexList:
        for column in maxColumIndexList:
            if row + 1 in codList and column + 1 in codList[row + 1]:
                continue
            else:
                print(result)
                return

    print((result - 1))


if __name__ == "__main__":
    main()


# Optimized solution
#!/usr/bin/env python3

# from typing import Optional
from typing import List

# from typing import Dict
from typing import Tuple
from typing import Set

# from typing import Sequence

Cod = Tuple[int, int]


def main():
    args = input().split()
    H = int(args[0])
    W = int(args[1])
    M = int(args[2])

    codList = set()
    columnSumList: List[int] = [0] * W
    rowSumList: List[int] = [0] * H
    for i in range(M):
        h, w = [int(x) for x in input().split()]
        item = (h, w)
        codList.add(item)
        # codList.setdefault(h, {})
        # codList[h][w] = item
        columnSumList[w - 1] += 1
        rowSumList[h - 1] += 1

    maxColumnSum = max(columnSumList)
    maxColumIndexList = [i for i, x in enumerate(columnSumList) if x == maxColumnSum]
    maxRowSum = max(rowSumList)
    maxRowIndexList = [i for i, x in enumerate(rowSumList) if x == maxRowSum]

    result = maxColumnSum + maxRowSum
    for row in maxRowIndexList:
        for column in maxColumIndexList:
            if (row + 1, column + 1) in codList:
                continue
            else:
                print(result)
                return

    print((result - 1))


if __name__ == "__main__":
    main()
# Original solution
H, W, M = list(map(int, input().split()))
bombs_h = [0] * H
bombs_w = [0] * W
S = [[] for _ in range(H)]
for _ in range(M):
    h, w = [int(x)-1 for x in input().split()]
    S[h].append(w)
    bombs_h[h] += 1
    bombs_w[w] += 1

max_h = max(bombs_h)
max_w = max(bombs_w)
hs = [i for i, x in enumerate(bombs_h) if x == max_h]
ws = [i for i, x in enumerate(bombs_w) if x == max_w]
p = 1
for i in hs:
    for j in ws:
        if j not in S[i]:
            p = 0
            break
ans = max_w + max_h - p
print(ans)

# Optimized solution
H, W, M = list(map(int, input().split()))
bombs_h = [0] * H
bombs_w = [0] * W
B = []
for _ in range(M):
    h, w = [int(x)-1 for x in input().split()]
    B.append((h, w))
    bombs_h[h] += 1
    bombs_w[w] += 1

max_h = max(bombs_h)
max_w = max(bombs_w)
hs = [i for i, x in enumerate(bombs_h) if x == max_h]
ws = [i for i, x in enumerate(bombs_w) if x == max_w]
k = len(hs)*len(ws)
cnt = 0
for h, w in B:
    if bombs_h[h] == max_h and bombs_w[w] == max_w:
        cnt += 1
ans = max_w + max_h - (cnt == k)
print(ans)
# Original solution
H, W, M = list(map(int, input().split()))
hk = [[0, i] for i in range(H + 1)]
wk = [[0, j] for j in range(W + 1)]
s = set()
for i in range(M):
    h, w = list(map(int, input().split()))
    hk[h][0] += 1
    wk[w][0] += 1
    s.add((h, w))
hk.sort(reverse=True)
wk.sort(reverse=True)
colmax = wk[0][0]
ans = 0
for lowacc, i in hk:
    if lowacc + colmax < ans:
        break
    for colacc, j in wk:
        ans = max(ans, lowacc + colacc - ((i, j) in s))
        if lowacc + colacc < ans:
            break
print(ans)


# Optimized solution
H, W, M = list(map(int, input().split()))
hk = [[0, i] for i in range(H + 1)]
wk = [[0, j] for j in range(W + 1)]
s = set()
for i in range(M):
    h, w = list(map(int, input().split()))
    hk[h][0] += 1
    wk[w][0] += 1
    s.add((h, w))
hk.sort(reverse=True)
wk.sort(reverse=True)
colmax = wk[0][0]
ans = 0
for lowacc, i in hk:
    if lowacc + colmax <= ans:
        break
    for colacc, j in wk:
        if lowacc + colacc <= ans:
            break
        else:
            ans = max(ans, lowacc + colacc - ((i, j) in s))
print(ans)
# Original solution
from collections import deque
h, w, m = list(map(int, input().split()))
hl=[0]*h
wl=[0]*w
mh=0
mw=0
mhi=deque([])
dic = {}
mwi=deque([])
#ans =[[0]*w for i in range(h)]
s = [list(map(int, input().split())) for i in range(m)]
 
for i in range(m):
  a, b = s[i]
  a-=1
  b-=1
  if not a in dic:
    dic[a] = deque([b])
  else:
    dic[a].append(b)
 
  hl[a]+=1
  if hl[a]>mh:
    mh=hl[a]
    mhi = [a]
  elif hl[a]==mh:
    mhi.append(a)
  
  wl[b]+=1
  if wl[b]>mw:
    mw=wl[b]
    mwi=[b]
  elif wl[b]==mw:
    mwi.append(b)
 
  #ans[a][b]+=1 
for i in mhi:
  for j in mwi:
    if not j in dic[i]:
      print((mw+mh))
      quit()

print((mh+mw-1))

# Optimized solution
from collections import deque
h, w, m = list(map(int, input().split()))
hl=[0]*h
wl=[0]*w
mh=0
mw=0
mhi=deque([])
dic = {}
mwi=deque([])
#ans =[[0]*w for i in range(h)]
s = [list(map(int, input().split())) for i in range(m)]
 
for i in range(m):
  a, b = s[i]
  a-=1
  b-=1
  if not a in dic:
    dic[a] = {}
    dic[a][b]=1
  else:
    dic[a][b]=1
 
  hl[a]+=1
  if hl[a]>mh:
    mh=hl[a]
    mhi = [a]
  elif hl[a]==mh:
    mhi.append(a)
  
  wl[b]+=1
  if wl[b]>mw:
    mw=wl[b]
    mwi=[b]
  elif wl[b]==mw:
    mwi.append(b)
 
  #ans[a][b]+=1

for i in mhi:
  for j in mwi:
    if not j in dic[i]:
      print((mw+mh))
      quit()

print((mh+mw-1))
# Original solution
from operator import itemgetter

h, w, m = (int(x) for x in input().split())
H = [0] * h
W = [0] * w
HW = []
for _ in range(m):
    h_, w_ = (int(x) - 1 for x in input().split())
    HW.append((h_, w_))
    H[h_] += 1
    W[w_] += 1
hmax = max(H)
wmax = max(W)
hindex = []
windex = []
ans = hmax + wmax - 1

HW.sort(key=itemgetter(0, 1))
for y in range(h):
    if H[y] == hmax:
        hindex.append(y)
for x in range(w):
    if W[x] == wmax:
        windex.append(x)

HW_set = set(HW)
for y in hindex:
    for x in windex:
        if not (y, x) in HW_set:
            ans = hmax + wmax

print(ans)


# Optimized solution
from operator import itemgetter

h, w, m = (int(x) for x in input().split())
H = [0] * h
W = [0] * w
HW = []
for _ in range(m):
    h_, w_ = (int(x) - 1 for x in input().split())
    HW.append((h_, w_))
    H[h_] += 1
    W[w_] += 1
hmax = max(H)
wmax = max(W)
hindex = set()
windex = set()

HW.sort(key=itemgetter(0, 1))
for y in range(h):
    if H[y] == hmax:
        hindex.add(y)
for x in range(w):
    if W[x] == wmax:
        windex.add(x)

count = 0
for h, w in HW:
    if h in hindex and w in windex:
        count += 1

if count == len(hindex)*len(windex):
    ans = hmax + wmax - 1
else:
    ans = hmax + wmax

print(ans)
# Original solution
h,w,m = list(map(int,input().split()))
l = [list(map(int,input().split())) for _ in range(m)]
count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]
bit = list([0 for i in range(w)] for _ in range(h))
for j,k in l:
    count_h[j-1] += 1
    count_w[k-1] += 1
    bit[j-1][k-1] = 1
h_max = max(count_h)
w_max = max(count_w)
h_kouho = []
w_kouho = []
ans = h_max + w_max - 1
for i in range(h):
    if count_h[i]==h_max:
        h_kouho.append(i)
for j in range(w):
    if count_w[j]==w_max:
        w_kouho.append(j)

for i in w_kouho:
    for j in h_kouho:
        if bit[j][i] == 0:
            ans += 1
            print(ans)
            exit()
print(ans)


# Optimized solution
h,w,m = list(map(int,input().split()))
l = [list(map(int,input().split())) for _ in range(m)]
count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]

for j,k in l:
    count_h[j-1] += 1
    count_w[k-1] += 1

h_max = max(count_h)
w_max = max(count_w)
h_kouho = []
ko_hh = [0 for _ in range(h)]
ko_ww = [0 for _ in range(w)]
w_kouho = []
ans = h_max + w_max -1
for i in range(h):
    if count_h[i]==h_max:
        h_kouho.append(i)
        ko_hh[i] = 1
for j in range(w):
    if count_w[j]==w_max:
        w_kouho.append(j)
        ko_ww[j] = 1


ans_kouho = len(h_kouho) * len(w_kouho)
su = 0
for j,k in l:
    if ko_hh[j-1]==1 and ko_ww[k-1]==1:
        su += 1
if su==ans_kouho:
    print(ans)
else:
    print((ans+1))
# Original solution
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 6

H, W, M = list(map(int, input().split()))
hw = [list(map(int, input().split())) for _ in range(M)]

cnt = defaultdict(int)
cnt_h = defaultdict(int)
cnt_w = defaultdict(int)

for h, w in hw:
    cnt[h * INF + w] += 1
#print(cnt)

for h, w in hw:
    cnt_h[h] += 1
    cnt_w[w] += 1
cnt_h = list(cnt_h.items())
cnt_w = list(cnt_w.items())
cnt_h.sort(key = lambda x: -x[1])
cnt_w.sort(key = lambda x: -x[1])
#print(cnt_h)
#print(cnt_w)

max_h = []
max_w = []
for h, n in cnt_h:
    if n == cnt_h[0][1]:
        max_h.append(h)
for w, n in cnt_w:
    if n == cnt_w[0][1]:
        max_w.append(w)
#print(max_h)
#print(max_w)

answer = cnt_h[0][1] + cnt_w[0][1]
for mh in max_h:
    for mw in max_w:
        if cnt[mh * INF + mw] == 0:
            print(answer)
            exit()
print((answer - 1))

# Optimized solution
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline

from collections import deque, defaultdict, Counter

H, W, M = list(map(int, input().split()))
hw = [list(map(int, input().split())) for _ in range(M)]

cnt = defaultdict(int)
cnt_h = defaultdict(int)
cnt_w = defaultdict(int)

for h, w in hw:
    cnt[(h, w)] += 1

for h, w in hw:
    cnt_h[h] += 1
    cnt_w[w] += 1
cnt_h = list(cnt_h.items())
cnt_w = list(cnt_w.items())
cnt_h.sort(key = lambda x: -x[1])
cnt_w.sort(key = lambda x: -x[1])

max_h = []
max_w = []
for h, n in cnt_h:
    if n == cnt_h[0][1]:
        max_h.append(h)
for w, n in cnt_w:
    if n == cnt_w[0][1]:
        max_w.append(w)

answer = cnt_h[0][1] + cnt_w[0][1]
for mh in max_h:
    for mw in max_w:
        if cnt[(mh, mw)] == 0:
            print(answer)
            exit()

print((answer - 1))