Buggy python submission (verdict: Runtime Error):
H,W,M = list(map(int,input().split()))

h = [0] * H
w = [0] * W

hw = []

for _ in range(H):
    hw.append([0] * W)

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1][b - 1] += 1
    
hm = max(h)
wm = max(w)

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

for x in hp:
    for y in wp:
        if hw[x][y] == 0:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)



Fixed submission:
from collections import defaultdict

h, w, m = 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)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
H,W,M = list(map(int,input().split()))

h = [0] * H
w = [0] * W

hw = defaultdict(set)

for _ in range(H):
    hw.append([0] * W)

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1].add(b - 1)
    
hm = max(h)
wm = max(w)

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

for x in hp:
    for y in wp:
        if y in hw[x]:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)



Fixed submission:
from collections import defaultdict

h, w, m = 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)

Buggy python submission (verdict: Runtime Error):
H,W,M = list(map(int,input().split()))

h = [0] * H
w = [0] * W

hw = []

for _ in range(H):
    hw.append([0] * W)

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1][b - 1] += 1
    
hm = max(h)
wm = max(w)

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

for x in hp:
    for y in wp:
        if hw[x][y] == 0:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)



Fixed submission:
from collections import defaultdict

h, w, m = 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)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

h, w, m = 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)

Fixed submission:
from collections import defaultdict

h, w, m = 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)