CodeEff/ECCO huggingface dataset:
# Original solution
H,W,M=list(map(int,input().split()))
h=[0]*M
w=[0]*M
for i in range(M):
    h[i],w[i]=list(map(int,input().split()))
t=[0]*H
y=[0]*W
for i in range(H):
    a = 0
    for j in range(M):
        if h[j] == i+1:
            a = a+1
        t[i] = a
for i in range(W):
    a = 0
    for j in range(M):
        if w[j] == i+1:
            a = a+1
        y[i] = a       
maxt = max(t)
maxy = max(y)
lt=[]
ly=[]
for i in range(len(t)):
    if t[i] == maxt:
        lt.append(i+1)
for i in range(len(y)):
    if y[i] == maxy:
        ly.append(i+1)
b = 0
for i in range(M):
    if h[i] in lt and w[i] in ly:
        b = b + 1
if b == len(lt)*len(ly):
    print((maxt+maxy-1))
else:
    print((maxt+maxy))

# Optimized solution
H,W,M=list(map(int,input().split()))
bomb=[]
h=[0]*H
w=[0]*W
for i in range(M):
    hi,wi=list(map(int,input().split()))
    h[hi-1] += 1
    w[wi-1] += 1
    bomb.append([hi,wi])    
maxh = max(h)
maxw = max(w)
ans = maxh +  maxw
lh=[]
lw=[]
for i in range(len(h)):
    if h[i] == maxh:
        lh.append(i+1)
for i in range(len(w)):
    if w[i] == maxw:
        lw.append(i+1)
a = 0
for i in range(M):
    if ans == h[bomb[i][0]-1]+w[bomb[i][1]-1]:
        a += 1
if a == len(lh)*len(lw):
    print((ans-1))
else:
    print(ans)
# Original solution
H,W,M = list(map(int,input().split()))
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = list(map(int,input().split()))
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in list(H_cnt.items())]
WL = [[w,cnt] for w,cnt in list(W_cnt.items())]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = []
max_cnt = 0
for h,cnt in HL:
    if max_cnt<=cnt:
        HS.append([h,cnt])
        max_cnt = max(max_cnt,cnt)
        continue
    break

WS = []
max_cnt = 0
for w,cnt in WL:
    if max_cnt<=cnt:
        WS.append([w,cnt])
        max_cnt = max(max_cnt,cnt)
        continue
    break

cnt = 0
ans = 0

# ここの判定を高速にする
#cross_cnt = 0
#for hw in HW.keys():
#    h,w = hw
#    if h in HS and w in WS:
#        cross_cnt+=1


for h,hcnt in HS:
    for w,wcnt in WS:
        if (h,w) in HW:
            cnt = hcnt+wcnt-1
            ans = max(ans,cnt)
            continue
        cnt = hcnt+wcnt
        ans = max(ans,cnt)

print(ans)

















# Optimized solution
H,W,M = list(map(int,input().split()))
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = list(map(int,input().split()))
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in list(H_cnt.items())]
WL = [[w,cnt] for w,cnt in list(W_cnt.items())]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = {}
max_cnth = 0
for h,cnt in HL:
    if max_cnth<=cnt:
        HS[h] = cnt
        max_cnth = max(max_cnth,cnt)
        continue
    break

WS = {}
max_cntw = 0
for w,cnt in WL:
    if max_cntw<=cnt:
        WS[w] = cnt
        max_cntw = max(max_cntw,cnt)
        continue
    break

cnt = 0
ans = 0

# ここの判定を高速にする
cross_cnt = 0
for hw in list(HW.keys()):
    h,w = hw
    if h in HS and w in WS:
        cross_cnt+=1
if len(WS) * len(HS)==cross_cnt:
    print((max_cnth+max_cntw-1))
    exit()
print((max_cnth+max_cntw))


#for h,hcnt in HS:
#    for w,wcnt in WS:
#        if (h,w) in HW:
#            cnt = hcnt+wcnt-1
#            ans = max(ans,cnt)
#            continue
#        cnt = hcnt+wcnt
#        ans = max(ans,cnt)
# Original solution
from collections import defaultdict

h, w, m = list(map(int, input().split()))
HW = [list(map(int, input().split())) for _ in range(m)]
H = [i for i, _ in HW]
W = [i for _, i in HW]

hd = defaultdict(int)
wd = defaultdict(int)

for i, j in HW:
  hd[i] += 1
  wd[j] += 1

hd = list(hd.items())
wd = list(wd.items())

hd.sort(key=lambda x: -x[1])
wd.sort(key=lambda x: -x[1])

kouhoh = []
kouhow = []

for i, j in hd:
  if j < hd[0][1]:
    break
  else:
    kouhoh.append(i)

for i, j in wd:
  if j < wd[0][1]:
    break
  else:
    kouhow.append(i)

for i in kouhoh:
  for j in kouhow:
    if [i, j] not in HW:
      ans = hd[0][1] + wd[0][1]
      print(ans)
      exit()

ans = hd[0][1] + wd[0][1] - 1  
print(ans)

# Optimized solution
from collections import defaultdict

h, w, m = list(map(int, input().split()))
HW = [list(map(int, input().split())) for _ in range(m)]
dicHW = defaultdict(set)

for h, w in HW:
  dicHW[h].add(w)

hd = defaultdict(int)
wd = defaultdict(int)

for i, j in HW:
  hd[i] += 1
  wd[j] += 1

hd = list(hd.items())
wd = list(wd.items())

hd.sort(key=lambda x: -x[1])
wd.sort(key=lambda x: -x[1])

kouhoh = []
kouhow = []

for i, j in hd:
  if j < hd[0][1]:
    break
  else:
    kouhoh.append(i)

for i, j in wd:
  if j < wd[0][1]:
    break
  else:
    kouhow.append(i)

for i in kouhoh:
  for j in kouhow:
    if j not in dicHW[i]:
      ans = hd[0][1] + wd[0][1]
      print(ans)
      exit()

ans = hd[0][1] + wd[0][1] - 1  
print(ans)
# Original solution
import queue
h,w,m = ( int(x) for x in input().split() )

h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
    hi,wi = ( int(x)-1 for x in input().split() )
    h_array[hi] += 1
    w_array[wi] += 1
    ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i in range( h ):
    if h_array[i] == h_great:
        h_greats.append(i)
for i in range( w ):
    if w_array[i] == w_great:
        w_greats.append(i)

ans = h_great + w_great - 1

escaper = False

for i in range( len(h_greats) ):
    hi = h_greats[i]
    for j in range( len(w_greats) ):
        wi = w_greats[j]
        if (hi,wi) not in ps:
            ans += 1
            escaper = True
            break
    if escaper:
        break

print(ans)

# Optimized solution
h,w,m = ( int(x) for x in input().split() )

h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
    hi,wi = ( int(x)-1 for x in input().split() )
    h_array[hi] += 1
    w_array[wi] += 1
    ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
    if hi == h_great:
        h_greats.append(i)
for i , wi in enumerate(w_array):
    if wi == w_great:
        w_greats.append(i)

ans = h_great + w_great


for _h in h_greats:
    for _w in w_greats:
        if (_h,_w) in ps:
            continue
        print(ans)
        exit()

print((ans-1))
# Original solution
h,w,m = ( int(x) for x in input().split() )

h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
    hi,wi = ( int(x)-1 for x in input().split() )
    h_array[hi] += 1
    w_array[wi] += 1
    ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
    if hi == h_great:
        h_greats.append(i)
for i , wi in enumerate(w_array):
    if wi == w_great:
        w_greats.append(i)

ans = h_great + w_great


for _h in h_greats:
    for _w in w_greats:
        if (_h,_w) in ps:
            continue
        print(ans)
        exit()

print((ans-1))

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

h,w,m = list(map(int,input().split()))

h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
    hi,wi = [int(x) - 1 for x in input().split()]
    h_array[hi] += 1
    w_array[wi] += 1
    ps.add( (hi,wi) )

h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
    if hi == h_great:
        h_greats.append(i)
for i , wi in enumerate(w_array):
    if wi == w_great:
        w_greats.append(i)

ans = h_great + w_great


for _h in h_greats:
    for _w in w_greats:
        if (_h,_w) in ps:
            continue
        print(ans)
        exit()

print((ans-1))
# Original solution
import sys
input = sys.stdin.readline

h,w,m = list(map(int,input().split()))

h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
    hi,wi = [int(x) - 1 for x in input().split()]
    h_array[hi] += 1
    w_array[wi] += 1
    ps.add( (hi,wi) )

h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
    if hi == h_great:
        h_greats.append(i)
for i , wi in enumerate(w_array):
    if wi == w_great:
        w_greats.append(i)

ans = h_great + w_great


for _h in h_greats:
    for _w in w_greats:
        if (_h,_w) in ps:
            continue
        print(ans)
        exit()

print((ans-1))

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

def main():
    h,w,m = list(map(int,input().split()))

    h_array = [ 0 for _ in range(h) ]
    w_array = [ 0 for _ in range(w) ]
    ps = set()
    for i in range(m):
        hi,wi = [int(x) - 1 for x in input().split()]
        h_array[hi] += 1
        w_array[wi] += 1
        ps.add( (hi,wi) )

    h_great = max(h_array)
    w_great = max(w_array)
    h_greats = list()
    w_greats = list()
    for i , hi in enumerate(h_array):
        if hi == h_great:
            h_greats.append(i)
    for i , wi in enumerate(w_array):
        if wi == w_great:
            w_greats.append(i)

    ans = h_great + w_great


    for _h in h_greats:
        for _w in w_greats:
            if (_h,_w) in ps:
                continue
            print(ans)
            exit()

    print((ans-1))

if __name__ == '__main__':
    main()
# Original solution
h,w,m=list(map(int,input().split()))
a=[[] for i in range(m)]
g=[0 for i in range(h)]
r=[0 for i in range(w)]

for i in range(m):
    x,y=list(map(int,input().split()))
    a[i].append(x)
    a[i].append(y)
    g[x-1]+=1
    r[y-1]+=1
G=[]
R=[]
d=max(g)
e=max(r)
for i in range(h):
    if g[i]==d:
        G.append(i+1)
for i in range(w):
    if r[i]==e:
        R.append(i+1)
f=0
for i in range(m):
    q=0
    p=0
    x=a[i][0]
    y=a[i][1]
    k=len(G)-1
    l=0
    j=(k+l)//2
    while k-l>1:
        j=(k+l)//2
        if G[j]>=x:
            k=j
        else:
            l=j
    if G[l]==x or G[k]==x:
        p=1

    k = len(R) - 1
    l = 0
    j = (k + l) // 2
    while k - l > 1:
        j = (k + l) // 2
        if R[j] >=y:
            k = j
        else:
            l = j
    if R[l] == y or R[k] == y:
        q = 1

    if p==q==1:
        f+=1
v=1
if f!=len(G)*len(R):
    v=0
ans=max(g)+max(r)
print((ans if v==0 else ans-1))


# Optimized solution
h,w,m=list(map(int,input().split()))
a=[[] for i in range(m)]
g=[0 for i in range(h)]
r=[0 for i in range(w)]

for i in range(m):
    x,y=list(map(int,input().split()))
    a[i].append(x)
    a[i].append(y)
    g[x-1]+=1
    r[y-1]+=1
G=[0 for i in range(h)]
R=[0 for i in range(w)]
d=max(g)
e=max(r)
for i in range(h):
    if g[i]==d:
        G[i]=1
for i in range(w):
    if r[i]==e:
        R[i]=1
f=0
for i in range(m):
    p=0
    q=0
    x=a[i][0]
    y=a[i][1]
    if G[x-1]==1:
        p=1
    if R[y-1]==1:
        q=1


    if p==q==1:
        f+=1
v=1
if f!=G.count(1)*R.count(1):
    v=0
ans=max(g)+max(r)
print((ans if v==0 else ans-1))
# Original solution
# -*- coding: utf-8 -*-
H, W, M = list(map(int, input().split()))

h_list = [0 for _ in range(H + 1)]
w_list = [0 for _ in range(W + 1)]
m_list = [[0 for _ in range(W + 1)] for _ in range(H + 1)]
for i in range(M):
    h, w = list(map(int, input().split()))
    h_list[h] += 1
    w_list[w] += 1
    m_list[h][w] = 1

max_h_list = []
max_h = -1
for i in range(H + 1):
    if max_h == h_list[i]:
        max_h_list.append(i)
    elif max_h < h_list[i]:
        max_h = h_list[i]
        max_h_list = [i]

max_w_list = []
max_w = -1
for i in range(W + 1):
    if max_w == w_list[i]:
        max_w_list.append(i)
    elif max_w < w_list[i]:
        max_w = w_list[i]
        max_w_list = [i]

adjust_dupl = 1
for i in range(len(max_h_list)):
    for j in range(len(max_w_list)):
        if m_list[max_h_list[i]][max_w_list[j]] == 0:
            adjust_dupl = 0
            break
    if adjust_dupl == 0:
        break
print((max_h + max_w - adjust_dupl))

# Optimized solution
# -*- coding: utf-8 -*-
H, W, M = list(map(int, input().split()))

h_list = [0 for _ in range(H + 1)]
w_list = [0 for _ in range(W + 1)]
m_dic = {}
for i in range(M):
    h, w = list(map(int, input().split()))
    h_list[h] += 1
    w_list[w] += 1
    m_dic["{}_{}".format(h, w)] = 1

max_h_list = []
max_h = -1
for i in range(H + 1):
    if max_h == h_list[i]:
        max_h_list.append(i)
    elif max_h < h_list[i]:
        max_h = h_list[i]
        max_h_list = [i]

max_w_list = []
max_w = -1
for i in range(W + 1):
    if max_w == w_list[i]:
        max_w_list.append(i)
    elif max_w < w_list[i]:
        max_w = w_list[i]
        max_w_list = [i]

adjust_dupl = 1
for i in range(len(max_h_list)):
    for j in range(len(max_w_list)):
        if "{}_{}".format(max_h_list[i], max_w_list[j]) not in m_dic:
            adjust_dupl = 0
            break
    if adjust_dupl == 0:
        break
print((max_h + max_w - adjust_dupl))
# Original solution
import itertools

h, w, m = list(map(int,input().split(' ')))
x = [0] * 300001
y = [0] * 300001
z = []
mx, my = 0, 0
for i in range(m):
    a, b = list(map(int,input().split(' ')))
    x[a] += 1
    y[b] += 1
    mx = max(mx, x[a])
    my = max(my, y[b])
    z.append((a, b))
x1 = [i for i in range(300001) if x[i] == mx]
y1 = [i for i in range(300001) if y[i] == my]
z1 = list(itertools.product(x1, y1))
if all(i in z for i in z1): print((mx + my - 1))
else: print((mx + my))

# Optimized solution
import itertools

h, w, m = list(map(int,input().split(' ')))
x = [0] * 300001
y = [0] * 300001
z = []
mx, my = 0, 0
for i in range(m):
    a, b = list(map(int,input().split(' ')))
    x[a] += 1
    y[b] += 1
    mx = max(mx, x[a])
    my = max(my, y[b])
    z.append((a, b))
x1 = x.count(mx)
y1 = y.count(my)
z1 = x1 * y1
for i, j in z:
    if x[i] == mx and y[j] == my:
        z1 -= 1
if z1: print((mx + my))
else: print((mx + my - 1))
# Original solution
import sys
from collections import Counter
def input(): return sys.stdin.readline().rstrip()


def main():
    H,W,m=list(map(int, input().split()))
    Hline=[]
    wline=[]
    blist=[]
    for k in range(m):
        h,w=list(map(int, input().split()))
        Hline.append(h)
        wline.append(w)
        blist.append([h,w])
    hc=Counter(Hline).most_common()
    wc=Counter(wline).most_common()
    ans=hc[0][1]+wc[0][1]
    hl=[]
    wl=[]
    for hcc in hc:
        if hcc[1]!= hc[0][1]:
            break
        hl.append(hcc[0])
    for wcc in wc:
        if wcc[1]!= wc[0][1]:
            break
        wl.append(wcc[0])
    for hll in hl:
        for wll in wl:
            if [hll,wll] not in blist:
                print(ans)
                exit()
    print((ans-1))

    
        



if __name__ == '__main__':
    main()

# Optimized solution
import sys
from collections import Counter
def input(): return sys.stdin.readline().rstrip()


def main():
    H,W,m=list(map(int, input().split()))
    Hline=[]
    wline=[]
    blist=dict()
    for k in range(m):
        h,w=list(map(int, input().split()))
        Hline.append(h)
        wline.append(w)
        blist[h*(W+2)+w]=0
    hc=Counter(Hline).most_common()
    wc=Counter(wline).most_common()
    ans=hc[0][1]+wc[0][1]
    hl=[]
    wl=[]
    for hcc in hc:
        if hcc[1]!= hc[0][1]:
            break
        hl.append(hcc[0])
    for wcc in wc:
        if wcc[1]!= wc[0][1]:
            break
        wl.append(wcc[0])
    for hll in hl:
        for wll in wl:
            if hll*(W+2)+wll not in blist:
                print(ans)
                exit()
    print((ans-1))

    
        



if __name__ == '__main__':
    main()
# Original solution
H, W, M = list(map(int, input().split()))

visited = set()

h_sum = [0] * H
w_sum = [0] * W

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

max_h = max_w = 0
can_h = []
can_w = []
for i in range(H):
    max_h = max(max_h, h_sum[i])
    
for i in range(W):
    max_w = max(max_w, w_sum[i])

for i in range(H):
    if h_sum[i] == max_h:
        can_h.append(i)
for i in range(W):
    if w_sum[i] == max_w:
        can_w.append(i)
        
ans = 0

for i in can_h:
    for j in can_w:
        if (i, j) in visited:
            ans = max(ans, max_h+max_w-1)
        else:
            ans = max(ans, max_h+max_w)
print(ans)                

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

visited = set()

h_sum = [0] * H
w_sum = [0] * W

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

max_h = max_w = 0
can_h = []
can_w = []
for i in range(H):
    max_h = max(max_h, h_sum[i])
    
for i in range(W):
    max_w = max(max_w, w_sum[i])

for i in range(H):
    if h_sum[i] == max_h:
        can_h.append(i)
for i in range(W):
    if w_sum[i] == max_w:
        can_w.append(i)
        
ans = max_h + max_w

for i in can_h:
    for j in can_w:
        if (i, j) not in visited:
            print(ans)
            exit()

print((ans-1))
# Original solution
H,W,M=list(map(int,input().split()))
nh=[0]*H
nw=[0]*W
boms=[]
for _ in range(H):
    boms.append([False]*W)
for _ in range(M):
    h,w=list(map(int,input().split()))
    nh[h-1] += 1
    nw[w-1] += 1
    boms[h-1][w-1]=True

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if not boms[i][j]:
            print((maxh + maxw))
            exit()
print((maxh + maxw - 1))


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

H,W,M=list(map(int,input().split()))
nh=[0]*H
nw=[0]*W
boms=set()
for _ in range(M):
    h,w=list(map(int,input().split()))
    nh[h-1] += 1
    nw[w-1] += 1
    boms.add((h-1, w-1))

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if (i,j) in boms:
            continue
        print((maxh + maxw))
        exit()
print((maxh + maxw - 1))
# Original solution
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=[]
#O(M)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.append([hi,wi])

#O(M)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(M)
hidx=[x for x,y in list(hcnt.items()) if y==hmax]
widx=[x for x,y in list(wcnt.items()) if y==wmax]

#O(M**2*)
ofst=-1
for i in hidx:
    for j in widx:
        if not [i,j] in bomb:
            ofst=0
            break
                
print((hmax+wmax+ofst))

# Optimized solution
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
#存在チェックのアクセスがリストで持たせるより高速
#リストは突っ込めないので注意(hashabeのみOK)
bomb=set()
#O(H)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

#O(H)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(H)
hidx=[x for x,y in list(hcnt.items()) if y==hmax]
widx=[x for x,y in list(wcnt.items()) if y==wmax]

#O(H**2)
ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print((hmax+wmax+ofst))
# Original solution
# E
from collections import Counter

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

most_h,most_w=Counter(h).most_common(),Counter(w).most_common()

def max_values(lis):
    max_num=lis[0][1]
    for i in range(len(lis)):
        if lis[i][1]<max_num:
            res=lis[:i]
            break
    else:
        res=lis
    return res

most_h=max_values(most_h)
most_w=max_values(most_w)

res=-1
k=0
for i,i_n in most_h:
    for j,j_n in most_w:
        if not (i,j) in bomb or k>M:
            res=i_n+j_n
            break
        k+=1
    if res>-1:
        break
else:
    res=i_n+j_n-1
print(res)


# Optimized solution
H,W,M=list(map(int,input().split()))
h,w,bomb=[0]*H,[0]*W,[]
for i in range(M):
    a,b=list(map(int,input().split()))
    bomb.append((a-1,b-1))
    h[a-1]+=1
    w[b-1]+=1
    
max_h=max(h)
max_w=max(w)

bomb_and_max=0
for i,j in bomb:
    if h[i]==max_h and w[j]==max_w:
        bomb_and_max+=1
    
if bomb_and_max==h.count(max_h)*w.count(max_w):
    print((max_h+max_w-1))
else:
    print((max_h+max_w))
# Original solution
ans=0

h,w,m=list(map(int,input().split()))
d=list()
from collections import defaultdict
r=defaultdict(int)
c=defaultdict(int)
r=[0]*(h+1)
c=[0]*(w+1)
for i in range(m):
  a,b=list(map(int,input().split()))
  d+=(a,b),
  r[a]+=1
  c[b]+=1
R=max(r)
C=max(c)

x=0
nr=r.count(R)
nc=c.count(C)
for i in range(m):
    a,b=d[i]
    if r[a]==R and c[b]==C:
        x+=1

ans=R+C
if x==nr*nc:
    ans-=1
print(ans)


# Optimized solution
H, W, M = list(map(int, input().split()))
lh = [0]*(H+1)
lw = [0]*(W+1)
l = []
for _ in range(M):
  h, w = list(map(int, input().split()))
  lh[h] += 1
  lw[w] += 1
  l += [[h, w]]

maxh = max(lh)
maxw = max(lw)
cnt = 0

ch = lh.count(maxh)
cw = lw.count(maxw)
for y, x in l:
  if lh[y] == maxh and lw[x] == maxw:
    cnt += 1

ans = maxh+maxw
if cnt == ch*cw:
  ans -= 1

print(ans)
# Original solution
H, W, M = list(map(int, input().split()))
countH = [[h, 0] for h in range(H)]
countW = [[w, 0] for w in range(W)]
Bh = {}

for i in range(M):
  h, w = list(map(int, input().split()))
  h, w = h-1, w-1
  if h in Bh:
    Bh[h].add(w)
  else:
    Bh[h] = {w}
  countH[h][1] += 1
  countW[w][1] += 1

countH.sort(reverse=True, key=lambda x: x[1])
countW.sort(reverse=True, key=lambda x: x[1])
#print(countH)
#print(countW)
#rint(Bh)

maxh = countH[0][1]
maxw = countW[0][1]
ans = maxh + maxw
ch = [countH[0][0]]
i = 1
while i < H and countH[i][1]==maxh:
  ch.append(countH[i][0])
  i += 1
cw = [countW[0][0]]
i = 1
while i < W and countW[i][1]==maxw:
  cw.append(countW[i][0])
  i += 1
flag = False
for h in ch:
  for w in cw:
    #print(h,w)
    if w not in Bh[h]:
      flag = True
      break
if flag:
  print(ans)
else:
  print((ans-1))

# Optimized solution
H, W, M = list(map(int, input().split()))
countH = [0 for h in range(H)]
countW = [0 for w in range(W)]
Bh = {}

for i in range(M):
  h, w = list(map(int, input().split()))
  h, w = h-1, w-1
  if h in Bh:
    Bh[h].add(w)
  else:
    Bh[h] = {w}
  countH[h] += 1
  countW[w] += 1

maxh = 0
ch = []
maxw = 0
cw = []
for i in range(H):
  if maxh==countH[i]:
    ch.append(i)
  elif maxh<countH[i]:
    ch = [i]
    maxh = countH[i]
for i in range(W):
  if maxw==countW[i]:
    cw.append(i)
  elif maxw<countW[i]:
    cw = [i]
    maxw = countW[i]

#print(countH)
#print(countW)
#rint(Bh)
ans = maxh + maxw
flag = False
for h in ch:
  for w in cw:
    #print(h,w)
    if w not in Bh[h]:
      flag = True
      break
if flag:
  print(ans)
else:
  print((ans-1))