Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
bomb=[list(map(int, input().split())) for _ in range(m)]
res1=[0]*h
res2=[0]*w
for i in range(m):
    bomb1=bomb[i]
    res1[bomb1[0]-1]+=1
    res2[bomb1[1]-1]+=1
ans1=max(res1)
ans2=max(res2)
ans=ans1+ans2
s1=0
l1=[]
for j in range(h):
    res3=res1[j]
    if res3>s1:
            l1=[j+1]
            s1=res3
    elif res3==s1:
            l1.append(j+1)
s2=0
l2=[]
for k in range(w):
    res4=res2[k]
    if res4>s2:
            l2=[k+1]
            s2=res4
    elif res4==s2:
            l2.append(k+1)
count=0
for l in range(m):
    bomb2=bomb[l]
    if bomb2[0] in l1 and bomb2[1] in l2:
        count+=1

if count!=len(l1)*len(l2):
    print(ans)
else:
    print(ans-1)


Fixed submission:
from collections import deque

h,w,m=map(int,input().split())
bomb=[list(map(int, input().split())) for _ in range(m)]
res1=[0]*h
res2=[0]*w
for i in range(m):
    bomb1=bomb[i]
    res1[bomb1[0]-1]+=1
    res2[bomb1[1]-1]+=1
ans1=max(res1)
ans2=max(res2)
ans=ans1+ans2
s1=0
l1=deque()
for j in range(h):
    res3=res1[j]
    if res3>s1:
            l1=[j+1]
            s1=res3
    elif res3==s1:
            l1.append(j+1)
s2=0
l2=deque()
for k in range(w):
    res4=res2[k]
    if res4>s2:
            l2=[k+1]
            s2=res4
    elif res4==s2:
            l2.append(k+1)
l3=set(l1)
l4=set(l2)
count=0

for l in range(m):
    bomb2=bomb[l]
    if bomb2[0] in l3 and bomb2[1] in l4:
        count+=1

if count!=len(l1)*len(l2):
    print(ans)
else:
    print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
bomb=[list(map(int, input().split())) for _ in range(m)]
res1=[0 for _ in range(h)]
res2=[0 for _ in range(w)]
for i in range(m):
    res1[bomb[i][0]-1]+=1
    res2[bomb[i][1]-1]+=1
ans1=max(res1)
ans2=max(res2)
ans=ans1+ans2
s1=0
l1=[]
for j in range(h):
    if res1[j]>s1:
            l1=[j+1]
            s1=res1[j]
    elif res1[j]==s1:
            l1.append(j+1)
s2=0
l2=[]
for k in range(w):
    if res2[k]>s2:
            l2=[k+1]
            s2=res2[k]
    elif res2[k]==s2:
            l2.append(k+1)
count=0
for l in range(m):
    bomb1=bomb[l]
    if bomb1[0] in l1 and bomb1[1] in l2:
        count+=1

if count!=len(l1)*len(l2):
    print(ans)
else:
    print(ans-1)


Fixed submission:
from collections import deque

h,w,m=map(int,input().split())
bomb=[list(map(int, input().split())) for _ in range(m)]
res1=[0]*h
res2=[0]*w
for i in range(m):
    bomb1=bomb[i]
    res1[bomb1[0]-1]+=1
    res2[bomb1[1]-1]+=1
ans1=max(res1)
ans2=max(res2)
ans=ans1+ans2
s1=0
l1=deque()
for j in range(h):
    res3=res1[j]
    if res3>s1:
            l1=[j+1]
            s1=res3
    elif res3==s1:
            l1.append(j+1)
s2=0
l2=deque()
for k in range(w):
    res4=res2[k]
    if res4>s2:
            l2=[k+1]
            s2=res4
    elif res4==s2:
            l2.append(k+1)
l3=set(l1)
l4=set(l2)
count=0

for l in range(m):
    bomb2=bomb[l]
    if bomb2[0] in l3 and bomb2[1] in l4:
        count+=1

if count!=len(l1)*len(l2):
    print(ans)
else:
    print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
bomb=sorted([list(map(int, input().split())) for _ in range(m)])
res1=[0 for _ in range(h)]
res2=[0 for _ in range(w)]
for i in range(m):
    res1[bomb[i][0]-1]+=1
    res2[bomb[i][1]-1]+=1
ans1=max(res1)
ans2=max(res2)
ans=ans1+ans2
s1=0
l1=[]
for j in range(h):
    if res1[j]>s1:
            l1=[j+1]
            s1=res1[j]
    elif res1[j]==s1:
            l1.append(j+1)
s2=0
l2=[]
for k in range(w):
    if res2[k]>s2:
            l2=[k+1]
            s2=res2[k]
    elif res2[k]==s2:
            l2.append(k+1)
count=0
for l in range(m):
    if bomb[l][0] in l1 and bomb[l][1] in l2:
        count+=1

if count!=len(l1)*len(l2):
    print(ans)
else:
    print(ans-1)


Fixed submission:
from collections import deque

h,w,m=map(int,input().split())
bomb=[list(map(int, input().split())) for _ in range(m)]
res1=[0]*h
res2=[0]*w
for i in range(m):
    bomb1=bomb[i]
    res1[bomb1[0]-1]+=1
    res2[bomb1[1]-1]+=1
ans1=max(res1)
ans2=max(res2)
ans=ans1+ans2
s1=0
l1=deque()
for j in range(h):
    res3=res1[j]
    if res3>s1:
            l1=[j+1]
            s1=res3
    elif res3==s1:
            l1.append(j+1)
s2=0
l2=deque()
for k in range(w):
    res4=res2[k]
    if res4>s2:
            l2=[k+1]
            s2=res4
    elif res4==s2:
            l2.append(k+1)
l3=set(l1)
l4=set(l2)
count=0

for l in range(m):
    bomb2=bomb[l]
    if bomb2[0] in l3 and bomb2[1] in l4:
        count+=1

if count!=len(l1)*len(l2):
    print(ans)
else:
    print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
bomb=sorted([list(map(int, input().split())) for _ in range(m)])
res1=[0 for _ in range(h)]
res2=[0 for _ in range(w)]
for i in range(m):
    res1[bomb[i][0]-1]+=1
    res2[bomb[i][1]-1]+=1
ans1=max(res1)
ans2=max(res2)
ans=ans1+ans2
s1=0
l1=[]
for j in range(h):
    if res1[j]>s1:
            l1=[j+1]
            s1=res1[j]
    elif res1[j]==s1:
            l1.append(j+1)
s2=0
l2=[]
for k in range(w):
    if res2[k]>s2:
            l2=[k+1]
            s2=res2[k]
    elif res2[k]==s2:
            l2.append(k+1)
count=0
for l in range(m):
    if bomb[l][0] in l1 and bomb[l][1] in l2:
        count+=1

if count!=len(l1)*len(l2):
    print(ans)
else:
    print(ans-1)


Fixed submission:
from collections import deque

h,w,m=map(int,input().split())
bomb=[list(map(int, input().split())) for _ in range(m)]
res1=[0]*h
res2=[0]*w
for i in range(m):
    bomb1=bomb[i]
    res1[bomb1[0]-1]+=1
    res2[bomb1[1]-1]+=1
ans1=max(res1)
ans2=max(res2)
ans=ans1+ans2
s1=0
l1=deque()
for j in range(h):
    res3=res1[j]
    if res3>s1:
            l1=[j+1]
            s1=res3
    elif res3==s1:
            l1.append(j+1)
s2=0
l2=deque()
for k in range(w):
    res4=res2[k]
    if res4>s2:
            l2=[k+1]
            s2=res4
    elif res4==s2:
            l2.append(k+1)
l3=set(l1)
l4=set(l2)
count=0

for l in range(m):
    bomb2=bomb[l]
    if bomb2[0] in l3 and bomb2[1] in l4:
        count+=1

if count!=len(l1)*len(l2):
    print(ans)
else:
    print(ans-1)