Problem p02580 (python)

Fixed submission:
import sys
HK,WK,M = map(int, input().split())
W = [0] * (WK + 1)
H = [0] * (HK + 1)
HW = {}
# 3*10^5

for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[(h,w)] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]

# 3*10^5
answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if not (h,w) in HW:
            print(answer)
            sys.exit(0)
print(answer-1)

Buggy submission (verdict: Runtime Error):
import sys
HK,WK,M = map(int, input().split())
W = [0] * WK + 1
H = [0] * HK + 1
HW = [[0 for i in range(WK+1)] for _ in range(HK+1)]
# 3*10^5

for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[h][w] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]

# 3*10^5
answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if HW[h][w] == 0:
            print(answer)
            sys.exit(0)
print(answer-1)

Buggy submission (verdict: Runtime Error):
import sys
HK,WK,M = map(int, input().split())
W = [0] * WK
H = [0] * HK
HW = [[0 for i in range(WK+1)] for _ in range(HK+1)]
# 3*10^5

for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[h][w] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]

# 3*10^5
answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if HW[h][w] == 0:
            print(answer)
            sys.exit(0)
print(answer-1)

Buggy submission (verdict: Runtime Error):
import sys
HK,WK,M = map(int, input().split())
hw_s = [list(map(int, input().split())) for _ in range(M)]
W = [0 for _ in range(HK+1)]
H = [0 for _ in range(WK+1)]
HW = [[0 for i in range(WK+1)] for _ in range(HK+1)]
# 3*10^5

for i, hw in enumerate(hw_s):
    h=hw[0]
    w=hw[1]

    H[h] += 1
    W[w] += 1

    HW[h][w] = 1

HMAXES = []
WMAXES = []
answer = 0
HMAX = max(H)
WMAX = max(W)


# 3*10^5
for i, h in enumerate(H):
    if h == HMAX:
        HMAXES.append(i)
for i, w in enumerate(W):
    if w == WMAX:
        HMAXES.append(i)
# 3*10^5
answer = HMAX + WMAX
for i, h in enumerate(HMAXES):
    for j, w in enumerate(WMAXES):
        if HW[i][j] == 0:
            print(answer)
            sys.exit(0)
print(answer-1)

Buggy submission (verdict: Runtime Error):
import sys
HK,WK,M = map(int, input().split())
hw_s = [list(map(int, input().split())) for _ in range(M)]
W = [0 for _ in range(HK+1)]
H = [0 for _ in range(WK+1)]
HW = [[0 for i in range(WK+1)] for _ in range(HK+1)]
# 3*10^5

for i, hw in enumerate(hw_s):
    h=hw[0]
    w=hw[1]

    H[h] += 1
    W[w] += 1

    HW[h][w] = 1

HMAXES = []
WMAXES = []
answer = 0
HMAX = max(H)
WMAX = max(W)


# 3*10^5
for i, h in enumerate(H):
    if h == HMAX:
        HMAXES.append(i)
for i, w in enumerate(W):
    if w == WMAX:
        HMAXES.append(i)
# 3*10^5
answer = HMAX + WMAX
for i, h in enumerate(HMAX):
    for j, w in enumerate(WMAX):
        if HW[i][j] == 0:
            print(answer)
            sys.exit(0)
print(answer-1)