Buggy python submission (verdict: Runtime Error):
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))
 
maxh=max(sumh)
maxw=max(sumw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==len(qh)*len(qw):
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Fixed submission:
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))
 
qh=[]
qw=[]
maxh=max(sumh)
maxw=max(sumw)
qh=[i for i,x in enumerate(sumh) if x==maxh]
qw=[i for i,x in enumerate(sumw) if x==maxw]

cnt=0
for h,w in bomb:
  if (h-1) in qh and (w-1) in qw:
    cnt+=1
if cnt==len(qh)*len(qw):
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Fixed submission:
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
s=[[] for _ in range(H)]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  s[h-1].append(w-1)
 
qh=[]
qw=[]
maxh=max(sumh)
maxw=max(sumw)
for i in range(H):
  if maxh==sumh[i]:
    qh.append(i)
for i in range(W):
  if maxw==sumw[i]:
    qw.append(i)
 
#print(s,H,W,sumh,sumw,qh,qw)
for i in qh:
  for j in qw:
    if j not in s[i]:
      print(maxh+maxw)
      exit()
 
print(maxh+maxw-1)

Fixed submission:
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
s=[[] for _ in range(H)]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  s[h-1].append(w-1)

maxh=maxw=0
qh=[]
qw=[]
for i in range(H):
  maxh=max(maxh, sumh[i])
for i in range(H):
  if maxh==sumh[i]:
    qh.append(i)

for i in range(W):
  maxw=max(maxw, sumw[i])
for i in range(W):
  if maxw==sumw[i]:
    qw.append(i)

#print(s,H,W,sumh,sumw,qh,qw)
for i in qh:
  for j in qw:
    if j not in s[i]:
      print(maxh+maxw)
      exit()

print(maxh+maxw-1)

Fixed submission:
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Buggy python submission (verdict: Runtime Error):
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
s=[[0]*W for _ in range(H)]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  s[h-1][w-1]=1

maxh=maxw=0
qh=[]
qw=[]
for i in range(H):
  maxh=max(maxh, sumh[i])
for i in range(H):
  if maxh==sumh[i]:
    qh.append(i)

for i in range(W):
  maxw=max(maxw, sumw[i])
for i in range(W):
  if maxw==sumw[i]:
    qw.append(i)

for i in qh:
  for j in qw:
    if s[i][j]==0:
      print(maxh+maxw)
      exit()

print(maxh+maxw-1)

Fixed submission:
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Buggy python submission (verdict: Runtime Error):
H,W,M=map(int, input().split())
sumh=[[_,0] for _ in range(H)]
sumw=[[_,0] for _ in range(W)]
s=[[0]*W for _ in range(H)]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1][1]+=1
  sumw[w-1][1]+=1
  s[h-1][w-1]=1

maxh=maxw=0
qh=[]
qw=[]
for i in range(H):
  maxh=max(maxh, sumh[i][1])
for i in range(H):
  if maxh==sumh[i][1]:
    qh.append(i)

for i in range(W):
  maxw=max(maxw, sumw[i][1])
for i in range(W):
  if maxw==sumw[i][1]:
    qw.append(i)

for i in qh:
  for j in qw:
    if s[i][j]==0:
      print(maxh+maxw)
      exit()

print(maxh+maxw-1)

Fixed submission:
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Buggy python submission (verdict: Runtime Error):
H,W,M=map(int, input().split())
sumh=[[_,0] for _ in range(H)]
sumw=[[_,0] for _ in range(W)]
s=[[0]*W for _ in range(H)]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1][1]+=1
  sumw[w-1][1]+=1
  s[h-1][w-1]=1

sumh.sort(reverse=True, key=lambda x:x[1])
sumw.sort(reverse=True, key=lambda x:x[1])

maxh=sumh[0][1]
maxw=sumw[0][1]

flg=s[sumh[0][0]][sumw[0][0]]
for i in range(H):
  if sumh[i][1]<maxh:
    print(maxh+maxw-flg)
    exit()
  for j in range(W):
    if sumw[j][1]<maxw:
      j=W-1
    else:
      flg=min(flg,s[sumh[i][0]][sumw[j][0]])
#      print("###",i,j,sumh[i],sumw[j])


print(maxh+maxw-flg)

Fixed submission:
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)