Problem p02580 (python)

Fixed submission:
def main():
    import sys
    from collections import defaultdict
    readline = sys.stdin.readline

    H, W, M = map(int, readline().rstrip().split())
    HB = [0] * H
    WB = [0] * W
    HW = defaultdict(lambda : False)
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        h -= 1
        w -= 1
        HW[(h,w)] = True
        HB[h] += 1
        WB[w] += 1
    hb = max(HB)
    max_h = [i for i, x in enumerate(HB) if x == hb]
    wb = max(WB)
    max_w = [i for i, x in enumerate(WB) if x == wb]
    
    ans = hb + wb
    for mh in max_h:
        for mw in max_w:
            if HW[(mh, mw)] == False:
                print(ans)
                sys.exit(0)
    print(ans - 1)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(500005)
readline = sys.stdin.buffer.readline

def main():
    H, W, M = map(int, readline().rstrip().split())
    HW = [[0] * W for _ in range(H)]
    HB = [0] * H
    WB = [0] * W
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        h -= 1
        w -= 1
        HW[h][w] = 1
        HB[h] += 1
        WB[w] += 1
    hb = max(HB)
    max_h = [i for i, x in enumerate(HB) if x == hb]
    wb = max(WB)
    max_w = [i for i, x in enumerate(WB) if x == wb]
    
    ans = hb + wb
    for mh in max_h:
        for mw in max_w:
            if HW[mh][mw] == 0:
                print(ans)
                exit()
    print(ans - 1)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.buffer.readline

def main():
    H, W, M = map(int, readline().rstrip().split())
    HW = [[0] * W for _ in range(H)]
    HB = [0] * H
    WB = [0] * W
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        h -= 1
        w -= 1
        HW[h][w] = 1
        HB[h] += 1
        WB[w] += 1
    hb = max(HB)
    max_h = [i for i, x in enumerate(HB) if x == hb]
    wb = max(WB)
    max_w = [i for i, x in enumerate(WB) if x == wb]
    ch = False
    for mh in max_h:
        for mw in max_w:
            if HW[mh][mw] == 0:
                ch = True
                break
        if ch:
            break

    ans = hb + wb
    if not ch:
        ans -= 1
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.readline

def main():
    H, W, M = map(int, readline().rstrip().split())
    HW = [[0] * (W + 1) for _ in range(H + 1)]
    HS = set()
    WS = set()
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        HW[h][w] = 1
        HW[h][0] += 1
        HS.add(h)
        HW[0][w] += 1
        WS.add(w)

    ans = 0
    for h in HS:
        for w in WS:
            tmp = HW[h][0] + HW[0][w]
            if HW[h][w] == 1:
                tmp -= 1
            ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.readline

def main():
    H, W, M = map(int, readline().rstrip().split())
    HW = [[0] * (W + 1) for _ in range(H + 1)]
    HB = [0] * (H + 1)
    HS = set()
    WB = [0] * (W + 1)
    WS = set()
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        HW[h][w] = 1
        HB[h] += 1
        HS.add(h)
        WB[w] += 1
        WS.add(w)
    ans = 0
    for h in HS:
        for w in WS:
            tmp = HB[h] + WB[w]
            if HW[h][w] == 1:
                tmp -= 1
            ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.buffer.readline

import numpy as np
from numba import jit
# stdin = open('sample.txt')

@jit(cache=True)
def main():
    H, W, M = map(int, readline().rstrip().split())
    HW = np.zeros((H + 1, W + 1), np.int64)
    HB = np.zeros((H + 1), np.int64)
    HS = set()
    WB = np.zeros((W + 1), np.int64)
    WS = set()
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        HW[h, w] = 1
        HB[h] += 1
        HS.add(h)
        WB[w] += 1
        WS.add(w)
    ans = 0
    for h in HS:
        for w in WS:
            tmp = HB[h] + WB[w]
            if HW[h, w] == 1:
                tmp -= 1
            ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.buffer.readline

def main():
    H , W, M = map(int, readline().rstrip().split())
    HW = [[0] * (W + 1) for _ in range(H + 1)]
    HB = [0] * (H + 1)
    HS = set()
    WB = [0] * (W + 1)
    WS = set()
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        HW[h][w] = 1
        HB[h] += 1
        HS.add(h)
        WB[w] += 1
        WS.add(w)
    ans = 0
    for h in HS:
        for w in WS:
            tmp = HB[h] + WB[w]
            if HW[h][w] == 1:
                tmp -= 1
            ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()