CodeEff/ECCO huggingface dataset:
# Original solution
H, W, M = list(map(int, input().split()))
m = [[False] * W for _ in range(H)]
dh = dict()
dw = dict()
for _ in range(M):
    h_, w_ = list(map(int, input().split()))
    m[h_ - 1][w_ - 1] = True
    
    if h_ in dh:
        dh[h_] += 1
    else:
        dh[h_] = 1
        
    if w_ in dw:
        dw[w_] += 1
    else:
        dw[w_] = 1

dhl = list(dh.items())
dhl.sort(key=lambda x: x[1], reverse=True)
dwl = list(dw.items())
dwl.sort(key=lambda x: x[1], reverse=True)

h, w = [], []
maxh = dhl[0][1]
maxw = dwl[0][1]

for i, n in dhl:
    if n == maxh:
        h.append(i)
for i, n in dwl:
    if n == maxw:
        w.append(i)

res = maxh + maxw - 1
for hh in h:
    for ww in w:
        if m[hh - 1][ww - 1] is False:
            res = maxh + maxw
            break

print(res)


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

hmax = max(h)
wmax = max(w)

cnt = h.count(hmax) * w.count(wmax)
for hh, ww in boms:
    if hmax == h[hh] and wmax == w[ww]:
        cnt -= 1

print((hmax + wmax - (cnt == 0)))
# Original solution
h,w,m = list(map(int,input().split()))
p = [[0 for i in range(w)]for i in range(h)]
hlist = [0 for i in range(h)]
wlist = [0 for i in range(w)]
for i in range(m):
    a,b = list(map(int,input().split()))
    hlist[a-1] += 1
    wlist[b-1] += 1
    p[a-1][b-1] = 1
q = 0
for i in range(h):
    q = max(q,hlist[i])
s = []
for i in range(h):
    if hlist[i] == q:
        s.append(i)
r = 0
for i in range(w):
    r = max(r,wlist[i])
t = []
for i in range(w):
    if wlist[i] == r:
        t.append(i)
ans = 0
for i in range(len(s)):
    for j in range(len(t)):
        if p[s[i]][t[j]] == 1:
            pass
        else:
            ans = q+r
            break
if ans == 0:
    print((q+r-1))
else:
    print(ans)

# Optimized solution
h,w,m = list(map(int,input().split()))
p = []
hlist = [0 for i in range(h)]
wlist = [0 for i in range(w)]
for i in range(m):
    a,b = list(map(int,input().split()))
    hlist[a-1] += 1
    wlist[b-1] += 1
    p.append([a-1,b-1])
q = 0
for i in range(h):
    q = max(q,hlist[i])
s = []
for i in range(h):
    if hlist[i] == q:
        s.append(i)
r = 0
for i in range(w):
    r = max(r,wlist[i])
t = []
for i in range(w):
    if wlist[i] == r:
        t.append(i)
z = 0
for i in range(m):
    if hlist[p[i][0]] == q and wlist[p[i][1]] == r:
        z += 1
if z == len(s)*len(t):
    print((q+r-1))
else:
    print((q+r))
# Original solution
from collections import defaultdict
H, W, M = list(map(int, input().split()))
r = defaultdict(int)
c = defaultdict(int)
rc = defaultdict(int)
for i in range(M):
    h, w = list(map(int, input().split()))
    rc[(h, w)] += 1
    r[w] += 1
    c[h] += 1

ri, rmax = 0, 0
ci, cmax = 0, 0
for i in list(r.keys()):
    v = r[i]
    if v > rmax:
        ri = i
        rmax = v
for i in list(c.keys()):
    v = c[i]
    if v > cmax:
        ci = i
        cmax = v

rml, cml = [], []
for i, v in list(r.items()):
    if v == rmax:
        rml.append((i, v))
for i, v in list(c.items()):
    if v == cmax:
        cml.append((i, v))


ans = rmax+cmax-1
for i, vi in rml:
    find = False
    for j, vj in cml:
        if not (j, i) in rc:
            ans += 1
            find = True
            break
    if find:
        break
print(ans)


# Optimized solution
H, W, M = list(map(int, input().split()))
r = [0]*(W+1)
c = [0]*(H+1)
rc = {}
for i in range(M):
    h, w = list(map(int, input().split()))
    rc[(h, w)] = True
    r[w] += 1
    c[h] += 1

rm = max(r)
cm = max(c)

ri = {i for i, v in enumerate(r) if v == rm}
ci = {i for i, v in enumerate(c) if v == cm}

cnt = sum([w in ri and h in ci for h, w in rc])
print((rm+cm-(len(ri)*len(ci) == cnt)))
# Original solution
from collections import Counter
from collections import defaultdict

def li():
    return [int(x) for x in input().split()]

H, W, M = li()
PH = []
PW = []
PF = defaultdict(int)

for i in range(M):
    h, w = li()
    PH.append(h)
    PW.append(w)
    PF[h, w] += 1

frequency_h_list = Counter(PH).most_common()
frequency_w_list = Counter(PW).most_common()
most_common_h_cnt = frequency_h_list[0][1]
most_common_w_cnt = frequency_w_list[0][1]

most_common_h_list = []
for x in frequency_h_list:
    if x[1] < most_common_h_cnt:
        break
    most_common_h_list.append(x[0])

most_common_w_list = []
for x in frequency_w_list:
    if x[1] < most_common_w_cnt:
        break
    most_common_w_list.append(x[0])

add = -1
for h in most_common_h_list:
    for w in most_common_w_list:
        if PF[h, w] == 0:
            add = 0

cnt = most_common_h_cnt + most_common_w_cnt + add

print(cnt)

# Optimized solution
from collections import Counter
from collections import defaultdict

def li():
    return [int(x) for x in input().split()]

H, W, M = li()
PH = []
PW = []
PF = defaultdict(int)

for i in range(M):
    h, w = li()
    PH.append(h)
    PW.append(w)
    PF[h, w] += 1

frequency_h_list = Counter(PH).most_common()
frequency_w_list = Counter(PW).most_common()
most_common_h_cnt = frequency_h_list[0][1]
most_common_w_cnt = frequency_w_list[0][1]

most_common_h_list = []
for x in frequency_h_list:
    if x[1] < most_common_h_cnt:
        break
    most_common_h_list.append(x[0])

most_common_w_list = []
for x in frequency_w_list:
    if x[1] < most_common_w_cnt:
        break
    most_common_w_list.append(x[0])

add = -1
for h in most_common_h_list:
    for w in most_common_w_list:
        if PF[h, w] == 0:
            add = 0
            break

cnt = most_common_h_cnt + most_common_w_cnt + add

print(cnt)
# Original solution
h,w,m=list(map(int,input().split()))
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=[]


for i in range(m):
  a,b=list(map(int,input().split()))
  hlist[a]+=1
  wlist[b]+=1
  cnt.append([a,b])


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if [i,j] not in cnt:
      print((hcnt+wcnt))
      exit()


print((hcnt+wcnt-1))

# Optimized solution
h,w,m=list(map(int,input().split()))
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=list(map(int,input().split()))
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if not (i,j) in cnt:
      print((hcnt+wcnt))
      exit()


print((hcnt+wcnt-1))
# Original solution
h,w,m=list(map(int,input().split()))
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=list(map(int,input().split()))
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if not (i,j) in cnt:
      print((hcnt+wcnt))
      exit()


print((hcnt+wcnt-1))


# Optimized solution
h,w,m=list(map(int,input().split()))
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=list(map(int,input().split()))
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if (i,j) not in cnt:
      print((hcnt+wcnt))
      exit()


print((hcnt+wcnt-1))
# Original solution
h,w,m=list(map(int,input().split()))

hlis=[0 for i in range(h)]
wlis=[0 for i in range(w)]
lis=[[0 for _ in range(w)] for _ in range(h)]

for i in range(m):
  hi,wi=list(map(int,input().split()))
  hlis[hi-1]+=1
  wlis[wi-1]+=1
  lis[hi-1][wi-1]+=1


hmax=max(hlis)
wmax=max(wlis)

ph=[]
pw=[]
for i in range(h):
  if hlis[i]==hmax:
    ph.append(i)
for i in range(w):
  if wlis[i]==wmax:
    pw.append(i)


cvac=0
for phi in ph:
  for pwj in pw:
    if lis[phi][pwj]==0:
      cvac+=1
      break
  if cvac==1:
    break

if cvac==1:
  print((hmax+wmax))
else:
  print((hmax+wmax-1))

# Optimized solution
import sys

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


hlis=[0 for i in range(h)]
wlis=[0 for i in range(w)]
hw=[]

for i in range(m):
  hi,wi=list(map(int,input().split()))
  hlis[hi-1]+=1
  wlis[wi-1]+=1
  hw.append([hi-1,wi-1])

hmax=max(hlis)
wmax=max(wlis)

ph=[]
pw=[]
for i in range(h):
  if hlis[i]==hmax:
    ph.append(i)
for i in range(w):
  if wlis[i]==wmax:
    pw.append(i)

if len(ph)*len(pw)>3*(10**5):
  print((hmax+wmax))
  sys.exit()

plis=[]
for phi in ph:
  for pwj in pw:
    plis.append(phi*(10**6)+pwj)

plis.sort()

hwlis=[]
for hi,wi in hw:
  hwlis.append(hi*(10**6)+wi)

hwlis.sort()
    
c=0
check=0

for pi in plis:
  while pi!=hwlis[c]:
    c+=1
    if c>=len(hwlis):
      check=1
      break
  if check==1:
    break

if check==1:
  print((hmax+wmax))
else:
  print((hmax+wmax-1))
# Original solution
import itertools
H, W, M = list(map(int, input().split()))
row=[0]*H
col=[0]*W

mat=[[0 for i in range(W)] for j in range(H)]

for i in range(M):
  h, w = list(map(int, input().split()))
  h-=1
  w-=1
  row[h]+=1
  col[w]+=1
  mat[h][w]+=1

r=max(row)
c=max(col)

rr=[i for i in range(H) if row[i]==r]
cc=[i for i in range(W) if col[i]==c]

x=min([min([mat[i][j] for j in cc]) for i in rr])

if x==0:
  print((r+c))
else:
  print((r+c-1))

# Optimized solution
H, W, M = list(map(int, input().split()))
row=[0]*H
col=[0]*W

mat=[]

for i in range(M):
  h, w = list(map(int, input().split()))
  row[h-1]+=1
  col[w-1]+=1
  mat.append((h-1,w-1))
  
r=max(row)
c=max(col)

rr=[1 if row[i]==r else 0 for i in range(H)]
cc=[1 if col[i]==c else 0 for i in range(W)]

x=0
for k in mat:
  if rr[k[0]]==1 and cc[k[1]]==1:
    x+=1

if sum(rr)*sum(cc)==x:
  print((r+c-1))
else:
  print((r+c))
# Original solution
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


H, W, M = MI()
h = [0] * H
w = [0] * W
item_list = [[0, 0] for _ in range(M)]

for i in range(M):
    item_h, item_w = MI()
    item_h -= 1
    item_w -= 1
    h[item_h] += 1
    w[item_w] += 1
    item_list[i][0] = item_h
    item_list[i][1] = item_w

ans = max(h) + max(w)
index_num_h = [n for n, v in enumerate(h) if v == max(h)]
index_num_w = [n for n, v in enumerate(w) if v == max(w)]

cnt = 0
for item in item_list:
    if item[0] in index_num_h and item[1] in index_num_w:
        cnt += 1

x = len(index_num_h) * len(index_num_w)
if cnt == x:
    ans -= 1

print(ans)


# Optimized solution
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


H, W, M = MI()
h = [0] * H
w = [0] * W
item_list = [[0, 0] for _ in range(M)]

for i in range(M):
    item_h, item_w = MI()
    item_h -= 1
    item_w -= 1
    h[item_h] += 1
    w[item_w] += 1
    item_list[i][0] = item_h
    item_list[i][1] = item_w

h_max = max(h)
w_max = max(w)
h_cnt = h.count(h_max)
w_cnt = w.count(w_max)
ans = h_max + w_max

cnt = 0
for item in item_list:
    if h[item[0]] == h_max and w[item[1]] == w_max:
        cnt += 1

x = h_cnt * w_cnt
if cnt == x:
    ans -= 1

print(ans)
# Original solution
H, W, M = list(map(int, input().split()))
HW = list(tuple(int(x) - 1 for x in input().split()) for _ in range(M))
h = [0] * H
w = [0] * W
for hi, wi in HW:
	h[hi] += 1
	w[wi] += 1
hm = max(h)
wm = max(w)

hh = [i for i, v in enumerate(h) if v == hm]
ww = [i for i, v in enumerate(w) if v == wm]

ans = hm + wm - 1
for h in hh:
	for w in ww:
		if (h, w) not in HW:
			ans += 1
			break 	
	else:
		continue
	break
print(ans)


# Optimized solution
H, W, M = list(map(int, input().split()))
HW = set(tuple(int(x) - 1 for x in input().split()) for _ in range(M))
h = [0] * H
w = [0] * W
for hi, wi in HW:
	h[hi] += 1
	w[wi] += 1
hm = max(h)
wm = max(w)

hh = [i for i, v in enumerate(h) if v == hm]
ww = [i for i, v in enumerate(w) if v == wm]

ans = hm + wm - 1
for h in hh:
	for w in ww:
		if (h, w) not in HW:
			ans += 1
			break 	
	else:
		continue
	break
print(ans)
# Original solution
from collections import defaultdict

def get_keys_of_max_value(d):
    v_max = 0
    keys = []
    for k, v in list(d.items()):
        if v_max < v:
            v_max = v
            keys = [k]
        elif v_max == v:
            keys.append(k)
    return keys, v_max

h, w, m = list(map(int, input().split()))
targets = [tuple(map(int, input().split())) for _ in range(m)]
n_r = defaultdict(int)
n_c = defaultdict(int)
for x, y in targets:
    n_r[x] += 1
    n_c[y] += 1

rows, n_r_max = get_keys_of_max_value(n_r)
columns, n_c_max = get_keys_of_max_value(n_c)

for r in rows:
    for c in columns:
        if (r, c) not in targets:
            print((n_r_max + n_c_max))
            break
    else:
        continue
    break
else:
    print((n_r_max + n_c_max - 1))


# Optimized solution
from collections import defaultdict

def get_keys_of_max_value(d):
    v_max = 0
    keys = []
    for k, v in list(d.items()):
        if v_max < v:
            v_max = v
            keys = [k]
        elif v_max == v:
            keys.append(k)
    return keys, v_max

h, w, m = list(map(int, input().split()))
targets = {tuple(map(int, input().split())) for _ in range(m)}
n_r = defaultdict(int)
n_c = defaultdict(int)
for x, y in targets:
    n_r[x] += 1
    n_c[y] += 1

rows, n_r_max = get_keys_of_max_value(n_r)
columns, n_c_max = get_keys_of_max_value(n_c)

for r in rows:
    for c in columns:
        if (r, c) not in targets:
            print((n_r_max + n_c_max))
            break
    else:
        continue
    break
else:
    print((n_r_max + n_c_max - 1))
# Original solution
from collections import Counter
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()))


S = Counter(h)
T = Counter(w)

if (S.most_common()[0][1] > T.most_common()[0][1]):
    for i in range(M):
        if (h[i] == S.most_common()[0][0]):
            w[i] = 'boom'

    w1 = [s for s in w if s != 'boom']
    T = Counter(w1)
    for i in range(len(w1)):
        if (w1[i] == T.most_common()[0][0]):
            w1[i] = 'boom' 

    w2 = [s for s in w1 if s != 'boom']
    print((M-len(w2)))

else:
    for i in range(M):
        if (w[i] == T.most_common()[0][0]):
            h[i] = 'boom'

    h1 = [s for s in h if s != 'boom']
    S = Counter(h1)
    for i in range(len(h1)):
        if (h1[i] == S.most_common()[0][0]):
            h1[i] = 'boom' 

    h2 = [s for s in h1 if s != 'boom']
    print((M-len(h2)))

# Optimized solution
from collections import Counter
import sys
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()))


S = Counter(h)
T = Counter(w)

if (M == 1):
    print((1))

else:
    if (S.most_common()[0][1] > T.most_common()[0][1]):
        smc = S.most_common()[0][0]
        for i in range(M):
            if (h[i] == smc):
                w[i] = 'boom'

        w1 = [s for s in w if s != 'boom']
        T = Counter(w1)
        if (len(w1) == 0):
            print(M)
            sys.exit()
        tmc = T.most_common()[0][0]
        for i in range(len(w1)):
            if (w1[i] == tmc):
                w1[i] = 'boom' 

        w2 = [s for s in w1 if s != 'boom']
        print((M-len(w2)))

    else:
        tmc = T.most_common()[0][0]
        for i in range(M):
            if (w[i] == tmc):
                h[i] = 'boom'

        h1 = [s for s in h if s != 'boom']
        S = Counter(h1)
        if (len(h1) == 0):
            print(M)
            sys.exit()
        smc = S.most_common()[0][0]
        for i in range(len(h1)):
            if (h1[i] == smc):
                h1[i] = 'boom' 

        h2 = [s for s in h1 if s != 'boom']
        print((M-len(h2)))
# Original solution
H, W, M = list(map(int, input().split()))
A = [0]*H
B = [0]*W
D = set()
for _ in range(M):
    h,w = list(map(int, input().split()))
    A[h-1] += 1
    B[w-1] += 1
    D.add((h-1,w-1))
a, b = max(A), max(B)
res = a+b-1
for i in range(H):
    for j in range(W):
        if (A[i],B[j]) == (a,b):
            if (i,j) not in D:
                print((res+1))
                exit()
print(res)

# Optimized solution
H, W, M = list(map(int, input().split()))
A = [0]*H
B = [0]*W
D = set()
for _ in range(M):
    h,w = list(map(int, input().split()))
    A[h-1] += 1
    B[w-1] += 1
    D.add((h-1,w-1))
a, b = max(A), max(B)
res = a+b-1
E, F = [], []
for i in range(H):
    if A[i] == a:
        E.append(i)
for j in range(W):
    if B[j] == b:
        F.append(j)
for i in E:
    for j in F:
        if (i,j) not in D:
            print((res+1))
            exit()
print(res)
# Original solution
H, W, M = list(map(int, input().split()))
h = [0] * (H+1)
w = [0] * (W+1)
l = set()
for i in range(M):
  x, y = list(map(int, input().split()))
  h[x] += 1
  w[y] += 1
  l.add((x, y))
  
a = [i for i, x in enumerate(h) if x == max(h)]
b = [i for i, x in enumerate(w) if x == max(w)]

flag = False
for s in a:
  for t in b:
    if (s, t) not in l:
      flag = True
      break
  if flag:
    break
ans = max(h)+max(w)
if not flag:
  ans -= 1
print(ans)


# Optimized solution
H, W, M = list(map(int, input().split()))
h = [0] * (H+1)
w = [0] * (W+1)
l = set()
for i in range(M):
  x, y = list(map(int, input().split()))
  h[x] += 1
  w[y] += 1
  l.add((x, y))
  
c = max(h)
d = max(w)
a = [i for i, x in enumerate(h) if x == c]
b = [i for i, x in enumerate(w) if x == d]

flag = False
for s in a:
  for t in b:
    if (s, t) not in l:
      flag = True
      break
  if flag:
    break
ans = c+d
if not flag:
  ans -= 1
print(ans)
# Original solution
h,w,n=list(map(int,input().split()))
H=[0]*h
W=[0]*w
L=[[0 for i in range(w)] for i in range(h)]
for i in range(n):
    a,b=list(map(int,input().split()))
    L[a-1][b-1]=1
    H[a-1]+=1
    W[b-1]+=1
h_max=max(H)
w_max=max(W)
H_max=[i+1 for i, x in enumerate(H) if x == h_max]
W_max=[i+1 for i, x in enumerate(W) if x == w_max]
ans=h_max+w_max-1
for hh in H_max:
    for ww in W_max:
        if L[hh-1][ww-1]==0:
            ans+=1
            break
    else:
        continue
    break
print(ans)

# Optimized solution
h,w,n=list(map(int,input().split()))
H=[0]*h
W=[0]*w
L=[(0,0)]*n
for i in range(n):
    a,b=list(map(int,input().split()))
    L[i]=(a,b)
    H[a-1]+=1
    W[b-1]+=1
h_max=max(H)
w_max=max(W)
ans=h_max+w_max
cnt=0
for l in L:
    if H[l[0]-1]==h_max and W[l[1]-1]==w_max:
        cnt+=1
if H.count(h_max)*W.count(w_max)==cnt:
    ans-=1
print(ans)
# Original solution
import sys
readline = sys.stdin.buffer.readline
from collections import defaultdict
dic1 = defaultdict(int)

def even(n): return 1 if n%2==0 else 0


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

columns = [0]*W
row = [0]*H
for i in range(M):
    h,w = list(map(int,readline().split()))
    h,w = h-1,w-1
    dic1[(h,w)] = 1
    columns[w] += 1
    row[h] += 1

def rank(lst,syoujun=False):
    res2 = list(set(lst))
    ans = []
    if syoujun:
        res2.sort()
    else:
        res2.sort(reverse=True)
    dic1 = dict()
    for i in range(len(res2)):
        dic1[res2[i]] = i
    for idx,i in enumerate(lst):
        if dic1[i] == 0:
            ans.append(idx)
    
    return ans

col2 = rank(columns)
row2 = rank(row)

ans = 0
for i in col2:
    for j in row2:
        if dic1[(j,i)]:
            ans = max(ans,columns[i]+row[j]-1)
        else:
            ans = max(ans,columns[i]+row[j])

print(ans)

# Optimized solution
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0


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

col = [0]*W
row = [0]*H
elements = []
for i in range(M):
    h,w = list(map(int,readline().split()))
    h,w = h-1,w-1
    elements.append((h,w))
    col[w] += 1
    row[h] += 1

def rank(lst,syoujun=False):
    res2 = list(set(lst))
    ans = []
    if syoujun:
        res2.sort()
    else:
        res2.sort(reverse=True)
    dic1 = dict()
    for i in range(len(res2)):
        dic1[res2[i]] = i
    for i in lst:
        #ans.append(dic1[i]) #zero-indexed
        ans.append(dic1[i] + 1) #one-indexed
    
    return ans

col2 = rank(col)
row2 = rank(row)

cmax = col2.count(1)
rmax = row2.count(1)

counter = 0
for i,j in elements:
    if col2[j] == 1 and row2[i] == 1:
        counter += 1

if counter == cmax*rmax:
    print((max(col) + max(row)-1))
else:
    print((max(col) + max(row)))
# Original solution
h,w,m=list(map(int,input().split()))
a=[list(map(int,input().split())) for _ in range(m)]
b,c=[0]*h,[0]*w
for t1,t2 in a:
    b[t1-1]+=1
    c[t2-1]+=1
bm,cm=max(b),max(c)
b1,c1=[],[]
d=[]
for x,y in a:
    d.append((x-1,y-1))
d=set(d)
for i in range(h):
    if b[i]==bm:
        b1.append(i)
for i in range(w):
    if c[i]==cm:
        c1.append(i)
f=1
for i in b1:
    for j in c1:
        if (i,j) not in d:
            f=0
print((bm+cm-f))

# Optimized solution
h,w,m=list(map(int,input().split()))
a=[list(map(int,input().split())) for _ in range(m)]
b,c=[0]*h,[0]*w
for t1,t2 in a:
    b[t1-1]+=1
    c[t2-1]+=1
bm,cm=max(b),max(c)
b1,c1=[],[]
d=[]
for x,y in a:
    d.append((x-1,y-1))
d=set(d)
for i in range(h):
    if b[i]==bm:
        b1.append(i)
for i in range(w):
    if c[i]==cm:
        c1.append(i)
for i in b1:
    for j in c1:
        if (i,j) not in d:
            print((bm+cm))
            exit()
print((bm+cm-1))
# Original solution
import pprint
H, W, M = list(map(int, input().split()))
bombs = set()
hCount = [0]*H
vCount = [0]*W

for i in range(M):
    h, w = list(map(int, input().split()))
    h -= 1; w -= 1;
    hCount[h] += 1
    vCount[w] += 1
    bombs.add((h, w))

hMax = max(hCount)
vMax = max(vCount)
hMaxIndex = [i for i, x in enumerate(hCount) if x==max(hCount)]
vMaxIndex = [i for i, x in enumerate(vCount) if x==max(vCount)]

ans = -1
for x in vMaxIndex:
    for y in hMaxIndex:
        if (y, x) in bombs:
            continue
        else:
            print((hMax + vMax))
            exit()
print((hMax + vMax - 1))


# Optimized solution
import pprint
H, W, M = list(map(int, input().split()))
bombs = set()
hCount = [0]*H
vCount = [0]*W

for i in range(M):
    h, w = list(map(int, input().split()))
    h -= 1; w -= 1;
    hCount[h] += 1
    vCount[w] += 1
    bombs.add((h, w))

hMax = max(hCount)
vMax = max(vCount)
hMaxIndex = [i for i, x in enumerate(hCount) if x==hMax]
vMaxIndex = [i for i, x in enumerate(vCount) if x==vMax]

ans = -1
for x in vMaxIndex:
    for y in hMaxIndex:
        if (y, x) in bombs:
            continue
        else:
            print((hMax + vMax))
            exit()
print((hMax + vMax - 1))
# Original solution
H, W, M = list(map(int, input().split()))
bomb = [tuple([int(a) - 1 for a in input().split()]) for _ in range(M)]

cntRow = [0] * H
cntCol = [0] * W
for h, w in bomb:
    cntRow[h] += 1
    cntCol[w] += 1

mxR = max(cntRow)
mxC = max(cntCol)

R = set([h for h in range(H) if cntRow[h] == mxR])
C = set([w for w in range(W) if cntCol[w] == mxC])

ans = mxR + mxC
if len([0 for h, w in bomb if h in R and w in C]) == len(R) * len(C):
    ans -= 1

print(ans)


# Optimized solution
H, W, M = list(map(int, input().split()))
bombs = set([tuple(map(int, input().split())) for _ in range(M)])

cntH = [0] * (H + 1)
cntW = [0] * (W + 1)
for h, w in bombs:
    cntH[h] += 1
    cntW[w] += 1

mxH = max(cntH)
mxW = max(cntW)

ans = mxH + mxW - 1

mxH = [h for h in range(1, H + 1) if cntH[h] == mxH]
mxW = [w for w in range(1, W + 1) if cntW[w] == mxW]

for h in mxH:
    for w in mxW:
        if not (h, w) in bombs:
            ans += 1
            print(ans)
            exit()
print(ans)