Problem p03240 (python)

Fixed submission:
N = int(input())
coordinate = []
ans = -1
for _ in range(N):
    x, y, h = map(int, input().split())
    if h == 0:
        continue
    coordinate.append([x, y, h])
N = len(coordinate)
for cx in range(101):
    for cy in range(101):
        x1, y1, h1 = coordinate[0]
        H1 = h1 + abs(cx-x1) + abs(cy-y1)
        f = 1
        if N == 1:
            f = 2
            Cx = x1
            Cy = y1
            ans = h1
            break
        for n in range(1, N):
            x, y, h = coordinate[n]
            H = h + abs(cx-x) + abs(cy-y)
            if H == H1:
                f *= 1
            else:
                f *= 0
            if f and n == N-1:
                break
        if f == 1:
            Cx = cx
            Cy = cy
            ans = H1
            break
    if f:
        break
        
print(Cx, Cy, ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
coordinate = []
ans = -1
for _ in range(N):
    x, y, h = map(int, input().split())
    if h == 0:
        continue
    coordinate.append([x, y, h])

for cx in range(101):
    for cy in range(101):
        x1, y1, h1 = coordinate[0]
        H1 = h1 + abs(cx-x1) + abs(cy-y1)
        f = 1
        for n in range(1, N):
            x, y, h = coordinate[n]
            H = h + abs(cx-x) + abs(cy-y)
            if H == H1:
                f *= 1
            else:
                f *= 0
            if f and n == N-1:
                break
        if f:
            Cx = cx
            Cy = cy
            ans = H1
            break
    if f:
        break
        
print(Cx, Cy, ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
Inputs = [tuple(map(int, input().split())) for _ in range(N)]
H = 0
f = 0
for cx in range(101):
    for cy in range(101):
        n = 0
        while(n < N-1):
            x1, y1, h1 = Inputs[n]
            H1 = h1 + abs(x1-cx) + abs(y1-cy)
            x2, y2, h2 = Inputs[n+1]
            H2 = h2 + abs(x2-cx) + abs(y2-cy)
            n += 1
            if h1 == 0:
                continue
            if H1 != H2:
                f = 0
                break
            else:
                f = 1
        if f:
            Cx = cx
            Cy = cy
            H = H1
            
                
print(Cx, Cy, H)

Buggy submission (verdict: Runtime Error):
N = int(input())
Inputs = [tuple(map(int, input().split())) for _ in range(N)]
H = 0
f = 0
for cx in range(101):
    for cy in range(101):
        n = 0
        while(n < N-1):
            x1, y1, h1 = Inputs[n]
            if h1 == 0:
                continue
            H1 = h1 + abs(x1-cx) + abs(y1-cy)
            x2, y2, h2 = Inputs[n+1]
            H2 = h2 + abs(x2-cx) + abs(y2-cy)
            if H1 != H2:
                f = 0
                break
            else:
                f = 1
                n += 1
        if f:
            print('aaaa')
            Cx = cx
            Cy = cy
            H = H1
            
                
print(Cx, Cy, H)

Buggy submission (verdict: Runtime Error):
N = int(input())
Inputs = [tuple(map(int, input().split())) for _ in range(N)]

f = 0
for cx in range(101):
    for cy in range(101):
        n = 0
        while(n < N-1):
            x1, y1, h1 = Inputs[n]
            H1 = h1 + abs(x1-cx) + abs(y1-cy)
            x2, y2, h2 = Inputs[n+1]
            H2 = h2 + abs(x2-cx) + abs(y2-cy)
            if H1 != H2:
                f = 0
                break
            else:
                f = 1
                n += 1
        if f:
            Cx = cx
            Cy = cy
            H = H1
            
                
print(Cx, Cy, H)