Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
S = [[0]*W for _ in range(H)]
lh = [0]*(H+1)
lw = [0]*(W+1)
l = []
for _ in range(M):
  h, w = map(int, input().split())
  lh[h] += 1
  lw[w] += 1
  l += [[h, w]]

maxh = max(lh)
maxw = max(lw)
cnt = 0

ch = lh.count(maxh)
cw = lw.count(maxw)
for y, x in l:
  if lh[y] == maxh and lw[x] == maxw:
    cnt += 1

ans = maxh+maxw
if cnt == ch*cw:
  ans -= 1

print(ans)    


Fixed submission:
ans=0

h,w,m=map(int,input().split())
d=list()
from collections import defaultdict
r=defaultdict(int)
c=defaultdict(int)
r=[0]*(h+1)
c=[0]*(w+1)
for i in range(m):
  a,b=map(int,input().split())
  d+=(a,b),
  r[a]+=1
  c[b]+=1
R=max(r)
C=max(c)

x=0
nr=r.count(R)
nc=c.count(C)
for i in range(m):
    a,b=d[i]
    if r[a]==R and c[b]==C:
        x+=1

ans=R+C
if x==nr*nc:
    ans-=1
print(ans)

Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
S = [[0]*W for _ in range(H)]
lh = [0]*H
lw = [0]*W
l = []
for _ in range(M):
  h, w = map(lambda x: int(x)-1, input().split())
  lh[h] += 1
  lw[w] += 1
  l.append((h, w))

maxh = max(lh)
maxw = max(lw)
cnt = 0

ch = lh.count(maxh)
cw = lw.count(maxw)
for y, x in l:
  if lh[y] == maxh and lw[x] == maxw:
    cnt += 1

ans = maxh+maxw
if cnt == ch*cw:
  ans -= 1

print(ans)    


Fixed submission:
ans=0

h,w,m=map(int,input().split())
d=list()
from collections import defaultdict
r=defaultdict(int)
c=defaultdict(int)
r=[0]*(h+1)
c=[0]*(w+1)
for i in range(m):
  a,b=map(int,input().split())
  d+=(a,b),
  r[a]+=1
  c[b]+=1
R=max(r)
C=max(c)

x=0
nr=r.count(R)
nc=c.count(C)
for i in range(m):
    a,b=d[i]
    if r[a]==R and c[b]==C:
        x+=1

ans=R+C
if x==nr*nc:
    ans-=1
print(ans)

Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
S = [[0]*W for _ in range(H)]
dich = {i: 0 for i in range(H)}
dicw = {i: 0 for i in range(W)}
l = []
for _ in range(M):
  h, w = map(lambda x: int(x)-1, input().split())
  dich[h] += 1
  dicw[w] += 1
  l.append((h, w))

maxh = max(dich.values())
maxw = max(dicw.values())
cnt = 0

ch = sum([1 for i in dich.values() if i == maxh])
cw = sum([1 for i in dicw.values() if i == maxw])
for y, x in l:
  if dich[y] == maxh and dicw[x] == maxw:
    cnt += 1

ans = maxh+maxw
if cnt == ch*cw:
  ans -= 1

print(ans)    


Fixed submission:
ans=0

h,w,m=map(int,input().split())
d=list()
from collections import defaultdict
r=defaultdict(int)
c=defaultdict(int)
r=[0]*(h+1)
c=[0]*(w+1)
for i in range(m):
  a,b=map(int,input().split())
  d+=(a,b),
  r[a]+=1
  c[b]+=1
R=max(r)
C=max(c)

x=0
nr=r.count(R)
nc=c.count(C)
for i in range(m):
    a,b=d[i]
    if r[a]==R and c[b]==C:
        x+=1

ans=R+C
if x==nr*nc:
    ans-=1
print(ans)

Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
S = [[0]*W for _ in range(H)]
dich = {i: 0 for i in range(H)}
dicw = {i: 0 for i in range(W)}
dic = set()
for _ in range(M):
  h, w = map(lambda x: int(x)-1, input().split())
  dich[h] += 1
  dicw[w] += 1
  dic.add((h, w))

sh = sorted(dich.items(), key=lambda x:-x[1])
sw = sorted(dicw.items(), key=lambda x:-x[1])
maxh = max([i for _, i in sh])
maxw = max([i for _, i in sw])
ans = 0
for h, c1 in sh:
  flg = False
  if c1 < maxh:
    break
  for w, c2 in sw:
    if c2 < maxw:
      flg = True
      break
    if (h, w) in dic:
      ans = max(ans, c1+c2-1)
    else:
      ans = max(ans, c1+c2)
  if flg:
    break

print(ans)    


Fixed submission:
ans=0

h,w,m=map(int,input().split())
d=list()
from collections import defaultdict
r=defaultdict(int)
c=defaultdict(int)
r=[0]*(h+1)
c=[0]*(w+1)
for i in range(m):
  a,b=map(int,input().split())
  d+=(a,b),
  r[a]+=1
  c[b]+=1
R=max(r)
C=max(c)

x=0
nr=r.count(R)
nc=c.count(C)
for i in range(m):
    a,b=d[i]
    if r[a]==R and c[b]==C:
        x+=1

ans=R+C
if x==nr*nc:
    ans-=1
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
H, W, M = map(int, input().split())
S = [[0]*W for _ in range(H)]
for _ in range(M):
  h, w = map(lambda x: int(x)-1, input().split())
  S[h][w] = 1

S = np.array(S)
T = np.array([[0]*W for _ in range(H)])
for i in range(H):
  T[i] += np.sum(S[i])

for i in range(W):
  T[:, i] += np.sum(S[:, i])

T -= S
print(np.max(T))

Fixed submission:
ans=0

h,w,m=map(int,input().split())
d=list()
from collections import defaultdict
r=defaultdict(int)
c=defaultdict(int)
r=[0]*(h+1)
c=[0]*(w+1)
for i in range(m):
  a,b=map(int,input().split())
  d+=(a,b),
  r[a]+=1
  c[b]+=1
R=max(r)
C=max(c)

x=0
nr=r.count(R)
nc=c.count(C)
for i in range(m):
    a,b=d[i]
    if r[a]==R and c[b]==C:
        x+=1

ans=R+C
if x==nr*nc:
    ans-=1
print(ans)