Problem p03240 (python)

Fixed submission:
N = int(input())

infos = []
first_info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0 and len(first_info) == 0:
        first_info = [x, y, h]
    else:
        infos.append([x, y, h])


# cxとcyを1つに絞り込む
x1, y1, h1 = first_info
for cx in range(101):
    for cy in range(101):
        isValid = True
        H = h1 + abs(x1-cx) + abs(y1-cy)
        for x2, y2, h2 in infos:
            if h2 != max(H - abs(x2-cx) - abs(y2-cy), 0):
                isValid = False

        if isValid:
            ans = [cx, cy]

cx, cy = ans
H = h1 + abs(x1-cx) + abs(y1-cy)
print(cx, cy, H)

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())

if N == 1:
    print('aaa')
    sys.exit(0)
    

infos = []
first_info = []
second_info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0 and len(first_info) == 0:
        first_info = [x, y, h]
    elif h > 0 and len(second_info) == 0:
        second_info = [x, y, h]
    elif h > 0:
        infos.append([x, y, h])


# cxとcyを1つに絞り込む
x1, y1, h1 = first_info
x2, y2, h2 = second_info
kouhos = []
for cx in range(101):
    for cy in range(101):
        if h1-h2 == abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouhos.append([cx, cy])

#print(kouhos)
kouho_isvalid = [True for _ in range(len(kouhos))]

for info in infos:
    x2, y2, h2 = info
    for i in range(len(kouhos)):
        cx, cy = kouhos[i]
        if h1-h2 != abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouho_isvalid[i] = False


for i in range(len(kouhos)):
    if kouho_isvalid[i]:
        cx, cy = kouhos[i]

H = h1 + abs(x1-cx) + abs(y1-cy)
print(cx, cy, H)

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

infos = []
first_info = []
second_info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0 and len(first_info) == 0:
        first_info = [x, y, h]
    elif h > 0 and len(second_info) == 0:
        second_info = [x, y, h]
    elif h > 0:
        infos.append([x, y, h])


# cxとcyを1つに絞り込む
x1, y1, h1 = first_info
x2, y2, h2 = second_info
kouhos = []
for cx in range(101):
    for cy in range(101):
        if h1-h2 == abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouhos.append([cx, cy])

#print(kouhos)
kouho_isvalid = [True for _ in range(len(kouhos))]

for info in infos:
    x2, y2, h2 = info
    for i in range(len(kouhos)):
        cx, cy = kouhos[i]
        if h1-h2 != abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouho_isvalid[i] = False

cx = 0
cy = 0
for i in range(len(kouhos)):
    if kouho_isvalid[i]:
        cx, cy = kouhos[i]

H = h1 + abs(x1-cx) + abs(y1-cy)
print(cx, cy, H)

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

infos = []
first_info = []
second_info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0 and len(first_info) == 0:
        first_info = [x, y, h]
    elif h > 0 and len(second_info) == 0:
        second_info = [x, y, h]
    elif h > 0:
        infos.append([x, y, h])


# cxとcyを1つに絞り込む
x1, y1, h1 = first_info
x2, y2, h2 = second_info
kouhos = []
for cx in range(101):
    for cy in range(101):
        if h1-h2 == abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouhos.append([cx, cy])

#print(kouhos)
kouho_isvalid = [True for _ in  range(len(kouhos))]

for info in infos:
    x2, y2, h2 = info
    for i in range(len(kouhos)):
        cx, cy = kouhos[i]
        if h1-h2 != abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouho_isvalid[i] = False


for i in range(len(kouhos)):
    if kouho_isvalid[i]:
        #print(kouhos[i])
        cx, cy = kouhos[i]

H = h1 + abs(x1-cx) + abs(y1-cy)

print(cx, cy, H)