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

H, W, M = map(int, input().split())
counterH = [0] * H
counterW = [0] * W
setHW = set({})
for _ in range(M):
    hi, wi = map(lambda x: int(x) - 1, input().split())
    setHW.add((hi, wi))
    counterH[hi] += 1
    counterW[wi] += 1


set_max_h, set_max_w = set(), set()
max_h, max_w = -1, -1

for h in range(H):
    if counterH[h] > max_h:
        max_h = counterH[h]
        set_max_h = set({h})
    elif counterH[h] == max_h:
        set_max_h.add(h)

for w in range(W):
    if counterW[w] > max_w:
        max_w = counterW[w]
        set_max_w = set({w})
    elif counterW[w] == max_w:
        set_max_w.add(w)
    
def count(h, w):
    bomb = 0 if (h, w) not in setHW else -1
    bomb += counterH[h]
    bomb += counterW[w]
    return bomb

m = -1
for h in set_max_h:
    for w in range(W):
        m = max(m, count(h, w))
for w in set_max_w:
    for h in range(H):
        m = max(m, count(h, w))

print(m)

Fixed submission:
H, W, M = map(int,input().split())
Bomb = []
for _ in range(M):
    hi, wi = map(lambda x: int(x) - 1, input().split())
    Bomb.append((hi, wi))

counterH = [0] * H
counterW = [0] * W

for (hi, wi) in Bomb:
    counterH[hi] += 1
    counterW[wi] += 1

# 最大のところを選ぶ
max_h = max(counterH)
max_w = max(counterW)

count = 0
for (hi, wi) in Bomb:
    if counterH[hi] == max_h and counterW[wi] == max_w:
        count += 1

# 共通部分を確認 (-1)
ans = max_h + max_w
if count == counterH.count(max_h) * counterW.count(max_w):
    ans -= 1
print(ans)

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

H, W, M = map(int, input().split())
Bomb = [[0] * W for _ in range(H)]

counterH = Counter()
counterW = Counter()

for _ in range(M):
    hi, wi = map(lambda x: int(x) - 1, input().split())
    counterH[hi] += 1
    counterW[wi] += 1
    Bomb[hi][wi] += 1

# for row in Bomb:
#     print(*row)


HH = [h for (h, _) in counterH.most_common(1)]
WW = [w for (w, _) in counterW.most_common(1)]

def count(h, w):
    bomb = 0
    for _w in range(W):
        if Bomb[h][_w] > 0:
            bomb += 1
    for _h in range(H):
        if Bomb[_h][w] > 0:
            bomb += 1
    if Bomb[h][w] > 0:
        bomb -= 1
    return bomb

m = -1
for h in HH:
    for w in range(W):
        m = max(m, count(h, w))
for w in WW:
    for h in range(H):
        m = max(m, count(h, w))

print(m)
# # 2次元累積和
# BombW = [[0] * (W + 1) for _ in range(H)]
# BombH = [[0] * W for _ in range(H + 1)]
# for h in range(H):
#     for w in range(W):
#         BombW[h][w + 1] = BombW[h][w] + Bomb[h][w]
# for w in range(W):
#     for h in range(H):
#         BombH[h + 1][w] = BombH[h][w] + Bomb[h][w]
# for row in BombW:
#     print(*row)
# for row in BombH:
#     print(*row)

Fixed submission:
H, W, M = map(int,input().split())
Bomb = []
for _ in range(M):
    hi, wi = map(lambda x: int(x) - 1, input().split())
    Bomb.append((hi, wi))

counterH = [0] * H
counterW = [0] * W

for (hi, wi) in Bomb:
    counterH[hi] += 1
    counterW[wi] += 1

# 最大のところを選ぶ
max_h = max(counterH)
max_w = max(counterW)

count = 0
for (hi, wi) in Bomb:
    if counterH[hi] == max_h and counterW[wi] == max_w:
        count += 1

# 共通部分を確認 (-1)
ans = max_h + max_w
if count == counterH.count(max_h) * counterW.count(max_w):
    ans -= 1
print(ans)