Problem p03240 (python)

Fixed submission:
N = int(input())
p_x = []
p_y = []
p_h = []
for i in range(N):
    x1,y1,h1 = [int(i) for i in input().split()]
    p_x.append(x1)
    p_y.append(y1)
    p_h.append(h1)


#h = H - |X-CX| - |Y-CY|　⇔　H = h + |X-CX| + |Y-CY|
#方針：上記式から与えられた全座標でHの値が一致する点を見つける。
for x in range(101):
    for y in range(101):
        #点を見つけたときにfor文から離脱
        hantei1 = 0
        #一致したときにカウント
        count = 0
        #判定用の変数
        tmp = -1
        #判定用の変数(0) or 判定する値（1）
        tmp_count = 0
        #h[i]==0の保留リスト
        horyu = []
        for i in range(N):
            if p_h[i] == 0:
                horyu.append(i)
            else:
                tmp1 = p_h[i] + abs(x - p_x[i]) + abs(y - p_y[i])
                if tmp1 < 0 :
                    break
                elif tmp_count == 0:
                    tmp = tmp1
                    tmp_count += 1
                elif tmp_count != 0 and tmp1 > 0:
                    if tmp == tmp1:
                        count += 1
            
        if count == N-1 or N-1 == count + len(horyu):
            if len(horyu) == 0:
                Cx = x
                Cy = y
                H = tmp
                hantei1 = 1
                break
            else:
                count2 = 0
                for j in range(len(horyu)):
                    if 0 == max(0, tmp -abs(p_x[horyu[j]] - x) -abs(p_y[horyu[j]] - y)):
                        count2 += 1
                if count2 == len(horyu):
                    Cx = x
                    Cy = y
                    H = tmp
                    hantei1 = 1
    if hantei1 == 1:
        break

print(Cx,Cy,H)

Buggy submission (verdict: Runtime Error):
N = int(input())
p_x = []
p_y = []
p_h = []
for i in range(N):
    x1,y1,h1 = [int(i) for i in input().split()]
    p_x.append(x1)
    p_y.append(y1)
    p_h.append(h1)


#h = H - |X-CX| - |Y-CY|　⇔　H = h + |X-CX| + |Y-CY|
#方針：上記式から与えられた全座標でHの値が一致する点を見つける。
for x in range(101):
    for y in range(101):
        hantei1 = 0
        count = 0
        hantei = 1
        for i in range(N):
            if i == 0 :
                tmp = p_h[i] + abs(x - p_x[i]) + abs(y - p_y[i])
                if tmp < 0:
                   hantei = 0
            else:
                if hantei == 1:
                    tmp1 = p_h[i] + abs(x - p_x[i]) + abs(y - p_y[i])
                    if tmp == tmp1:
                        #print(tmp,tmp1,x,y,i)
                        count += 1
                    else :
                        break
                else :
                    break
        if count == N-1:
            Cx = x
            Cy = y
            H = tmp
            hantei1 = 1
            break  
    if hantei1 == 1:
        break

print(Cx,Cy,H)

Buggy submission (verdict: Runtime Error):
N = int(input())
p_x = []
p_y = []
p_h = []
for i in range(N):
    x1,y1,h1 = [int(i) for i in input().split()]
    p_x.append(x1)
    p_y.append(y1)
    p_h.append(h1)


#h = H - |X-CX| - |Y-CY|　⇔　H = h + |X-CX| + |Y-CY|
#方針：上記式から与えられた全座標でHの値が一致する点を見つける。
for x in range(101):
    for y in range(101):
        hantei1 = 0
        count = 0
        hantei = 1
        for i in range(N):
            if i == 0 :
                tmp = p_h[i] + abs(x - p_x[i]) + abs(y - p_y[i])
                if tmp < 0:
                   hantei = 0
            else:
                if hantei == 1:
                    tmp1 = p_h[i] + abs(x - p_x[i]) + abs(y - p_y[i])
                    if tmp == tmp1:
                        #print(tmp,tmp1,x,y,i)
                        count += 1
                    else :
                        break
                else :
                    break
        if count == N-1:
            Cx = x
            Cy = y
            H = tmp
            hantei1 = 1
            break  
    if hantei1 == 1:
        break

print(Cx," ", Cy, " ",H")

Buggy submission (verdict: Runtime Error):
N = int(input())
p_x = []
p_y = []
p_h = []
for i in range(N):
    x1,y1,h1 = [int(i) for i in input().split()]
    p_x.append(x1)
    p_y.append(y1)
    p_h.append(h1)


#h = H - |X-CX| - |Y-CY|　⇔　H = h + |X-CX| + |Y-CY|
#方針：上記式から与えられた全座標でHの値が一致する点を見つける。
for x in range(101):
    count = 0
    hantei = 1
    for y in range(101):
        hantei1 = 0
        for i in range(N):
            if i == 0 :
                tmp = p_h[i] + abs(x - p_x[i]) + abs(y - p_y[i])
                if tmp < 0:
                   hantei = 0
            else:
                if hantei == 1:
                    tmp1 = p_h[i] + abs(x - p_x[i]) + abs(y - p_y[i])
                    if tmp == tmp1:
                        #print(tmp,tmp1,x,y)
                        count += 1
                    else :
                        break
                else :
                    break
        if count == N-1: 
            #print (x,y,tmp)
            Cx = x
            Cy = y
            H = tmp
            hantei1 = 1
            break  
    if hantei1 == 1:
        break

print(Cx," ", Cy, " ",H)