Problem p03240 (python)

Fixed submission:
n = int(input())
info = [[int(i) for i in input().split()] for j in range(n)]
info.sort(key=lambda x:x[2])
if n == 1:
    print(info[0][0], info[0][1], info[0][2])
else:
    for i in range(n):
        if info[i][2] > 0:
            r = i
    for x in range(101):
        for y in range(101):
            h = info[r][2] + abs(x - info[r][0]) + abs(y - info[r][1])
            for i in range(n):
                if i < n-1 :
                    if info[i][2] == 0:
                        if h > abs(x - info[i][0]) + abs(y - info[i][1]):
                            break
                    else:
                        if h != info[i][2] + abs(x - info[i][0]) + abs(y - info[i][1]):
                            break
                elif i == n-1:
                    if h == info[i][2] + abs(x - info[i][0]) + abs(y - info[i][1]):
                        cx = x
                        cy = y
                        ch = h
    print(cx, cy, ch)

Buggy submission (verdict: Runtime Error):
n = int(input())
info = [[int(i) for i in input().split()] for j in range(n)]
if n == 1:
    print(info[0][0], info[0][1], info[0][2])
else:
    for x in range(101):
        for y in range(101):
            for i in range(n):
                if i == 0:
                    cx = x
                    cy = y
                    h = info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1])
                elif 0 < i < n-1:
                    if h != info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                        break
                elif i == n-1:
                    if h == info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                        kakutei_cx = cx
                        kakutei_cy = cy
                        kakutei_h = h
    print(kakutei_cx, kakutei_cy, kakutei_h)

Buggy submission (verdict: Runtime Error):
n = int(input())
info = [[int(i) for i in input().split()] for j in range(n)]
for x in range(101):
    for y in range(101):
        for i in range(n):
            if n == 1:
                kakutei_cx = x
                kakutei_cy = y
                kakutei_h = info[i][2] + abs(x - info[i][0]) + abs(y - info[i][1])
            else:
                if i == 0:
                    cx = x
                    cy = y
                    h = info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1])
                elif 0 < i < n-1:
                    if h != info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                        break
                elif i == n-1:
                    if h == info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                        kakutei_cx = cx
                        kakutei_cy = cy
                        kakutei_h = h
print(kakutei_cx, kakutei_cy, kakutei_h)

Buggy submission (verdict: Runtime Error):
n = int(input())
info = [[int(i) for i in input().split()] for j in range(n)]
for x in range(101):
    for y in range(101):
        for i in range(n):
            if i == 0:
                cx = x
                cy = y
                h = info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1])
            elif 0 < i < n-1:
                if h != info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                    break
            elif i == n-1:
                if h == info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                    kakutei_cx = cx
                    kakutei_cy = cy
                    kakutei_h = h
print(kakutei_cx, kakutei_cy, kakutei_h)