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

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

cnt_h = [0] * h
cnt_w = [0] * w
dic = defaultdict(int)

for _ in range(m):
    h_m, w_m = map(int, input().split())
    cnt_h[h_m - 1] += 1
    cnt_w[w_m - 1] += 1
    dic[(h_m - 1, w_m - 1)] += 1

max_h = max(cnt_h)
max_w = max(cnt_w)

mh = []
mw = []

for i in range(h):
    if max_h == cnt_h[i]:
        mh.append(i)

for i in range(w):
    if max_w == cnt_w[i]:
        mw.append(i)

flag = False
for i in mh:
    for j in mw:
        if dic[(i, j)] == 0:
            flag = True

if flag:
    print(max_h + max_w)
else:
    print(max_h + max_w - 1)

Fixed submission:
from collections import defaultdict

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

cnt_h = [0] * h
cnt_w = [0] * w
dic = defaultdict(int)

for _ in range(m):
    h_m, w_m = map(int, input().split())
    cnt_h[h_m - 1] += 1
    cnt_w[w_m - 1] += 1
    dic[(h_m - 1, w_m - 1)] += 1

max_h = max(cnt_h)
max_w = max(cnt_w)

mh = []
mw = []

for i in range(h):
    if max_h == cnt_h[i]:
        mh.append(i)

for i in range(w):
    if max_w == cnt_w[i]:
        mw.append(i)

for i in mh:
    for j in mw:
        if dic[(i, j)] == 0:
            print(max_h + max_w)
            quit()

print(max_h + max_w - 1)

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

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

cnt_h = [0] * h
cnt_w = [0] * w
dic = defaultdict(int)

for _ in range(m):
    h_m, w_m = map(int, input().split())
    cnt_h[h_m - 1] += 1
    cnt_w[w_m - 1] += 1
    dic[h_m - 1, w_m - 1] += 1

max_h = max(cnt_h)
max_w = max(cnt_w)

mh = []
mw = []

for i in range(h):
    if max_h == cnt_h[i]:
        mh.append(i)

for i in range(w):
    if max_w == cnt_w[i]:
        mw.append(i)

flag = False
for i in mh:
    for j in mw:
        if dic[i, j] == 0:
            flag = True

if flag:
    print(max_h + max_w)
else:
    print(max_h + max_w - 1)

Fixed submission:
from collections import defaultdict

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

cnt_h = [0] * h
cnt_w = [0] * w
dic = defaultdict(int)

for _ in range(m):
    h_m, w_m = map(int, input().split())
    cnt_h[h_m - 1] += 1
    cnt_w[w_m - 1] += 1
    dic[(h_m - 1, w_m - 1)] += 1

max_h = max(cnt_h)
max_w = max(cnt_w)

mh = []
mw = []

for i in range(h):
    if max_h == cnt_h[i]:
        mh.append(i)

for i in range(w):
    if max_w == cnt_w[i]:
        mw.append(i)

for i in mh:
    for j in mw:
        if dic[(i, j)] == 0:
            print(max_h + max_w)
            quit()

print(max_h + max_w - 1)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
import numpy as np
from pprint import pprint

h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

grid = [[0] * h for _ in range(w)]

for i in range(m):
    grid[hw[i][1]-1][hw[i][0]-1] = 1


cnt_grid = []
for i in range(w):
    cnt_grid.append(Counter(grid[i]))


cnt_grid_h = 0
max_h = 0
for i in range(w):
    if cnt_grid_h < cnt_grid[i][1]:
        cnt_grid_h = cnt_grid[i][1]
        max_h = i
grid = np.rot90(grid)
grid = grid.tolist()
cnt_grid = []
for i in range(h):
    cnt_grid.append(Counter(grid[i]))

cnt_grid_w = 0
max_w = 0
for i in range(h):
    if cnt_grid_w < cnt_grid[i][1]:
        cnt_grid_w = cnt_grid[i][1]
        max_w = i
max_w = h - max_w - 1

if grid[max_h][max_w] == 1:
    print(cnt_grid_h + cnt_grid_w - 1)
else:
    print(cnt_grid_h + cnt_grid_w)

Fixed submission:
from collections import defaultdict

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

cnt_h = [0] * h
cnt_w = [0] * w
dic = defaultdict(int)

for _ in range(m):
    h_m, w_m = map(int, input().split())
    cnt_h[h_m - 1] += 1
    cnt_w[w_m - 1] += 1
    dic[(h_m - 1, w_m - 1)] += 1

max_h = max(cnt_h)
max_w = max(cnt_w)

mh = []
mw = []

for i in range(h):
    if max_h == cnt_h[i]:
        mh.append(i)

for i in range(w):
    if max_w == cnt_w[i]:
        mw.append(i)

for i in mh:
    for j in mw:
        if dic[(i, j)] == 0:
            print(max_h + max_w)
            quit()

print(max_h + max_w - 1)