Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=[[0 for _ in range(w)] for _ in range(h)]
for i in range(m):
  h1,w1=map(int,input().split())
  l[h1-1][w1-1]=1
  lh[h1-1]+=1
  lw[w1-1]+=1
hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    lw2.append(i)
 
s=1
for m in lh2:
  for m2 in lw2:
    if l[m][m2]==0:
      s=0
      
print(hmax+wmax-s)

Fixed submission:
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=set()
for i in range(m):
  h1,w1=input().split()
  l.add(h1+"_"+w1)
  lh[int(h1)-1]+=1
  lw[int(w1)-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    for m in lh2:
      if str(m+1)+"_"+str(i+1) not in l:
        print(hmax+wmax)
        exit()      
print(hmax+wmax-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=[set() for _ in range(h)]
for i in range(m):
  h1,w1=map(int,input().split())
  l[h1-1].add(w1-1)
  lh[h1-1]+=1
  lw[w1-1]+=1
hmax=max(lh)

ans=0
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lw2=lw[:]
    for m in l[i]:
      lw2[m]-=1
    ans=max(ans,hmax+max(lw2))

print(ans)

Fixed submission:
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=set()
for i in range(m):
  h1,w1=input().split()
  l.add(h1+"_"+w1)
  lh[int(h1)-1]+=1
  lw[int(w1)-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    for m in lh2:
      if str(m+1)+"_"+str(i+1) not in l:
        print(hmax+wmax)
        exit()      
print(hmax+wmax-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=set()
for i in range(m):
  h1,w1=input().split()
  l.add(h1+"_"+w1)
  lh[int(h1)-1]+=1
  lw[int(w1)-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    lw2.append(i)

s=1
for m in lh2:
  for m2 in lw2:
    if str(m+1)+"_"+str(m2+1) not in l:
      s=0
      
print(hmax+wmax-s)

Fixed submission:
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=set()
for i in range(m):
  h1,w1=input().split()
  l.add(h1+"_"+w1)
  lh[int(h1)-1]+=1
  lw[int(w1)-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    for m in lh2:
      if str(m+1)+"_"+str(i+1) not in l:
        print(hmax+wmax)
        exit()      
print(hmax+wmax-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=[]
for i in range(m):
  h1,w1=map(int,input().split())
  l.append([h1,w1])
  lh[h1-1]+=1
  lw[w1-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    lw2.append(i)

s=1
for m in lh2:
  for m2 in lw2:
    if [m+1,m2+1] not in l:
      s=0
      
print(hmax+wmax-s)

Fixed submission:
h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=set()
for i in range(m):
  h1,w1=input().split()
  l.add(h1+"_"+w1)
  lh[int(h1)-1]+=1
  lw[int(w1)-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    for m in lh2:
      if str(m+1)+"_"+str(i+1) not in l:
        print(hmax+wmax)
        exit()      
print(hmax+wmax-1)