Buggy python submission (verdict: Time Limit Exceeded):
def main():
    h, w, m = map(int, input().split())
    bombs_h = [0] * h
    bombs_w = [0] * w
    B = []
    for n in range(m):
        h1, w1 = map(int, input().split())
        B.append((h1-1, w1-1))
        bombs_w[w1-1] += 1
        bombs_h[h1-1] += 1
    h_maxindex = [i for i, x in enumerate(bombs_h) if x == max(bombs_h)]
    w_maxindex = [i for i, x in enumerate(bombs_w) if x == max(bombs_w)]
    max_h = max(bombs_h)
    max_w = max(bombs_w)
    cnt = 0
    k = len(h_maxindex) * len(w_maxindex)
    for i, j in B:
        if bombs_h[i] == max_h and bombs_w[j] == max_w:
            cnt += 1
    ans = max_h + max_w - (cnt == k)
    print(ans)
    
    
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    h, w, m = map(int, input().split())
    bombs_h = [0] * h
    bombs_w = [0] * w
    B = []
    for n in range(m):
        h1, w1 = map(lambda x: int(x)-1, input().split())
        B.append((h1, w1))
        bombs_w[w1] += 1
        bombs_h[h1] += 1
    max_h = max(bombs_h)
    max_w = max(bombs_w)
    h_maxindex = [i for i, x in enumerate(bombs_h) if x == max_h]
    w_maxindex = [i for i, x in enumerate(bombs_w) if x == max_w]
    cnt = 0
    k = len(h_maxindex) * len(w_maxindex)
    for i, j in B:
        if bombs_h[i] == max_h and bombs_w[j] == max_w:
            cnt += 1
    ans = max_h + max_w - (cnt == k)
    print(ans)
    
    
if __name__ == "__main__":
    main()

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


def main():
    h, w, m = map(int, input().split())
    base = np.zeros((h, w), dtype=int)
    B = []
    for n in range(m):
        h1, w1 = map(int, input().split())
        B.append((h1-1, w1-1))
        base[h1-1][w1-1] = 1
    hs, ws = [], []
    for n in range(h):
        hs.append(sum(base[n]))
    for n in range(w):
        ws.append(sum(base[:, n]))
    hs = np.array(hs)
    ws = np.array(ws)
    h_maxindex = [i for i, x in enumerate(hs) if x == max(hs)]
    w_maxindex = [i for i, x in enumerate(ws) if x == max(ws)]
    cnt = 0
    k = len(h_maxindex) * len(w_maxindex)
    for i, j in B:
        if hs[i] == max(hs) and ws[j] == max(ws):
            cnt += 1
    ans = max(hs) + max(ws) - (cnt == k)
    print(ans)
    
    
    
    
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    h, w, m = map(int, input().split())
    bombs_h = [0] * h
    bombs_w = [0] * w
    B = []
    for n in range(m):
        h1, w1 = map(lambda x: int(x)-1, input().split())
        B.append((h1, w1))
        bombs_w[w1] += 1
        bombs_h[h1] += 1
    max_h = max(bombs_h)
    max_w = max(bombs_w)
    h_maxindex = [i for i, x in enumerate(bombs_h) if x == max_h]
    w_maxindex = [i for i, x in enumerate(bombs_w) if x == max_w]
    cnt = 0
    k = len(h_maxindex) * len(w_maxindex)
    for i, j in B:
        if bombs_h[i] == max_h and bombs_w[j] == max_w:
            cnt += 1
    ans = max_h + max_w - (cnt == k)
    print(ans)
    
    
if __name__ == "__main__":
    main()

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


def main():
    h, w, m = map(int, input().split())
    base = np.zeros((h, w), dtype=int)
    for n in range(m):
        h1, w1 = map(int, input().split())
        base[h1-1][w1-1] = 1
    hs, ws = [], []
    for n in range(h):
        hs.append(sum(base[n]))
    for n in range(w):
        ws.append(sum(base[:, n]))
    hs = np.array(hs)
    ws = np.array(ws)
    h_maxindex = [i for i, x in enumerate(hs) if x == max(hs)]
    w_maxindex = [i for i, x in enumerate(ws) if x == max(ws)]
    fla = 0
    for i in h_maxindex:
        for j in w_maxindex:
            if base[i][j] == 0:
                print(max(hs) + max(ws))
                fla = 1
                break
    if fla == 0:
        print(max(hs) + max(ws) - 1)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    h, w, m = map(int, input().split())
    bombs_h = [0] * h
    bombs_w = [0] * w
    B = []
    for n in range(m):
        h1, w1 = map(lambda x: int(x)-1, input().split())
        B.append((h1, w1))
        bombs_w[w1] += 1
        bombs_h[h1] += 1
    max_h = max(bombs_h)
    max_w = max(bombs_w)
    h_maxindex = [i for i, x in enumerate(bombs_h) if x == max_h]
    w_maxindex = [i for i, x in enumerate(bombs_w) if x == max_w]
    cnt = 0
    k = len(h_maxindex) * len(w_maxindex)
    for i, j in B:
        if bombs_h[i] == max_h and bombs_w[j] == max_w:
            cnt += 1
    ans = max_h + max_w - (cnt == k)
    print(ans)
    
    
if __name__ == "__main__":
    main()