Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import sys

h, w, m = map(lambda x: int(x), input().split())

y_to_num = [0] * h
x_to_num = [0] * w
existing_h_to_w = defaultdict(set)


for _ in range(m):
    hh, ww = map(lambda x: int(x), input().split())
    y_to_num[hh-1] += 1
    x_to_num[ww-1] += 1
    existing_h_to_w[hh].add(ww)

max_vertical_num = max(y_to_num)
max_horizontal_num = max(x_to_num)

y_coor_with_max_num = [i for i, num in enumerate(y_to_num) if num == max_vertical_num]
x_coor_with_max_num = [i for i, num in enumerate(x_to_num) if num == max_horizontal_num]

if (len(y_coor_with_max_num) >=2) | (len(x_coor_with_max_num) >= 2):
    print(max_vertical_num + max_horizontal_num)
    sys.exit()

if (x_coor_max_num[0] in existing_h_to_w[y_coor_with_max_num[0]]):
    print(max_vertical_num + max_horizontal_num - 1)

Fixed submission:
from collections import defaultdict
import sys

h, w, m = map(lambda x: int(x), input().split())

y_to_num = [0] * h
x_to_num = [0] * w
existing_h_to_w = defaultdict(set)


for _ in range(m):
    hh, ww = map(lambda x: int(x), input().split())
    y_to_num[hh-1] += 1
    x_to_num[ww-1] += 1
    existing_h_to_w[hh-1].add(ww-1)

max_vertical_num = max(y_to_num)
max_horizontal_num = max(x_to_num)

y_coor_with_max_num = [i for i, num in enumerate(y_to_num) if num == max_vertical_num]
x_coor_with_max_num = [i for i, num in enumerate(x_to_num) if num == max_horizontal_num]

# print(y_coor_with_max_num, x_coor_with_max_num, existing_h_to_w)

for y in y_coor_with_max_num:
    for x in x_coor_with_max_num:
        if x not in existing_h_to_w[y]:
            print(max_vertical_num + max_horizontal_num)
            sys.exit()

print(max_vertical_num + max_horizontal_num - 1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

h, w, m = map(lambda x: int(x), input().split())

y_to_num = defaultdict(int)
x_to_num = defaultdict(int)

# y_indexes = set()
# x_indexes = set()
y_to_sum = defaultdict(set)


for _ in range(m):
    hh, ww = map(lambda x: int(x), input().split())
    y_to_num[hh] += 1
    x_to_num[ww] += 1
    
    y_to_sum[hh].add(hh + ww)
    
# print(y_to_num, x_to_num)
    
# for y, num_y in y_to_num:
#     for x, num_x in x_to_num:

max_num = 0
  
for y in range(h):
    for x in range(w):
        num = y_to_num[y+1] + x_to_num[x+1]
        if x+y+2 in y_to_sum[y+1]:
            num -= 1
        max_num = max(max_num, num)
        
print(max_num)

Fixed submission:
from collections import defaultdict
import sys

h, w, m = map(lambda x: int(x), input().split())

y_to_num = [0] * h
x_to_num = [0] * w
existing_h_to_w = defaultdict(set)


for _ in range(m):
    hh, ww = map(lambda x: int(x), input().split())
    y_to_num[hh-1] += 1
    x_to_num[ww-1] += 1
    existing_h_to_w[hh-1].add(ww-1)

max_vertical_num = max(y_to_num)
max_horizontal_num = max(x_to_num)

y_coor_with_max_num = [i for i, num in enumerate(y_to_num) if num == max_vertical_num]
x_coor_with_max_num = [i for i, num in enumerate(x_to_num) if num == max_horizontal_num]

# print(y_coor_with_max_num, x_coor_with_max_num, existing_h_to_w)

for y in y_coor_with_max_num:
    for x in x_coor_with_max_num:
        if x not in existing_h_to_w[y]:
            print(max_vertical_num + max_horizontal_num)
            sys.exit()

print(max_vertical_num + max_horizontal_num - 1)