CodeEff/ECCO huggingface dataset:
# Original solution
import collections
H,W,M=list(map(int,input().split()))
h=[None]*M
w=[None]*M
for i in range(M):
    h[i],w[i]=list(map(int,input().split()))
c1=collections.Counter(h)
c2=collections.Counter(w)
cnt=0
ans=0
for i in range(min(len(c1),20)):
    for j in range(min(len(c2),20)):
        for x in range(M):
            flag=True
            if h[x]==c1.most_common()[i][0] and w[x]==c2.most_common()[j][0]:
                ans=max(ans,c1.most_common()[i][1]+c2.most_common()[j][1]-1)
                flag=False
                break
        if flag:
            ans=max(ans,c1.most_common()[i][1]+c2.most_common()[j][1])
print(ans)

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M = list(map(int, readline().split()))
bomb = [tuple([int(x) - 1 for x in s.split()]) for s in 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 = [h for h, x in enumerate(X) if x == maxX]  
C = [w for w, y in enumerate(Y) if y == maxY] 

bomb = set(bomb)
for r in R:
    for c in C:
        if (r, c) not in bomb:
            print((maxX + maxY))
            exit()
print((maxX + maxY - 1))
# Original solution
H, W, M = list(map(int, input().split()))
hws = [list([int(x)-1 for x in input().split()]) for _ in range(M)]

booms = [set() for _ in range(H)]

yoko = [0 for _ in range(W)]
tate = [0 for _ in range(H)]

for hw in hws:
    tate[hw[0]] += 1
    yoko[hw[1]] += 1
    booms[hw[0]].add(hw[1])
    
max_tate = max(tate)
max_yoko = max(yoko)


tate_candidates = []
yoko_candidates = []

for i in range(H):
    if tate[i] == max_tate:
        tate_candidates.append(i)
        
for i in range(W):
    if yoko[i] == max_yoko:
        yoko_candidates.append(i)

exist = 0
for tate_candidate in tate_candidates:
    for yoko_candidate in yoko_candidates:
        if yoko_candidate not in booms[tate_candidate]:
            exist = 1

print((max_tate + max_yoko + (exist-1)))

# Optimized solution
H, W, M = list(map(int, input().split()))
hws = [list([int(x)-1 for x in input().split()]) for _ in range(M)]

booms = [set() for _ in range(H)]

yoko = [0 for _ in range(W)]
tate = [0 for _ in range(H)]

for hw in hws:
    tate[hw[0]] += 1
    yoko[hw[1]] += 1
    booms[hw[0]].add(hw[1])
    
max_tate = max(tate)
max_yoko = max(yoko)


tate_candidates = []
yoko_candidates = []

for i in range(H):
    if tate[i] == max_tate:
        tate_candidates.append(i)
        
for i in range(W):
    if yoko[i] == max_yoko:
        yoko_candidates.append(i)

exist = 0
for tate_candidate in tate_candidates:
    for yoko_candidate in yoko_candidates:
        if yoko_candidate not in booms[tate_candidate]:
            exist = 1
            break
    else:
        continue
    break
print((max_tate + max_yoko + (exist-1)))
# Original solution
h, w, m = list(map(int, input().split()))
target_points = {tuple([int(x) - 1 for x in input().split()]) for _ in range(m)}

row_points = [0] * h
col_points = [0] * w
for row, col in target_points:
    row_points[row] += 1
    col_points[col] += 1

row_max = max(row_points)
col_max = max(col_points)

row_max_indexes = [i for i in range(h) if row_points[i] == row_max]
col_max_indexes = [i for i in range(w) if col_points[i] == col_max]

crossing_points = {(row, col) for row in row_max_indexes for col in col_max_indexes}

print((row_max + col_max - (not (crossing_points - target_points))))


# Optimized solution
h, w, m = list(map(int, input().split()))
target_points = {tuple([int(x) - 1 for x in input().split()]) for _ in range(m)}

row_points = [0] * h
col_points = [0] * w
for row, col in target_points:
    row_points[row] += 1
    col_points[col] += 1

row_max = max(row_points)
col_max = max(col_points)

row_max_indexes = [i for i in range(h) if row_points[i] == row_max]
col_max_indexes = [i for i in range(w) if col_points[i] == col_max]

empty_crossing_exist = False
for row in row_max_indexes:
    for col in col_max_indexes:
        if (row, col) not in target_points:
            empty_crossing_exist = True
            break
    if empty_crossing_exist:
        break

print((row_max + col_max - (not empty_crossing_exist)))
# Original solution
h,w,m = list(map(int,input().split()))
hli = [0]*h
wli = [0]*w
li = []
for i in range(m):
    a,b = list(map(int,input().split()))
    li.append([a,b])
    hli[a-1] += 1
    wli[b-1] += 1
a = max(hli)
b = max(wli)
hli2 = []
wli2 = []
for i in range(h):
    if hli[i] == a:
        hli2.append(i+1)
for i in range(w):
    if wli[i] == b:
        wli2.append(i+1)
for i in hli2:
    for j in wli2:
        if [i,j] not in li:
            print((a + b))
            exit()
print((a + b - 1))

# Optimized solution
h,w,m = list(map(int,input().split()))
hli = [0]*h
wli = [0]*w
li = []
liset = set()
for i in range(m):
    a,b = list(map(int,input().split()))
    li.append([a,b])
    liset.add((a,b))
    hli[a-1] += 1
    wli[b-1] += 1
a = max(hli)
b = max(wli)
hli2 = []
wli2 = []
for i in range(h):
    if hli[i] == a:
        hli2.append(i+1)
for i in range(w):
    if wli[i] == b:
        wli2.append(i+1)
for i in hli2:
    for j in wli2:
        if (i,j) not in liset:
            print((a + b))
            exit()
print((a + b - 1))
# Original solution
h,w,m=list(map(int,input().split()))
H=[0]*(3*10**5+1)
W=[0]*(3*10**5+1)
M=[]
for i in range(m):
    h,w=list(map(int,input().split()))
    M.append([h,w])
    H[h]+=1
    W[w]+=1

p=max(H)
q=max(W)

X=set([i for i in range(3*10**5+1) if H[i]==p])
Y=set([i for i in range(3*10**5+1) if W[i]==q])

Z=[[M[i][0],M[i][1]] for i in range(m) if M[i][0] in X or M[i][1] in Y ]

cnt=1
flag=True
for x in X:
    if flag:
        for y in Y:
            if not [x,y] in Z:
                cnt=0
                flag=False
                break

print((p+q-cnt))

# Optimized solution
h,w,m=list(map(int,input().split()))
H=[0]*(3*10**5+1)
W=[0]*(3*10**5+1)
M=[]
for i in range(m):
    h,w=list(map(int,input().split()))
    M.append([h,w])
    H[h]+=1
    W[w]+=1

p=max(H)
q=max(W)

X=set([i for i in range(3*10**5+1) if H[i]==p])
Y=set([i for i in range(3*10**5+1) if W[i]==q])

cnt=0
for i in range(m):
    if M[i][0] in X and M[i][1] in Y:
        cnt+=1

if cnt==len(X)*len(Y):
    print((p+q-1))
else:
    print((p+q))
# Original solution

from collections import defaultdict

H,W,M=list(map(int,input().split()))
AB=[tuple(map(int,input().split()))for i in range(M)]
AB=[(a-1,b-1)for a,b in AB]
st=set(AB)

Wc=defaultdict(lambda :0)
Hc=defaultdict(lambda :0)
for a,b in AB:
    Hc[a]+=1
    Wc[b]+=1

Hm=max(Hc.values())
hhh=list(Hc.keys())
www=list(Wc.keys())
for i in hhh:
    if Hc[i]!=Hm:
        Hc.pop(i)
Wm=max(Wc.values())
for j in www:
    if Wc[j]!=Wm:
        Wc.pop(j)

ans=0
count=0
for i in list(Hc.keys()):
    for j in list(Wc.keys()):
        add = -1 if (i,j) in st else 0
        tmp= Hc[i] + Wc[j] + add
        ans=max(ans,tmp)
        if count>300000:
            break
        count+=1

print(ans)


# Optimized solution
H,W,M=list(map(int,input().split()))
HW=[tuple(map(int,input().split()))for i in range(M)]
HW=[(h-1,w-1)for h,w in HW]
st=set(HW)
countH=[0]*H
countW=[0]*W
for h,w in HW:
    countH[h]+=1
    countW[w]+=1
maxH=max(countH)
maxW=max(countW)
candiH=[]
candiW=[]
for i in range(H):
    if maxH==countH[i]:
        candiH.append(i)
for i in range(W):
    if maxW==countW[i]:
        candiW.append(i)
count=0
ans=maxH+maxW-1
add=0
for i in candiH:
    for j in candiW:
        if (i,j) not in st:
            add=1
        if count>300000:
            break
        count+=1
print((ans+add))
# Original solution
from collections import defaultdict as ddict

H,W,M=list(map(int,input().split()))
tgts=set()
for _ in range(M):
    i,j=list(map(int,input().split()))
    tgts.add((i,j))

rows=ddict(int)
cols=ddict(int)

ii=jj=0
ia,ja=[],[]
for i,j in tgts:
    rows[i]+=1
    cols[j]+=1
    x=rows[i]
    if x>ii:
        ii=x
        ia=[i]
    elif x==ii:
        ia.append(i)
    y=cols[j]
    if y>jj:
        jj=y
        ja=[j]
    elif y==jj:
        ja.append(j)



ans=0
for i in ia:
    for j in ja:
        k=rows[i]+cols[j]
        if (i,j) in tgts:
            k-=1
        ans=max(ans,k)

print(ans)


# Optimized solution
from collections import defaultdict as ddict

ii=jj=0
ia,ja=[],[]
rows=ddict(int)
cols=ddict(int)
H,W,M=list(map(int,input().split()))
tgts=set()
for _ in range(M):
    i,j=list(map(int,input().split()))
    tgts.add((i,j))

    rows[i]+=1
    cols[j]+=1
    x=rows[i]
    if x>ii:
        ii=x
        ia=[i]
    elif x==ii:
        ia.append(i)
    y=cols[j]
    if y>jj:
        jj=y
        ja=[j]
    elif y==jj:
        ja.append(j)



ans=0
for i in ia:
    for j in ja:
        k=rows[i]+cols[j]
        if (i,j) in tgts:
            k-=1
        else:
            ans=k
            break
        ans=max(ans,k)

print(ans)
# Original solution
from collections import defaultdict as ddict

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

xs=[0]*w
ys=[0]*h
xsmx=ysmx=0
pts=set()
for _ in range(m):
    y,x=list(map(int,input().split()))
    x,y=x-1,y-1
    xs[x]+=1
    ys[y]+=1
    pts.add((x,y))
    xsmx=max(xsmx,xs[x])
    ysmx=max(ysmx,ys[y])

xsc=[x for x in range(w) if xs[x]==xsmx]
ysc=[y for y in range(h) if ys[y]==ysmx]
ans=xsmx+ysmx-1
ok=False
for y in ysc:
    for x in xsc:
        if (x,y) not in pts:
            ans+=1
            ok=True
            break
    if ok:
        break

print(ans)


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

xsct=[0]*w
ysct=[0]*h
ips=set()
xsmx=ysmx=0
for _ in range(m):
    y,x=list(map(int,input().split()))
    x,y=x-1,y-1
    xsct[x]+=1
    ysct[y]+=1
    ips.add((x,y))
    xsmx=max(xsmx,xsct[x])
    ysmx=max(ysmx,ysct[y])

xs=[x for x in range(w) if xsct[x]==xsmx]
ys=[y for y in range(h) if ysct[y]==ysmx]

ans=xsmx+ysmx-1
ok=False
for y in ys:
    for x in xs:
        if (x,y) not in ips:
            ans+=1
            ok=True
            break
    if ok:
        break

print(ans)
# Original solution
h,w,m=list(map(int,input().split()))

cx=[0]*w
cy=[0]*h
xy=set()
for _ in range(m):
    y,x=list(map(int,input().split()))
    x,y=x-1,y-1
    cx[x]+=1
    cy[y]+=1
    xy.add((x,y))

xmx=max(cx)
ymx=max(cy)
xs=[x for x in range(w) if cx[x]==xmx]
ys=[y for y in range(h) if cy[y]==ymx]

ans=xmx+ymx-1
ok=False
for y in ys:
    for x in xs:
        if (x,y) not in xy:
            ans+=1
            ok=True
            break
    if ok:
        break

print(ans)


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

r=[0]*h
c=[0]*w
s=set()
for _ in range(m):
    i,j=list(map(int,input().split()))
    i-=1
    j-=1
    r[i]+=1
    c[j]+=1
    s.add(i*w+j)

rmx=max(r)
cmx=max(c)
rc=[i for i in range(h) if r[i]==rmx]
cc=[j for j in range(w) if c[j]==cmx]

ans=rmx+cmx-1
ok=False
for i in rc:
    for j in cc:
        if i*w+j not in s:
            ans+=1
            ok=True
            break
    if ok:
        break

print(ans)
# Original solution
h,w,m=list(map(int,input().split()))

r=[0]*h
c=[0]*w
s=set()
for _ in range(m):
    i,j=list(map(int,input().split()))
    i-=1
    j-=1
    r[i]+=1
    c[j]+=1
    s.add(i*w+j)

rmx=max(r)
cmx=max(c)
rc=[i for i in range(h) if r[i]==rmx]
cc=[j for j in range(w) if c[j]==cmx]

ans=rmx+cmx-1
ok=False
for i in rc:
    for j in cc:
        if i*w+j not in s:
            ans+=1
            ok=True
            break
    if ok:
        break

print(ans)


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

r=[0]*h
c=[0]*w
s=set()
for _ in range(m):
    i,j=list(map(int,input().split()))
    i-=1
    j-=1
    r[i]+=1
    c[j]+=1
    s.add(i*w+j)

rmx=max(r)
cmx=max(c)
rc=[i for i in range(h) if r[i]==rmx]
cc=[j for j in range(w) if c[j]==cmx]

ans=rmx+cmx-1
for i in rc:
    for j in cc:
        if i*w+j not in s:
            print((ans+1))
            exit()

print(ans)
# Original solution
from collections import deque

def argmax_poss(a):
    if len(a) == 0:
        return []
    all_ = [0]
    max_ = a[0]
    for i in range(1, len(a)):
        if a[i] > max_:
            all_ = [i]
            max_ = a[i]
        elif a[i] == max_:
            all_.append(i)
    return all_

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

h_scores = [0 for i in range(h)]
w_scores = [0 for i in range(w)]

record = deque([])

for i in range(m):
  h,w = list(map(int,input().split()))
  record.append((h-1,w-1))
  h_scores[h-1] += 1
  w_scores[w-1] += 1

max_h_poss = argmax_poss(h_scores)
max_w_poss = argmax_poss(w_scores)

out_pos_count = 0 

is_ok = False

for h in max_h_poss:
    for w in max_w_poss:
        if (h,w) not in record:
            is_ok = True
            break
        
if is_ok:
    print((max(h_scores) + max(w_scores)))
else:
    print((max(h_scores) + max(w_scores)-1))



# Optimized solution
from collections import deque

def argmax_poss(a):
    if len(a) == 0:
        return []
    all_ = [0]
    max_ = a[0]
    for i in range(1, len(a)):
        if a[i] > max_:
            all_ = [i]
            max_ = a[i]
        elif a[i] == max_:
            all_.append(i)
    return all_

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

h_scores = [0 for i in range(h)]
w_scores = [0 for i in range(w)]

record = set()

for i in range(m):
  h,w = list(map(int,input().split()))
  record.add((h-1,w-1))
  h_scores[h-1] += 1
  w_scores[w-1] += 1

max_h_poss = argmax_poss(h_scores)
max_w_poss = argmax_poss(w_scores)

out_pos_count = 0 

is_ok = False

for h in max_h_poss:
    for w in max_w_poss:
        if (h,w) not in record:
            is_ok = True
            break
        
if is_ok:
    print((max(h_scores) + max(w_scores)))
else:
    print((max(h_scores) + max(w_scores)-1))
# Original solution
import itertools
H, W, M = list(map(int, input().split()))
Bh = [0]*(H+1)
Bw = [0]*(W+1)
OD = set()

for _ in range(M):
    h, w = list(map(int, input().split()))
    Bh[h] += 1
    Bw[w] += 1
    OD.add((h, w))

l1 = [i for i, x in enumerate(Bh) if x == max(Bh)]
l2 = [j for j, x in enumerate(Bw) if x == max(Bw)]
for i, j in itertools.product(l1, l2):
    if (i, j) not in OD:
        break
else:
    print((max(Bh)+max(Bw)-1))
    exit()
print((max(Bh)+max(Bw)))


# Optimized solution
import itertools
H, W, M = list(map(int, input().split()))
Bh = [0]*(H+1)
Bw = [0]*(W+1)
OD = set()

for _ in range(M):
    h, w = list(map(int, input().split()))
    Bh[h] += 1
    Bw[w] += 1
    OD.add((h, w))

M1 = max(Bh)
M2 = max(Bw)
l1 = [i for i, x in enumerate(Bh) if x == M1]
l2 = [j for j, x in enumerate(Bw) if x == M2]
for i, j in itertools.product(l1, l2):
    if (i, j) not in OD:
        break
else:
    print((M1+M2-1))
    exit()
print((M1+M2))
# Original solution
from collections import defaultdict

H,W,M = list(map(int,input().split()))
bomb = [[0,0] for _ in range(M)]
bomb_d = defaultdict(int)

for i in range(M):
    bomb[i] = list(map(int,input().split()))
    bomb[i][0] -= 1
    bomb[i][1] -= 1
    bomb_d[tuple(bomb[i])] = 1


dh = [0]*H
dw = [0]*W

for i in range(M):
    dh[bomb[i][0]] += 1
    dw[bomb[i][1]] += 1

Maxh = max(dh)
Maxw = max(dw)

h_p = []
w_p = []

for i in range(H):
    if dh[i] == Maxh:
        h_p.append(i)
for i in range(W):
    if dw[i] == Maxw:
        w_p.append(i)

f = 0
for h in h_p:
    for w in w_p:
        if bomb_d[(h,w)] != 1:
            f = 1

if f == 0:
    print((Maxh+Maxw-1))
else:
    print((Maxh+Maxw))













# Optimized solution
from collections import defaultdict

H,W,M = list(map(int,input().split()))
bomb = [[0,0] for _ in range(M)]
bomb_d = defaultdict(int)

for i in range(M):
    bomb[i] = list(map(int,input().split()))
    bomb[i][0] -= 1
    bomb[i][1] -= 1
    bomb_d[tuple(bomb[i])] = 1


dh = [0]*H
dw = [0]*W

for i in range(M):
    dh[bomb[i][0]] += 1
    dw[bomb[i][1]] += 1

Maxh = max(dh)
Maxw = max(dw)

h_p = []
w_p = []

for i in range(H):
    if dh[i] == Maxh:
        h_p.append(i)
for i in range(W):
    if dw[i] == Maxw:
        w_p.append(i)

f = 0
for h in h_p:
    for w in w_p:
        if bomb_d[(h,w)] != 1:
            f = 1
            break
    else:
        continue
    break

if f == 0:
    print((Maxh+Maxw-1))
else:
    print((Maxh+Maxw))
# Original solution
# E - Bomber

from collections import Counter

h, w, m = list(map(int, input().split()))
hw = [tuple(map(int, input().split())) for i in range(m)]

ys, xs = list(zip(*hw))
ymax, = Counter(ys).most_common(1)
xmax, = Counter(xs).most_common(1)

bombed = max(ymax[1], xmax[1])

if bombed < m:
    if ymax[1] > xmax[1]:
        hw2 = [(a, b) for a, b in hw if a != ymax[0]]
        _, xs = list(zip(*hw2))
        xmax, = Counter(xs).most_common(1)
        bombed += xmax[1]
    else:
        hw2 = [(a, b) for a, b in hw if b != xmax[0]]
        ys, _ = list(zip(*hw2))
        ymax, = Counter(ys).most_common(1)
        bombed += ymax[1]

print(bombed)


# Optimized solution
# E - Bomber

from collections import Counter

h, w, m = list(map(int, input().split()))
hw = [tuple(map(int, input().split())) for i in range(m)]

ys, xs = list(zip(*hw))
ymax, = Counter(ys).most_common(1)
xmax, = Counter(xs).most_common(1)

bombed = max(ymax[1], xmax[1])

if bombed < m:
    if ymax[1] > xmax[1]:
        xs = [b for a, b in hw if a != ymax[0]]
        xmax, = Counter(xs).most_common(1)
        bombed += xmax[1]
    else:
        ys = [a for a, b in hw if b != xmax[0]]
        ymax, = Counter(ys).most_common(1)
        bombed += ymax[1]

print(bombed)
# Original solution
import random
import time
start=time.time()
h,w,m=map(int,input().split())
hh=[[0,i]for i in range(h)]
ww=[[0,i]for i in range(w)]
hw=set()
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  hh[a][0]+=1
  ww[b][0]+=1
  hw.add((a,b))
ww.sort(reverse=1)
s=ww[0][0]
w=[]
for x,j in ww:
  if x==s:w.append(j)
hh.sort(reverse=1)
t=hh[0][0]
hhh=[]
for x,i in hh:
  if x==t:hhh.append((x,i))
ans=[]
random.shuffle(w)
for j in w:
  for x,i in hhh:
    if (i,j) in hw:
      ans.append(s+x-1)
    else:
      exit(print(s+x))
  if time.time()-start>=1.7:
    m=ans[0]
    if h-50000<=len(hhh)<=h-random.randint(10,100):m+=1
    exit(print(m))
print(ans[0])


# Optimized solution
import random
import time
start=time.time()
h,w,m=map(int,input().split())
hh=[[0,i]for i in range(h)]
ww=[[0,i]for i in range(w)]
hw=set()
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  hh[a][0]+=1
  ww[b][0]+=1
  hw.add((a,b))
ww.sort(reverse=1)
s=ww[0][0]
w=[]
for x,j in ww:
  if x==s:w.append(j)
hh.sort(reverse=1)
t=hh[0][0]
hhh=[]
for x,i in hh:
  if x==t:hhh.append((x,i))
ans=[]
random.shuffle(w)
for j in w:
  for x,i in hhh:
    if (i,j) in hw:
      ans.append(s+x-1)
    else:
      exit(print(s+x))
  if time.time()-start>=1.7:
    m=ans[0]
    if h-100000<=len(hhh)<=h-random.randint(100,1000):m+=1
    exit(print(m))
print(ans[0])
# Original solution
h,w,m=map(int,input().split())
hh=[[0,i]for i in range(h)]
ww=[[0,i]for i in range(w)]
hw=set()
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  hh[a][0]+=1
  ww[b][0]+=1
  hw.add((a,b))
ww.sort(reverse=1)
s=ww[0][0]
w=[]
for x,j in ww:
  if x==s:w.append(j)
ans=0
t=max(hh)[0]
for j in w:
  for x,i in sorted(hh,reverse=1):
    if x!=t:break
    if (i,j) in hw:
      ans=s+x-1
    else:
      exit(print(s+x))
print(ans)


# Optimized solution
h,w,m=map(int,input().split())
hh=[[0,i]for i in range(h)]
ww=[[0,i]for i in range(w)]
hw=set()
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  hh[a][0]+=1
  ww[b][0]+=1
  hw.add((a,b))
ww.sort(reverse=1)
s=ww[0][0]
w=[]
for x,j in ww:
  if x==s:w.append(j)
hh.sort(reverse=1)
ans=0
t=max(hh)[0]
for j in w:
  for x,i in hh:
    if x!=t:break
    if (i,j) in hw:
      ans=s+x-1
    else:
      exit(print(s+x))
print(ans)
# Original solution
h,w,m=map(int,input().split())
hh=[[0,i]for i in range(h)]
ww=[[0,i]for i in range(w)]
hw=set()
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  hh[a][0]+=1
  ww[b][0]+=1
  hw.add((a,b))
ww.sort(reverse=1)
s=ww[0][0]
w=[]
for x,j in ww:
  if x==s:w.append(j)
hh.sort(reverse=1)
ans=0
t=max(hh)[0]
for j in w:
  for x,i in hh:
    if x!=t:break
    if (i,j) in hw:
      ans=s+x-1
    else:
      exit(print(s+x))
print(ans)


# Optimized solution
import sys
input = lambda: sys.stdin.readline().rstrip()

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

hw = []
hcount = [0] * h
wcount = [0] * w
for _ in range(m):
  a, b = list(map(int, input().split()))
  a -= 1
  b -= 1
  hcount[a] += 1
  wcount[b] += 1
  hw.append([a, b])

hmax = max(hcount)
wmax = max(wcount)

x = hcount.count(hmax) * wcount.count(wmax)
for a, b in hw:
  if hcount[a] == hmax and wcount[b] == wmax:
    x -= 1

if x == 0:
  print((hmax + wmax - 1))
else:
  print((hmax + wmax))
# Original solution
n,m,k=list(map(int,input().split()))
r=[0]*(n+1)
c=[0]*(m+1)
l=[]
for _ in range(k):
  a,b=list(map(int,input().split()))
  l.append([a,b])
  r[a]+=1
  c[b]+=1
m1=max(r)
x=[]
for i in range(n+1):
  if(r[i]==m1):
    x.append(i)
m2=max(c)
y=[]
for i in range(m+1):
  if(c[i]==m2):
    y.append(i)
ans=m1+m2
z=0
for i in x:
  for j in y:
    if([i,j] not in l):
      z=-1
      break
if(z==0):
  print((ans-1))
else:
  print(ans)   
      

  

# Optimized solution
n,m,k=list(map(int,input().split()))
m+=1
n+=1
r=[0]*(n)
c=[0]*(m)
d={}
for _ in range(k):
  a,b=list(map(int,input().split()))
  d[(a,b)]=1
  r[a]+=1
  c[b]+=1
m1=max(r)
x=[]
for i in range(n):
  if(r[i]==m1):
    x.append(i)
m2=max(c)
y=[]
for i in range(m):
  if(c[i]==m2):
    y.append(i)
ans=m1+m2
z=0
for i in x:
  for j in y:
    if((i,j) not in  d):
      z=-1
      break
if(z==0):
  print((ans-1))
else:
  print(ans)
# Original solution
H, W, M = list(map(int, input().split()))

Hc = [0 for i in range(H)]
Wc = [0 for i in range(W)]
HW = [[0 for i in range(W)] for i in range(H)]

for m in range(M):
  h, w = list(map(int, input().split()))
  Hc[h - 1] += 1
  Wc[w - 1] += 1
  HW[h - 1][w - 1] = 1
Hcmax = max(Hc)
Hcmax_idx = [i for i, x in enumerate(Hc) if x == Hcmax] 
Wcmax = max(Wc)
Wcmax_idx = [i for i, x in enumerate(Wc) if x == Wcmax] 

ans = Hcmax + Wcmax - 1
f = False
for i in Hcmax_idx:
  for j in Wcmax_idx:
    if HW[i][j] == 0:
      ans = Hcmax + Wcmax
      f = True
      break
  if f:
    break
print(ans)

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

Hc = [0 for i in range(H)]
Wc = [0 for i in range(W)]
B = []

for m in range(M):
  h, w = list(map(int, input().split()))
  Hc[h - 1] += 1
  Wc[w - 1] += 1
  B.append((h - 1, w - 1))
Hcmax = max(Hc)
Hcmax_idx = [i for i, x in enumerate(Hc) if x == Hcmax] 
Wcmax = max(Wc)
Wcmax_idx = [i for i, x in enumerate(Wc) if x == Wcmax] 

ans = Hcmax + Wcmax - 1
B = set(B)
f = False
for i in Hcmax_idx:
  if f:
    break
  for j in Wcmax_idx:
    if (i, j) not in B:
      ans = Hcmax + Wcmax
      f = True
      break
print(ans)
# Original solution
########### E
H, W, M = list(map(int, input().split()))
bombs = []
for _ in range(M):
    bomb = list([int(x)-1 for x in input().split()])
    bombs.append(bomb)

H_list = [0]*H
W_list = [0]*W
sign = True
for h,w in bombs:
    H_list[h] += 1
    W_list[w] += 1

max_H = [i for i,k in enumerate(H_list) if k == max(H_list)]
max_W = [i for i,k in enumerate(W_list) if k == max(W_list)]

cross = []

for i in max_H:
    for k in max_W:
        if [i,k] not in bombs:
            sign = False
            print((max(H_list) + max(W_list)))
            break
    break

if sign:
    print((max(H_list) + max(W_list) -1))


# 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  # X:各行の爆破対象の個数
Y = [0] * W  # Y:各列の爆破対象の個数
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = [h for h, x in enumerate(X) if x == maxX]  # R:爆破対象の数が最大となる行の番号
C = [w for w, y in enumerate(Y) if y == maxY]  # C:爆破対象の数が最大となる列の番号

bomb = set(bomb)
for r in R:
    for c in C:
        if (r, c) not in bomb:
            # (r, c)に爆破対象が存在しないとき, maxX + maxY が答えとなることが確定するため, 
            # 即座に探索を終了する. これによりループの回数は最大でもM+1回となる.
            print((maxX + maxY))
            exit()
print((maxX + maxY - 1))