Problem p02580 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M = map(int, readline().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in readlines()]
X = [0] * H 
Y = [0] * W 
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = [h for h, x in enumerate(X) if x == maxX]  
C = [w for w, y in enumerate(Y) if y == maxY] 

bomb = set(bomb)
for r in R:
    for c in C:
        if (r, c) not in bomb:
            print(maxX + maxY)
            exit()
print(maxX + maxY - 1)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H,W,M=map(int,readline().split())
bomb=[[0 for j in range(2)] for i in range(M)]
h=[0]*M
w=[0]*M
for i in range(M):
    x,y=map(lambda x: int(x) - 1, readline().split())
    bomb[i]=x,y
    h[x]+=1
    w[y]+=1
maxh=max(h)
maxw=max(w)
R=[h for h, x in enumerate(h) if x == maxh] 
C = [w for w, y in enumerate(w) if y == maxw]
for r in R:
    for c in C:
        if (r, c) not in bomb:
            print(maxh + maxw)
            exit()
print(maxh + maxw - 1)

Buggy submission (verdict: Runtime Error):
import collections
H,W,M=map(int,input().split())
h=[None]*M
w=[None]*M
for i in range(M):
    h[i],w[i]=map(int,input().split())
c1=collections.Counter(h)
c2=collections.Counter(w)
ans=0
cnt=0
while cnt<len(c1)-1:
    cnt2=0
    while cnt2<len(c2)-1:
        flag=True
        for x in range(M):
            if h[x]==c1.most_common()[cnt][0] and w[x]==c2.most_common()[cnt2][0]:
                ans=max((ans,c1.most_common()[cnt][1]+c2.most_common()[cnt2][1]-1))
                flag=False
                break
        if flag:
            ans=max((ans,c1.most_common()[cnt][1]+c2.most_common()[cnt2][1]))
        if c2.most_common()[cnt][1]>c2.most_common()[cnt+1][1]:
            break
        cnt2+=1
    if c1.most_common()[cnt][1]>c1.most_common()[cnt+1][1]:
        break
    cnt+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
H,W,M=map(int,input().split())
h=[None]*M
w=[None]*M
for i in range(M):
    h[i],w[i]=map(int,input().split())
c1=collections.Counter(h)
c2=collections.Counter(w)
ans=0
cnt=0
while cnt<len(c1)-1:
    cnt2=0
    while cnt2<len(c2)-1:
        flag=True
        for x in range(M):
            if h[x]==c1.most_common()[cnt][0] and w[x]==c2.most_common()[cnt2][0]:
                ans=max((ans,c1.most_common()[cnt][1]+c2.most_common()[cnt2][1]-1))
                flag=False
                break
        if flag:
            ans=max((ans,c1.most_common()[cnt][1]+c2.most_common()[cnt2][1]-1))
        if c2.most_common()[cnt][0]>c2.most_common()[cnt+1][0]:
            break
        cnt2+=1
    if c1.most_common()[cnt][0]>c1.most_common()[cnt+1][0]:
        break
    cnt+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
H,W,M=map(int,input().split())
h=[None]*M
w=[None]*M
for i in range(M):
    h[i],w[i]=map(int,input().split())
c1=collections.Counter(h)
c2=collections.Counter(w)
for x in range(M):
    flag=True
    if h[x]==c1.most_common()[i][0] and w[x]==c2.most_common()[j][0]:
        print(c1.most_common()[i][1]+c2.most_common()[j][1]-1)
        exit()
print(c1.most_common()[i][1]+c2.most_common()[j][1])