CodeEff/ECCO huggingface dataset:
# Original solution
from collections import Counter

def main(H, W, M, obj_h, obj_w, obj):
    c_h = Counter(obj_h)
    c_w = Counter(obj_w)
    max_h = max(c_h.values())
    max_w = max(c_w.values())
    lst_h = [kv[0] for kv in list(c_h.items()) if kv[1] == max_h]
    lst_w = [kv[0] for kv in list(c_w.items()) if kv[1] == max_w]
    for h in lst_h:
        for w in lst_w:
            if [h, w] not in obj:
                print((max_h + max_w))
                exit()
    else:
        print((max_h + max_w - 1))



if __name__ == '__main__':
    H, W, M = list(map(int, input().split()))
    obj = []
    obj_h = []
    obj_w = []
    for _ in range(M):
        i = list(map(int, input().split()))
        obj.append(i)
        obj_h.append(i[0])
        obj_w.append(i[1])
    main(H, W, M, obj_h, obj_w, obj)

# Optimized solution
from collections import Counter

def main(H, W, M, obj_h, obj_w, obj):
    c_h = Counter(obj_h)
    c_w = Counter(obj_w)
    max_h = max(c_h.values())
    max_w = max(c_w.values())
    lst_h = [kv[0] for kv in list(c_h.items()) if kv[1] == max_h]
    lst_w = [kv[0] for kv in list(c_w.items()) if kv[1] == max_w]
    for h in lst_h:
        for w in lst_w:
            if (h, w) not in obj:
                print((max_h + max_w))
                exit()
    else:
        print((max_h + max_w - 1))



if __name__ == '__main__':
    H, W, M = list(map(int, input().split()))
    obj = set()
    obj_h = []
    obj_w = []
    for _ in range(M):
        i = list(map(int, input().split()))
        obj.add(tuple(i))
        obj_h.append(i[0])
        obj_w.append(i[1])
    main(H, W, M, obj_h, obj_w, obj)
# Original solution
h,w,m=list(map(int,input().split()))
HW=[list(map(int,input().split())) for _ in range(m)]

H,W=[0 for _ in range(h)],[0 for _ in range(w)]
for i,j in HW:
    i,j=i-1,j-1
    H[i] +=1
    W[j] +=1

max_h,max_w=max(H),max(W)
ans=max_h+max_w
cnt=H.count(max_h)*W.count(max_w)
for i,j in HW:
    if H[i-1]==max_h and W[j-1]==max_w:
        cnt -=1
print((ans if cnt!=0 else ans-1))

# Optimized solution
h,w,m=list(map(int,input().split()))
HW=[list(map(int,input().split())) for _ in range(m)]

H,W=[0]*h,[0]*w
for i,j in HW:
    H[i-1] +=1
    W[j-1] +=1

max_h,max_w=max(H),max(W)
ans=max_h+max_w
cnt=H.count(max_h)*W.count(max_w)
for i,j in HW:
    if H[i-1]==max_h and W[j-1]==max_w:
        cnt -=1
print((ans if cnt!=0 else ans-1))
# Original solution
H,W,M = list(map(int, input().split()))

hs = [0] * H
ws = [0] * W
s = set()

for i in range(M):
  h,w = list(map(int, input().split()))
  h -= 1
  w -= 1
  hs[h] += 1
  ws[w] += 1
  s.add((h,w))

mh = 0
mw = 0
for i in range(H):
  mh = max(mh,hs[i])
for j in range(W):
  mw = max(mw,ws[j])
i_s = list()
j_s = list()
for i in range(H):
  if mh == hs[i]:
    i_s.append(i)
for j in range(W):
  if mw == ws[j]:
    j_s.append(j)
ans = mh + mw
for i in i_s:
  for j in j_s:
    if (i,j) in s:
      continue
    print(ans)
    exit()
ans -= 1
print(ans)

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

hs = [0] * H
ws = [0] * W
s = set()

for i in range(M):
  h,w = list(map(int, input().split()))
  h -= 1
  w -= 1
  hs[h] += 1
  ws[w] += 1
  s.add((h,w))

mh = 0
mw = 0
for i in range(H):
  mh = max(mh, hs[i])
for j in range(W):
  mw = max(mw, ws[j])
  
l_s = list()
j_s = list()
for i in range(H):
  if mh == hs[i]:
    l_s.append(i)
for j in range(W):
  if mw == ws[j]:
    j_s.append(j)
    
ans = mh+mw
for i in l_s:
  for j in j_s:
    if (i,j) in s:
      continue
    print(ans)
    exit()
ans -= 1
print(ans)
# Original solution
H,W,M = list(map(int, input().split()))

hs = [0] * H
ws = [0] * W
s = set()
for i in range(M):
  h,w = list(map(int, input().split()))
  h -= 1
  w -= 1
  hs[h] += 1
  ws[w] += 1
  s.add((h,w))
  
mh = 0
mw = 0
for i in range(H):
  mh = max(mh, hs[i])
for j in range(W):
  mw = max(mw, ws[j])
  
i_s = list()
j_s = list()
for i in range(H):
  if hs[i] == mh:
    i_s.append(i)
for j in range(W):
  if ws[j] == mw:
    j_s.append(j)
    
ans = mh + mw
for i in i_s:
  for j in j_s:
    if (i,j) in s:
      continue
    print(ans)
    exit()
ans -= 1
print(ans)

# Optimized solution
H,W,M = list(map(int, input().split()))
hs = [0] * H
ws = [0] * W
s = set()
for i in range(M):
  h,w = list(map(int, input().split()))
  h -= 1
  w -= 1
  s.add((h,w))
  hs[h] += 1
  ws[w] += 1
  
mh = 0
mw = 0
for i in range(H):
  mh = max(mh, hs[i])
for j in range(W):
  mw = max(mw, ws[j])
  
i_s = list()
j_s = list()
for i in range(H):
  if mh == hs[i]:
    i_s.append(i)
for j in range(W):
  if mw == ws[j]:
    j_s.append(j)
ans = mh + mw
for i in i_s:
  for j in j_s:
    if (i,j) in s:
      continue
    print(ans)
    exit()
ans -= 1
print(ans)
# Original solution
h,w,m=list(map(int,input().split()))
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
if len(aa)*len(bb)>m:
    print((am+bm))
    exit()
for i in aa:
    for j in bb:
        if [i,j] in bomb:
            continue
        else:
            print((am+bm))
            exit()
print((am+bm-1))

# Optimized solution
h,w,m=list(map(int,input().split()))
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print((ans-1))
else:
    print(ans)
# Original solution
H, W, M = list(map(int, input().split()))
 
h = [0] * H
w = [0] * W
Mem = [tuple(map(int, input().split())) for _ in range(M) ]
for i, j in Mem:
  h[i-1] += 1
  w[j-1] += 1

maxh = max(h)
maxw = max(w)
 
listh = [i for i, v in enumerate(h, 1) if v == maxh]
listw = [j for j, v in enumerate(w, 1) if v == maxw]

cnt = len(listh) * len(listw)

for i, j in Mem:
  if i in listh and j in listw:
    cnt -= 1
 
if cnt:
  ans = maxh + maxw
else:
  ans = maxh + maxw - 1

print(ans)

# Optimized solution
h,w,m=list(map(int,input().split()))
item=[list(map(int,input().split())) for i in range(m)]
row=[0]*h
col=[0]*w
for i in range(m):
    x,y=item[i]
    row[x-1]+=1
    col[y-1]+=1
mr,mc=max(row),max(col)
xr=set([i for i in range(h) if row[i]==mr])
xc=set([i for i in range(w) if col[i]==mc])
check=len(xr)*len(xc)
for i in range(m):
    r,c=item[i]
    if r-1 in xr and c-1 in xc:
        check-=1
print((mr+mc if check>0 else mr+mc-1))
# Original solution
H, W, M = list(map(int, input().split()))
bombs = [list([int(x) - 1 for x in input().split()]) for _ in range(M)]
field = [[False] * W for _ in range(H)]

max_hw = max(H, W)
H_count = {i:0 for i in range(max_hw)}
W_count = {i:0 for i in range(max_hw)}

for i in range(M):
    h, w = bombs[i]
    field[h][w] = True
    H_count[h] += 1
    W_count[w] += 1


A = max(H_count.values())
B = max(W_count.values())
Ah = []
Bw = []

for i in range(max_hw):
    if H_count[i] == A:
        Ah.append(i)
    if W_count[i] == B:
        Bw.append(i)

ans = A + B
FLG = True
for h in Ah:
    for w in Bw:
        if not field[h][w]:
            FLG = False
            break
    if not FLG:
        break

print((ans - FLG))


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

H_count = [0 for i in range(H)]
W_count = [0 for i in range(W)]

for i in range(M):
    h, w = [int(x) - 1 for x in input().split()]
    bombs.add((h, w))
    H_count[h] += 1
    W_count[w] += 1


A = max(H_count)
B = max(W_count)
Ah = []
Bw = []

for i, count in enumerate(H_count):
    if count == A:
        Ah.append(i)

for i, count in enumerate(W_count):
    if count == B:
        Bw.append(i)

ans = A + B
for h in Ah:
    for w in Bw:
        if (h, w) not in bombs:
            print(ans)
            exit()

print((ans - 1))
# Original solution
def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

H,W,M=list(map(int,input().split()))
P=list()
P_X=[0]*(H+1)
P_Y=[0]*(W+1)
for m  in range(M):
    P.append(list(map(int,input().split())))
    P_X[P[m][0]]+=1
    P_Y[P[m][1]]+=1
Max_X=max(P_X)
Max_Y=max(P_Y)
max_X=my_index(P_X,Max_X)
max_Y=my_index(P_Y,Max_Y)
m_count=0
for k in P:
    if  k[0] in max_X and k [1] in max_Y:
        m_count += 1
if m_count==len(max_X)*len(max_Y):
    answer=Max_X+Max_Y-1
else:
     answer=Max_X+Max_Y
    
print(answer)

    



# Optimized solution

def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

H,W,M=list(map(int,input().split()))
P=list()
P_X=[0]*(H+1)
P_Y=[0]*(W+1)
for m  in range(M):
    P.append(list(map(int,input().split())))
    P_X[P[m][0]]+=1
    P_Y[P[m][1]]+=1
Max_X=max(P_X)
Max_Y=max(P_Y)
max_X=my_index(P_X,Max_X)
max_Y=my_index(P_Y,Max_Y)
m_count=0
for k in P:
    if  P_X[k[0]] == Max_X and P_Y[k [1]] == Max_Y:
        m_count += 1
if m_count==len(max_X)*len(max_Y):
    answer=Max_X+Max_Y-1
else:
     answer=Max_X+Max_Y
    
print(answer)
# Original solution
H, W, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(M)]

takasa = [0]*(H)
haba = [0]*(W)

for i in range(M):
    takasa[A[i][0]-1] += 1
    haba[A[i][1]-1] += 1

mt = max(takasa)
mh = max(haba)
ct = takasa.count(mt)
ch = haba.count(mh)

a = 0
for i in range(M):
    if takasa[A[i][0]-1] == mt and haba[A[i][1]-1] == mh:
        a += 1

if a == ct*ch:
    print((mt+mh-1))
else:
    print((mt+mh))

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

hl, wl = [0]*H, [0]*W
for i,j in A:
    hl[i-1] += 1
    wl[j-1] += 1

mt,mh = max(hl),max(wl)

a = 0
for i,j in A:
    if hl[i-1] == mt and wl[j-1] == mh:
        a += 1

print((mt+mh-1 if a == hl.count(mt) * wl.count(mh) else mt+mh))
# Original solution
H,W,M=list(map(int,input().split()))
mine=[list(map(int,input().split()))for i in range(M)]
mine_h=[0]*H
mine_w=[0]*W
ans=0
val=-1
for i in range(M):
    mine_h[mine[i][0]-1]+=1
    mine_w[mine[i][1]-1]+=1
max_h=max(mine_h)
max_w=max(mine_w)
h_index=[i+1 for i, x in enumerate(mine_h)if x == max_h]
w_index=[i+1 for i, x in enumerate(mine_w)if x == max_w]
for i in h_index:
    for j in w_index:
        if [i,j] in mine:
            continue
        else:
            val=0
            break
print((max_h+max_w+val))

# Optimized solution
H,W,M=list(map(int,input().split()))
mine_h=[0]*H
mine_w=[0]*W
val=-1
mine=set()
for i in range(M):
    a,b=list(map(int,input().split()))
    mine_h[a-1]+=1
    mine_w[b-1]+=1
    mine.add((a,b))
max_h=max(mine_h)
max_w=max(mine_w)
h_index=[i+1 for i, x in enumerate(mine_h)if x == max_h]
w_index=[i+1 for i, x in enumerate(mine_w)if x == max_w]
for i in h_index:
    for j in w_index:
        if (i,j) in mine:
            continue
        else:
            val=0
            break
print((max_h+max_w+val))
# Original solution
h,w,m=list(map(int,input().split()))
bomb=[]
x=[0]*(h+1)
y=[0]*(w+1)
for i in range(m):
    h1,w1=list(map(int,input().split()))
    x[h1]+=1
    y[w1]+=1
    bomb.append((h1,w1))
maxx=max(x)
maxy=max(y)
r=[]
c=[]
for i in range(1,h+1):
    if x[i]==maxx:
        r.append(i)
for j in range(1,w+1):
    if y[j]==maxy:
        c.append(j)
for j in r:
    for k in c:
        if (j,k) not in bomb:
            print((maxx+maxy))
            exit()
print((maxx+maxy-1))

# Optimized solution
h,w,m=list(map(int,input().split()))
bomb=[]
x=[0]*(h+1)
y=[0]*(w+1)
for i in range(m):
    h1,w1=list(map(int,input().split()))
    x[h1]+=1
    y[w1]+=1
    bomb.append((h1,w1))
maxx=max(x)
maxy=max(y)
r=[]
c=[]
bomb=set(bomb)
for i in range(1,h+1):
    if x[i]==maxx:
        r.append(i)
for j in range(1,w+1):
    if y[j]==maxy:
        c.append(j)
for j in r:
    for k in c:
        if (j,k) not in bomb:
            print((maxx+maxy))
            exit()
print((maxx+maxy-1))
# Original solution
H,W,M = list(map(int,input().split()))
P = [0]*(H+1)
Q = [0]*(W+1)
A = set()
for k in range(M):
  a,b = list(map(int,input().split()))
  P[a] += 1
  Q[b] += 1
  A.add((a,b))
Pindex = [i for i, v in enumerate(P) if v == max(P)]
Qindex = [i for i, v in enumerate(Q) if v == max(Q)]
Pmax = P[Pindex[0]]
Qmax = Q[Qindex[0]]
ans = Pmax+Qmax-1
key = 0
for x in Pindex:
  for y in Qindex:
    if (x,y) not in A:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)


# Optimized solution
H,W,M = list(map(int,input().split()))
P = [0]*(H+1)
Q = [0]*(W+1)
A = set()
for k in range(M):
    a,b = list(map(int,input().split()))
    P[a] += 1
    Q[b] += 1
    A.add((a,b))
Pmax = max(P)
Qmax = max(Q)
Pindex = []
Qindex = []
for i in range(H+1):
    if P[i] == Pmax:
        Pindex.append(i)
for i in range(W+1):
    if Q[i] == Qmax:
        Qindex.append(i)
ans = Pmax+Qmax-1
key = 0
for x in Pindex:
  for y in Qindex:
    if (x,y) not in A:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)
# Original solution
from collections import Counter
H,W,m = list(map(int,input().split()))
ci = Counter([])
cj = Counter([])
s = set()
for i in range(m):
    h,w = list(map(int,input().split()))
    ci[h] += 1
    cj[w] += 1
    s.add((h,w))
mi = max(ci.values())
mj = max(cj.values())
ci = sorted(list(ci.items()),key=lambda x:x[1], reverse=True)
cj = sorted(list(cj.items()),key=lambda x:x[1], reverse=True)
xi = [ci[i][0] for i in range(len(ci)) if ci[i][1] == mi]
xj = [cj[i][0] for i in range(len(cj)) if cj[i][1] == mj]
for i in xi:
    for j in xj:
        if (i,j) not in s:
            print((mi+mj))
            quit()
print((mi+mj-1))

# Optimized solution
from collections import Counter
H,W,m = list(map(int,input().split()))
ci = Counter([])
cj = Counter([])
s = set()
for i in range(m):
    h,w = list(map(int,input().split()))
    ci[h] += 1
    cj[w] += 1
    s.add((h,w))
mi = max(ci.values())
mj = max(cj.values())
ci = list(ci.items())
cj = list(cj.items())
xi = [ci[i][0] for i in range(len(ci)) if ci[i][1] == mi]
xj = [cj[i][0] for i in range(len(cj)) if cj[i][1] == mj]
for i in xi:
    for j in xj:
        if (i,j) not in s:
            print((mi+mj))
            quit()
print((mi+mj-1))
# Original solution
def e_bomber():
    from collections import defaultdict
    H, W, M = [int(i) for i in input().split()]

    bomb_row = [0] * H
    bomb_col = [0] * W
    bomb_pos = defaultdict(int)
    for _ in range(M):
        r, c = [int(i) - 1 for i in input().split()]
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos[(r, c)] += 1

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    # 破壊できる数が最大になるような行と列の組を全探索する。
    # (行, 列) が破壊対象の上になってしまわないような組があれば、そこに置けばいい。
    # そのような組がまったくなければ、破壊対象の上に置かざるを得ない (-1 される)。
    flag = False
    for row in [r for r in range(H) if bomb_row_max == bomb_row[r]]:
        for col in [c for c in range(W) if bomb_col_max == bomb_col[c]]:
            if bomb_pos[(row, col)] == 0:
                return bomb_row_max + bomb_col_max
    return bomb_row_max + bomb_col_max - 1

print((e_bomber()))

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

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

    bomb_row = [0] * H
    bomb_col = [0] * W
    bomb_pos = set()
    for _ in range(M):
        r, c = [int(i) - 1 for i in input().split()]
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos.add((r, c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)
    row_index_list = [r for r, v in enumerate(bomb_row) if v == bomb_row_max]
    col_index_list = [c for c, v in enumerate(bomb_col) if v == bomb_col_max]

    # 破壊できる数が最大になるような行と列の組を全探索する。
    # (行, 列) が破壊対象の上になってしまわないような組があれば、そこに置けばいい。
    # そのような組がまったくなければ、破壊対象の上に置かざるを得ない (-1 される)。
    for row in row_index_list:
        for col in col_index_list:
            if (row, col) not in bomb_pos:
                return bomb_row_max + bomb_col_max
    return bomb_row_max + bomb_col_max - 1

print((e_bomber()))
# Original solution
import collections as c

h,w,m = list(map(int,input().split()))
x = []
y = []
z = []
for i in range(m):
    s,t = list(map(int,input().split()))
    x.append(s)
    y.append(t)
    z.append(tuple([s,t]))
a = c.Counter(x)
b = c.Counter(y)
a = a.most_common()
b = b.most_common()
c = []
d = []
e = a[0][1]
f = b[0][1]

for sa in a:
    if sa[1] == e:
        c.append(sa[0])
    else:
        break
for sb in b:
    if sb[1] == f:
        d.append(sb[0])
    else:
        break

fl = 0
ans = e+f-1
for s in c:
    for t in d:
        if tuple([s,t]) not in z:
            fl = 1
            ans += 1
            break
    if fl == 1:
        break
    
print(ans)


# Optimized solution
import collections as c

h,w,m = list(map(int,input().split()))
x = []
y = []
z = set([])
for i in range(m):
    s,t = list(map(int,input().split()))
    x.append(s)
    y.append(t)
    z.add(tuple([s,t]))
a = c.Counter(x)
b = c.Counter(y)
a = a.most_common()
b = b.most_common()
c = []
d = []
e = a[0][1]
f = b[0][1]

for sa in a:
    if sa[1] == e:
        c.append(sa[0])
    else:
        break
for sb in b:
    if sb[1] == f:
        d.append(sb[0])
    else:
        break

fl = 0
ans = e+f-1
for s in c:
    for t in d:
        if tuple([s,t]) not in z:
            fl = 1
            ans += 1
            break
    if fl == 1:
        break
    
print(ans)
# Original solution
import sys
H, W, M = list(map(int, input().split()))
lis =[]
Hlis = [0]*H
Wlis = [0]*W
for _ in range(M):
    Ch, Cm = list(map(int, input().split()))
    Hlis[Ch-1] += 1
    Wlis[Cm-1] += 1
    lis.append([Ch, Cm])

Hmax = max(Hlis)
Hidx = [i+1 for i, v in enumerate(Hlis) if v == Hmax]
Wmax = max(Wlis)
Widx = [i+1 for i, v in enumerate(Wlis) if v == Wmax]

lis=tuple(lis)

for i in range(len(Hidx)):
    for j in range(len(Widx)):
        if [Hidx[i], Widx[j]] not in lis:
            print((Hmax+Wmax))
            sys.exit()
else:
    print((Hmax + Wmax -1))

# Optimized solution
import sys
H, W, M = list(map(int, input().split()))
lis =set()
Hlis = [0]*H
Wlis = [0]*W
for _ in range(M):
    Ch, Cm = list(map(int, input().split()))
    Hlis[Ch-1] += 1
    Wlis[Cm-1] += 1
    lis.add((Ch, Cm))

Hmax = max(Hlis)
Hidx = [i+1 for i, v in enumerate(Hlis) if v == Hmax]
Wmax = max(Wlis)
Widx = [i+1 for i, v in enumerate(Wlis) if v == Wmax]

for i in range(len(Hidx)):
    for j in range(len(Widx)):
        if (Hidx[i], Widx[j]) not in lis:
            print((Hmax+Wmax))
            sys.exit()
else:
    print((Hmax + Wmax -1))
# Original solution
H,W,M = list(map(int,input().split()))

h_target = [0]*(H+1)
w_target = [0]*(W+1)
target = []

for _ in range(M):
    h,w = list(map(int,input().split()))
    target.append((h,w))
    h_target[h] += 1
    w_target[w] += 1

max_h = max(h_target)
max_w = max(w_target)

num_max_h = 0
num_max_w = 0

for i in h_target:
    if i == max_h:
        num_max_h += 1

for i in w_target:
    if i == max_w:
        num_max_w += 1

total = num_max_h*num_max_w
point = 0

for i,j in target:
    if h_target[i] == max_h and w_target[j] == max_w:
        point += 1

if point == total:
    print((max_h+max_w-1))
else:
    print((max_h+max_w))

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

h_target = [0]*(H+1)
w_target = [0]*(W+1)
target = []

for _ in range(M):
    h,w = list(map(int,input().split()))
    target.append((h,w))
    h_target[h] += 1
    w_target[w] += 1

max_h = max(h_target)
max_w = max(w_target)

num_max_h = 0
num_max_w = 0

for i in h_target:
    if i == max_h:
        num_max_h += 1

for i in w_target:
    if i == max_w:
        num_max_w += 1

total = num_max_h*num_max_w # 最適地点の組み合わせ個数
point = 0 # 最適地点のうち爆破対象地点の個数

for i,j in target:
    if h_target[i] == max_h and w_target[j] == max_w:
        point += 1

if point == total:
    print((max_h+max_w-1))
else:
    print((max_h+max_w))
# Original solution
import sys
input = sys.stdin.readline
 
H, W, M = list(map(int, input().split()))
Hsum = [0] * H
Wsum = [0] * W
hw = set()
for m in range(M):
  h, w = list(map(int, input().split()))
  Hsum[h-1] += 1
  Wsum[w-1] += 1
  hw.add((h-1, w-1))

hcnt = Hsum.count(max(Hsum))
wcnt = Wsum.count(max(Wsum))
if hcnt * wcnt > M:
  print((max(Hsum) + max(Wsum)))
  sys.exit()

hidx = [i for i, _ in enumerate(Hsum) if _ == max(Hsum)]
widx = [i for i, _ in enumerate(Wsum) if _ == max(Wsum)]
for h in hidx:
  for w in widx:
    if (h, w) not in hw:
      print((max(Hsum) + max(Wsum)))
      sys.exit()
print((max(Hsum) + max(Wsum) - 1))

# Optimized solution
import sys
input = sys.stdin.readline
 
H, W, M = list(map(int, input().split()))
Hsum = [0] * H
Wsum = [0] * W
hw = set()
for m in range(M):
  h, w = [int(x) - 1 for x in input().split()]
  Hsum[h] += 1
  Wsum[w] += 1
  hw.add((h, w))

mh = max(Hsum)
mw = max(Wsum)
hidx = [i for i, _ in enumerate(Hsum) if _ == mh]
widx = [i for i, _ in enumerate(Wsum) if _ == mw]
 
if len(hidx) * len(widx) > M:
  print((mh + mw))
else:
  fi_flg = False
  for h in hidx:
    for w in widx:
      if (h, w) not in hw:
        print((mh + mw))
        fi_flg = True
        break
    if fi_flg:
      break
  if fi_flg is False:
    print((mh + mw - 1))
# Original solution
import sys
input = sys.stdin.readline

h, w, m = list(map(int, input().split()))
col = [0]*w
row = [0]*h
ypos = []
xpos = []
bomb = []

for i in range(m):
    H, W = [int(x) - 1 for x in input().split()]
    col[W] += 1
    row[H] += 1
    bomb.append((H, W))

maxcol = max(col)
maxrow = max(row)

xpos = [h for h, x in enumerate(col) if x == maxcol]
ypos = [w for w, y in enumerate(row) if y == maxrow]

ans = maxcol + maxrow - 1

for i in ypos:
    for j in xpos:
        if (i, j) not in bomb:
            ans += 1
            print(ans)
            exit()
print(ans)

# Optimized solution
h, w, m = list(map(int, input().split()))
col = [0]*w
row = [0]*h
ypos = []
xpos = []
bomb = []

for i in range(m):
    H, W = [int(x) - 1 for x in input().split()]
    col[W] += 1
    row[H] += 1
    bomb.append((H, W))

maxcol = max(col)
maxrow = max(row)

for i in range(w):
    if col[i] == maxcol:
        xpos.append(i)
for i in range(h):
    if row[i] == maxrow:
        ypos.append(i)

ans = maxcol + maxrow - 1
bomb = set(bomb) #setにすると速い

for i in ypos:
    for j in xpos:
        if (i, j) not in bomb:
            ans += 1
            print(ans)
            exit()
print(ans)
# Original solution
H, W, M = list(map(int, input().split()))
hn = {}
wn = {}
flag = set()
for i in range(M):
  h, w = list(map(int, input().split()))
  if (h,w) not in flag: 
    if h in hn:
      hn[h] += 1
    else:
      hn[h] = 1
    if w in wn:
      wn[w] += 1
    else:
      wn[w] = 1
  flag.add((h,w))
  
hrank = sorted(list(hn.items()), key=lambda t:-t[1])
wrank = sorted(list(wn.items()), key=lambda t:-t[1])

hmax = hrank[0][1]
wmax = wrank[0][1]

hmaxlist =[]
for k,v in hrank:
  if v == hmax:
    hmaxlist.append(k)
  else:
    break

wmaxlist =[]
for k,v in wrank:
  if v == wmax:
    wmaxlist.append(k)
  else:
    break

flag2 = set()
for i in hmaxlist:
  for j in wmaxlist:
    flag2.add((i,j))

if len(flag2 - flag) == 0:
  print((hmax+wmax -1))
else:
  print((hmax+wmax))

# Optimized solution
import sys
H, W, M = list(map(int, input().split()))
hn = [0]*H
wn = [0]*W
flag = set()
for i in range(M):
  h, w = list(map(int, input().split()))
  hn[h-1] += 1
  wn[w-1] += 1
  flag.add((h,w))
  
#hrank = sorted(hn, key=lambda t:-t[1])
#wrank = sorted(wn, key=lambda t:-t[1])

hmax = max(hn)
wmax = max(wn)

hmaxlist = {i+1 for i,h in enumerate(hn) if h == hmax}
#for h in hn:
#  if h == hmax:
#    hmaxlist.append(h)
  
wmaxlist = {i+1 for i,w in enumerate(wn) if w == wmax}
#for w in wn:
#  if w == wmax:
#    wmaxlist.append(w)
  

for i in hmaxlist:
  for j in wmaxlist:
    if (i,j) not in flag:
      print((hmax+wmax))
      sys.exit()
print((hmax+wmax-1))