Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
bombs_h = [0] * H
bombs_w = [0] * W
S = [[] for _ in range(H)]
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    S[h].append(w)
    bombs_h[h] += 1
    bombs_w[w] += 1

max_h = max(bombs_h)
max_w = max(bombs_w)
hs = [i for i, x in enumerate(bombs_h) if x == max_h]
ws = [i for i, x in enumerate(bombs_w) if x == max_w]
p = 1
for i in hs:
    for j in ws:
        if j not in S[i]:
            p = 0
            break
ans = max_w + max_h - p
print(ans)

Fixed submission:
H, W, M = map(int, input().split())
bombs_h = [0] * H
bombs_w = [0] * W
B = []
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    B.append((h, w))
    bombs_h[h] += 1
    bombs_w[w] += 1

max_h = max(bombs_h)
max_w = max(bombs_w)
hs = [i for i, x in enumerate(bombs_h) if x == max_h]
ws = [i for i, x in enumerate(bombs_w) if x == max_w]
k = len(hs)*len(ws)
cnt = 0
for h, w in B:
    if bombs_h[h] == max_h and bombs_w[w] == max_w:
        cnt += 1
ans = max_w + max_h - (cnt == k)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
S = [[0 for _ in range(W)] for i in range(H)]
bombs_h = [0] * H
bombs_w = [0] * W
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    S[h][w] = 1
    bombs_h[h] += 1
    bombs_w[w] += 1

max_h = max(bombs_h)
max_w = max(bombs_w)
hs = [i for i, x in enumerate(bombs_h) if x == max_h]
ws = [i for i, x in enumerate(bombs_w) if x == max_w]
p = 1
for i in hs:
    for j in ws:
        if S[i][j] == 0:
            p = 0
            break
ans = max_w + max_h - p
print(ans)

Fixed submission:
H, W, M = map(int, input().split())
bombs_h = [0] * H
bombs_w = [0] * W
B = []
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    B.append((h, w))
    bombs_h[h] += 1
    bombs_w[w] += 1

max_h = max(bombs_h)
max_w = max(bombs_w)
hs = [i for i, x in enumerate(bombs_h) if x == max_h]
ws = [i for i, x in enumerate(bombs_w) if x == max_w]
k = len(hs)*len(ws)
cnt = 0
for h, w in B:
    if bombs_h[h] == max_h and bombs_w[w] == max_w:
        cnt += 1
ans = max_w + max_h - (cnt == k)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
S = [[0 for _ in range(W)] for i in range(H)]
bombs_h = [0] * H
bombs_w = [0] * W
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    S[h][w] = 1
    bombs_h[h] += 1
    bombs_w[w] += 1

max_h = max(bombs_h)
max_w = max(bombs_w)
hs = [i for i, x in enumerate(bombs_h) if x == max_h]
ws = [i for i, x in enumerate(bombs_w) if x == max_w]
p = 1
for i in hs:
    for j in ws:
        if S[i][j] == 0:
            p = 0
            break
ans = max_w + max_h - p
print(ans)

Fixed submission:
H, W, M = map(int, input().split())
bombs_h = [0] * H
bombs_w = [0] * W
B = []
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    B.append((h, w))
    bombs_h[h] += 1
    bombs_w[w] += 1

max_h = max(bombs_h)
max_w = max(bombs_w)
hs = [i for i, x in enumerate(bombs_h) if x == max_h]
ws = [i for i, x in enumerate(bombs_w) if x == max_w]
k = len(hs)*len(ws)
cnt = 0
for h, w in B:
    if bombs_h[h] == max_h and bombs_w[w] == max_w:
        cnt += 1
ans = max_w + max_h - (cnt == k)
print(ans)