Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=[]


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.append([a,b])


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if [i,j] not in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)

Fixed submission:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if not (i,j) in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=[]


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.append([a,b])


hcnt,wcnt=max(hlist),max(wlist)

hh,ww=[],[]
hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in range(1,h+1):
  if hlist[i]==hcnt:
    hh+=[i]

for i in range(1,w+1):
  if wlist[i]==wcnt:
    ww+=[i]

for i in hh:
  for j in ww:
    if [i,j] not in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)

Fixed submission:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if not (i,j) in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)

cnt=[[False]*(w+1) for i in range(h+1)]
for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt[a][b]=True
  

hcnt,wcnt=max(hlist),max(wlist)

hh,ww=[],[]

for i in range(1,h+1):
  if hlist[i]==hcnt:
    hh+=[i]

for i in range(1,w+1):
  if wlist[i]==wcnt:
    ww+=[i]

for i in hh:
  for j in ww:
    if cnt[i][j]==False:
      print(hcnt+wcnt)
      exit()
  
print(hcnt+wcnt-1)


Fixed submission:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if not (i,j) in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)

cnt=[[False]*(w+1) for i in range(h+1)]
for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt[a][b]=True
  
hcnt,wcnt=0,0
for i in range(1,h+1):
  hcnt=max(hcnt,hlist[i])
  
for i in range(1,w+1):
  wcnt=max(wcnt,wlist[i])

hh,ww=[],[]

for i in range(1,h+1):
  if hlist[i]==hcnt:
    hh+=[i]

for i in range(1,h+1):
  if wlist[i]==wcnt:
    ww+=[i]

ans=0

for i in hh:
  for j in ww:
    if cnt[i][j]==False:
      print(hcnt+wcnt)
      exit()
  
print(hcnt+wcnt-1)

Fixed submission:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if not (i,j) in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)

cnt=[[False]*(w+1) for i in range(h+1)]
for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt[a][b]=True
  
hcnt,wcnt=0,0
for i in range(1,h+1):
  hcnt=max(hcnt,hlist[i])
  
for i in range(1,w+1):
  wcnt=max(wcnt,wlist[i])

hh,ww=[],[]

for i in range(1,h+1):
  if hlist[i]==hcnt:
    hh+=[i]

for i in range(1,h+1):
  if wlist[i]==wcnt:
    ww+=[i]

ans=0

for i in hh:
  for j in ww:
    if cnt[i][j]==True:
      print(hcnt+wcnt-1)
      exit()
  
print(hcnt+wcnt)

Fixed submission:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if not (i,j) in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)