Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
hn = [0]*W
wn = [0]*W
flag = set()
for i in range(M):
  h, w = map(int, input().split())
  hn[h-1] += 1
  wn[w-1] += 1
  flag.add((h,w))
  
#hrank = sorted(hn, key=lambda t:-t[1])
#wrank = sorted(wn, key=lambda t:-t[1])

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

hmaxlist =[]
for h in hn:
  if h == hmax:
    hmaxlist.append(h)
  
wmaxlist =[]
for w in wn:
  if w == wmax:
    wmaxlist.append(w)
  
flag2 = set()
for i in hmaxlist:
  for j in wmaxlist:
    flag2.add((i,j))

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

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

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

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

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

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
hn = {}
wn = {}
flag = set()
for i in range(M):
  h, w = map(int, input().split())
  if (h,w) not in flag: 
    if h in hn:
      hn[h] += 1
    else:
      hn[h] = 1
    if w in wn:
      wn[w] += 1
    else:
      wn[w] = 1
  flag.add((h,w))
  
hrank = sorted(hn.items(), key=lambda t:-t[1])
wrank = sorted(wn.items(), key=lambda t:-t[1])

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

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

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

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

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

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

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

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

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

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
hn = {}
wn = {}
flag = set()
for i in range(M):
  h, w = map(int, input().split())
  if (h,w) not in flag: 
    if h in hn:
      hn[h] += 1
    else:
      hn[h] = 1
    if w in wn:
      wn[w] += 1
    else:
      wn[w] = 1
  flag.add((h,w))
  
hrank = sorted(hn.items(), key=lambda t:-t[1])
wrank = sorted(wn.items(), key=lambda t:-t[1])

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

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

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

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

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

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

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

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

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