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):
import sys
MOD = 10**9 + 7


def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    p = [list(map(int,input().split())) for _ in range(n)]
    p = sorted(p,key=lambda x: -x[2])
    for x in range(0,101):
        for y in range(0,101):
            h = p[0][2] + abs(x-p[0][0]) + abs(y-p[0][1])
            flag = 1
            for (a,b,c) in p:
                if c != max(0,h-abs(x-a)-abs(y-b)):
                    flag = 0
                    break
            if flag == 1:
                print(x,y,h)
                exit(0)
if __name__ == '__main__':
    main()

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)


for i in range(101):
    for j in range(101):
        H = -1
        flag = True
        for k in range(n):
            h, x, y = XYH[k]
            if H == -1:
                H = abs(x-i)+abs(y-j)+h
            else:
                if max(H-abs(x-i)-abs(y-j), 0) != h:
                    flag = False
        if flag:
            print(i, j, H)
            exit()

Solution (Python):
n=int(input())
info=[]
import sys
for i in range(n):
  x,y,h=map(int,input().split())
  info.append([x,y,h])
for x in range(0,101):
  for y in range(0,101):
    for A in info:
      if A[2]!=0:
        h=A[2]+abs(x-A[0])+abs(y-A[1])
        break
    failflag=0
    for A in info:
      if A[2]!=max(0,h-abs(x-A[0])-abs(y-A[1])):
        failflag=1
        break
    if failflag==0:
      print(x)
      print(y)
      print(h)
      sys.exit()

Solution (Python):
from sys import exit

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

for cx in range(101):
    for cy in range(101):
        correct_flag = True
        for i in range(n):
            x, y, h = l[i]
            if h > 0:
                res_h = abs(x - cx) + abs(y - cy) + h
                break
        for i in range(n):
            x, y, h = l[i]
            if max(res_h - abs(x - cx) - abs(y - cy), 0) != h:
                correct_flag = False
                break
        if correct_flag:
            print(cx, cy, res_h)
            exit()

Solution (Python):
def solve():
    n = int(input())
    x = [0 for _ in range(n)]
    y = [0 for _ in range(n)]
    h = [0 for _ in range(n)]
    for i in range(n):
        x[i], y[i], h[i] = map(int, input().split())
        if h[i]:
            xn, yn, hn = x[i], y[i], h[i]

    for cx in range(101):
        for cy in range(101):
            H = hn + abs(xn - cx) + abs(yn - cy)
            if all(h[i] == max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) for i in range(n)):
                print(cx, cy, H)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    XYH = [list(map(int, input().split())) for _ in range(n)]

    info = []
    for x, y, h in XYH:
        if h == 0:
            continue
        info.append([x, y, h])

    if len(info) == 1:
        print(*info[0])
        exit()

    for Cx in range(100 + 1):
        for Cy in range(100 + 1):
            tmp = set()
            for x, y, h in info:
                if h == 0:
                    continue
                H = h + abs(x - Cx) + abs(y - Cy)
                tmp.add(H)
            if len(tmp) == 1:
                print(Cx, Cy, *list(tmp))
                exit()


if __name__ == '__main__':
    resolve()

Solution (Python):
import numpy as np
from itertools import product

N = int(input())

points = []
non_zero_point = None
for _ in range(N):
    x, y, h = map(int, input().split(' '))
    points.append((x, y, h))
    if non_zero_point is None and h > 0:
        non_zero_point = (x, y, h)

points = np.array(points)
zeros = np.zeros(shape=N, dtype=np.int64)

for cx, cy in product(range(0, 101), repeat=2):
    H = abs(non_zero_point[0] - cx) + abs(non_zero_point[1] - cy) + non_zero_point[2]
    h = np.maximum(H - np.abs(points[:, 0] - cx) - np.abs(points[:, 1] - cy), zeros)
    if np.all(h == points[:, 2]):
        print(cx, cy, H)
        break

Solution (Python):
N, *_XYH = map(int, open(0).read().split())
XYH = list(zip(*[iter(_XYH)]*3))

C = [(x, y) for x in range(101) for y in range(101)]

for c in C:
    for i, xyh in enumerate(sorted(XYH, key=lambda x: x[2], reverse=True)):
        if i==0:
            H = xyh[2] + abs(xyh[0] - c[0]) + abs(xyh[1] - c[1])
        elif max(H - abs(xyh[0] - c[0]) - abs(xyh[1] - c[1]), 0) == xyh[2]:
            is_ans = True
        else:
            is_ans = False
            break
        
    if is_ans:
        break

print(*c, H)

Solution (Python):

import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N = z()
X, Y, H = [], [], []
Cx, Cy, Hc = 0, 0, 0
for i in range(N):
    x, y, h = zz()
    if (h != 0):
        x_t, y_t, h_t = x, y, h
    X.append(x)
    Y.append(y)
    H.append(h)
for Cx, Cy in itertools.product(range(0, 101), repeat=2):
    Hc = h_t + abs(Cx-x_t) + abs(Cy - y_t)
    
    ok_count = 0
    for x, y, h in zip(X, Y, H):
        tmp = Hc - abs(Cx - x) - abs(Cy - y)
        if (h == max(tmp, 0)):
            ok_count += 1
        else:
            break
    if (ok_count == N):
        print(Cx, Cy, Hc)
        exit()

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

ans = []
for i in range(101):
  for j in range(101):
    h.sort(key=lambda x: -x[2])
    hmax = h[0][2] + abs(i-h[0][0]) + abs(j-h[0][1])
    for k in range(1,n):

      if max(hmax - abs(h[k][0] - i) - abs(h[k][1] - j) , 0) != h[k][2]:
        break

    else:
      ans = [i,j,hmax]
    
    if(len(ans)):
      break
  if(len(ans)):
    break

ans = map(str,ans)
print(' '.join(ans))

Solution (Python):

import sys
input = lambda: sys.stdin.readline().rstrip()
 
l = []
for _ in range(int(input())):
    t = list(map(int,input().split()))
    l.append(t)
    if t[2]: 
        x,y,h = t[0], t[1], t[2]
        
for X in range(101):
    for Y in range(101):
        H = h + abs(x - X) + abs(y - Y)
        if all(h==max(H - abs(x-X) - abs(y-Y), 0) for x,y,h in l): print(X, Y, H)

Solution (Python):
l=[]
for _ in range(int(input())):
  t=[*map(int,input().split())]
  l+=[t]
  if t[2]: x,y,h=t
for X in range(101):
  for Y in range(101):
    H=h+abs(x-X)+abs(y-Y)
    if all(h==max(H-abs(x-X)-abs(y-Y),0) for x,y,h in l): print(X,Y,H)

Solution (Python):
l=sorted([[*map(int,input().split())] for _ in range(int(input()))],key=lambda k:-k[2])
x,y,h=l[0]
for X in range(101):
  for Y in range(101):
    H=h+abs(x-X)+abs(y-Y)
    if all(h==max(H-abs(x-X)-abs(y-Y),0) for x,y,h in l): print(X,Y,H)

Solution (Python):
f=lambda:map(int,input().split())
n=int(input())
lh,lz=[],[]
for _ in range(n):
  x,y,h=f()
  if h: lh+=[(x,y,h)]
  else: lz+=[(x,y)]
for X in range(101):
  for Y in range(101):
    x,y,h=lh[0]
    H=h+abs(x-X)+abs(y-Y)
    for x,y,h in lh:
      if H!=h+abs(x-X)+abs(y-Y): break
    else:
      if all(H-abs(x-X)-abs(y-Y)<1 for x,y in lz):
        print(X,Y,H)

Solution (Python):
n = int(input())
dat = []
for _ in range(n):
    a,b,c = map(int,input().split())
    dat.append( [a,b,c] )
can = True

for x in range(101):
    for y in range(101):
        for i in range(n):
            h = None
            can = True
            xx, yy, hh = dat[i]
            h = hh + abs(xx - x) + abs(yy - y)
            for j in range(n):
                xx, yy, hh = dat[j]
                canh = h - abs(xx - x) - abs(yy - y)
                canh = max(canh, 0)
                if canh != hh:
                    can = False
            if can:
                break
        if can:
            break
    if can:
        break
print(x, y, h)

Solution (Python):
N=int(input())
x=[list(map(int,input().split())) for _ in range(N)]
x.sort(key=lambda x:-x[2])
dp=[[0]*101 for i in range(101)]
bp=[[0]*101 for i in range(101)]
for j in range(101):
  for k in range(101):
    a,b,c=x[0]
    r=0
    asa=abs(a-j)+abs(b-k)+c
    for i in range(N):
      count=abs(x[i][0]-j)+abs(x[i][1]-k)
      if x[i][2]==max(asa-count,0):
        r+=1
    if r==N:
      print(j,k,asa)
      exit()

Solution (Python):
import sys
import numpy as np

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(101):
    for cy in range(101):
        x, y, h = xyh[0]
        tmp_h = abs(cy - y) + abs(cx - x) + h
        H = np.zeros(n, dtype=np.bool)
        for i, a in enumerate(xyh):
            H[i] = a[2] == max(tmp_h - abs(cx - a[0]) - abs(cy - a[1]), 0)
        if np.all(H):
            print(cx, cy, tmp_h)
            sys.exit()

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

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

for cx in range(101):
    for cy in range(101):
        needH = -1
        for x, y, h in H:
            if h > 0:
                tmp = h+abs(x-cx)+abs(y-cy)
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break
        if needH == -2:
            continue
        f = 1
        for x, y, h in H:
            if h == 0:
                if max(needH-abs(x-cx)-abs(y-cy), 0) != 0:
                    f = 0
                    break
        if f:
            print(cx, cy, needH)
            exit()

Solution (Python):
N=int(input())
q=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        F=1
        r=[]
        for k in range(101):
            x,y,h=q[k]
            if h > 0:
              break
            r.append([x,y])
        s=h+abs(x-i)+abs(y-j)
        for x,y,h in q[1:]:
            if h==0:
                r.append([x,y])
                continue
            y=h+abs(x-i)+abs(y-j)
            if s!=y:
              F=0
              break
        if r:
          for x,y in r:
            if s-abs(x-i)-abs(y-j) > 0:
              F=0
              break
        if F==1:
          print(i,j,s)
          exit()

Solution (Python):
n = int(input())
L = []
for _ in range(n):
    x, y, h = map(int, input().split())
    if h > 0:
        sx, sy, sh = x, y, h
    L.append((x, y, h))
for cy in range(101):
    for cx in range(101):
        d = abs(sx - cx) + abs(sy - cy)
        H = sh + d
        for x, y, h in L:
            if h == 0:
                if H > abs(x - cx) + abs(y - cy):
                    break
            else:
                if H - abs(x - cx) - abs(y - cy) != h:
                    break
        else:
            print(cx, cy, H)
            exit()

Solution (Python):
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
A.sort(key=lambda x: x[2], reverse=True)
for c_x in range(101):
    for c_y in range(101):
        H = -1
        H_upper = 10**9
        for i, v in enumerate(A):
            if v[2] == 0:
                H_upper = min(H_upper, abs(c_x - v[0]) + abs(c_y - v[1]))
                if H_upper < H:
                    break
            else:
                tmp_H = abs(c_x - v[0]) + abs(c_y - v[1]) + v[2]
                if H == -1:
                    H = tmp_H
                elif H != tmp_H:
                    break
            if i == N-1:
                if H == -1:
                    print(c_x, c_y, H_upper)
                else:
                    print(c_x, c_y, H)

Solution (Python):
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
c = 0
for x,y,h in xyh:
    if h==0:
        c += 1
    else:ans = [x,y,h]
if c==n-1:
    print(*ans)
    exit()

for i in range(101):
    for j in range(101):
        a = -1
        ok = True
        for x,y,h in xyh:
            if h>0:
                if a==-1:
                    a = h+abs(x-i)+abs(y-j)
                elif h+abs(x-i)+abs(y-j)!=a:
                    ok = False
        if ok:
            print(i,j,a)
            exit()

Solution (Python):
from itertools import product
def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(list(map(int, input().split())))
    for a in A:
        if a[2] > 0:
            t = a
            break
    for x, y in product(range(0, 101), repeat = 2):
        H = t[2] + abs(t[0] - x) + abs(t[1] - y)
        for a in A:
            if a[2] == 0 and H > abs(a[0] - x) + abs(a[1] - y):
                break
            elif a[2] != 0 and a[2] != H - abs(a[0] - x) - abs(a[1] - y):
                break
        else:
            ansx, ansy = x, y
            break
    H = t[2] + abs(t[0] - ansx) + abs(t[1] - ansy)
    print('{} {} {}'.format(ansx, ansy, H))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
lis = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        sx, sy, sh = x, y, h
    lis.append((x, y, h))
for i in range(101):
    for j in range(101):
        high = sh + abs(sx - i) + abs(sy - j)
        judge = True
        for x, y, h in lis:
            if h > 0 and high != h + abs(x - i) + abs(y - j):
                judge = False
                break
            if h == 0 and high > abs(x - i) + abs(y - j):
                judge = False
                break
        if judge:
            print(i, j, sh + abs(sx - i) + abs(sy - j))
            exit()

Solution (Python):
N = int(input())
lis = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        sx, sy, sh = x, y, h
    lis.append((x, y, h))
for i in range(101):
    for j in range(101):
        high = sh + abs(sx - i) + abs(sy - j)
        judge = -1
        for x, y, h in lis:
            if h > 0 and high != h + abs(x - i) + abs(y - j):
                judge = 0
                break
        if judge == 0:
            continue
        for x, y, h in lis:
            if h == 0 and high > abs(x - i) + abs(y - j):
                judge = 0
                break
        if judge == 0:
            continue
        
        print(i, j, sh + abs(sx - i) + abs(sy - j))
        exit()

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

def esth(x, y, h, cx, cy):
    return h + abs(x-cx) + abs(y-cy)


for cx in range(101):
    for cy in range(101):
        f = True
        ch = 0
        for x, y, h in xyh:
            if ch == 0 and h > 0:
                ch = esth(x, y, h, cx, cy)
            elif h > 0:
                if ch != esth(x, y, h, cx, cy):
                    f = False
                    break
            else:
                if max(ch - abs(x-cx) - abs(y-cy), 0) != h:
                    f = False
                    break
        if f:
            print('{} {} {}'.format(cx, cy, ch))
            break

Solution (Python):
n = int(input())
xyh = []
for i in range(n):
    temp = list(map(int,input().split()))
    if temp[2] > 0:
        x,y,h = temp[0],temp[1],temp[2]
    xyh.append(temp)
for i in range(101):
    for j in range(101):
        for k in xyh:
            if k[2] > 0 and k[2]+abs(k[0]-j)+abs(k[1]-i) != h+abs(x-j)+abs(y-i):
                break
            elif k[2]+abs(k[0]-j)+abs(k[1]-i) < h+abs(x-j)+abs(y-i):
                break
        else:
            print(j,i,h+abs(x-j)+abs(y-i))
            exit()

Solution (Python):















mod = int(1e9+7)

INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    a = [0] * n
    b = [0] * n
    c = [0] * n
    for i in range(n):
        a[i],b[i],c[i] = readInt()
    for i in range(101):
        for j in range(101):
            for k in range(max(c),max(c)+105):
                res = False
                for l in range(n):
                    if max(k-abs(a[l]-i)-abs(b[l]-j),0)!=c[l]:
                        res = True
                        break
                if res:
                    continue
                else:
                    print(i,j,k)
                    return
    return

if __name__=='__main__':
    main()

Solution (Python):





def main():
    N = int(input())

    x, y, h = [None] * N, [None] * N, [None] * N

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

    for cx in range(0, 101):
        for cy in range(0, 101):
            first = True
            notans = False
            for i in range(N):
                
                if h[i] > 0:
                    H = h[i] + abs(x[i]-cx) + abs(y[i]-cy)
                    if first:
                        first = False
                        pre_H = H
                    else:
                        if H != pre_H:
                            break
            if H == pre_H:
                for i in range(N):
                    if h[i] == 0:
                        if H - abs(x[i]-cx) - abs(y[i]-cy) > 0:
                            notans = True
                            break

                if notans:
                    continue

                print(cx, cy, H)
                return None


main()

Solution (Python):

import sys

def solve(N: int, X: "List[int]", Y: "List[int]", H: "List[int]"):
    def calc_h(cx, cy):
        h = None
        for xx, yy, hh in filter(lambda xyh: xyh[2]>0, zip(X, Y, H)):
            th = hh + abs(cx - xx) + abs(cy - yy)
            if h is not None and th != h:
                return None
            h = th
        h = h if h else 1
        for xx, yy, _ in filter(lambda xyh: xyh[2]==0, zip(X, Y, H)):
            if abs(cx - xx) + abs(cy - yy) < h:
                return None
        return h

    for cx in range(101):
        for cy in range(101):
            h = calc_h(cx, cy)
            if h is not None:
                return cx, cy, h



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = [int()] * (N)  
    y = [int()] * (N)  
    h = [int()] * (N)  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        h[i] = int(next(tokens))
    print(*solve(N, x, y, h))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
def k(H,cx,cy,f):
    for x,y,h in f:
        if h==max(H-abs(x-cx)-abs(y-cy),0):
            continue
        else:
            return
    print(cx,cy,H)
    exit()
for x,y,h in f:
    if h==0:
        continue
    for cx in range(101):
        for cy in range(101):
            H=h+abs(x-cx)+abs(y-cy)
            k(H,cx,cy,f)

Solution (Python):
from operator import itemgetter
n = int(input())
data = []
for _ in range(n):
    x,y,h = map(int,input().split())
    data.append((x,y,h))
data.sort(key=itemgetter(2),reverse=True)
for x in range(101):
    for y in range(101):
        c = -1
        for a,b,h in data:
            if c == -1:
                c = h+abs(a-x)+abs(b-y)
            else:
                if h != max(c-abs(a-x)-abs(y-b),0):
                    break
        else:
            print(x,y,c)
            exit()

Solution (Python):
def solve():
    n = int(input())
    
    P = set()
    for i in range(n):
        x,y,h = map(int,input().split())
        if h != 0:
            P.add((x,y,h))
    x,y,h = P.pop()
    if not P:
        return x,y,h
    for cx in range(101):
        for cy in range(101):
            H = h + abs(x-cx) + abs(y-cy)
            for p in P:
                if H != p[2] + abs(p[0]-cx) + abs(p[1]-cy):
                    break
            else:
                return cx,cy,H
        
if __name__ == '__main__':
    print(*(solve()))

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

d = {}
l = []
p = 0

for i in range(N):
  l.append(list(map(int, input().split())))

while True:
  if(l[0][2] == 0):
    l.append(l[0])
    del l[0]
  else:
    x, y, h= l[0]
    for i in range(101):
      for j in range(101):
        d[(i, j)] = abs(i- x)+ abs(j- y)+ h
    break

for k in range(N- 1):
  x, y, h = l[k+ 1]
  if(h == 0):
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)]- abs(i- x)- abs(j- y)> 0):
            del d[(i, j)]
  else:
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)] != abs(i- x)+ abs(j- y)+ h):
            del d[(i, j)]

zahyou, height = list(d.items())[0]
  
print("{0[0]} {0[1]} {1}".format(zahyou, height))

Solution (Python):
n = int(input())
low = 0
hi = 10**9

li = []
lin = []

for _ in range(n):
    x,y,h = map(int,input().split())
    if h != 0:
        li.append((x,y,h))
    lin.append((x,y,h))

for i in range(101):
    for j in range(101):
        flag = True
        h = li[0][2]+abs(i-li[0][0])+abs(j-li[0][1])
        for a,b,c in lin:
            if max(h-abs(i-a)-abs(j-b),0) != c:
                flag = False
                break
        if flag:
            print(i,j,h)
            exit()

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

sortthird = lambda x: x[2]
l.sort(key = sortthird)

for i in range(101):
    for j in range(101):
        ref = l[-1][2] + abs(l[-1][0] - i) + abs (l[-1][1] - j)
        for k in range(n):
            if l[k][2] == max(0, ref - abs(l[k][0] - i) - abs (l[k][1] - j)):
                continue
            else:
                break
        else:
            print(i, j, ref)
            exit()

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

for x, y, h in xyh:
    if h!= 0:
        x0, y0, h0 = (x, y, h)
        break

for i in range(101):
    for j in range(101):
        res = 1
        for x, y, h in xyh:
            if h == max(h0+abs(x0-i)+abs(y0-j)-abs(x-i)-abs(y-j), 0):
                res *= 1
            else:
                res *= 0
        if res:
            print(i, j, h0 + abs(x0-i) + abs(y0-j))
            exit()

Solution (Python):
import sys



N = int(input())
xs = []
ys = []
hs = []
reference = None
for i in range(N):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)
    
    if h > 0:
        reference = (x, y, h)

for cx in range(0, 100+1):
    for cy in range(0, 100+1):
        
        rx, ry, rh = reference
        ref_H = rh + abs(rx-cx) + abs(ry-cy)
        
        ok = True
        for i in range(N):
            calc_H = max(ref_H - abs(xs[i]-cx) - abs(ys[i]-cy), 0)
            if calc_H != hs[i]:
                ok = False
                break
        if ok:
            print(cx, cy, ref_H)
            sys.exit(0)

Solution (Python):
N=int(input())
x=[]
y=[]
h=[]
for i in range(N):
  a,b,c=map(int,input().split())
  x.append(a)
  y.append(b)
  h.append(c)
field=[[-1 for i in range(101)] for i in range(101)]
for i in range(N):
  for j in range(101):
    for k in range(101):
      if(h[i]!=0):
        if(field[j][k]==-1):
          field[j][k]=h[i]+abs(j-x[i])+abs(k-y[i])
        elif(field[j][k]!=h[i]+abs(j-x[i])+abs(k-y[i])):
          field[j][k]=-2
      else:
        if(field[j][k]>h[i]+abs(j-x[i])+abs(k-y[i])):
          field[j][k]=-2
cx=0
cy=0
H=0
for i in range(101):
  for j in range(101):
    if(field[i][j]>=0):
      cx=i
      cy=j
      H=field[i][j]
print(cx,cy,H)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint


INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
xyh = LI(n)

xyh = mysort(xyh,2,True)


for i in range(101):
    for j in range(101):
        flag = True
        for k in range(n):
            x = xyh[k][0]
            y = xyh[k][1]
            h = xyh[k][2]
            if k==0: 
                H = h + abs(x-i) + abs(y-j)
            elif k==(n-1):
                l = max( H - abs(x-i) - abs(y-j), 0 )
                if l==h:
                    ans = [i,j,H]
                else:
                    flag = False
            else:
                l = max( H - abs(x-i) - abs(y-j), 0 )
                if l==h:
                    pass
                else:
                    flag = False
        if flag:
            myoutput(ans,True)
            exit()
        else:
            continue
exit()

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(101):
    for cy in range(101):
        x, y, h = xyh[0]
        H = abs(x - cx) + abs(y - cy) + h
        f = True

        for i in range(1, n):
            x, y, h = xyh[i]
            h2 = max(0, H - abs(x - cx) - abs(y - cy))
            if h != h2:
                f = False
                break

        if f:
            ans = (cx, cy, H)

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

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)
sx,sy,sh=l[0]
for xx in range(0,101):
  for yy in range(0,101):
    hh=sh+abs(sx-xx)+abs(sy-yy)
    for ll in l[1:]:
      if ll[2]!=max(0,hh-abs(ll[0]-xx)-abs(ll[1]-yy)):
        break
    else:
      print(xx,yy,hh)

Solution (Python):
n=int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
max_h = 0
max_x = 0
max_y = 0
for p,q,h in xy:
    if max_h < h:
        max_h = h
        max_x = p
        max_y = q

for top_x in range(101):
    for top_y in range(101):
        top_h = abs(max_x-top_x)+abs(max_y-top_y)+max_h
        for x,y,h in xy:
            if max(top_h-abs(top_x-x)-abs(top_y-y),0) != h:
                break
        else:
            print(top_x,top_y,top_h)
            exit()

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
P = []
for _ in range(N):
    x, y, h = list(map(int, input().split()))
    P.append([x, y, h])
    if h != 0:
        tx, ty, th = x, y, h


for cx in range(101):
    for cy in range(101):
        H = th + abs(tx-cx)+abs(ty-cy)
        if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P):
            print(cx, cy, H)
            exit(0)

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


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

for i in range(N):
    x, y, h = P[i]
    for cx in range(101):
        for cy in range(101):
            H = h + abs(x-cx)+abs(y-cy)
            if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P):
                print(cx, cy, H)
                exit(0)

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

found = False
for i in range(len(P)):
    x, y, h = P[i]
    for cy in range(101):
        for cx in range(101):
            H = h + abs(x - cx) + abs(y - cy)
            if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P):
                print(cx, cy, H)
                found = True
                break
        if found:
            break
    if found:
        break

Solution (Python):
from operator import itemgetter
N = int(input())
XYZ = [list(map(int, input().split())) for _ in range(N)]

XYZ.sort(key=itemgetter(2), reverse=True)

for x in range(101):
    for y in range(0, 101):
        H = XYZ[0][2]+abs(XYZ[0][0]-x)+abs(XYZ[0][1]-y)
        judge = True
        for xyz in XYZ[1:]:
            if xyz[2] == max(H-abs(xyz[0]-x)-abs(xyz[1]-y),0):
                pass
            else:
                judge = False
                break
        if judge:
            X = x
            Y = y
            break
    if judge:
        break
print(X, Y, H)