Problem p03240 (python)

Fixed submission:
import sys
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x: x[2],reverse=True)
ans=[]

if a[0][2]==100:
    print(a[0][0],a[0][1],a[0][2])
    sys.exit()



for i in range(0,101):
    for j in range(0,101):
        p=a[0][2]+abs(i-a[0][0])+abs(j-a[0][1])
#       q=a[1][2]+abs(i-a[1][0])+abs(j-a[1][1])
        for k in range(1,N):
            if a[k][2]>0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])!=p : break
            elif a[k][2]==0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])<p : break
            if k==N-1:
                print(i,j,p)
                sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x: x[2],reverse=True)
ans=[]

if a[1][2]==0:
    print(ans[0][0],ans[0][1],ans[0][2])

for i in range(0,101):
    for j in range(0,101):
        p=a[0][2]+abs(i-a[0][0])+abs(j-a[0][1])
        q=a[1][2]+abs(i-a[1][0])+abs(j-a[1][1])
        if p==q:
            for k in range(2,N):
                if a[k][2]>0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])!=p : break
                elif a[k][2]==0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])<=p : break
                if k==N-1:
                    print(i,j,p)
                    sys.exit()

        if p==100: print(i,j,100)

Buggy submission (verdict: Runtime Error):
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x: x[2],reverse=True)
ans=[]
for i in range(0,101):
    for j in range(0,101):
        p=a[0][2]+abs(i-a[0][0])+abs(j-a[0][1])
        q=a[1][2]+abs(i-a[1][0])+abs(j-a[1][1])
        if N>2: r=a[2][2]+abs(i-a[2][0])+abs(j-a[2][1])

        if N==2 and p==q: ans.append([i,j,p])
        elif p==q and p==r: ans.append([i,j,p])


for i in range(2,N) :
    if len(ans)==1: break
    for x in ans:
        if x[2]!=a[i][2]+abs(x[0]-a[i][0])+abs(x[1]-a[i][1]):
            ans.remove(x)

print(ans[0][0],ans[0][1],ans[0][2])

Buggy submission (verdict: Runtime Error):
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x: x[1],reverse=True)

ans=[]
for i in range(0,101):
    for j in range(0,101):
        p=a[0][2]+abs(i-a[0][0])+abs(j-a[0][1])
        q=a[1][2]+abs(i-a[1][0])+abs(j-a[1][1])
        if N>2: r=a[2][2]+abs(i-a[2][0])+abs(j-a[2][1])

        if N==2 and p==q: ans.append([i,j,p])
        elif p==q and p==r: ans.append([i,j,p])

for i in range(3,N) :
    if len(ans)==1: break
    for x in ans:
        if x[2]!=a[i][2]+abs(x[0]-a[i][0])+abs(x[1]-a[i][1]):
            ans.remove(x)

print(ans[0][0],ans[0][1],ans[0][2])

Buggy submission (verdict: Runtime Error):
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x: x[1])

ans=[]
for i in range(0,101):
    for j in range(0,101):
        p=a[0][2]+abs(i-a[0][0])+abs(j-a[0][1])
        q=a[1][2]+abs(i-a[1][0])+abs(j-a[1][1])
        if N>2: r=a[2][2]+abs(i-a[2][0])+abs(j-a[2][1])

        if N==2 and p==q: ans.append([i,j,p])
        elif p==q and p==r: ans.append([i,j,p])

for i in range(3,N) :
    if len(ans)==1: break
    for x in ans:
        if x[2]!=a[i][2]+abs(x[0]-a[i][0])+abs(x[1]-a[i][1]):
            ans.remove(x)

print(ans[0][0],ans[0][1],ans[0][2])