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 .

Solution (Python):
n = int(input())
P = []
for _ in range(n):
  x, y, h = map(int, input().split())
  P.append([h, x, y])
P.sort(reverse=True)

for cx in range(101):
  for cy in range(101):
    H = P[0][0] + abs(P[0][1]-cx) + abs(P[0][2]-cy)
    for i in range(1,n):
      if max(H-abs(P[i][1]-cx)-abs(P[i][2]-cy), 0) != P[i][0]:
        break
    else:
      print(cx, cy, H)
      exit()

Solution (Python):
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
L.sort(key=lambda x:x[2],reverse=True)
for i in range(101):
  for j in range(101):
    s=L[0][2]+abs(i-L[0][0])+abs(j-L[0][1])
    for l in L[1:]:
      h=l[2]+abs(i-l[0])+abs(j-l[1])
      if s==h:
        continue
      elif l[2]==0 and s<h:
        continue
      else:
        break
    else:
      print(i,j,s)
      exit()

Solution (Python):



import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
2 3 5
2 1 5
1 2 5
3 2 5"""
        output = """2 2 6"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
0 0 100
1 1 98"""
        output = """0 0 100"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3
99 1 191
100 1 192
99 0 192"""
        output = """100 0 193"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """4
59 3 0
64 94 56
5 62 11
3 93 14"""
        output = """55 80 79"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    XYH = [list(map(int, input().split())) for _ in range(N)]
    XYH.sort(key=lambda x: x[2], reverse=True)

    CX = CY = H = 0
    flag = False
    for cx in range(101):
        if flag == True:
            break
        for cy in range(101):
            H = XYH[0][2]+abs(XYH[0][0]-cx)+abs(XYH[0][1]-cy)
            for xyh in XYH[1:]:
                x, y, h = xyh
                if h != max(H - abs(x-cx) - abs(y-cy), 0):
                    break
            else:
                flag = True
                CX = cx
                CY = cy
                break

    print(f"{CX} {CY} {H}")


if __name__ == "__main__":
    
    resolve()

Solution (Python):
n = int(input())
xyh = [tuple(map(int,input().split())) for i in range(n)]
for xi,yi,hi in xyh:
    if hi:
        xt,yt,ht = xi,yi,hi

for i in range(101):
    for j in range(101):
        a = ht+abs(i-xt)+abs(j-yt)
        for xi,yi,hi in xyh:
            x = max(a - abs(xi-i)-abs(yi-j),0)
            if hi != x:
                break
        else:
            print(i,j,a)
            exit(0)

Solution (Python):
n=int(input())
info=[list(map(int,input().split())) for i in range(n)]
for cx in range(0,101):
    for cy in range(0,101):
        H=-10**20
        lim=10**20
        for l in info:
            x,y,h=l 
            if h==0:
                 lim=min(lim,abs(x-cx)+abs(y-cy))
                 
            else:
                if H!=-10**20 and H!=abs(x-cx)+abs(y-cy)+h :break
                H=abs(x-cx)+abs(y-cy)+h 
            if H>lim:break
        else:
            print(cx,cy,H);exit()

Solution (Python):
n = int(input())
if n == 1:
    x, y, h = map(int, input().split())
    print(x, y, h)
    exit()
s = [list(map(int, input().split())) for _ in range(n)]
for i in range(101):
    for j in range(101):
        h = -1
        ok = 1
        for t in s:
            if t[2] == 0:
                ok += 1
            elif h == -1:
                h = abs(t[0] - i) + abs(t[1] - j) + t[2]
            else:
                h0 = abs(t[0] - i) + abs(t[1] - j) + t[2]
                if h == h0:
                    ok += 1
        if ok == n:
            for t in s:
                if abs(t[0] - i) + abs(t[1] - j) <= h:
                    if not h == abs(t[0] - i) + abs(t[1] - j) + t[2]:
                        ok = 0
                else:
                    if not t[2] == 0:
                        ok = 0
            if ok == n:
                print(i, j, h)
                exit()

Solution (Python):
N=int(input())
l=[list(map(int,input().split())) for i in range(N)]
for i,j,k in l:
   if k>0:
      fx,fy,fh=i,j,k
for i in range(0,101):
   for j in range(0,101):
      sw=0
      cer_h=fh+abs(fx-i)+abs(fy-j)
      for x,y,h in l:
         if max(cer_h-abs(i-x)-abs(j-y),0)!=h:
            sw=1
            break
      if sw==0:
         print(i,j,cer_h)
         exit()

Solution (Python):
n=int(input())
data=[]
for i in range(n):
    data.append(list(map(int,input().split())))
    
first_h_index=0
for i in range(n):
    if data[i][2] > 0:
        first_h_index=i
        break
    
for i in range(101):
    for j in range(101):
        h=data[first_h_index][2]+abs(data[first_h_index][0]-i)+abs(data[first_h_index][1]-j)
        for k in range(n):
            if data[k][2] != max(h-abs(data[k][0]-i)-abs(data[k][1]-j),0):
                break
        else:
            print(i,j,h)
            break

Solution (Python):
n=int(input())
data=[]
for i in range(n):
    data.append(list(map(int,input().split())))
    
first_h_index=0
for i in range(n):
    if data[i][2] > 0:
        first_h_index=i
        break
    
for i in range(101):
    for j in range(101):
        h=data[first_h_index][2]+abs(data[first_h_index][0]-i)+abs(data[first_h_index][1]-j)
        for k in range(n):
            if data[k][2] != max(h-abs(data[k][0]-i)-abs(data[k][1]-j),0):
                break
        else:
            print(i,j,h)
            exit()

Solution (Python):



def main():

    n = int(input())
    li = []
    for i in range(n):
        x, y, h = map(int, input().split())
        li.append({"x": x, "y": y, "h": h})
    li.sort(key=lambda x: x["h"], reverse=True)

    tops = []
    for i in range(101):
        for j in range(101):
            h = li[0]["h"] + abs(li[0]["x"] - i) + abs(li[0]["y"] - j)
            tops.append({"x": i, "y": j, "h": h})

    for i in range(1, n):
        tmp = []
        for j in range(len(tops)):
            x = li[i]["x"]
            y = li[i]["y"]
            h = li[i]["h"]
            topX = tops[j]["x"]
            topY = tops[j]["y"]
            topH = tops[j]["h"]
            if h == max(topH - abs(topX - x) - abs(topY - y), 0):
                tmp.append(tops[j])
        tops = tmp
    print(f"{tops[0]['x']} {tops[0]['y']} {tops[0]['h']}")


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
XYH = [[0, 0, 0] for _ in range(N)]
for i in range(N):
    XYH[i] = list(map(int, input().split()))

XYH.sort(key = lambda x: x[2], reverse = True)
for x in range(101):
    for y in range(101):
        diff_x = abs(XYH[0][0] - x)
        diff_y = abs(XYH[0][1] - y)
        H = XYH[0][2] + diff_x + diff_y
        for xyh in XYH[1:]:
            if xyh[2] != max(H - abs(xyh[0] - x) - abs(xyh[1] - y), 0):
                break
        else:
            print(x, y, H)
            exit()

Solution (Python):
def dist(h,xi, yi, cx, cy):
    return h + abs(xi - cx) + abs(yi - cy)

N = int(input())
P = []
for i in range(N):
    xi, yi, h= map(int, input().split())
    P.append([h, xi, yi])
P.sort(reverse = True)

for i in range(101):
    for j in range(101):
        H = dist(P[0][0], P[0][1], P[0][2],i, j)
        for p in P[1:]:
            if max(H - abs(p[1]-i)-abs(p[2]-j), 0) != p[0]:
                break
        else:
            print(i, j, H)
            break

Solution (Python):
def dist(a, b, x, y, h):
    return h + abs(a - x) + abs(b - y)

N = int(input())
P = []
for i in range(N):
    x, y, h = map(int, input().split())
    P.append([h, x, y])
P.sort(reverse = True)

for i in range(101):
    for j in range(101):
        H = dist(i, j, P[0][1], P[0][2], P[0][0])
        for p in P[1:]:
            if max(H - abs(p[1]-i)-abs(p[2]-j), 0) != p[0]:
                break
        else:
            print(i, j, H)
            break

Solution (Python):
n = int(input())
x_list = []
y_list = []
h_list = []

for i in range(n):
    a, b, c = map(int, input().split())
    x_list.append(a)
    y_list.append(b)
    h_list.append(c)

k = h_list.index(max(h_list))

for x in range(101):
    for y in range(101):
        h_max = h_list[k] + abs(x_list[k] - x) + abs(y_list[k] - y)
        
        for j in range(n):
            if h_list[j] == 0 :
                if h_max - (abs(x_list[j] - x) + abs(y_list[j] - y)) > 0 :
                    h_max = -1
            else:
                if h_max != abs(x_list[j] - x) + abs(y_list[j] - y) + h_list[j]:
                    h_max = -1
        
        if h_max != -1:
            print(str(x)+' '+str(y)+ ' '+ str(h_max))
            break

Solution (Python):
N = int(input())
xs, ys, hs = [],[],[]
for _ in range(N):
    x,y,h = map(int,input().split())
    if h != 0:
        xx,yy,hh = x,y,h
    xs.append(x)
    ys.append(y)
    hs.append(h)
for cx in range(101):
    for cy in range(101):
        H = hh+abs(xx-cx)+abs(yy-cy)
        if all([hs[i] == max(0,H-abs(cx-xs[i])-abs(cy-ys[i])) for i in range(N)]):
            print(cx,cy,H)
            exit(0)

Solution (Python):
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

for _ in range(0,n):
    if ab[_][2] !=0:
        x = ab[_][0]
        y = ab[_][1]
        h = ab[_][2]
        break

for i in range(101):
    for j in range(101):
        f = True
        l = abs(i-x)+abs(j-y)+h
        for k in range(0,n):
            dx = ab[k][0]
            dy = ab[k][1]
            dh = ab[k][2]
            if max(l-abs(i-dx)-abs(j-dy),0) ==dh:
                pass
            else:
                f = False
        if f:
            ansx =i
            ansy =j
            ansr = l
            break
print(str(ansx)+" "+str(ansy)+" "+str(ansr))

Solution (Python):

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

ans = []
X.sort(key=lambda x: x[2])
for c_x in range(0, 101):
    for c_y in range(0, 101):
        height = X[-1][2] + abs(X[-1][0] - c_x) + abs(X[-1][1] - c_y)
        flag = True
        for x, y, h in X:
            flag &= h == max(height - abs(x - c_x) - abs(y - c_y), 0)

        if flag:
            print(c_x, c_y, height)
            exit()

Solution (Python):
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
xyh = sorted(xyh, key=lambda x:(x[2]), reverse=True)

ans = -1, -1, -1
for cx in range(101):
    for cy in range(101):
        flg = True
        x, y, h = xyh[0][0], xyh[0][1], xyh[0][2]
        ch = abs(cx-x) + abs(cy-y) + h
        for i in range(1,n):
            x, y, h = xyh[i][0], xyh[i][1], xyh[i][2]
            tmph = max(ch - abs(cx-x) - abs(cy-y), 0)
            if h != tmph:
                flg = False
                break
        if flg:
            ans = cx, cy, ch
print(*ans)

Solution (Python):
N = int(input())
p = [0] * N
for i in range(N):
    p[i] = list(map(int, input().split()))

for i in range(N):
    if p[i][2] > 0:
        pp = p[i]

f = 0

for i in range(101):
    for j in range(101):
        H = pp[2] + abs(i - pp[0]) + abs(j - pp[1])
        for k in range(N):
            
            if p[k][2] != max(H - abs(i - p[k][0]) - abs(j - p[k][1]), 0):
                break
            if k == (N - 1):
                xa = i
                ya = j
                Ha = H
                f = 1
                break
        if f == 1:
            break
    if f == 1:
        break


print(xa, ya, Ha)

Solution (Python):
N=int(input())
L=[]
for h in range(N):
    Cx,Cy,h=map(int,input().split())
    L.append([h,Cx,Cy])
L.sort(reverse=True)

for x in range(101):
    for y in range(101):
        cond=True
        H=L[0][0]+abs(x-L[0][1])+abs(y-L[0][2])
        for i in range(1,N):
            h=L[i][0]+abs(x-L[i][1])+abs(y-L[i][2])
            if L[i][0]>0:
                if h!=H:
                    cond=False
                    break
            else:
                if h<H:
                    cond=False
                    break
        if cond:
            break
    if cond:
        break

print(x,y,H)

Solution (Python):
from itertools import product
xyh = []
xyh0 = []
N=int(input())
for _ in range(N):
    tmp1, tmp2, tmp3 = map(int, input().split())
    if tmp3 > 0:
        xyh.append((tmp1, tmp2, tmp3))
    else:
        xyh0.append((tmp1, tmp2, tmp3))
ans = None
for cx, cy in product(range(101), repeat=2):
    H = None
    H_lower = 1
    H_upper = 10**100
    is_ok = 1
    for x, y, h in xyh:
        if H is None:
            H = abs(x-cx)+abs(y-cy)+h
        else:
            if H != abs(x-cx)+abs(y-cy)+h:
                is_ok = 0
                break
    if not is_ok or H is None:
        continue
    for x, y, h in xyh0:
        H_upper = min(H_upper, abs(x-cx)+abs(y-cy))
    if H > H_upper or H < H_lower:
        continue
    ans = (cx, cy, H)
    break

print(*ans)

Solution (Python):
n=int(input())
xyh=[]
for i in range(n):
  x,y,h=map(int,input().split())
  xyh.append([h,x,y])
xyh.sort(reverse=True)
ans=0

for cx in range(101):
  for cy in range(101):
    for N in range(n):
      if abs(xyh[0][1]-cx)+abs(xyh[0][2]-cy)+xyh[0][0]>0:
        H=abs(xyh[0][1]-cx)+abs(xyh[0][2]-cy)+xyh[0][0]
      else:
        break
      if xyh[N][0]!=max(H-abs(xyh[N][1]-cx)-abs(xyh[N][2]-cy),0):
        break
      if N == n-1:
        ans=[cx,cy,H]
print(*ans)

Solution (Python):
import sys









MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def solve(info):
    for Cx in range(101):
        for Cy in range(101):
            height = abs(Cx - info[0][0]) + abs(Cy - info[0][1]) + info[0][2]
            flag = True
            for x,y,h in info[1:]:
                val = max(height - abs(Cx - x) - abs(Cy - y), 0)
                if h == val:
                    continue
                else:
                    flag = False
                    break
            if flag:
                return Cx, Cy, height

def Main():
    n = read_int()
    info = [tuple(read_ints()) for _ in range(n)]
    info.sort(key=lambda x: x[2], reverse=True)

    print(*solve(info))

if __name__ == '__main__':
    Main()

Solution (Python):




def solve(n,queries):
    def calcTopHeight(h,x,y,cx,cy):
        return h + abs(x-cx) + abs(y-cy)
    def calcHeight(h,x,y,cx,cy):
        return max(h - abs(x-cx) - abs(y-cy), 0)
    cand = [query for query in queries if query[2] != 0][0]
    for cx in range(101):
        for cy in range(101):
            cnt = 0
            probHeight = calcTopHeight(cand[2],cand[0],cand[1],cx,cy)
            for query in queries:
                x,y,h = query
                if calcHeight(probHeight,x,y,cx,cy) == h:
                    cnt += 1
            if cnt == n:
                return cx,cy,probHeight
    return -1,-1,-1


def main():
    N = int(int(input()))
    queries = [list(map(int,input().split())) for _ in range(N)]
    print(*solve(N,queries))
    return
    


if __name__ == '__main__':
    main()

Solution (Python):
from copy import copy
N=int(input())
K=100

Data=[]
for i in range(N):
    x,y,h=map(int,input().split())
    Data.append((x,y,h))

Data.sort(key=lambda x:-x[-1])
for i in range(N):
    x,y,h=Data[i]

    if i==0:
        C=[]
        for X in range(K+1):
            for Y in range(K+1):
                H=h+abs(x-X)+abs(y-Y)
                if H>0:
                    C.append((X,Y,H))
    else:
        D=[]
        for (X,Y,H) in C:
            if max(H-abs(x-X)-abs(y-Y),0)==h:
                D.append((X,Y,H))
        C=copy(D)

X,Y,H=C[0]
print(X,Y,H)

Solution (Python):
S=int(input())
L=[list(map(int,input().split())) for i in range(S)]
for i in range(S):
  if L[i][2]!=0:
    for cx in range(101):
      for cy in range(101):
        ans=0
        hpre=L[i][2]+abs(L[i][0]-cx)+abs(L[i][1]-cy)
        for j in range(S):
          if max(hpre-abs(cx-L[j][0])-abs(cy-L[j][1]),0)==L[j][2]:
            ans+=1
        if ans==S:
          print(cx,cy,hpre)
          exit()

Solution (Python):
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]

for i in l:
    if i[2] != 0:
        x,y,h = i


for cx in range(101):
    for cy in range(101):
        h_pre = h+abs(x-cx)+abs(y-cy)
        flag = True
        for i in range(n):
            X,Y,H = l[i]
            if H != max(h_pre-abs(X-cx)-abs(Y-cy),0):
                flag = False
        if flag:
            print(cx,cy,h_pre)
            exit()

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
x, y, h = zip(*[list(map(int, input().split())) for _ in range(N)])
j = -1
for i in range(N):
    if h[i] != 0:
        j = i
        break
for cx in range(101):
    for cy in range(101):
        H = h[j] + abs(x[j] - cx) + abs(y[j] - cy)
        for i in range(N):
            if h[i] != max(H - abs(x[i] - cx) - abs(y[i] - cy), 0):
                break
        else:
            print(cx, cy, H)

Solution (Python):
n = int(input())
hs = [list(map(int, input().split())) for _ in range(n)]
hs.sort(key= lambda x: x[2], reverse = True)

def main():
    for x in range(101):
        for y in range(101):
            height = hs[0][2] + abs(x-hs[0][0]) + abs(y-hs[0][1])
            for i in range(1,n):
                if max(height-(abs(x-hs[i][0]) + abs(y-hs[i][1])),0)== hs[i][2]:
                    pass
                else:
                    break
                
                if i ==n-1:
                    print(x,y,height)
                    return x,y,height
main()

Solution (Python):
N = int(input())
K = 101
D = []
for _ in range(N):
    x, y, h = map(int, input().split())
    D.append((x,y,h))
D.sort(key=lambda x:x[2], reverse=True)
for i in range(K):
    for j in range(K):
        flg = True
        H = -1
        for x, y, h in D:
            if h == 0:
                if H > abs(x-i) + abs(y-j):
                    flg = False
                    break
                continue
            if H == -1:
                H = abs(x-i) + abs(y-j) + h
                continue
            if H != abs(x-i) + abs(y-j) + h:
                flg = False
                break
        if flg:
            print(i,j,H)
            exit()

Solution (Python):
n=int(input())
data=[]
for i in range(n):
    X,Y,H=map(int,input().split())
    data.append([H,X,Y])
data.sort(reverse=True)
for i in range(101):
    for j in range(101):
        H=abs(data[0][1]-i)+abs(data[0][2]-j)+data[0][0]
        for k in range(1,n):
            if max(H-abs(data[k][1]-i)-abs(data[k][2]-j),0)==data[k][0]:
                continue
            else:
                break
        else:
            print(str(i), str(j), str(H))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines




def check(pos):
    
    flg = True
    for x, y, h in xyh[1:]:
        if h != max(pos[2] - abs(x - pos[0]) - abs(y - pos[1]), 0):
            flg = False
            break
    return flg


def main(xyh):
    
    A = []
    
    
    xyh.sort(key=lambda x: x[2], reverse=True)
    x, y, h = xyh[0]
    for i in range(101):
        for j in range(101):
            H = h + abs(x - i) + abs(y - j)
            A.append([i, j, H])
    
    for pos in A:
        if check(pos):
            break
    top = pos
    return top


n = int(readline())
xyh = [list(map(int, readline().split())) for _ in range(n)]

top = main(xyh)
print(*top)

Solution (Python):
n=int(input())
alist=[list(map(int, input().split())) for i in range(n)]
alist.sort(key=lambda x:x[2],reverse=True)
for i in range(101):
  for j in range(101):
    h=abs(alist[0][0]-i)+abs(alist[0][1]-j)+alist[0][2]
    ans=True
    for k in range(n):
      if max((h-abs(alist[k][0]-i)-abs(alist[k][1]-j)),0)!=alist[k][2]:
        ans=False 
    if ans:
      ansx=i
      ansy=j
      ansh=h
print(ansx,ansy,ansh)

Solution (Python):
n=int(input())
xyh=sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: -x[2])

for cx in range(0,101):
    for cy in range(0,101):
        flag=True
        h=abs(cx-xyh[0][0])+abs(cy-xyh[0][1])+xyh[0][2]
        for i in range(n):
            if max(h-abs(cx-xyh[i][0])-abs(cy-xyh[i][1]), 0)!=xyh[i][2]:
                flag=False
        if flag:
            print(cx,cy,h)
            exit()

Solution (Python):
n=int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda x:x[2], reverse=True)

ansh=-1
ans=[[]]
flag=True
for cx in range(0,101):
  if flag==False:
    break
    
  for cy in range(0,101):
    ansh = 0
    for pira in xyh:
      if ansh==0:
        ansh=pira[2]+(abs(cx-pira[0])+abs(cy-pira[1]))
        ans[0]=[cx,cy,ansh]
        
      elif len(ans[0])>0 and max(ansh -(abs(cx-pira[0])+abs(cy-pira[1])), 0) != pira[2]:
        ans[0]=[]
    if len(ans[0])>0:
      flag=False
      break
print(*ans[0])

Solution (Python):
n = int(input())

xyh = [list(map(int, input().split())) for _ in range(n)]

xyh.sort(key=lambda x:x[2], reverse=True)

for i in range(101):
    meta = False
    for j in range(101):
        H = 0
        flag = True
        for x, y, h in xyh:
            
            if H == 0:
                H = abs(x - i) + abs(y - j) + h
            elif max(H - abs(x - i) - abs(y - j), 0) != h:
                flag = False
                break
        if flag:
            print(i, j, H)
            meta = True
            break
    if meta:
        break

Solution (Python):
import sys
n = int(input())
inf_ls = [[0]*3 for _ in range(n)]
for i in range(n):
    x,y,h = map(int,input().split())
    inf_ls[i] = x,y,h
for Cx in range(101):
    for Cy in range(101):
        this_is_C = True
        H_set = set()
        zero_ls = []
        for i in range(n):
            x,y,h = inf_ls[i]
            if h > 0:
                H = abs(x-Cx) + abs(y-Cy) + h
                H_set.add(H)
            else:
                zero_ls.append([x,y])
        if len(H_set) != 1:
            this_is_C = False
            continue
        H = list(H_set)[0]
        for x,y in zero_ls:
            if H - abs(x-Cx) - abs(y-Cy) > 0:
                this_is_C = False
        if this_is_C:
            print(Cx,Cy,H)
            exit()

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())  

N = I()
xyh = [tuple(MI()) for i in range(N)]

for i in range(101):  
    for j in range(101):  
        for k in range(N):
            x,y,h = xyh[k]
            if h != 0:
                H = h + abs(x-i) + abs(y-j)
                break
        for k in range(N):
            x,y,h = xyh[k]
            if h != max(H - abs(x-i) - abs(y-j),0):
                break
        else:
            print(i,j,H)
            exit()

Solution (Python):





N = int(input())
















data = []
for i in range(N):
    data.append(list(map(int, input().split())))
data = sorted(data, reverse=True, key=lambda x:x[2])

ans_x = 0
ans_y = 0
ans_h = 0
for i in range(101):
    for j in range(101):
        H = -1
        for l in data:
            if H == -1:
                _ = l[2] + abs(l[0] - i) + abs(l[1] - j)
                H = _
            else:
                h_i_cal = max(H - abs(l[0] - i) - abs(l[1] - j), 0)
                if h_i_cal != l[2]:
                    break
        else:
            ans_x = i
            ans_y = j
            ans_h = H

print(ans_x, ans_y, ans_h)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *XYH = map(int, read().split())

    for x, y, h in zip(*[iter(XYH)] * 3):
        if h != 0:
            x0, y0, h0 = x, y, h

    for cx in range(101):
        for cy in range(101):
            H = h0 + abs(x0 - cx) + abs(y0 - cy)
            ok = True
            for x, y, h in zip(*[iter(XYH)] * 3):
                if max(H - abs(x - cx) - abs(y - cy), 0) != h:
                    ok = False
                    break
            if ok:
                print(cx, cy, H)
                return

    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *XYH = map(int, read().split())

    for cx in range(101):
        for cy in range(101):
            ok = 10 ** 9 + 100
            ng = 0
            while ok - ng > 1:
                mid = (ok + ng) // 2
                valid = True
                for x, y, h in zip(*[iter(XYH)] * 3):
                    if max(mid - abs(x - cx) - abs(y - cy), 0) < h:
                        valid = False
                        break
                if valid:
                    ok = mid
                else:
                    ng = mid
            H = ok
            valid = True
            for x, y, h in zip(*[iter(XYH)] * 3):
                if max(H - abs(x - cx) - abs(y - cy), 0) != h:
                    valid = False
                    break
            if valid:
                print(cx, cy, H)
                return

    return


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)

for cx in range(0,101):
    for cy in range(0,101):
        x,y,h=xyh[0]
        H=h+abs(x-cx)+abs(y-cy)
        if H<0:
            continue

        for i in range(1,n):
            x,y,h=xyh[i]

            if h!=max(H-abs(x-cx)-abs(y-cy),0):
                break
        else:
            print('{} {} {}'.format(cx,cy,H))
            exit(0)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    xyh = [None] * N
    for i in range(N):
        xyh[i] = tuple(map(int, input().split()))

    for i in range(N):
        if xyh[i][2] > 0:
            Bx, By, Bh = xyh[i]
            break

    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H = Bh + abs(Bx - Cx) + abs(By - Cy)
            is_ok = True
            for x, y, h in xyh:
                if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:
                    is_ok = False
                    break
            if is_ok:
                print(Cx, Cy, H)
                exit()


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    n = ii()
    x = [0]*n
    y = [0]*n
    h = [0]*n
    for i in range(n):
        x[i], y[i], h[i] = mi()
    idx = h.index(max(h))
    for cx in range(101):
        for cy in range(101):
            flag = True
            H = abs(cx-x[idx])+abs(cy-y[idx])+h[idx]
            for i in range(n):
                tmp = abs(cx-x[i])+abs(cy-y[i])
                if h[i] == 0:
                    flag &= (tmp >= H)
                else:
                    tmp += h[i]
                    flag &= (tmp==H)
            if flag:
                print(cx, cy, H)
                return
            
            
        
        




if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
z=[]
aa=[]
for i in range(n):
     z.append(list(map(int,input().split())))
for cx in range(101):
    for cy in range(101):
        ans=set()
        for i in range(n):
            x,y,h=z[i][0],z[i][1],z[i][2]
            if h!=0:
                tmp=h+abs(x-cx)+abs(y-cy)
                ans.add(tmp)
        if len(ans)==1:
            ans=list(ans)
            aa.append((ans[0],cx,cy))

for a,cx,cy in aa:
    flg=True
    for i in range(n):
        x,y,h=z[i][0],z[i][1],z[i][2]
        if h!=max(a-abs(x-cx)-abs(y-cy),0):
                flg=False
    if flg:
        print(cx,cy,a)
        exit()

Solution (Python):
n,*xyh = map(int,open(0).read().split())
a = sorted([(xyh[i*3],xyh[i*3+1],xyh[i*3+2]) for i in range(n)],key=lambda x:x[2],reverse=True)
for i in range(101):
  for j in range(101):
    dh = abs(a[0][0]-i)+abs(a[0][1]-j)+a[0][2]
    for x,y,h in a[1:]:
      if h != max(dh-abs(x-i)-abs(y-j),0):
        break
    else:
      print(i,j,dh)
      exit()

Solution (Python):
n=int(input())
ar=[]
def g(i):
    return i[2]
for _ in range(n):
    a,b,c=map(int,input().strip().split(" "))
    ar.append((a,b,c))
ar.sort(key=g,reverse=True)

for x in range(101):
    for y in range(101):
        t=1
        p=(x,y)
        h=0
        for i in range(n):
            if h==0:
                h=ar[i][2]+abs(ar[i][0]-x)+abs(ar[i][1]-y)
            elif ar[i][2]>0:
                c_h=ar[i][2]+abs(ar[i][0]-x)+abs(ar[i][1]-y)
                if c_h!=h:
                    t=0
                    break
            else:
                if h-(abs(ar[i][0]-x)+abs(ar[i][1]-y))>0:
                    t=0
                    break
        if t==1:
            ans=(x,y,h)
            break
for i in ans:
    print(i,end=" ")