Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = set()
    row = np.zeros(h, dtype=int)
    col = np.zeros(w, dtype=int)
    for _ in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target.add((hi, wi))
        row[hi] += 1
        col[wi] += 1
    r = row.max()
    c = col.max()
    for ri in np.arange(h)[row == r]:
        for ci in np.arange(w)[col == c]:
            if (ri, ci) not in target:
                print(r + c)
                return
    print(r + c - 1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = set()
    row = [0] * h
    col = [0] * w
    for _ in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target.add((hi, wi))
        row[hi] += 1
        col[wi] += 1
    row_max = max(row)
    r = [i for i in range(h) if row[i] == row_max]
    col_max = max(col)
    c = [i for i in range(w) if col[i] == col_max]
    for ri in r:
        for ci in c:
            if (ri, ci) not in target:
                print(row_max + col_max)
                return
    print(row_max + col_max - 1)


if __name__ == '__main__':
    main()

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


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    bitboard = 0
    for _ in range(m):
        hi, wi = map(int, read().split())
        bitboard += 1 << (w * (hi - 1) + (wi - 1))
    ans = 0
    for hi in range(h):
        for wi in range(w):
            b = bitboard & (((2**w - 1) << hi * w) | (sum(1 << (w * i) for i in range(h)) << wi))
            ans = max(bin(b).count("1"), ans)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = set()
    row = [0] * h
    col = [0] * w
    for _ in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target.add((hi, wi))
        row[hi] += 1
        col[wi] += 1
    row_max = max(row)
    r = [i for i in range(h) if row[i] == row_max]
    col_max = max(col)
    c = [i for i in range(w) if col[i] == col_max]
    for ri in r:
        for ci in c:
            if (ri, ci) not in target:
                print(row_max + col_max)
                return
    print(row_max + col_max - 1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = [(0, 0) for _ in range(m)]
    row = [0] * h
    col = [0] * w
    for i in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target[i] = (hi, wi)
        row[hi] += 1
        col[wi] += 1
    r = max(row)
    ri = [i for i in range(h) if row[i] == r]
    c = 0
    for rii in ri:
        ci = col[:]
        for y, x in target:
            if y == rii:
                ci[x] -= 1
        c = max(max(ci), c)
    ans = r + c
    c = max(col)
    ci = [i for i in range(w) if col[i] == c]
    r = 0
    for cii in ci:
        ri = row[:]
        for y, x in target:
            if x == cii:
                ri[y] -= 1
        r = max(max(ri), r)
    ans = max(r + c, ans)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = set()
    row = [0] * h
    col = [0] * w
    for _ in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target.add((hi, wi))
        row[hi] += 1
        col[wi] += 1
    row_max = max(row)
    r = [i for i in range(h) if row[i] == row_max]
    col_max = max(col)
    c = [i for i in range(w) if col[i] == col_max]
    for ri in r:
        for ci in c:
            if (ri, ci) not in target:
                print(row_max + col_max)
                return
    print(row_max + col_max - 1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = [(0, 0) for _ in range(m)]
    row = np.zeros(h, dtype=int)
    col = np.zeros(w, dtype=int)
    for i in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target[i] = (hi, wi)
        row[hi] += 1
        col[wi] += 1
    r = row.max()
    ri = [i for i in range(h) if row[i] == r]
    c = 0
    for rii in ri:
        ci = col.copy()
        for y, x in target:
            if y == rii:
                ci[x] -= 1
        c = max(ci.max(), c)
    ans = r + c
    c = col.max()
    ci = [i for i in range(w) if col[i] == c]
    r = 0
    for cii in ci:
        ri = row.copy()
        for y, x in target:
            if x == cii:
                ri[y] -= 1
        r = max(ri.max(), r)
    ans = max(r + c, ans)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = set()
    row = [0] * h
    col = [0] * w
    for _ in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target.add((hi, wi))
        row[hi] += 1
        col[wi] += 1
    row_max = max(row)
    r = [i for i in range(h) if row[i] == row_max]
    col_max = max(col)
    c = [i for i in range(w) if col[i] == col_max]
    for ri in r:
        for ci in c:
            if (ri, ci) not in target:
                print(row_max + col_max)
                return
    print(row_max + col_max - 1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = [(0, 0) for _ in range(m)]
    row = np.zeros(h, dtype=int)
    col = np.zeros(w, dtype=int)
    for i in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target[i] = (hi, wi)
        row[hi] += 1
        col[wi] += 1
    r = row.max()
    ri = [i for i in range(h) if row[i] == r]
    c = 0
    for rii in ri:
        ci = col.copy()
        for y, x in target:
            if y == rii:
                ci[x] -= 1
        c = max(ci.max(), c)
    ans = r + c
    c = col.max()
    ci = [i for i in range(w) if col[i] == c]
    r = 0
    for cii in ci:
        ri = row.copy()
        for y, x in target:
            if x == cii:
                ri[y] -= 1
        r = max(ri.max(), r)
    ans = max(r + c, ans)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = set()
    row = [0] * h
    col = [0] * w
    for _ in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target.add((hi, wi))
        row[hi] += 1
        col[wi] += 1
    row_max = max(row)
    r = [i for i in range(h) if row[i] == row_max]
    col_max = max(col)
    c = [i for i in range(w) if col[i] == col_max]
    for ri in r:
        for ci in c:
            if (ri, ci) not in target:
                print(row_max + col_max)
                return
    print(row_max + col_max - 1)


if __name__ == '__main__':
    main()