Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline
from collections import defaultdict, deque
h, w, m = map(int,input().split())
row = defaultdict(int)
col = defaultdict(int)
grid = defaultdict(int)
for _ in range(m):
    x,y = map(int,input().split())
    row[x]+=1
    col[y]+=1
    grid[(x,y)]=1


row = sorted(list(row.items()), key = lambda x: x[1], reverse = True)
col = sorted(list(col.items()), key = lambda x: x[1], reverse = True)
i,j = 0,0
ans = row[0][1]+col[0][1] + (-1 if grid[(row[0][0], col[0][0])] else 0)
dq = deque([(i,j)])
while dq:
    i,j = dq.popleft()
    temp = row[i][1]+col[j][1] + (-1 if grid[(row[i][0], col[j][0])] else 0)
    if ans<temp:
        ans = temp
        break
    
    if i+1<len(row):dq.append((i+1,j))
    if j+1<len(col):dq.append((i,j+1))

    
print(ans)

Fixed submission:
from sys import stdin
input = stdin.readline
from collections import defaultdict, deque
h, w, m = map(int,input().split())
row = defaultdict(int)
col = defaultdict(int)
grid = defaultdict(int)
for _ in range(m):
    x,y = map(int,input().split())
    row[x]+=1
    col[y]+=1
    grid[(x,y)]=1


row = sorted(list(row.items()), key = lambda x: x[1], reverse = True)
col = sorted(list(col.items()), key = lambda x: x[1], reverse = True)


#print(row)
#print(col)

t = len(row)
for idx, ele in enumerate(row):
    i,j = ele
    if j!=row[0][1]:
        t = idx
        break
row = row[:t]
t = len(col)
for idx, ele in enumerate(col):
    i,j = ele
    if j!=col[0][1]:
        t = idx
        break
col = col[:t]

#print(row)
#print(col)
#print(grid)

ans = row[0][1]+col[0][1] + (-1 if grid[(row[0][0], col[0][0])] else 0)

i,j = 0,0
for r,cr in row:
    for c,cc in col:
        if not grid[(r,c)]:
            ans = cr+cc
            break
print(ans)


# dq = deque([(i,j)])
# while dq:
#     i,j = dq.popleft()
#     temp = row[i][1]+col[j][1] + (-1 if grid[(row[i][0], col[j][0])] else 0)
#     if ans<temp:
#         ans = temp
#         break
    
#     if i+1<len(row):dq.append((i+1,j))
#     if j+1<len(col):dq.append((i,j+1))

    
# print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline
from collections import defaultdict
h, w, m = map(int,input().split())
row = defaultdict(int)
col = defaultdict(int)
grid = defaultdict(int)
for _ in range(m):
    x,y = map(int,input().split())
    row[x]+=1
    col[y]+=1
    grid[(x,y)]+=1

maxi = 0
for i in row:
    for j in col:
        if maxi<row[i]+col[j]:
            maxi = row[i]+col[j]
            if grid[(i,j)]:
                maxi-=1
print(maxi)

Fixed submission:
from sys import stdin
input = stdin.readline
from collections import defaultdict, deque
h, w, m = map(int,input().split())
row = defaultdict(int)
col = defaultdict(int)
grid = defaultdict(int)
for _ in range(m):
    x,y = map(int,input().split())
    row[x]+=1
    col[y]+=1
    grid[(x,y)]=1


row = sorted(list(row.items()), key = lambda x: x[1], reverse = True)
col = sorted(list(col.items()), key = lambda x: x[1], reverse = True)


#print(row)
#print(col)

t = len(row)
for idx, ele in enumerate(row):
    i,j = ele
    if j!=row[0][1]:
        t = idx
        break
row = row[:t]
t = len(col)
for idx, ele in enumerate(col):
    i,j = ele
    if j!=col[0][1]:
        t = idx
        break
col = col[:t]

#print(row)
#print(col)
#print(grid)

ans = row[0][1]+col[0][1] + (-1 if grid[(row[0][0], col[0][0])] else 0)

i,j = 0,0
for r,cr in row:
    for c,cc in col:
        if not grid[(r,c)]:
            ans = cr+cc
            break
print(ans)


# dq = deque([(i,j)])
# while dq:
#     i,j = dq.popleft()
#     temp = row[i][1]+col[j][1] + (-1 if grid[(row[i][0], col[j][0])] else 0)
#     if ans<temp:
#         ans = temp
#         break
    
#     if i+1<len(row):dq.append((i+1,j))
#     if j+1<len(col):dq.append((i,j+1))

    
# print(ans)