Problem p03240 (python)

Fixed submission:
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
cnt=0
for a in A:
    if a[2]!=0:
        cnt+=1
        ans=a
if cnt==1:
    print(*ans)
    exit()
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True

        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)

            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        #print(i,j,hi)
        if flg:
            ans=[i,j,hi[0]]

print(*ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
cnt=0
for a in A:
    if a[2]!=0:
        cnt+=1
        ans=a
if cnt=1:
    print(ans)
    exit()
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True

        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)

            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        #print(i,j,hi)
        if flg:
            ans=[i,j,hi[0]]

print(*ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True
        B=[]
        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)
            else:
                B.append(a)
            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        for b in B:
            if hi[0]-abs(a[1]-j)-abs(a[0]-i)>0:
                flg=False
        #print(i,j,hi)
        if flg:
            ans=[i,j,hi[0]]
print(*ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True
        B=[]
        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)
            else:
                if hi[0]-abs(a[1]-j)-abs(a[0]-i)>0:
                    flg=False
            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        #print(i,j,hi)
        if flg:
            ans=[i,j,hi[0]]
print(*ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True
        B=[]
        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)
            else:
                B.append([a[0],a[1]])
            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        #print(i,j,hi)
        if flg:
            flg2=True
            for b in B:
                if hi[0]-abs(a[1]-j)-abs(a[0]-i)>0:
                    flg2=False
            if flg2:
                ans=[i,j,hi[0]]
print(*ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True
        B=[]
        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)
            else:
                B.append([a[0],a[1])
            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        #print(i,j,hi)
        if flg:
            flg2=True
            for b in B:
                if hi[0]-abs(a[1]-j)-abs(a[0]-i)>0:
                    flg2=False
        if flg2:
            ans=[i,j,hi[0]]
print(*ans)