Buggy python submission (verdict: Runtime Error):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, M = map(int, readline().split())
    row = [0] * H
    column = [0] * W
    grid = [[0] * W for _ in range(H)]

    for _ in range(M):
        h, w = map(int, readline().split())
        row[h-1] += 1
        column[w-1] += 1
        grid[h-1][w-1] += 1

    max_row = [i for i,x in enumerate(row) if x == max(row)]
    max_column = [i for i,x in enumerate(column) if x == max(column)]
    ans = 0
    for h in max_row:
        for w in max_column:
            tmp = row[h] + column[w] - grid[h][w]
            ans = max(tmp,ans)
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, M = map(int, readline().split())
    row = [0] * H
    column = [0] * W
    grid = set()

    for _ in range(M):
        h, w = map(int, readline().split())
        row[h-1] += 1
        column[w-1] += 1
        grid.add((h-1,w-1))

    max_row = max(row)
    max_column = max(column)

    idx_row = [i for i,x in enumerate(row) if x == max_row]
    idx_column = [i for i,x in enumerate(column) if x == max_column]

    ans = max_row+max_column
    flag = False

    for h in idx_row:
        for w in idx_column:
            if not (h,w) in grid:
                flag = True
                break

    if flag:
        print(ans)
    else:
        print(ans-1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, M = map(int, readline().split())
    row = [0] * H
    column = [0] * W
    grid = [[0] * W for _ in range(H)]

    for _ in range(M):
        h, w = map(int, readline().split())
        row[h-1] += 1
        column[w-1] += 1
        grid[h-1][w-1] += 1

    max_row = [i for i,x in enumerate(row) if x == max(row)]
    max_column = [i for i,x in enumerate(column) if x == max(column)]
    ans = 0
    for h in max_row:
        for w in max_column:
            tmp = row[h] + column[w] - grid[h][w]
            ans = max(tmp,ans)
    print(tmp)

if __name__ == '__main__':
    main()


Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, M = map(int, readline().split())
    row = [0] * H
    column = [0] * W
    grid = set()

    for _ in range(M):
        h, w = map(int, readline().split())
        row[h-1] += 1
        column[w-1] += 1
        grid.add((h-1,w-1))

    max_row = max(row)
    max_column = max(column)

    idx_row = [i for i,x in enumerate(row) if x == max_row]
    idx_column = [i for i,x in enumerate(column) if x == max_column]

    ans = max_row+max_column
    flag = False

    for h in idx_row:
        for w in idx_column:
            if not (h,w) in grid:
                flag = True
                break

    if flag:
        print(ans)
    else:
        print(ans-1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, M = map(int, readline().split())
    H_list = [0] * H
    W_list = [0] * W
    grid = [[0]*W for _ in range(H)]

    for  _ in range(M):
        h, w = map(int, readline().split())
        H_list[h-1] += 1
        W_list[w-1] += 1
        grid[h-1][w-1] += 1
    H_max = 0
    W_max = 0
    H_max_index = []
    W_max_index = []

    for h in range(H):
        if H_list[h]>H_max:
            H_max = H_list[h]
            H_max_index = [h]
        elif H_list[h]==H_max:
            H_max_index.append(h)
        else:
            continue

    for w in range(W):
        if W_list[w]>W_max:
            W_max = W_list[w]
            W_max_index = [w]
        elif W_list[w]==W_max:
            W_max_index.append(w)
        else:
            continue
    ans = 0
    for h in H_max_index:
        for w in W_max_index:
            ans = max(ans, H_list[h]+W_list[w]-grid[h][w])
    print(ans)



if __name__ == '__main__':
    main()


Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, M = map(int, readline().split())
    row = [0] * H
    column = [0] * W
    grid = set()

    for _ in range(M):
        h, w = map(int, readline().split())
        row[h-1] += 1
        column[w-1] += 1
        grid.add((h-1,w-1))

    max_row = max(row)
    max_column = max(column)

    idx_row = [i for i,x in enumerate(row) if x == max_row]
    idx_column = [i for i,x in enumerate(column) if x == max_column]

    ans = max_row+max_column
    flag = False

    for h in idx_row:
        for w in idx_column:
            if not (h,w) in grid:
                flag = True
                break

    if flag:
        print(ans)
    else:
        print(ans-1)


if __name__ == '__main__':
    main()