CodeEff/ECCO huggingface dataset:
# Original solution
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = list(map(int, input().split()))
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = list(map(int, input().split()))
        bombs.append([h-1, w-1])
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    isfound = False

    for i in maxhindex:
        for j in maxwindex:
            if [i, j] not in bombs:
                print(ans)
                exit()

    print((ans-1))

if __name__ == '__main__':
    main()

# Optimized solution
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = list(map(int, input().split()))
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = list(map(int, input().split()))
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    isfound = False

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                exit()

    print((ans-1))

if __name__ == '__main__':
    main()
# Original solution
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = list(map(int, input().split()))
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = list(map(int, input().split()))
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    isfound = False

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                exit()

    print((ans-1))

if __name__ == '__main__':
    main()

# Optimized solution
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = list(map(int, input().split()))
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = list(map(int, input().split()))
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                exit()

    print((ans-1))

if __name__ == '__main__':
    main()
# Original solution
h,w,m = list(map(int, input().split()))
hl = [0] * h
wl = [0] * w
dic = set()
for i in range(m):
  x,y = list(map(int, input().split()))
  dic.add((x,y))
  hl[x-1] += 1
  wl[y-1] += 1

h_max = max(hl)
r = [i for i in range(h) if hl[i] == h_max]
w_max = max(wl)
c = [i for i in range(w) if wl[i] == w_max]

flg = 0
for rc in r:
  for cc in c:
    if (rc+1,cc+1) not in dic:
      flg = 1
      
if flg == 0:
  print((h_max + w_max - 1))
else:
  print((h_max + w_max))

# Optimized solution
def main():
  h,w,m = list(map(int, input().split()))
  hl = [0] * h
  wl = [0] * w
  dic = set()
  for i in range(m):
    x,y = list(map(int, input().split()))
    dic.add((x,y))
    hl[x-1] += 1
    wl[y-1] += 1

  h_max = max(hl)
  r = [i for i in range(h) if hl[i] == h_max]
  w_max = max(wl)
  c = [i for i in range(w) if wl[i] == w_max]

  flg = 0
  for rc in r:
    for cc in c:
      if (rc+1,cc+1) not in dic:
        print((h_max + w_max))
        return

  print((h_max + w_max - 1))
  
if __name__ == '__main__':
    main()
# Original solution
h,w,m=list(map(int, input().split()))
hw=[list(map(int, input().split())) for _ in range(m)]

tate=[]
yoko=[]

for i in range(m):
    tate.append(hw[i][0])
    yoko.append(hw[i][1])

from collections import Counter
tatec=Counter(tate).most_common()
yokoc=Counter(yoko).most_common()

c_1_max=tatec[0][1]
c_1s=[]
for t in tatec:
    if t[1]==c_1_max:
        c_1s.append(t[0])
    else:
        break

c_2_max=yokoc[0][1]
c_2s=[]
for y in yokoc:
    if y[1]==c_2_max:
        c_2s.append(y[0])
    else:
        break

flag=False

for c_1 in c_1s:
    for c_2 in c_2s:
        tmp_flag=0
        for i in range(m):
            h_i=hw[i][0]
            w_i=hw[i][1]
            if h_i!=c_1 or w_i!=c_2:
                tmp_flag+=1
        if tmp_flag==m:
            flag=True
        if flag:
            break
    if flag:
        break

print((max(tatec[0][1]+yokoc[0][1], 1) if flag else max(tatec[0][1]+yokoc[0][1]-1, 1)))


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

y_list=[0]*h
x_list=[0]*w

for h_i, w_i in hw:
    y_list[h_i-1]+=1
    x_list[w_i-1]+=1

my_cnt=max(y_list)
mx_cnt=max(x_list)

y_cnt=0
x_cnt=0

my_set=set()
mx_set=set()

for h_i, w_i in hw:
    if y_list[h_i-1]==my_cnt:
        my_set.add(h_i-1)
    if x_list[w_i-1]==mx_cnt:
        mx_set.add(w_i-1)

cnt=0
for h_i, w_i in hw:
    if y_list[h_i-1]==my_cnt and x_list[w_i-1]==mx_cnt:
        cnt+=1

print((my_cnt+mx_cnt-1 if cnt==len(my_set)*len(mx_set) else my_cnt+mx_cnt))
# Original solution
h,w,m=list(map(int,input().split()))
r=dict()
c=dict()
pos=[]
rmax=0
cmax=0
for i in range(m):
    row,col=list(map(int,input().split()))
    if(row in r):
        r[row]+=1
        rmax=max(r[row],rmax)
    else:
        r[row]=1
        rmax=max(r[row],rmax)
    if(col in c):
        c[col]+=1
        cmax=max(c[col],cmax)
    else:
        c[col]=1
        cmax=max(c[col],cmax)
    pos.append(str(row)+str(col))
    
sorted(list(r.items()),key=lambda x:x[1])
sorted(list(c.items()),key=lambda x:x[1])
ans=-100
for i in list(r.keys()):
    if(r[i]<rmax):
        continue
    for j in list(c.keys()):
        if(c[j]<cmax):
            continue
        tmp=r[i]+c[j]
        if((str(i)+str(j)) in pos):
            tmp-=1
        ans=max(ans,tmp)
        
print(ans)

# Optimized solution
h,w,m=list(map(int,input().split()))
row=[0 for i in range(h)]
col=[0 for i in range(w)]
a=[]
for i in range(m):
    r,c=[int(x)-1 for x in input().split()]
    a.append([r,c])
    row[r]+=1
    col[c]+=1
rmax=max(row)
cmax=max(col)
ans=rmax+cmax
flag=row.count(rmax)*col.count(cmax)
for i,j in a:
    if(row[i]==rmax and col[j]==cmax):
        flag-=1
if(flag==0):
    ans-=1
print(ans)
# Original solution
import sys
from collections import deque


def input():
    return sys.stdin.readline().rstrip()


def main():
    H, W, M = list(map(int, input().split()))
    lh = [0] * H
    lw = [0] * W
    s = set()
    for _ in range(M):
        h, w = list(map(int, input().split()))
        lh[h - 1] += 1
        lw[w - 1] += 1
        s.add((h-1, w-1))

    maxh = max(lh)
    maxw = max(lw)
    for i in range(H):
        if lh[i] !=maxh:
            continue
        for j in range(W):
            if lw[j] !=maxw:
                continue
            if (i,j) not in s:
                print((maxh+maxw))
                exit()

    print((maxh+maxw-1))



if __name__ == "__main__":
    main()


# Optimized solution
import sys
from collections import deque


def input():
    return sys.stdin.readline().rstrip()


def main():
    H, W, M = list(map(int, input().split()))
    lh = [0] * H
    lw = [0] * W
    s = set()
    for _ in range(M):
        h, w = list(map(int, input().split()))
        lh[h - 1] += 1
        lw[w - 1] += 1
        s.add((h-1, w-1))

    maxh = max(lh)
    maxw = max(lw)
    wlist=[]
    for j in range(W):
        if maxw==lw[j]:
            wlist.append(j)



    for i in range(H):
        if lh[i] !=maxh:
            continue
        for j in wlist:
            if (i,j) not in s:
                print((maxh+maxw))
                exit()

    print((maxh+maxw-1))



if __name__ == "__main__":
    main()
# Original solution
import collections

h, w, m = list(map(int, input().split()))
x = []
y = []
bomb = []
for i in range(m):
  tmp_x, tmp_y = list(map(int, input().split()))
  x.append(tmp_x)
  y.append(tmp_y)
  bomb.append([tmp_x, tmp_y])

c_x = collections.Counter(x)
c_y = collections.Counter(y)
_max_x = c_x.most_common()[0][1]
_max_y = c_y.most_common()[0][1]

count = 0
for i in bomb:
  if c_x[i[0]] == _max_x and c_y[i[1]] == _max_y:
    count += 1

if count == len([kv[0] for kv in list(c_x.items()) if kv[1] == max(c_x.values())]) * len([kv[0] for kv in list(c_y.items()) if kv[1] == max(c_y.values())]):
  print((_max_x + _max_y - 1))
else:
  print((_max_x + _max_y))

# 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 heapq

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

bn_h = {}
bn_v = {}

for i in range(M):
    h, w = list(map(int, input().split()))
    bn_h.setdefault(h, set())
    bn_h[h].add(w)
    bn_v.setdefault(w, set())
    bn_v[w].add(h)

b1 = sorted(list(bn_h.items()), key = lambda x:len(x[1]), reverse=True)
b2 = sorted(list(bn_v.items()), key = lambda x:len(x[1]), reverse=True)

m1 = len(b1[0][1])
m2 = len(b2[0][1])

max_result = 0
for i in b1:
    h, sh = i
    if len(sh) < m1:
        break
    for j in b2:
        v, sv = j
        if len(sv) < m2:
            break
        result = len(sh) + len(sv) - 1
        if h not in sv:
            result += 1
        max_result = max(max_result, result)
print(max_result)


# Optimized solution
import heapq
def main():
    H, W, M = list(map(int, input().split()))

    bn_h = {}
    bn_v = {}

    for i in range(M):
        h, w = list(map(int, input().split()))
        bn_h.setdefault(h, set())
        bn_h[h].add(w)
        bn_v.setdefault(w, set())
        bn_v[w].add(h)

    b1 = sorted(list(bn_h.items()), key = lambda x:len(x[1]), reverse=True)
    b2 = sorted(list(bn_v.items()), key = lambda x:len(x[1]), reverse=True)

    m1 = len(b1[0][1])
    m2 = len(b2[0][1])

    flag = False
    max_result = 0
    for i in b1:
        h, sh = i
        if len(sh) < m1:
            break
        for j in b2:
            v, sv = j
            if len(sv) < m2:
                break
            result = len(sh) + len(sv) - 1
            if h not in sv:
                result += 1
                flag = True
            max_result = max(max_result, result)
            if flag == True:
                break
        if flag == True:
            break
    print(max_result)

if __name__ == '__main__':
    main()
# Original solution
h, w, m = list(map(int, input().split()))
bord_x, bord_y = [0 for i in range(h)], [0 for i in range(w)]
bord = [[0 for _j in range(w)] for _i in range(h)]

hw = []
for _i in range(m):
    s, t = list(map(int, input().split()))
    s -= 1
    t -= 1
    bord_x[s] += 1
    bord_y[t] += 1
    hw.append([s, t])

x_max, y_max = max(bord_x), max(bord_y)

cnt = 0
for i, j in hw:
    if bord_x[i] == x_max and bord_y[j] == y_max:
        cnt += 1

if cnt == bord_x.count(x_max)*bord_y.count(y_max):
    x_max -= 1

print((x_max+y_max))

# Optimized solution
h, w, m = list(map(int, input().split()))
bord_x, bord_y = [0]*h, [0]*w
 
hw = []
for _i in range(m):
    s, t = list(map(int, input().split()))
    s -= 1
    t -= 1
    bord_x[s] += 1
    bord_y[t] += 1
    hw.append([s, t])
 
x_max, y_max = max(bord_x), max(bord_y)
 
cnt = 0
for i, j in hw:
    if bord_x[i] == x_max and bord_y[j] == y_max:
        cnt += 1
 
if cnt == bord_x.count(x_max)*bord_y.count(y_max):
    x_max -= 1
 
print((x_max+y_max))
# Original solution
H, W, M = list(map(int, input().split()))
h = [0 for i in range(H)]
w = [0 for i in range(W)]
dp = [[0 for i in range(W)] for j in range(H)]

for i in range(M):
    hh, ww = list(map(int, input().split()))
    dp[hh - 1][ww - 1] += 1

for i in range(H):
    h[i] = sum(dp[i])

for i in range(W):
    w[i] = sum(dp[j][i] for j in range(H))

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0


for i in hhhh:
    if check == 1:
        break
    for j in wwww:
        if dp[i][j] == 0:
            check = 1
            break
print((hhh + www - (1 - check)))


# Optimized solution
H, W, M = list(map(int, input().split()))
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = []
for i in range(M):
    hh, ww = list(map(int, input().split()))
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP.append((hh - 1, ww - 1))

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0

for i in hhhh:
    for j in wwww:
        if (i, j) not in DP:
            check = 1
            break
print((hhh + www - (1 - check)))
# Original solution
import sys
h,w,m = list(map(int, input().split()))
h_t = []
w_t = []
s = []
for i1 in range(h):
  h_t.append(0)
for i2 in range(w):
  w_t.append(0)
for i in range(h):
  s.append([])
  for j in range(w):
    s[i].append(0)
for i3 in range(m):
  hi,wi = list(map(int, input().split()))
  h_t[hi-1] += 1
  w_t[wi-1] += 1
  s[hi-1][wi-1] = 1
hmax = max(h_t)
wmax = max(w_t)
hmaxi = [i for i, v in enumerate(h_t) if v == max(h_t)]
wmaxi = [i for i, v in enumerate(w_t) if v == max(w_t)]
for ht in hmaxi:
  for wt in wmaxi:
    if s[ht][wt] == 0:
      print((hmax + wmax))
      sys.exit()
print((hmax + wmax-1))


# Optimized solution
import sys
h,w,m = list(map(int, input().split()))
h_t = [0 for _ in range(h)]
w_t = [0 for _ in range(w)]
t = []
for _ in range(m):
  hi,wi = list(map(int, input().split()))
  h_t[hi-1] += 1
  w_t[wi-1] += 1
  t.append([hi-1,wi-1])
hmax = max(h_t)
wmax = max(w_t)
hmaxi = [i1 for i1 in range(h) if h_t[i1] == hmax]
wmaxi = [i2 for i2 in range(w) if w_t[i2] == wmax]
c = len(hmaxi)*len(wmaxi)
d = 0
for ht,wt in t:
  if h_t[ht] == hmax:
    if w_t[wt] == wmax:
      d += 1
if c ==d:
  print((hmax + wmax-1))
else:
  print((hmax + wmax))
# Original solution
h,w,m=list(map(int,input().split()))
h_=[0]*(h+1)
w_=[0]*(w+1)
plot=set()
for _ in range(m):
    x,y=list(map(int,input().split()))
    h_[x]+=1
    w_[y]+=1
    plot.add((x,y))
x=max(h_)
y=max(w_)
a=[i for i,v in enumerate(h_) if v==x]
b=[j for j,q in enumerate(w_) if q==y]
u=0
c=0
for i in a:
    for j in b:
        if (i,j) in plot:
          u+=1
        c+=1
        
ans=x+y
if u==c:
    print((ans-1))
else:
    print(ans)                
               


# Optimized solution
h,w,m=list(map(int,input().split()))
h_=[0]*(h+1)
w_=[0]*(w+1)
plot=set()
for _ in range(m):
    x,y=list(map(int,input().split()))
    h_[x]+=1
    w_[y]+=1
    plot.add((x,y))
x=max(h_)
y=max(w_)
a=[i for i,v in enumerate(h_) if v==x]
b=[j for j,q in enumerate(w_) if q==y]
ans=x+y-1
c=False
for i in a:
    for j in b:
        if (i,j) not in plot:
          c=True
          break
    if c:
      break
if c:
  print((ans+1))
else:
  print(ans)
# Original solution
H,W,M=list(map(int,input().split()))
l = [ list(map(int,input().split(" "))) for i in range(M)]
h=[0]*H
w=[0]*W
for i in range(M):
    h[l[i][0]-1]+=1
    w[l[i][1]-1]+=1
maxh=max(h)
maxw=max(w)
hlist=[]
wlist=[]
for i in range(H):
    if h[i]==maxh:
        hlist.append(i)
for i in range(W):
    if w[i]==maxw:
        wlist.append(i)
c=0
for i in hlist:
    for j in wlist:
        flag=0
        for k in range(M):
            if (i+1)==l[k][0] and (j+1)==l[k][1]:
                flag=1
                break
        if flag==0:
            print((maxh+maxw))
            c=1
            break
    if c==1:
        break
if c==0:
    print((maxh+maxw-1))


# Optimized solution
H,W,M=list(map(int,input().split()))
l = [ list(map(int,input().split(" "))) for i in range(M)]
h=[0]*H
w=[0]*W
for i in range(M):
    h[l[i][0]-1]+=1
    w[l[i][1]-1]+=1
maxh=max(h)
maxw=max(w)
hlist=[]
wlist=[]
for i in range(H):
    if h[i]==maxh:
        hlist.append(i)
for i in range(W):
    if w[i]==maxw:
        wlist.append(i)
c=0
for i in range(M):
  if h[l[i][0]-1]==maxh and w[l[i][1]-1]==maxw:
    c+=1
if len(hlist)*len(wlist)==c:
  print((maxh+maxw-1))
else:
  print((maxh+maxw))
# Original solution
h,w,m=list(map(int,input().split()))
s=[]
t=[]
st=[[] for i in range(h+1)]
for i in range(m):
  H,W=list(map(int,input().split()))
  s.append(H)
  t.append(W)
  st[H].append(W)
from collections import Counter
u=Counter(s)
v=Counter(t)
max_u=max(u.values())
max_v=max(v.values())
import sys
for i in u:
  if u[i]==max_u:
    for j in v:
      if v[j]==max_v:
        if j not in st[i]:
          print((max_u+max_v))
          sys.exit()
      
      
print((max_u+max_v-1))


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

for i in range(m):
  H,W=list(map(int,input().split()))
  s.append(H)
  t.append(W)
  
from collections import Counter
u=Counter(s)
v=Counter(t)
max_u=max(u.values())
max_u_set = set([kv[0] for kv in list(u.items()) if kv[1]==max_u])
max_v=max(v.values())
max_v_set = set([kv[0] for kv in list(v.items()) if kv[1]==max_v])
check=len(max_u_set)*len(max_v_set)

ans=0
for i in range(m):
  if u[s[i]]==max_u and v[t[i]]==max_v:
    ans=ans+1

if check-ans==0:
  print((max_u+max_v-1))
else:
  print((max_u+max_v))
# Original solution
H, W, M = list(map(int, input().split()))
hw = []

h_cnt = [0] * H
w_cnt = [0] * W
hw = [tuple([int(x)-1 for x in input().split()]) for _ in range(M)]
for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1

max_h = max(h_cnt)
max_w = max(w_cnt)
hs = [i for i in range(H) if h_cnt[i]==max_h]
ws = [i for i in range(W) if w_cnt[i]==max_w]

cnt = 0
for h, w in hw:
    if h in hs and w in ws:
        cnt += 1
if cnt < len(hs)*len(ws):
    print((max_h+max_w))
else:
    print((max_h+max_w-1))



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

h_cnt = [0] * H
w_cnt = [0] * W
hw = [tuple([int(x)-1 for x in input().split()]) for _ in range(M)]
for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1

max_h = max(h_cnt)
max_w = max(w_cnt)
hs = [i for i in range(H) if h_cnt[i]==max_h]
ws = [i for i in range(W) if w_cnt[i]==max_w]

ans = max_h+max_w-1
hw = set(hw)
for h in hs:
    for w in ws:
        if (h, w) not in hw:
            print((max_h+max_w))
            exit()
print((max_h+max_w-1))
# Original solution
from collections import defaultdict
h, w, m = list(map(int, input().split()))
targets = defaultdict(int)
targets_count_yoko = defaultdict(int)
targets_count_tate = defaultdict(int)
for _ in range(m):
    y, x = list(map(int, input().split()))
    y -= 1
    x -= 1
    targets_count_yoko[x] += 1
    targets_count_tate[y] += 1
    targets[(y, x)] = -1

max_row = max(targets_count_yoko.values())
max_line = max(targets_count_tate.values())
y_idx = []
x_idx = []
max_count_x = 0
max_count_y = 0
for i in range(w):
    if targets_count_yoko[i] == max_row:
        x_idx.append(i)
        max_count_x += 1
for i in range(h):
    if targets_count_tate[i] == max_line:
        y_idx.append(i)
        max_count_y += 1


ans = max_line + max_row
kumi = max_count_x*max_count_y
for key_y, key_x in list(targets.keys()):
    if key_y in y_idx and key_x in x_idx:
        kumi -= 1
    if kumi == 0:
        break

if kumi == 0:
    print((ans-1))
else:
    print(ans)



# Optimized solution
from collections import defaultdict
h, w, m = list(map(int, input().split()))
targets = defaultdict(int)
targets_count_yoko = defaultdict(int)
targets_count_tate = defaultdict(int)
for _ in range(m):
    y, x = list(map(int, input().split()))
    y -= 1
    x -= 1
    targets_count_yoko[x] += 1
    targets_count_tate[y] += 1
    targets[(y, x)] = -1

max_row = max(targets_count_yoko.values())
max_line = max(targets_count_tate.values())
y_idx = defaultdict(bool)
x_idx = defaultdict(bool)
max_count_x = 0
max_count_y = 0
for i in range(w):
    if targets_count_yoko[i] == max_row:
        x_idx[i] = True
        max_count_x += 1
for i in range(h):
    if targets_count_tate[i] == max_line:
        y_idx[i] = True
        max_count_y += 1


ans = max_line + max_row
kumi = max_count_x*max_count_y
for key_y, key_x in list(targets.keys()):
    if y_idx[key_y] and x_idx[key_x]:
        kumi -= 1
    if kumi == 0:
        break

if kumi == 0:
    print((ans-1))
else:
    print(ans)
# Original solution
from collections import defaultdict
h, w, m = list(map(int, input().split()))
targets = []
targets_count_yoko = [0]*w
targets_count_tate = [0]*h
for _ in range(m):
    y, x = list(map(int, input().split()))
    y -= 1
    x -= 1
    targets_count_yoko[x] += 1
    targets_count_tate[y] += 1
    targets.append((y, x))

max_row = max(targets_count_yoko)
max_line = max(targets_count_tate)
y_idx = [i for i, v in enumerate(targets_count_tate) if v == max_line]
x_idx = [i for i, v in enumerate(targets_count_yoko) if v == max_row]

ans = max_line + max_row
flag = False
for y in y_idx:
    for x in x_idx:
        if (y, x) not in targets:
            flag = True
            break
    else:
        continue
    break

if flag:
    print(ans)
else:
    print((ans-1))


# Optimized solution
from collections import defaultdict
h, w, m = list(map(int, input().split()))
targets = []
targets_count_w = defaultdict(int)
targets_count_h = defaultdict(int)
for _ in range(m):
    y, x = list(map(int, input().split()))
    y -= 1
    x -= 1
    targets_count_w[x] += 1
    targets_count_h[y] += 1
    targets.append((y, x))

max_w = max(targets_count_w.values())
max_h = max(targets_count_h.values())
y_idx = defaultdict(bool)
x_idx = defaultdict(bool)
max_count_x = 0
max_count_y = 0
for i in range(w):
    if targets_count_w[i] == max_w:
        x_idx[i] = True
        max_count_x += 1
for i in range(h):
    if targets_count_h[i] == max_h:
        y_idx[i] = True
        max_count_y += 1


ans = max_w + max_h
kumi = max_count_x*max_count_y
for ty, tx in targets:
    if y_idx[ty] and x_idx[tx]:
        kumi -= 1
    if kumi == 0:
        break

if kumi == 0:
    print((ans-1))
else:
    print(ans)
# Original solution
from collections import defaultdict
H, W, M = list(map(int, input().split()))
tate = defaultdict(int)
yoko = defaultdict(int)
T = {}
for i in range(M):
    h, w = list(map(int, input().split()))
    tate[h-1] += 1
    yoko[w-1]+= 1
    T[(h-1, w-1)] = 1

tate = sorted(list(tate.items()), key=lambda x:x[1], reverse=True)
yoko = sorted(list(yoko.items()), key=lambda x:x[1], reverse=True)
tate_m = tate[0][1]
yoko_m = yoko[0][1]
ans = 0
for i in range(len(tate)):
    if tate[i][1] == tate_m:
        for j in range(len(yoko)):
            if yoko[j][1] == yoko_m:
                if (tate[i][0], yoko[j][0]) in T:
                    ans = max(ans, tate_m + yoko_m - 1)
                else:
                    ans = max(ans, tate_m + yoko_m)
            else:
                break
    else:
        break
print(ans)

# Optimized solution
from collections import defaultdict
H, W, M = list(map(int, input().split()))
tate = defaultdict(int)
yoko = defaultdict(int)
T = {}
for i in range(M):
    h, w = list(map(int, input().split()))
    tate[h-1] += 1
    yoko[w-1]+= 1
    T[(h-1, w-1)] = 1

tate = sorted(list(tate.items()), key=lambda x:x[1], reverse=True)
yoko = sorted(list(yoko.items()), key=lambda x:x[1], reverse=True)
tate_m = tate[0][1]
yoko_m = yoko[0][1]
ans = 0
for i in range(len(tate)):
    if ans == tate_m + yoko_m:
        break
    if tate[i][1] == tate_m:
        for j in range(len(yoko)):
            if yoko[j][1] == yoko_m:
                if (tate[i][0], yoko[j][0]) in T:
                    ans = max(ans, tate_m + yoko_m - 1)
                else:
                    ans = max(ans, tate_m + yoko_m)
            else:
                break
    else:
        break
print(ans)