Buggy python submission (verdict: Time Limit Exceeded):
def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = [0] * height
    count_by_width = [0] * width
    bomb_is = [[False] * width for _ in range(height)]
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is[bom_h][bom_w] = True
    max_h, max_w = max(count_by_height), max(count_by_width)
    max_h_is = [i for i, x in enumerate(count_by_height) if x == max_h]
    max_w_is = [i for i, x in enumerate(count_by_width) if x == max_w]
    no_cross = any(not bomb_is[hh][ww] for hh in max_h_is for ww in max_w_is)
    return max_h + max_w - (not no_cross)


if __name__ == '__main__':
    ans = main()
    print(ans)


Fixed submission:
from collections import defaultdict


def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = defaultdict(int)
    count_by_width = defaultdict(int)
    bomb_is = set()
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is.add((bom_h, bom_w))
    max_h = max(v for v in count_by_height.values())
    max_w = max(v for v in count_by_width.values())
    max_h_index = [i for i, x in count_by_height.items() if x == max_h]
    max_w_index = [i for i, x in count_by_width.items() if x == max_w]
    no_cross = any(
        (hh, ww) not in bomb_is for hh in max_h_index for ww in max_w_index)
    return max_h + max_w - (not no_cross)


if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy python submission (verdict: Runtime Error):
def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = [0] * height
    count_by_width = [0] * width
    bomb_is = [[False] * width for _ in range(height)]
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is[bom_h][bom_w] = True
    max_h, max_w = max(count_by_height), max(count_by_width)
    max_h_is = [i for i, x in enumerate(count_by_height) if x == max_h]
    max_w_is = [i for i, x in enumerate(count_by_width) if x == max_w]
    no_cross = any(not bomb_is[hh][ww] for hh in max_h_is for ww in max_w_is)
    return max_h + max_w - (not no_cross)


if __name__ == '__main__':
    ans = main()
    print(ans)


Fixed submission:
from collections import defaultdict


def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = defaultdict(int)
    count_by_width = defaultdict(int)
    bomb_is = set()
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is.add((bom_h, bom_w))
    max_h = max(v for v in count_by_height.values())
    max_w = max(v for v in count_by_width.values())
    max_h_index = [i for i, x in count_by_height.items() if x == max_h]
    max_w_index = [i for i, x in count_by_width.items() if x == max_w]
    no_cross = any(
        (hh, ww) not in bomb_is for hh in max_h_index for ww in max_w_index)
    return max_h + max_w - (not no_cross)


if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = [0] * height
    count_by_width = [0] * width
    bomb_is = [[False] * width for _ in range(height)]
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is[bom_h][bom_w] = True
        # 最大らしき十字はわかるが，交差点にあるかどうかが不明だ。
        # 最大になりそうな十字がいっぱい（前マスに爆弾，など）だと，
        # 結局 O(H*W) で間に合わなそう。3秒あるけど 10^10 じゃあなあ。
        # DP ぽくはあるが，どう DP を作るかだ。

    # h, w にでいくつ爆破できるか。
    dp = [[0] * width for _ in range(height)]
    dp[0][0] = count_by_height[0] + count_by_width[0] - bomb_is[0][0]
    ans = 0
    for x in range(height):
        for y in range(width):
            now = dp[x][y]
            ans = max(ans, now)
            if x < height - 1:
                if dp[x + 1][y] != 0:
                    continue
                dp[x + 1][y] = (
                    now + count_by_height[x + 1] - count_by_height[x]
                    + bomb_is[x][y] - bomb_is[x + 1][y])
            if y < width - 1:
                if dp[x][y + 1] != 0:
                    continue
                dp[x][y + 1] = (
                    now + count_by_width[y + 1] - count_by_width[y]
                    + bomb_is[x][y] - bomb_is[x][y + 1])
    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)


Fixed submission:
from collections import defaultdict


def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = defaultdict(int)
    count_by_width = defaultdict(int)
    bomb_is = set()
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is.add((bom_h, bom_w))
    max_h = max(v for v in count_by_height.values())
    max_w = max(v for v in count_by_width.values())
    max_h_index = [i for i, x in count_by_height.items() if x == max_h]
    max_w_index = [i for i, x in count_by_width.items() if x == max_w]
    no_cross = any(
        (hh, ww) not in bomb_is for hh in max_h_index for ww in max_w_index)
    return max_h + max_w - (not no_cross)


if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = [0] * height
    count_by_width = [0] * width
    bomb_is = [[False] * width for _ in range(height)]
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is[bom_h][bom_w] = True
        # 最大らしき十字はわかるが，交差点にあるかどうかが不明だ。
        # 最大になりそうな十字がいっぱい（前マスに爆弾，など）だと，
        # 結局 O(H*W) で間に合わなそう。3秒あるけど 10^10 じゃあなあ。
        # DP ぽくはあるが，どう DP を作るかだ。

    # h, w にでいくつ爆破できるか。
    # dp = [[0] * width for _ in range(height)]
    # dp[0][0] = count_by_height[0] + count_by_width[0] - bomb_is[0][0]
    ans = 0
    for x in range(height):
        for y in range(width):
            now = count_by_height[x] + count_by_width[y] - bomb_is[x][y]
            ans = max(ans, now)
            # if x < height - 1:
            #     dp[x + 1][y] = (
            #         now + count_by_height[x + 1] - count_by_height[x])
            # if y < width - 1:
            #     dp[x][y + 1] = (
            #         now + count_by_width[y + 1] - count_by_width[y])
    # print(dp)
    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)


Fixed submission:
from collections import defaultdict


def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = defaultdict(int)
    count_by_width = defaultdict(int)
    bomb_is = set()
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is.add((bom_h, bom_w))
    max_h = max(v for v in count_by_height.values())
    max_w = max(v for v in count_by_width.values())
    max_h_index = [i for i, x in count_by_height.items() if x == max_h]
    max_w_index = [i for i, x in count_by_width.items() if x == max_w]
    no_cross = any(
        (hh, ww) not in bomb_is for hh in max_h_index for ww in max_w_index)
    return max_h + max_w - (not no_cross)


if __name__ == '__main__':
    ans = main()
    print(ans)