Problem p03240 (python)

Fixed submission:
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]

for x in range(101):
    for y in range(101):
        h_memo = 0
        for i in range(n):
            if xy[i][2] != 0:
                h_memo = xy[i][2] + abs(xy[i][0]-x) + abs(xy[i][1]-y)
                break
        for i in range(n):
            if xy[i][2] != max(0,h_memo-abs(xy[i][0]-x)-abs(xy[i][1]-y)):
                break

        else:               
            #print(x+1,y+1,h[0])

            print(x,y,h_memo)
            break

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]

for x in range(101):
    for y in range(101):
        h = [0,10**10]
        h_memo = 0
        for i in range(n):
            if xy[i][2] == 0:
                h[1] = min(h[1],abs(xy[i][0]-x) + abs(xy[i][1]-y))
            else:
                h_memo = xy[i][2] + abs(xy[i][0]-x) + abs(xy[i][1]-y)
            #print(x,y,h[1],h_memo)
            if h[0]!=0:
                if h_memo == h[0]:
                    continue
                elif h_memo != h[0]:
                    break
                elif h[1] < h[0]:
                    break
            elif h[0]==0 and h_memo!=0:
                h[0] = h_memo
            elif h[0]==0 and h_memo==0:
                if h[1] < (abs(xy[0]-x) + abs(xy[1]-y)):
                    break
        else:               
            #print(x+1,y+1,h[0])
            if h[0]==0:
                continue
            else:
                print(x,y,h[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]

for x in range(101):
    for y in range(101):
        h = [0,10**10]
        h_memo = 0
        for i in range(n):
            if xy[i][2] == 0:
                h[1] = min(h[1],abs(xy[0]-x) + abs(xy[1]-y))
            else:
                h_memo = xy[i][2] + abs(xy[i][0]-x) + abs(xy[i][1]-y)
            #print(x,y,h[1],h_memo)
            if h[0]!=0:
                if h_memo == h[0]:
                    continue
                elif h_memo != h[0]:
                    break
                elif h[1] < h[0]:
                    break
            elif h[0]==0 and h_memo!=0:
                h[0] = h_memo
            elif h[0]==0 and h_memo==0:
                if h[1] < (abs(xy[0]-x) + abs(xy[1]-y)):
                    break
        else:               
            #print(x+1,y+1,h[0])
            if h[0]==0:
                continue
            else:
                print(x,y,h[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]

for x in range(101):
    for y in range(101):
        h = [0,10**10]
        h_memo = 0
        for i in range(n):
            if xy[i][2] == 0:
                h[1] = min(h[1],abs(xy[0]-x) + abs(xy[1]-y))
            else:
                h_memo = xy[i][2] + abs(xy[i][0]-x) + abs(xy[i][1]-y)
            #print(x,y,h[1],h_memo)
            if h[0]!=0:
                if h_memo == h[0]:
                    continue
                elif h_memo != h[0]:
                    break
                elif h[1] < h[0]:
                    break
            elif h[0]==0 and h_memo!=0:
                h[0] = h_memo
            elif h==0 and h_memo==0:
                if h[1] < (abs(xy[0]-x) + abs(xy[1]-y)):
                    break
        else:               
            #print(x+1,y+1,h[0])
            if h[0]==0:
                continue
            else:
                print(x,y,h[0])