Problem p03240 (python)

Fixed submission:
N = int(input())

xyh = []
not_zero = -100
flag_zero = True

for i in range(N):
    x,y,h = map(int,input().split())
    if h > 0 and flag_zero:
        not_zero = i
        flag_zero = False
    xyh.append([x,y,h])

for i in range(101):
    for j in range(101):

        Cx = i
        Cy = j
        H = xyh[not_zero][2] + abs(Cx-xyh[not_zero][0]) + abs(Cy-xyh[not_zero][1])
        ans = True

        for x,y,h in xyh:
            tmp_h = h+abs(Cx-x)+abs(Cy-y)
            if h>0:
                if tmp_h != H:
                    ans = False
                    break
            else:
                if H - abs(Cx-x) -abs(Cy-y) > 0:
                    ans = False
                    break
            
        if ans:
            print(Cx,Cy,H)
            exit()

Buggy submission (verdict: Runtime Error):
def check(X,Y):
    Hs = []
    for x,y,h in xyh:
        if h > 0:
            H = h + abs(X-x) + abs(Y-y)
            Hs.append(H)
        else:
            if abs(X-x) + abs(Y-y) < H:
                return False
    
    if len(set(Hs)) == 1:
        print(X,Y,Hs[0])
        return True
    else:
        return False

N = int(input())

xyh = [list(map(int,input().split())) for _ in range(N)]

for i in range(101):
    for j in range(101):
        if check(i,j):
            exit()

Buggy submission (verdict: Runtime Error):
def check(X,Y):
    Hs = []
    for x,y,h in xyh:
        if h > 0:
            H = h + abs(X-x) + abs(Y-y)
            Hs.append(H)
        else:
            if abs(X-x) + abs(Y-y) < H:
                return False

    if len(set(Hs)) == 1:
        print(X,Y,Hs[0])
        return True
    else:
        return False

N = int(input())

xyh = [tuple(map(int,input().split())) for _ in range(N)]

for i in range(101):
    for j in range(101):
        if check(i,j):
            exit()

Buggy submission (verdict: Runtime Error):
def check(X,Y):
    Hs = []
    for x,y,h in xyh:

        if h > 0:
            H = h + abs(X-x) + abs(Y-y)
            Hs.append(H)
        else:
            if abs(X-x) + abs(Y-y) < H:
                return False
    if len(set(Hs)) == 1:
        print(X,Y,Hs[0])
        return True

N = int(input())

xyh = [tuple(map(int,input().split())) for _ in range(N)]

for i in range(101):
    for j in range(101):
        if check(i,j):
            exit()

Buggy submission (verdict: Runtime Error):
N = int(input())

xyh = []

for i in range(N):
    x,y,h = map(int,input().split())
    xyh.append([x,y,h])

for i in range(101):
    for j in range(101):

        Cx = i
        Cy = j
        ans = True
        flag_h = True

        for x,y,h in xyh:

            if h>0 and flag_h:
                H = h+abs(Cx-x)+abs(Cy-y)
                flag_h = False

            else:
                tmp_h = h+abs(Cx-x)+abs(Cy-y)
                if h>0:
                    if tmp_h != H:
                        ans = False
                        break
                else:
                    if H - abs(Cx-x) -abs(Cy-y) > 0:
                        ans = False
                        break
            
        if ans:
            print(Cx,Cy,H)
            exit()

Buggy submission (verdict: Runtime Error):
N = int(input())

xyh = []

for i in range(N):
    x,y,h = map(int,input().split())
    xyh.append([x,y,h])

for i in range(101):
    for j in range(101):

        Cx = i
        Cy = j
        ans = True
        flag_h = True

        for x,y,h in xyh:

            if h>0 and flag_h:
                H = h+abs(Cx-x)+abs(Cy-y)
                flag_h = False

            elif h>0:
                tmp_h = h+abs(Cx-x)+abs(Cy-y)
                if tmp_h != H:
                    ans = False
                    ##break

        elif ans:
            print(Cx,Cy,H)
            exit()