Buggy python submission (verdict: Time Limit Exceeded):
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

H,W,M=nm()
r=[0]*(10**6)
c=[0]*(10**6)
ans=0
mass=[]
for i in range(M):
    h,w=nm()
    mass.append((h,w))
    r[h]+=1
    c[w]+=1

inds1=list(range(10**6))
inds1.sort(reverse=True,key=lambda x: r[x])

inds2=list(range(10**6))
inds2.sort(reverse=True,key=lambda x: c[x])

r.sort(reverse=True)
c.sort(reverse=True)

r1=0
l1=0

while(1):
    if(r[r1+1]==r[r1]):
        r1+=1
    else:
        break

while(1):
    if(c[l1+1]==c[l1]):
        l1+=1
    else:
        break



flag=False
for i in range(r1+1):
    for j in range(l1+1):
        flag=True
        for k in mass:
                if(k[0]==inds1[i] and k[1]==inds2[j]):
                    flag=False
        if(flag==True):
            print(r[0]+c[0])
            sys.exit(0)


print(r[0]+c[0]-1)






Fixed submission:
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

H,W,M=nm()
r=[0]*(10**6)
c=[0]*(10**6)
mass=set()
for i in range(M):
    h,w=nm()
    mass.add(H*h+w)
    r[h]+=1
    c[w]+=1

rl=[]
cl=[]

r_max=0
for i in range(1,H+1):
    r_max=max(r[i],r_max)
    
c_max=0
for i in range(1,W+1):
    c_max=max(c[i],c_max)

for i in range(1,H+1):
    if(r[i]==r_max):
        rl.append(i)

for i in range(1,W+1):
    if(c[i]==c_max):
        cl.append(i)



for i in rl:
    for j in cl:
        if(i*H+j not in mass):
            print(r_max+c_max)
            sys.exit(0)


print(r_max+c_max-1)

Buggy python submission (verdict: Runtime Error):
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

H,W,M=nm()
r=[0]*(10**6)
c=[0]*(10**6)
ans=0
mass=[[0 for i in range(10**6)] for j in range(10**6)]
for i in range(M):
    h,w=nm()
    mass[h][w]=1
    r[h]+=1
    c[w]+=1

inds1=list(range(10**6))
inds1.sort(key=lambda x: r[x])

inds2=list(range(10**6))
inds2.sort(key=lambda x: c[x])

r.sort(reverse=True)
l.sort(reverse=True)

r1=0
l1=0

while(1):
    if(r[r1+1]==r[r1])
        r1+=1
    else:
        break

while(1):
    if(l[l1+1]==l[l1])
        l1+=1
    else:
        break

flag=False
for i in range(r1+1):
    for j in range(l1+1):
        if(mass[inds1[i]][inds2[j]]==0):
            flag=True
        
if(flag==True):
    print(r[0]+l[0])
else:
    print(r[0]+l[0]-1)






Fixed submission:
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

H,W,M=nm()
r=[0]*(10**6)
c=[0]*(10**6)
mass=set()
for i in range(M):
    h,w=nm()
    mass.add(H*h+w)
    r[h]+=1
    c[w]+=1

rl=[]
cl=[]

r_max=0
for i in range(1,H+1):
    r_max=max(r[i],r_max)
    
c_max=0
for i in range(1,W+1):
    c_max=max(c[i],c_max)

for i in range(1,H+1):
    if(r[i]==r_max):
        rl.append(i)

for i in range(1,W+1):
    if(c[i]==c_max):
        cl.append(i)



for i in rl:
    for j in cl:
        if(i*H+j not in mass):
            print(r_max+c_max)
            sys.exit(0)


print(r_max+c_max-1)