Problem p02580 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys 
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M = map(int,readline().split())
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
bomb = []
 
for i in range(M):
    h,w = map(int,readline().split())
    bomb.append((h,w))
    h_cnt[h] += 1 
    w_cnt[w] += 1
    
maxh = max(h_cnt)
maxw = max(w_cnt)
maxhCnt = h_cnt.count(maxh)
maxwCnt = w_cnt.count(maxw)

total = maxhCnt*maxwCnt
ans = maxh+maxw
cnt = 0
for h,w in bomb:
    if h_cnt[h] == maxh and w_cnt[w] == maxw:
       cnt += 1

print(ans-1 if cnt == total else ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys 
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M = map(int,readline().split())
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
data = [[False]*(W+1) for i in range(H+1)]
 
for i in range(M):
    h,w = map(int,readline().split())
    data[h][w] = True
    h_cnt[h] += 1 
    w_cnt[w] += 1
    
maxh = max(h_cnt)
maxw = max(w_cnt)
maxhInd = []
maxwInd = []
maxhInd = [i for i,a in enumerate(h_cnt) if a == maxh]
maxwInd = [i for i,a in enumerate(w_cnt) if a == maxw]
maxhCnt = len(maxhInd)
maxwCnt = len(maxwInd)

if max_w_cnt * max_h_cnt > M:
    print(max_h+max_w)
else:
    t = list(itertools.product(max_h_ind, max_w_ind))
    for h,w in t:
        if data[h][w] == False:
            print(max_h+max_w)
            sys.exit()
    print(max_h+max_w-1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys 
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M= map(int,readline().split())
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
data = [[False]*(W+1) for i in range(H+1)]
 
for i in range(M):
    h,w = map(int,readline().split())
    data[h][w] = True
    h_cnt[h] += 1 
    w_cnt[w] += 1
    
max_h = max(h_cnt)
max_w = max(w_cnt)
 
max_h_ind = []
max_w_ind = []
max_h_cnt = 0
max_w_cnt = 0
 
for i in range(H+1):
    if max_h == h_cnt[i]:
        max_h_cnt += 1
        max_h_ind.append(i)
        
for i in range(W+1):
    if max_w == w_cnt[i]:
        max_w_cnt += 1
        max_w_ind.append(i)
max_h_ind = set(max_h_ind)
max_w_ind = set(max_w_ind)
 
if max_w_cnt * max_h_cnt > M:
    print(max_h+max_w)
else:
    t = list(itertools.product(max_h_ind, max_w_ind))
    for h,w in t:
        if data[h][w] == False:
            print(max_h+max_w)
            sys.exit()
    print(max_h+max_w-1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys 
import itertools
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M= map(int,readline().split())
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
data = [[False]*(W+1) for i in range(H+1)]

for i in range(M):
    h,w = map(int,readline().split())
    data[h][w] = True
    h_cnt[h] += 1 
    w_cnt[w] += 1
    
max_h = max(h_cnt)
max_w = max(w_cnt)

max_h_ind = []
max_w_ind = []
max_h_cnt = 0
max_w_cnt = 0

for i in range(H+1):
    if max_h == h_cnt[i]:
        max_h_cnt += 1
        max_h_ind.append(i)

for i in range(W+1):
    if max_w == w_cnt[i]:
        max_w_cnt += 1
        max_w_ind.append(i)
max_h_ind = set(max_h_ind)
max_w_ind = set(max_w_ind)

a = np.array(max_h_ind)
b = np.array(max_w_ind)
c = np.outer(a,b)


if max_w_cnt * max_h_cnt > M:
    print(max_h+max_w)
else:
    for h,w in c:
        if data[h][w] == False:
            print(max_h+max_w)
            sys.exit()
    print(max_h+max_w-1)