CodeEff/ECCO huggingface dataset:
# Original solution
H, W, M = [int(i) for i in input().split()]

cnt_dict_h = {}
cnt_dict_w = {}
bomb_list = []

for i in range(M):
    h, w = [int(i)-1 for i in input().split()]
    bomb_list.append((h,w))
    cnt_dict_h.setdefault(h, 0)
    cnt_dict_h[h] += 1
    cnt_dict_w.setdefault(w, 0)
    cnt_dict_w[w] += 1

max_h_key_list = [kv[0] for kv in list(cnt_dict_h.items()) if kv[1] == max(cnt_dict_h.values())]
max_w_key_list = [kv[0] for kv in list(cnt_dict_w.items()) if kv[1] == max(cnt_dict_w.values())]
max_h = max(cnt_dict_h.values())
max_w = max(cnt_dict_w.values())

bomb_num = max_h + max_w - 1

flag = False

for h in max_h_key_list:
    for w in max_w_key_list:
        if (h, w) not in bomb_list:
            bomb_num = max_h + max_w
            break
        else :
            continue
        break
        
print(bomb_num)

# Optimized solution
H, W, M = [int(i) for i in input().split()]

sum_h = [0] * W
sum_w = [0] * H
bomb_list = set()

for _ in range(M):
    h, w = [int(i) for i in input().split()]
    h -= 1
    w -= 1
    bomb_list.add((h,w))
    sum_h[w] += 1
    sum_w[h] += 1

max_sum_h = max(sum_h)
max_sum_w = max(sum_w)
output = max_sum_h + max_sum_w - 1

max_bombs_h = [h for h in range(H) if sum_w[h] == max_sum_w]
max_bombs_w = [w for w in range(W) if sum_h[w] == max_sum_h]

for h in max_bombs_h:
    for w in max_bombs_w:
        if (h, w) not in bomb_list:
            output = max_sum_h + max_sum_w
            break
        else:
            continue
        break
        
print(output)
# Original solution
import sys
input = sys.stdin.readline

H,W,M=list(map(int,input().split()))
B=set([tuple(map(int,input().split())) for i in range(M)])

HH=[0]*(H+1)
WW=[0]*(W+1)

for x,y in B:
    HH[x]+=1
    WW[y]+=1

MAXH=max(HH)
MAXW=max(WW)

ANS=MAXH+MAXW-1

for i in range(1,H+1):
    if HH[i]!=MAXH:
        continue
    for j in range(1,W+1):
        if WW[j]!=MAXW:
            continue

        if (i,j) in B:
            continue
        else:
            print((ANS+1))
            sys.exit()
print(ANS)

        


# Optimized solution
import sys
input = sys.stdin.readline

H,W,M=list(map(int,input().split()))
B=set([tuple(map(int,input().split())) for i in range(M)])

HH=[0]*(H+1)
WW=[0]*(W+1)

for x,y in B:
    HH[x]+=1
    WW[y]+=1

MAXH=max(HH)
MAXW=max(WW)

ANS=MAXH+MAXW-1

HLIST=[]
WLIST=[]
for i in range(1,H+1):
    if HH[i]==MAXH:
        HLIST.append(i)

for j in range(1,W+1):
    if WW[j]==MAXW:
        WLIST.append(j)

for i in HLIST:
    for j in WLIST:
        if (i,j) in B:
            continue
        else:
            print((ANS+1))
            sys.exit()
print(ANS)
# Original solution
import sys,math,collections,itertools
input = sys.stdin.readline

H,W,M=list(map(int,input().split()))
bom = [] #ボムの場所
bomH =[0]*(H+1) 
bomW=[0]*(W+1)

for _ in range(M):
    h,w=list(map(int,input().split()))
    bom.append((h,w))
    bomH[h]+=1
    bomW[w]+=1

#縦の爆弾と横の爆弾は独立。爆弾を置く場所に爆弾があると-1
max_bomH = max(bomH)
max_bomW = max(bomW)

index_max_H = []
index_max_W = []

for ih in range(H+1):
    if bomH[ih] == max_bomH:
        index_max_H.append(ih)

for iw in range(W+1):
    if bomW[iw] == max_bomW:
        index_max_W.append(iw)

point = itertools.product(index_max_H,index_max_W)#置き場所候補
sPoint = set(point)
sBom = set(bom)
#爆弾が置き場所候補から爆弾場所を消す,すべてなくなれば、-1,どこか残れば0
for sb in sBom:
    sPoint.discard(sb)

print((max_bomH+max_bomW - (len(sPoint)==0) ))
    


# Optimized solution
import sys,math,collections,itertools
input = sys.stdin.readline

H,W,M=list(map(int,input().split()))
bom = [] #ボムの場所
bomH =[0]*(H+1) 
bomW=[0]*(W+1)

for _ in range(M):
    h,w=list(map(int,input().split()))
    bom.append((h,w))
    bomH[h]+=1
    bomW[w]+=1

#縦の爆弾と横の爆弾は独立。爆弾を置く場所に爆弾があると-1
max_bomH = max(bomH)
max_bomW = max(bomW)

cnt = 0#爆弾が置かれた場所のbomH,bomWがともにMaxの場所の数
for h,w in bom:
    if bomH[h]==max_bomH and bomW[w] == max_bomW:
        cnt += 1

print((max_bomH +max_bomW -(cnt == bomH.count(max_bomH) * bomW.count(max_bomW))))
# Original solution
H, W, M = list(map(int, input().split()))
cntH = {}
cntW = {}
bomb = set()
for i in range(M):
    h, w = list(map(int, input().split()))
    bomb.add((h-1,w-1))
    cntH[h-1] = cntH.get(h-1, 0) + 1
    cntW[w-1] = cntW.get(w-1, 0) + 1

max_H_list = [kv[0] for kv in list(cntH.items()) if kv[1] == max(cntH.values())]
max_W_list = [kv[0] for kv in list(cntW.items()) if kv[1] == max(cntW.values())]
ans = max(cntH.values()) + max(cntW.values())

flag = False
for i in max_H_list:
    for j in max_W_list:
        if (i, j) not in bomb:
            flag = True
            break
    else:
        continue
    break
if not flag:
    ans -= 1
print(ans)

# Optimized solution
H, W, M = list(map(int, input().split()))
cntH = {}
cntW = {}
bomb = set()
for i in range(M):
    h, w = list(map(int, input().split()))
    bomb.add((h-1, w-1))
    cntH[h-1] = cntH.get(h-1, 0) + 1
    cntW[w-1] = cntW.get(w-1, 0) + 1

maxH, maxW = max(cntH.values()), max(cntW.values())
max_H_list = [kv[0] for kv in list(cntH.items()) if kv[1] == maxH]
max_W_list = [kv[0] for kv in list(cntW.items()) if kv[1] == maxW]

ans = maxH + maxW - 1
flag = False
for i in max_H_list:
    for j in max_W_list:
        if (i, j) not in bomb:
            flag = True
            break
    else:
        continue
    break
if flag:
    ans += 1

print(ans)
# Original solution
h, w, m = list(map(int, input().split()))
count_row = [0 for _ in range(h)]
count_col = [0 for _ in range(w)]
X = [[0 for i in range(w)] for _ in range(h)]
max_col = 0
max_row = 0
max_row_index = []
max_col_index = []
for i in range(m):
    mh, mw = list(map(int, input().split()))
    X[mh-1][mw-1] = 1
    count_row[mh-1] += 1
    count_col[mw-1] += 1
    if count_row[mh-1] > max_row:
        max_row = count_row[mh-1]
        max_row_index = [mh-1]
    elif count_row[mh-1] == max_row:
        max_row_index.append(mh-1)
    
    if count_col[mw-1] > max_col:
        max_col = count_col[mw-1]
        max_col_index = [mw-1]
    elif count_col[mw-1] == max_col:
        max_col_index.append(mw-1)
# max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)]
# max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)]
# ans = max(count_row) + max(count_col) -1
ans = max_col + max_row -1

if len(max_col_index)*len(max_row_index) > m:
    ans += 1
else:
    flag = False
    for i in max_row_index:
        for j in max_col_index:
            if X[i][j] == 0:
                ans += 1
                flag = True
                break
        if flag:
            break
print(ans)

# Optimized solution
h, w, m = list(map(int, input().split()))
count_row = [0 for _ in range(h)]
count_col = [0 for _ in range(w)]
# X = [[0 for i in range(w)] for _ in range(h)]
max_col = 0
max_row = 0
max_row_index = []
max_col_index = []
M = set()
for i in range(m):
    mh, mw = list(map(int, input().split()))
    # X[mh-1][mw-1] = 1
    M.add((mh-1, mw-1))
    count_row[mh-1] += 1
    count_col[mw-1] += 1
    if count_row[mh-1] > max_row:
        max_row = count_row[mh-1]
        max_row_index = [mh-1]
    elif count_row[mh-1] == max_row:
        max_row_index.append(mh-1)
    
    if count_col[mw-1] > max_col:
        max_col = count_col[mw-1]
        max_col_index = [mw-1]
    elif count_col[mw-1] == max_col:
        max_col_index.append(mw-1)
# max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)]
# max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)]
# ans = max(count_row) + max(count_col) -1
ans = max_col + max_row -1

if len(max_col_index)*len(max_row_index) > m:
    ans += 1
else:
    flag = False
    for i in max_row_index:
        for j in max_col_index:
            if (i, j) not in M:
                ans += 1
                flag = True
                break
        if flag:
            break
print(ans)
# Original solution
h, w, m = list(map(int, input().split()))
count_row = [0 for _ in range(h)]
count_col = [0 for _ in range(w)]
# X = [[0 for i in range(w)] for _ in range(h)]
M = set()
for i in range(m):
    mh, mw = list(map(int, input().split()))
    # X[mh-1][mw-1] = 1
    M.add((mh-1, mw-1))
    # M[i] = [mh, mw]
    count_row[mh-1] += 1
    count_col[mw-1] += 1
max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)]
max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)]
ans = max(count_row) + max(count_col) -1

if len(max_col_index)*len(max_row_index) > m:
    ans += 1
else:
    flag = False
    for i in max_row_index:
        for j in max_col_index:
            if (i, j) not in M:
                ans += 1
                flag = True
                break
        if flag:
            break

print(ans)


# Optimized solution
h, w, m = list(map(int, input().split()))
count_row = [0 for _ in range(h)]
count_col = [0 for _ in range(w)]
max_col = 0
max_row = 0
max_row_index = []
max_col_index = []
M = set()
for i in range(m):
    mh, mw = list(map(int, input().split()))
    M.add((mh-1, mw-1))
    count_row[mh-1] += 1
    count_col[mw-1] += 1
    if count_row[mh-1] > max_row:
        max_row = count_row[mh-1]
        max_row_index = [mh-1]
    elif count_row[mh-1] == max_row:
        max_row_index.append(mh-1)
    
    if count_col[mw-1] > max_col:
        max_col = count_col[mw-1]
        max_col_index = [mw-1]
    elif count_col[mw-1] == max_col:
        max_col_index.append(mw-1)
# max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)]
# max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)]
# ans = max(count_row) + max(count_col) -1
ans = max_col + max_row -1

if len(max_col_index)*len(max_row_index) > m:
    ans += 1
else:
    flag = False
    for i in max_row_index:
        for j in max_col_index:
            if (i, j) not in M:
                ans += 1
                flag = True
                break
        if flag:
            break
print(ans)
# Original solution
import sys


H, W, M = list(map(int, input().split()))
X = [set() for _ in range(H)]
Y = [set() for _ in range(W)]
for s in sys.stdin.readlines():
    h, w = [int(x) - 1 for x in s.split()]
    X[h].add(w)
    Y[w].add(h)
cntX = []
cntY = []
for x in X:
    cntX.append((len(x), x))
for w, y in enumerate(Y):
    cntY.append((len(y), w))

cntX.sort(reverse=True)
cntY.sort(reverse=True)
maxX = cntX[0][0]
maxY = cntY[0][0]
ans = 0
for cnt, x in cntX:
    if cnt < maxX:
        break
    for tmp, w in cntY:
        if tmp < maxY:
            break
        tmp += cnt - (w in x)
        if ans < tmp:
            ans = tmp
    if cnt == maxX + maxY:
        break
print(ans)


# Optimized solution
import sys


H, W, M = list(map(int, input().split()))
bomb = [tuple([int(x) - 1 for x in s.split()]) for s in sys.stdin.readlines()]
X = [0] * H
Y = [0] * W
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = []
C = []
for h, x in enumerate(X):
    if x == maxX:
        R.append(h)
for w, y in enumerate(Y):
    if y == maxY:
        C.append(w)

if len(R) * len(C) > M:
    ans = maxX + maxY
else:
    done = set()
    for r in R:
        for c in C:
            done.add((r, c))
    for b in bomb:
        if b in done:
            done.remove(b)
    if len(done) > 0:
        ans = maxX + maxY
    else:
        ans = maxX + maxY - 1
print(ans)
# Original solution
from sys import exit, stdin

# import copy
from collections import deque, Counter

# import numpy as np
input = stdin.readline

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

col = Counter()
row = Counter()
D = Counter()
for i in range(M):
    h, w = list(map(int, input().split()))
    row.update([h])
    col.update([w])
    D.update([str(h) + str(w)])

# rmax = row.most_common(1)
# cmax = col.most_common(1)
# idx = str(rmax[0][0]) + str(cmax[0][0])
# p = D[idx]

# ans = rmax[0][1] + cmax[0][1] - p

rtmp = row.most_common(1)[0][1]
ctmp = col.most_common(1)[0][1]
rmax = []
cmax = []

for r in row.most_common():
    if r[1] < rtmp:
        break
    rmax.append(r)

for c in col.most_common():
    if c[1] < ctmp:
        break
    cmax.append(c)

ridx = str(rmax[0][0])
for d in cmax:
    if D[ridx + str(d[0])] == 0:
        ans = rmax[0][1] + d[1]
        break
else:
    ans = rmax[0][1] + d[1] - 1

cidx = str(cmax[0][0])
for d in rmax:
    if D[str(d[0]) + cidx] == 0:
        ans2 = cmax[0][1] + d[1]
        break
else:
    ans2 = cmax[0][1] + d[1] - 1

print((max(ans, ans2)))



# Optimized solution
from sys import exit, stdin

# import copy
from collections import deque, Counter

# import numpy as np
input = stdin.readline

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

col = Counter()
row = Counter()
D = Counter()
for i in range(M):
    h, w = input().split()
    row.update([h])
    col.update([w])
    D.update([h + w])

rtop = row.most_common(1)[0]
ctop = col.most_common(1)[0]


for c in col.most_common():
    if c[1] < ctop[1]:
        break
    else:
        if D[rtop[0] + c[0]] == 0:
            ans = rtop[1] + c[1]
            break
        else:
            ans = rtop[1] + c[1] - 1

for r in row.most_common():
    if r[1] < rtop[1]:
        break
    else:
        if D[r[0] + ctop[0]] == 0:
            ans2 = r[1] + ctop[1]
            break
        else:
            ans2 = r[1] + c[1] - 1

print((max(ans, ans2)))
# Original solution
H,W,m = list(map(int,input().split()))
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1] for i in range(H+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in hkouho:
    for j in wkouho:
        if j not in c[i]:
            print((mh+mw))
            exit()
print((mh+mw-1))

# Optimized solution

from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = list(map(int,input().split()))
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1,10**6] for i in range(H+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in range(H+1):
    c[i].sort()
# print(hkouho)
# print(wkouho)
for i in hkouho:
    for j in wkouho:
        # print(c[i],i,j,bisect_left(c[i],j))
        if c[i][bisect_left(c[i],j)] != j:
            print((mh+mw))
            exit()
print((mh+mw-1))
# Original solution

from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = list(map(int,input().split()))
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1,10**6] for i in range(H+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in range(H+1):
    c[i].sort()
# print(hkouho)
# print(wkouho)
for i in hkouho:
    for j in wkouho:
        # print(c[i],i,j,bisect_left(c[i],j))
        if c[i][bisect_left(c[i],j)] != j:
            print((mh+mw))
            exit()
print((mh+mw-1))

# Optimized solution
from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = list(map(int,input().split()))
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1,10**6] for i in range(H+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in hkouho:
    c[i].sort()
    for j in wkouho:
        if c[i][bisect_left(c[i],j)] != j:
            print((mh+mw))
            exit()
print((mh+mw-1))
# Original solution
from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = list(map(int,input().split()))
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1,10**6] for i in range(H+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in hkouho:
    c[i] = set(c[i])
    for j in wkouho:
        # if c[i][bisect_left(c[i],j)] != j:
        if j not in c[i]:
            print((mh+mw))
            exit()
print((mh+mw-1))

# Optimized solution
from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = list(map(int,input().split()))
h = [0]*(H+1)
w = [0]*(W+1)
c = [{-1,10**6} for i in range(H+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    h[a] += 1
    w[b] += 1
    c[a].add(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in hkouho:
    # c[i] = set(c[i])
    for j in wkouho:
        # if c[i][bisect_left(c[i],j)] != j:
        if j not in c[i]:
            print((mh+mw))
            exit()
print((mh+mw-1))
# Original solution
from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = list(map(int,input().split()))
h = [0]*(H+1)
w = [0]*(W+1)
c = [{-1,10**6} for i in range(H+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    h[a] += 1
    w[b] += 1
    c[a].add(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in hkouho:
    # c[i] = set(c[i])
    for j in wkouho:
        # if c[i][bisect_left(c[i],j)] != j:
        if j not in c[i]:
            print((mh+mw))
            exit()
print((mh+mw-1))

# Optimized solution
# from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = list(map(int,input().split()))
h = [0]*(H+1)
w = [0]*(W+1)
c = [{-1,10**6} for i in range(H+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    h[a] += 1
    w[b] += 1
    c[a].add(b)
mh = max(h)
mw = max(w)
# hkouho = []
# wkouho = []
hkouho= [i for i in range(H+1) if h[i] == mh]
wkouho= [i for i in range(W+1) if w[i] == mw]
# for i in range(H+1):
#     if h[i] == mh:
#         hkouho.append(i)
# for i in range(W+1):
#     if w[i] == mw:
#         wkouho.append(i)
for i in hkouho:
    # c[i] = set(c[i])
    for j in wkouho:
        # if c[i][bisect_left(c[i],j)] != j:
        if j not in c[i]:
            print((mh+mw))
            exit()
print((mh+mw-1))
# Original solution
H, W, M = list(map(int, input().split()))
bomb = [0] * M
H_list = [0] * H
W_list = [0] * W
for i in range(M):
  h, w = list(map(int, input().split())) 
  bomb[i] = [h - 1, w - 1]
  H_list[h - 1] += 1
  W_list[w - 1] += 1
  
#print(HW, H_list, W_list)  
H_max = max(H_list)
W_max = max(W_list)
H_index = []
W_index = []
for i in range(H):
  if H_list[i] == H_max:
    H_index.append(i)
    
for i in range(W):
  if W_list[i] == W_max:
    W_index.append(i)
    

x = 1
for i in H_index:
  for j in W_index:
    if [i, j] not in bomb:
      x = 0
      
print((H_max + W_max - x))      
    
    
    
    






# Optimized solution
H, W, M = list(map(int, input().split()))
bomb = [0] * M
H_list = [0] * H
W_list = [0] * W
for i in range(M):
  h, w = list(map(int, input().split())) 
  bomb[i] = [h - 1, w - 1]
  H_list[h - 1] += 1
  W_list[w - 1] += 1
  
#print(HW, H_list, W_list)  
H_max = max(H_list)
W_max = max(W_list)
H_count = H_list.count(H_max)
W_count = W_list.count(W_max)
HW_max = H_max + W_max

count = 0
for i, j in bomb:
  if H_list[i] + W_list[j] == HW_max:
    count += 1
    
if count == H_count * W_count:
  x = 1
else:
  x = 0
  
print((HW_max - x))
# Original solution
def solve():
    H, W, M = list(map(int, input().split()))
    N = 3 * 10 ** 5
    cnth = [0] * N
    cntw = [0] * N
    dic = dict()
    for i in range(M):
        h, w = [int(x) - 1 for x in input().split()]
        cnth[h] += 1
        cntw[w] += 1
        dic[(h, w)] = 1
    mh = max(cnth)
    mw = max(cntw)
    Y = []
    X = []
    for i in range(H):
        if cnth[i] == mh:
            Y.append(i)
    for i in range(W):
        if cntw[i] == mw:
            X.append(i)
    for y in Y:
        for x in X:
            if not (y, x) in dic:
                return mh + mw
    return mh + mw - 1

print((solve()))


# Optimized solution
def solve():
    H, W, M = list(map(int, input().split()))
    N = 3 * 10 ** 5
    cnth = [0] * N
    cntw = [0] * N
    st = set()
    for i in range(M):
        h, w = [int(x) - 1 for x in input().split()]
        cnth[h] += 1
        cntw[w] += 1
        st.add((h, w))
    mh = max(cnth)
    mw = max(cntw)
    Y = []
    X = []
    for i in range(H):
        if cnth[i] == mh:
            Y.append(i)
    for i in range(W):
        if cntw[i] == mw:
            X.append(i)
    for y in Y:
        for x in X:
            if not (y, x) in st:
                return mh + mw
    return mh + mw - 1

print((solve()))
# Original solution
H, W, M = list(map(int, input().split()))
hw = []
sum_h = [0] * W
sum_w = [0] * H
for _ in range(M):
    h, w = list(map(int, input().split()))
    hw.append([h, w])
    h -= 1
    w -= 1
    sum_h[w] += 1
    sum_w[h] += 1


max_h = max(sum_h)
max_w = max(sum_w)

new_H = [h for h in range(H) if sum_w[h] == max_w]
new_W = [w for w in range(W) if sum_h[w] == max_h]

max_num = max_h + max_w - 1
for i in new_H:
    for j in new_W:
        if [i + 1, j + 1] not in hw:
            print((max_h + max_w))
            exit()
        else:
            continue
        break

print(max_num)


# Optimized solution
H, W, M = list(map(int, input().split()))
hw = set()
sum_h = [0] * W
sum_w = [0] * H
for _ in range(M):
    h, w = list(map(int, input().split()))
    hw.add((h, w))
    h -= 1
    w -= 1
    sum_h[w] += 1
    sum_w[h] += 1


max_h = max(sum_h)
max_w = max(sum_w)

new_H = [h for h in range(H) if sum_w[h] == max_w]
new_W = [w for w in range(W) if sum_h[w] == max_h]

max_num = max_h + max_w - 1
for i in new_H:
    for j in new_W:
        if (i + 1, j + 1) not in hw:
            print((max_h + max_w))
            exit()
        else:
            continue
        break

print(max_num)
# Original solution
H, W, M = list(map(int, input().split()))
bombs = []
rows = [[]for _ in range(H)]
cols = [[]for _ in range(W)]
for _ in range(M):
    h, w = [int(x)-1 for x in input().split()]
    bombs.append((h, w))
    rows[h].append(w)
    cols[w].append(h)

max_row = 0
row_idx = set()
for i, row in enumerate(rows):
    if max_row < len(row):
        max_row = len(row)
        row_idx = {i}
        continue
    elif max_row == len(row):
        row_idx.add(i)

max_col = 0
col_idx = set()
for i, col in enumerate(cols):
    if max_col < len(col):
        max_col = len(col)
        col_idx = {i}
        continue
    elif max_col == len(col):
        col_idx.add(i)

ans = max_row+max_col
points = len(row_idx)*len(col_idx)
if M < points:
    print(ans)
else:
    for i, j in bombs:
        if i in row_idx and j in col_idx:
            points -= 1
    if points == 0:
        print((ans-1))
    else:
        print(ans)


# Optimized solution
import sys
input = sys.stdin.readline
H, W, M = list(map(int, input().split()))
bombs = []
rows = [[]for _ in range(H)]
cols = [[]for _ in range(W)]
for _ in range(M):
    h, w = [int(x)-1 for x in input().split()]
    bombs.append((h, w))
    rows[h].append(w)
    cols[w].append(h)

max_row = 0
row_idx = set()
for i, row in enumerate(rows):
    if max_row < len(row):
        max_row = len(row)
        row_idx = {i}
        continue
    elif max_row == len(row):
        row_idx.add(i)

max_col = 0
col_idx = set()
for i, col in enumerate(cols):
    if max_col < len(col):
        max_col = len(col)
        col_idx = {i}
        continue
    elif max_col == len(col):
        col_idx.add(i)

ans = max_row+max_col
points = len(row_idx)*len(col_idx)
if M < points:
    print(ans)
else:
    for i, j in bombs:
        if i in row_idx and j in col_idx:
            points -= 1
    if points == 0:
        print((ans-1))
    else:
        print(ans)