Problem:


Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).  

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:  

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.  

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."  

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.  

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:  

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.  

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.  

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.  



Sample input:
4
2 3 5
2 1 5
1 2 5
3 2 5


Sample output:
2 2 6

Submission status: Runtime Error

Solution code:
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
for i in range(101):
    for j in range(101):
        k = 0
        flag = True
        for x, y, h in xyh:
            H_ = calcH(x, i, y, j, h)
            if h == 0:
                flag = False
            if k > 0:
                if H_ != H and flag:
                    flag = False
                    break
                elif H_ != H:
                    H = H_
                    flag = True
                else:
                    continue
            else:
                H = H_
            k += 1
        if flag == False or H > Hmax:
            continue
        else:
            Cx = i
            Cy = j
            Ch = H
            break
print(Cx, Cy, Ch)

Submission status: Runtime Error

Solution code:
def c_pyramid(N, Pos):
    from itertools import product
    # 中心座標を全探索
    for cx, cy in product(range(101), repeat=2):
        height = set()
        for x, y, h in Pos:
            height.add(h + abs(cx - x) + abs(cy - y))
        if len(height) == 1:
            ans = (cx, cy, list(height)[0])
            break
    ans = '{0} {1} {2}'.format(*ans)
    return ans

N = int(input())
Pos = [[int(i) for i in input().split()] for j in range(N)]
print(c_pyramid(N, Pos))

Submission status: Runtime Error

Solution code:
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9 + 1
for i in range(101):
    for j in range(101):
        k = 0
        flag = True
        for x, y, h in xyh:
            H_ = calcH(x, i, y, j, h)
            if h == 0:
                flag = False
            if k > 0:
                if H_ != H and flag:
                    flag = False
                    break
                elif H_ != H:
                    H = H_
                    flag = True
                else:
                    continue
            else:
                H = H_
            k += 1
        if flag == False:
            continue
        else:
            Cx = i
            Cy = j
            Ch = H
            break
print(Cx, Cy, Ch)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for w in range(n):
   if l[w][2]>0:
     k=w
     break
for x in range(101):
  for y in range(101):
    a=max(l[z][2]-(abs(l[0][0]-x)-abs(l[0][1]-y)),0)
    c=0
    for z in range(1,n):
      if max(l[z][2]-(abs(l[0][0]-x)-abs(l[0][1]-y)),0)==a:c+=1
    if c==n-1:print(x,y,l[k][2]+(abs(l[k][0]-x)+abs(l[k][1]-y))

Submission status: Runtime Error

Solution code:
import numpy as np

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

for j in range(101):
    for k in range(101):
        can = True
        needH = a[0][2] + np.abs(a[0][0] - j) + np.abs(a[0][1] - k)
        for i in range(N):
            if a[i][2] > 0:
                if  a[i][2] != needH - np.abs(a[i][0] - j) - np.abs(a[i][1] - k):
                    can = False
                    break
        if can == False:
            continue
        for i in range(N):
            if a[i][2] == 0:
                if  first > np.abs(a[i][0] - j) - np.abs(a[i][1] - k):
                    can = False
                    break
        if can:
            print("{} {} {}\n".format(j, k, first))

Submission status: Runtime Error

Solution code:
n=int(input())
xyh = [list(map(int,input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        for i,r in enumerate(xyh):
            if r[2] > 1:
                ch = r[2] + abs(r[0] - cx) + abs(r[1] - cy)
                break
        j = False
        for i,r in enumerate(xyh):
            if r[2] != max((ch - abs(r[0] - cx) - abs(r[1] - cy)),0):
                j = True
                break
        if not j:
            print(cx,cy,ch)

Submission status: Runtime Error

Solution code:
n=int(input())
xyh = [list(map(int,input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        for i,r in enumerate(xyh):
            if r[2] > 1:
                ch = r[2] + abs(r[0] - cx) + abs(r[1] - cy)
        j = False
        for i,r in enumerate(xyh):
            if r[2] != ch - abs(r[0] - cx) - abs(r[1] - cy):
                j = True
                break
        if not j:
            print(cx,cy,ch)

Submission status: Runtime Error

Solution code:
import sys
N = int(input().strip())
grid = []
ref = 0
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
    if array[2]>0:
      ref = i
x = 0
y = 0
while y <= 100:
  x = 0
  while x <= 100:
    h0 = grid[ref][2]+abs(x-grid[ref][0])+abs(y-grid[ref][1])
    for arrays in grid:
      h = h0-abs(x-arrays[0])-abs(y-arrays[1])
      if h != arrays[2]:
        break
    print(x,y,h0)
      sys.exit()
    x += 1
  y += 1

Submission status: Runtime Error

Solution code:
import sys

# height is H minus the taxicab distance from (Cx, Cy) to (x, y)

def TaxicabDistance(pt_a, pt_b):
    return abs(pt_a[0] - pt_b[0]) + abs(pt_a[1] - pt_b[1])

def RemoveLeft(some_set, x):
    return {el for el in some_set if el[0] >= x[0]}

def RemoveRight(some_set, x):
    return {el for el in some_set if el[0] <= x[0]}

def RemoveBelow(some_set, x):
    return {el for el in some_set if el[1] >= x[1]}

def RemoveAbove(some_set, x):
    return {el for el in some_set if el[1] <= x[1]}

def RemoveAllExcept(some_set, other_set):
    return some_set & other_set

lines = sys.stdin.read().split('\n')
N = int(lines[0])

possible_c = set()
for x in range(101):
    for y in range(101):
        possible_c.add((x,y))

known_points = []

for i in range(1, N+1):
    np_text = lines[i].split(' ')
    new_point = (int(np_text[0]), int(np_text[1]), int(np_text[2]))
    for old_point in known_points:
        height_diff = new_point[2] - old_point[2]
        dist = TaxicabDistance(new_point, old_point)

        if dist == height_diff:
            # same quadrant, new_point closer to center
            if new_point[0] > old_point[0]:
                possible_c = RemoveLeft(possible_c, new_point)
            elif new_point[0] < old_point[0]:
                possible_c = RemoveRight(possible_c, new_point)

            if new_point[1] > old_point[1]:
                possible_c = RemoveBelow(possible_c, new_point)
            elif new_point[1] < old_point[1]:
                possible_c = RemoveAbove(possible_c, new_point)
        elif dist == -height_diff:
            # same quadrant, old_point closer to center
            if old_point[0] > new_point[0]:
                possible_c = RemoveLeft(possible_c, old_point)
            elif old_point[0] < new_point[0]:
                possible_c = RemoveRight(possible_c, old_point)

            if old_point[1] > new_point[1]:
                possible_c = RemoveBelow(possible_c, old_point)
            elif old_point[1] < new_point[1]:
                possible_c = RemoveAbove(possible_c, old_point)
        else:
            # different quadrants
            discrepancy = dist - abs(height_diff)
            # discrepancy is always even; the center has taxicab distance of 
            # exactly discrepancy/2 measured from one (or both) of the points
            # and lies between the two
            candidates = set()
            c_dist = discrepancy//2
            for j in range(c_dist + 1):
                if new_point[0] == old_point[0]:
                    if new_point[1] > old_point[1]:
                        candidates.add((new_point[0] - j, new_point[1] - c_dist + j))
                        candidates.add((new_point[0] + j, new_point[1] - c_dist + j))
                        candidates.add((old_point[0] - j, old_point[1] + c_dist - j))
                        candidates.add((old_point[0] + j, old_point[1] + c_dist - j))
                    else:
                        candidates.add((new_point[0] - j, new_point[1] + c_dist - j))
                        candidates.add((new_point[0] + j, new_point[1] + c_dist - j))
                        candidates.add((old_point[0] - j, old_point[1] - c_dist + j))
                        candidates.add((old_point[0] + j, old_point[1] - c_dist + j))
                if new_point[1] == old_point[1]:
                    if new_point[0] > old_point[0]:
                        candidates.add((new_point[0] - c_dist + j, new_point[1] + j))
                        candidates.add((new_point[0] - c_dist + j, new_point[1] - j))
                        candidates.add((old_point[0] + c_dist - j, old_point[1] + j))
                        candidates.add((old_point[0] + c_dist - j, old_point[1] - j))
                    else:
                        candidates.add((new_point[0] + c_dist - j, new_point[1] + j))
                        candidates.add((new_point[0] + c_dist - j, new_point[1] - j))
                        candidates.add((old_point[0] - c_dist + j, old_point[1] + j))
                        candidates.add((old_point[0] - c_dist + j, old_point[1] - j))

                if new_point[0] > old_point[0]:
                    if new_point[1] > old_point[1]:
                        candidates.add((new_point[0] - j, new_point[1] - c_dist + j))
                        candidates.add((old_point[0] + j, old_point[1] + c_dist - j))
                    elif new_point[1] < old_point[1]:
                        candidates.add((new_point[0] - j, new_point[1] + c_dist - j))
                        candidates.add((old_point[0] + j, old_point[1] - c_dist + j))
                if new_point[0] < old_point[0]:
                    if new_point[1] > old_point[1]:
                        candidates.add((new_point[0] + j, new_point[1] - c_dist + j))
                        candidates.add((old_point[0] - j, old_point[1] + c_dist - j))
                    elif new_point[1] < old_point[1]:
                        candidates.add((new_point[0] + j, new_point[1] + c_dist - j))
                        candidates.add((old_point[0] - j, old_point[1] - c_dist + j))
            # print("candidates for {", new_point, ',', old_point, "}:", candidates)
            possible_c &= candidates

        if len(possible_c) == 1:
            break

    known_points += [new_point]

if len(possible_c) != 1:
    raise Exception("no unique answer: " + str(len(possible_c)) + " possible c remaining")

(cx, cy) = possible_c.pop()
h = known_points[0][2] + TaxicabDistance(known_points[0], (cx, cy))
print(cx, cy, h)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for x in range(101):
  for y in range(101):
    a=abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2]
    w=0
    for z in range(1,n):
      if l[z][2]>0 and abs(l[z][0]-x)+abs(l[z][1]-y)+l[z][2]!=a:w=0
        break
      else:w=1
      if w==1:print(x,y,abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2])

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for x in range(101):
  for y in range(101):
    a=abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2]
    w=0
    for z in range(1,n):
      if l[z][2]>0 and abs(l[z][0]-x)+abs(l[z][1]-y)+l[z][2]!=a:w=0
        break
      else:w=1
      if w==1:print(x,y,abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2])​

Submission status: Runtime Error

Solution code:
n = int(input())
ma = []
for j in range(101):
    ma.append([0] * 101)
for i in range(n):
    x, y, h = map(int, input().split())
    if i == 0:
        for j in range(101):
            for k in range(101):
                ma[j][k] = h + abs(j - x) + abs(k - y)
    else:
        for j in range(101):
            for k in range(101):
                if ma[j][k] == h + abs(j - x) + abs(k - y) or ma[j][k] - abs(j - x) - abs(k - y) <= 0:
                    continue
                else:
                    ma[j][k] = 0
ans = 0
for i in range(101):
    if sum(ma[i]) != 0:
        print(i, ma[i].index(sum(ma[i])), sum(ma[i]))
        break

Submission status: Runtime Error

Solution code:
import numpy as np
 
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
x = np.array([xyh[i][0] for i in range(N)])
y = np.array([xyh[i][1] for i in range(N)])
h = np.array([xyh[i][2] for i in range(N)])
x_ = x[h != 0]
y_ = y[h != 0]
h_ = h[h != 0]
for Cx in range(101):
    for Cy in range(101):
        H = h_ + np.array(list(map(abs, [xi - Cx for xi in x_]))) + np.array(list(map(abs, [yi - Cy for yi in y_])))
        if len(set(H)) == 1 and list(set(H)) == h[[x==Cx]and[y==Cy]]:
            break
    else:
        continue
    break
H = list(set(H))
print("{} {} {}".format(Cx, Cy, H[0]))

Submission status: Runtime Error

Solution code:
a = int(input())

b = []

p = 0
pp = 0
ppp = 0

for i in range(a):
    b.append(list(map(int,input().split())))
if a == 1:
    print(b[0][0],b[0][1],b[0][2])
b.sort(b,key=lambda x:-x[2])
else:
    for i in range(0,101,-1):
        for j in range(0,101,-1):
            for k in range(a):
                if k == 0:
                 p = abs(b[k][0] - i) + abs(b[k][1]-j)+b[k][2]
            else:
                if max(0,p - abs(b[k][0]-i)- abs(b[k][1]-j)) != b[k][2]:
                    pp = 1
        if pp == 0:
            ppp = 1
            break
        else:
            pp = 0
    if ppp == 1:
        print(i,j,p)
        break

Submission status: Runtime Error

Solution code:
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

flg = True


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


for s in ss:
    x = s[0]
    y = s[1]
    h = s[2]
    if x == y == 0:
        print(x, y, h)
        flg = False

ans = []
if flg:
    for i in range(len(ss)-1):

        temp = [] if i == 0 else get_unique_list(ans)
        ans = []

        x1 = ss[i][0]
        y1 = ss[i][1]
        h1 = ss[i][2]
        x2 = ss[i+1][0]
        y2 = ss[i+1][1]
        h2 = ss[i+1][2]

        for a in range(101):
            for b in range(101):
                left = h1 + abs(x1-a) + abs(y1 - b)
                right = h2 + abs(x2-a) + abs(y2 - b)
                if left == right and left > 0 and right > 0:
                    if i == 0:  # 1回目のループ
                        ans.append([a, b])
                    elif [a, b] in temp:  # 2回目移行
                        ans.append([a, b])

    h = ss[0][2] + abs(ss[0][0] - ans[0][0]) + abs(ss[0][1] - ans[0][1])
    print(ans[0][0], ans[0][1], h)

Submission status: Runtime Error

Solution code:
N = int(input())
xyh = sorted([list(map(int,input().split())) for _ in range(N)], key=lambda x:x[2], reverse=True)
xyh = [(x,y,h) for x,y,h in xyh if h != 0]
N = len(xyh)

XY = [[True] * 101 for _ in range(101)]

for i in range(N-1):
    tmp = xyh[i][2] - xyh[i+1][2]
    for x in range(101):
        for y in range(101):
            if not XY[y][x]: 
                continue
            if xyh[i+1][2] != 0 and abs(x-xyh[i][0]) + abs(y-xyh[i][1]) + tmp != abs(x-xyh[i+1][0]) + abs(y-xyh[i+1][1]):
                XY[y][x] = False
            else if xyh[i+1][2] == 0 and abs(x-xyh[i][0]) + abs(y-xyh[i][1]) + tmp < abs(x-xyh[i+1][0]) + abs(y-xyh[i+1][1]):
                XY[y][x] = False

for x in range(101):
    for y in range(101):
        if XY[y][x]:
            print(x,y,abs(x-xyh[0][0]) + abs(y-xyh[0][1]) + xyh[0][2])
            exit()

print(xyh[0][0],xyh[0][1],xyh[0][2])

Submission status: Runtime Error

Solution code:
n = int(input())

x = [int(i) for i in range(n)]
y = [int(i) for i in range(n)]
h = [int(i) for i in range(n)]
for i in range(n):
  x[i], y[i], h[i] = [int(i) for i in input().split()]
for i in range(101):
  for j in range(101):
    for k in range(n):
      if h[k] != 0:
        H = abs(i - x[k]) + abs(j - y[k]) + h[k] 
    for k in range(n):
      if H - abs(i - x[k]) + abs(j - y[k]) <=0:
        if h[k] != 0:
          break
      elif  H != abs(i - x[k]) + abs(j - y[k]) + h[k]:
        break
    else:
      ansx = i
      ansy = j
      ansH = H
      
print(ansx, ansy, ansH)

Submission status: Runtime Error

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

n = int(input())
vh = {}
zx = []
zy = []
zh = []
for j in range(101):
    for k in range(101):
        vh[j, k] = -2
for i in range(n):
    x, y, h = list(map(int, input().split()))
    if h == 0:
        zx.append(x)
        zy.append(y)
        zh.append(h)
        continue
    for j in range(101):
        for k in range(101):
            hi = h + abs(j - x) + abs(k - y)
            if vh[j, k] == -2:
                vh[j, k] = hi
            elif vh[j, k] > -1:
                if vh[j, k] != hi:
                    vh[j, k] = -1

rs = 0
for j in range(101):
    for k in range(101):
        if vh[j, k] > -1:
            rs += 1
            rj = j
            rk = k

if rs == 1:
    print(rj, rk, vh[rj, rk])
else:
    for i in range(rs):
        dels = 0
        for j in range(101):
            for k in range(101):
                hi = zh + abs(j - zx) + abs(k - zy)
                if vh[j, k] > -1:
                    if vh[j, k] != hi:
                        dels += 1
        if dels == rs - 1:
            for j in range(101):
                for k in range(101):
                    hi = zh + abs(j - zx) + abs(k - zy)
                    if vh[j, k] > -1:
                        if vh[j, k] != hi:
                            vh[j, k] = -1
            for j in range(101):
                for k in range(101):
                    if vh[j, k] > -1:
                        print(j, k, vh[j, k])

Submission status: Runtime Error

Solution code:
N=int(input())
lis=[]
for i in range(101):
    for j in range(101):
        lis.append([i,j])
l2=[]
for i in range(N):
    l2.append(list(map(int, input().split())))
for i in lis:
    n=N
    l=0
    for j in l2:
        k=abs(i[0]-j[0])+abs(i[1]-j[1])+j[2]
        if l==k or l=0:
            l=k
            n-=1
            if n==0:
                print(j[0],j[1],l)
                break
        else: break
    break

Submission status: Runtime Error

Solution code:
import sys
import itertools


def height(x, y, Cx, Cy, H):
    return max([H - abs(x - Cx) - abs(y - Cy), 0])


N = int(sys.stdin.readline().strip())

set_list = []
for line in sys.stdin.readlines():
    x, y, h = list(map(int, line.strip().split()))
    ans_set = set()
    for Cx, Cy in itertools.product(range(101), range(101)):
        dx = abs(x - Cx)
        dy = abs(y - Cy)
        d = dx + dy
        H = h + d
        # if H >= d:
        if H >= 1:
            ans_set.add((Cx, Cy, H))
    set_list.append(ans_set)

ans_set = set_list[0]
for s in set_list[1:]:
    ans_set = ans_set & s

if len(ans_set) == 1:
    Cx, Cy, H = list(ans_set)[0]
    print(Cx, Cy, H)
else:
    for s in set_list:
        Cx, Cy, H = list(ans_set)[0]
        if H >= 1:
            print(Cx, Cy, H)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

x0, y0, h0 = map(int, input().split())
for i in range(N):
  xi, yi, hi = map(int, input().split())
  if xi-x0 == abs(xi-x0):
    hx = hi + (100 -xi)
  else:
    hx = hi +xi

  if yi-y0 == abs(yi-y0):
    hy = hx + (100 -yi)
  else:
    hy = hx +yi

print(hy)

Submission status: Runtime Error

Solution code:
n = int(input())
xyh = []
xyh0 = []
for i in range(0,n):
    X,Y,h = map(int,input().split())
    if h != 0:
        xyh.append((X,Y,h))
    else:
        xyh0.append((X,Y))
ans = []
for i in range(0,101):
    for j in range(0,101):
        flag = "f"
        if len(xyh)>0:
            x,y,h = xyh[0]
            H = h + abs(x-i)+abs(y-j)
            flag = "t"
        for x,y,h in xyh:
            if H !=  h + abs(x-i)+abs(y-j):
                flag = "f"
                break
        if flag == "t":
            ans.append((i,j,H))
if len(ans) > 0:
    for i,j,H in ans:
        flag == "f":
        for x,y in xyh0:
            flag = "t"
            if H < h + abs(x-i)+abs(y-j):
                flag = "f"
                break
        if flag == "t":
            ans = [(i,j,H)]
        if len(ans) == 1:
            break
print(x,y,h)













#

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
maxc = M//N
while True:
    if N == 1:
        print(1)
        break
    if M%maxc == 0:
        print(maxc)
        break
    maxc -=1

Submission status: Runtime Error

Solution code:
import sys


n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]


for i in range(0, 101):
    for j in range(0, 101):
        for k in range(n):
            c = 0
            dict = {}
            if l[k][2] != 0:
                h = l[k][2] + abs(i - l[k][0]) + abs(i - l[k][1])
                c += 1
                if h in dict:
                    dict[h] += 1
                else:
                    dict[h] = 1
        if dict[h] == c:
            print(i, j, k)
            sys.exit()

Submission status: Runtime Error

Solution code:
import sys

# height is H minus the taxicab distance from (Cx, Cy) to (x, y)

def TaxicabDistance(pt_a, pt_b):
    return abs(pt_a[0] - pt_b[0]) + abs(pt_a[1] - pt_b[1])

def RemoveLeft(some_set, x):
    return {el for el in some_set if el[0] >= x[0]}

def RemoveRight(some_set, x):
    return {el for el in some_set if el[0] <= x[0]}

def RemoveBelow(some_set, x):
    return {el for el in some_set if el[1] >= x[1]}

def RemoveAbove(some_set, x):
    return {el for el in some_set if el[1] <= x[1]}

def RemoveAllExcept(some_set, other_set):
    return some_set & other_set

lines = sys.stdin.read().split('\n')
N = int(lines[0])

possible_c = set()
for x in range(101):
    for y in range(101):
        possible_c.add((x,y))

known_points = []

for i in range(1, N+1):
    np_text = lines[i].split(' ')
    new_point = (int(np_text[0]), int(np_text[1]), int(np_text[2]))
    for old_point in known_points:
        height_diff = new_point[2] - old_point[2]
        dist = TaxicabDistance(new_point, old_point)

        if dist == height_diff:
            # same quadrant, new_point closer to center
            if new_point[0] > old_point[0]:
                RemoveLeft(possible_c, new_point)
            elif new_point[0] < old_point[0]:
                RemoveRight(possible_c, new_point)

            if new_point[1] > old_point[1]:
                RemoveBelow(possible_c, new_point)
            elif new_point[1] < old_point[1]:
                RemoveAbove(possible_c, new_point)
        elif dist == -height_diff:
            # same quadrant, old_point closer to center
            if old_point[0] > new_point[0]:
                RemoveLeft(possible_c, old_point)
            elif old_point[0] < new_point[0]:
                RemoveRight(possible_c, old_point)

            if old_point[1] > new_point[1]:
                RemoveBelow(possible_c, old_point)
            elif old_point[1] < new_point[1]:
                RemoveAbove(possible_c, old_point)
        else:
            # different quadrants
            discrepancy = dist - abs(height_diff)
            # discrepancy is always even; the center has taxicab distance of 
            # exactly discrepancy/2 measured from one (or both) of the points
            # and lies between the two
            candidates = set()
            c_dist = discrepancy//2
            for j in range(c_dist + 1):
                if new_point[0] == old_point[0]:
                    if new_point[1] > old_point[1]:
                        candidates.add((new_point[0] - j, new_point[1] - c_dist + j))
                        candidates.add((new_point[0] + j, new_point[1] - c_dist + j))
                        candidates.add((old_point[0] - j, old_point[1] + c_dist - j))
                        candidates.add((old_point[0] + j, old_point[1] + c_dist - j))
                    else:
                        candidates.add((new_point[0] - j, new_point[1] + c_dist - j))
                        candidates.add((new_point[0] + j, new_point[1] + c_dist - j))
                        candidates.add((old_point[0] - j, old_point[1] - c_dist + j))
                        candidates.add((old_point[0] + j, old_point[1] - c_dist + j))
                if new_point[1] == old_point[1]:
                    if new_point[0] > old_point[0]:
                        candidates.add((new_point[0] - c_dist + j, new_point[1] + j))
                        candidates.add((new_point[0] - c_dist + j, new_point[1] - j))
                        candidates.add((old_point[0] + c_dist - j, old_point[1] + j))
                        candidates.add((old_point[0] + c_dist - j, old_point[1] - j))
                    else:
                        candidates.add((new_point[0] + c_dist - j, new_point[1] + j))
                        candidates.add((new_point[0] + c_dist - j, new_point[1] - j))
                        candidates.add((old_point[0] - c_dist + j, old_point[1] + j))
                        candidates.add((old_point[0] - c_dist + j, old_point[1] - j))

                if new_point[0] > old_point[0]:
                    if new_point[1] > old_point[1]:
                        candidates.add((new_point[0] - j, new_point[1] - c_dist + j))
                        candidates.add((old_point[0] + j, old_point[1] + c_dist - j))
                    elif new_point[1] < old_point[1]:
                        candidates.add((new_point[0] - j, new_point[1] + c_dist - j))
                        candidates.add((old_point[0] + j, old_point[1] - c_dist + j))
                if new_point[0] < old_point[0]:
                    if new_point[1] > old_point[1]:
                        candidates.add((new_point[0] + j, new_point[1] - c_dist + j))
                        candidates.add((old_point[0] - j, old_point[1] + c_dist - j))
                    elif new_point[1] < old_point[1]:
                        candidates.add((new_point[0] + j, new_point[1] + c_dist - j))
                        candidates.add((old_point[0] - j, old_point[1] - c_dist + j))
            # print("candidates for {", new_point, ',', old_point, "}:", candidates)
            possible_c &= candidates

        if len(possible_c) == 1:
            break

    known_points += [new_point]

if len(possible_c) != 1:
    raise Exception("no unique answer: " + str(len(possible_c)) + " possible c remaining")

(cx, cy) = possible_c.pop()
h = known_points[0][2] + TaxicabDistance(known_points[0], (cx, cy))
print(cx, cy, h)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
n = ni()
xyh = []
for _ in range(n):
    xyh.append(tuple(list(li())))
    
 
# 中心になりうる点を全探索
def search_cent(xyh: list):
    n = len(xyh)
    for x_cent in range(101):
        for y_cent in range(101):
            
            # 各点と中心との距離
            dist = []
            is_cent = True
            for x,y,_ in xyh:
                dist.append((abs(x-x_cent), abs(y-y_cent)))
                
            # 中心との距離と高さの差に矛盾が無いかチェック
            for i in range(n):
                for j in range(n):
                    if xyh[i][2] == 0 and xyh[j][2] == 0:
                        continue
                    
                    if (xyh[i][2]-xyh[j][2]) != -(sum(dist[i]) - sum(dist[j])):
                        is_cent = False
                        break
                if not is_cent:
                    break
 
            if is_cent:
                return x_cent, y_cent
 
                
x_cent, y_cent = search_cent(xyh)
h_cent = xyh[0][2] + abs(xyh[0][0] - x_cent) + abs(xyh[0][1] - y_cent)
 
print(x_cent, y_cent, h_cent)

Submission status: Runtime Error

Solution code:
n = int(input())
X = [[int(i) for i in input().split()] for j in range(n)]

x_s = 0
x_e = 100
y_s = 0
y_e = 100

for x, y, z in X:
    for x2, y2, z2 in X:
        if (x, y) == (x2, y2):
            continue
        d = abs(x-x2) + abs(y-y2)
        if d == z - z2:            
            if x < x2:
                x_e = min(x_e, x) #左側
            elif x > x2:
                x_s = max(x_s, x) #右側
            if y < y2:
                y_e = min(y_e, y) #上川
            else y > y2:
                y_s = max(y_s, y) #下側

        else:
            if x < x2:
                x_s = max(x_s, x) #左側
            elif x > x2:
                x_e = min(x_e, x) #右側
            if y < y2:
                y_s = max(y_s, y) #上川
            elif y > y2:
                y_e = min(y_e, y) #下側

x, y, z = X[0]
print(x_e, y_e, z + abs(x_e - x) + abs(y_e - y))

Submission status: Runtime Error

Solution code:
n = int(input())
xyh = []
for i in range(n):
    xyh.append(list(map(int, input().split())))
h = 1
while True:
    for cx in range(100):
        for cy in range(100):
            for i in range(n):
                if xyh[2] != max(0, h - abs(xyh[0]-cx) - abs(xyh[0]-cy)):
                    break
            if i == n - 1:
                print(cx, cy, h)
                exit()
    h += 1