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):
def abs(x1,x2):
    if x1>x2:
        return x1-x2
    else:
        return x2-x1
    
n=int(input())
x=[]
y=[]
h=[]

for i in range(n):
    xi,yi,hi=map(int,input().split())
    x.append(xi)
    y.append(yi)
    h.append(hi)

hmax=h[0]
xhmax=x[0]
yhmax=y[0]
ihmax=0

for i in range(n):
    if hmax<h[i]:
        hmax=h[i]
        xhmax=x[i]
        yhmax=y[i]
        ihmax=i
    
for cx in range(101):
    for cy in range(101):
        hh=hmax+abs(xhmax,cx)+abs(yhmax,cy)
        yesno="yes"
        for i in range(n):
            if h[i]!=max(hh-abs(x[i],cx)-abs(y[i],cy),0):
                yesno="no"
                break
        if yesno=="yes":
            print(cx,cy,hh)

Solution (Python):

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

info.sort(key=lambda x: x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        flag = True
        s = False
        for i in range(N):
            x, y, h = info[i]
            
            
            if not s:
                H = h + abs(cx - x) + abs(cy - y)
                s = True
                continue
            else:
                if h != max(H - abs(cx - x) - abs(cy - y), 0):
                    flag = False
        if flag:
            print(cx, cy, H)
            exit()
ans = info[0]
for i in range(1, N):
    if ans[2] > info[i][2]:
        ans = info[i]
print(*ans)

Solution (Python):

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

info.sort(key=lambda x: x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        flag = True
        s = False
        for i in range(N):
            x, y, h = info[i]
            
            
            if not s:
                H = h + abs(cx - x) + abs(cy - y)
                s = True
                continue
            else:
                if h != max(H - abs(cx - x) - abs(cy - y), 0):
                    flag = False
        if flag:
            print(cx, cy, H)
            exit()
ans = info[0]
for i in range(1, N):
    if ans[2] > info[i][2]:
        ans = info[i]
print(*ans)

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

for x in range(101):
    for y in range(101):
        flg = True
        H = xyh[-1][2] + abs(xyh[-1][0] - x) + abs(xyh[-1][1] - y)
        X = x
        Y = y
        
        for i in range(N):
            if xyh[i][2] != max(H - abs(xyh[i][0]-x) - abs(xyh[i][1] - y),0):
                flg=False
                break
        
        if flg:
            break
    if flg:
        break
print(X,Y,H)

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


def get(cx, cy):
    for x, y, h in xyh:
        if h > 0:
            return h + abs(x - cx) + abs(y - cy)


def check(cx, cy, H):
    for x, y, h in xyh:
        if h != max(H - abs(x - cx) - abs(y - cy), 0):
            return False
    return True


for cx in range(101):
    for cy in range(101):
        H = get(cx, cy)
        if check(cx, cy, H):
            print(cx, cy, H)
            exit()

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

xyh = []
not_zero = -100
flag_zero = True

for i in range(N):
    x,y,h = map(int,input().split())
    if h > 0 and flag_zero:
        not_zero = i
        flag_zero = False
    xyh.append([x,y,h])

for i in range(101):
    for j in range(101):

        Cx = i
        Cy = j
        H = xyh[not_zero][2] + abs(Cx-xyh[not_zero][0]) + abs(Cy-xyh[not_zero][1])
        ans = True

        for x,y,h in xyh:
            tmp_h = h+abs(Cx-x)+abs(Cy-y)
            if h>0:
                if tmp_h != H:
                    ans = False
                    break
            else:
                if H - abs(Cx-x) -abs(Cy-y) > 0:
                    ans = False
                    break
            
        if ans:
            print(Cx,Cy,H)
            exit()

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
point = 0
for i in range(101):
    for j in range(101):
        flag = True
        kizyun = False
        count = 0
        for a,b,c in li:
            if c != 0:
                count += 1
                if kizyun == False:
                    h = c+abs(a-i)+abs(b-j)
                    ha = a
                    hb = b
                    hc = c
                    kizyun = True
                else:
                    k = c+abs(a-i)+abs(b-j)
                    if h != k:
                        flag = False
        if count == 1:
            print(ha,hb,hc)
            exit()
        if flag == True:
            point += 1
            print(i,j,h)

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
point = 0
for i in range(101):
    for j in range(101):
        flag = True
        kizyun = False
        count = 0
        for a,b,c in li:
            if c != 0:
                count += 1
                if kizyun == False:
                    h = c+abs(a-i)+abs(b-j)
                    if h-abs(a-i)-abs(b-j) != c:
                        flag = False
                    kizyun = True
                else:
                    k = c+abs(a-i)+abs(b-j)
                    if h != k and kizyun == True:
                        flag = False
        if count == 1:
            print(a,b-1,c+1)
            exit()
        if flag == True:
            point += 1
            print(i,j,h)

Solution (Python):
from operator import itemgetter
def main():
    N = int(input())
    xyh = sorted([list(map(int,input().split())) for _ in range(N)],key=itemgetter(2),reverse = True)
    for px in range(101):
        for py in range(101):
            X,Y,H = xyh[0][0],xyh[0][1],xyh[0][2]
            ph = H + abs(X-px) + abs(Y-py)
            for i in range(N):
                X,Y,H = xyh[i][0],xyh[i][1],xyh[i][2]
                tmp = max(ph - abs(X-px) - abs(Y-py),0)
                if tmp != H:
                    break
                if i == N-1:
                    print(px,py,ph)



if __name__ == '__main__':
    main()

Solution (Python):

n=int(input())
xyh=[]
idx=-1
for i in range(n):
    x,y,h=map(int,input().split())
    xyh.append([x,y,h])
    if h>=1:
        idx=i
for cx in range(101):
    for cy in range(101):
        H=abs(xyh[idx][0]-cx)+abs(xyh[idx][1]-cy)+xyh[idx][2]
        H=max(H,0)
        ok=True
        for i in range(n):
            t_height=H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)
            if xyh[i][2]==0 and t_height>0:
                ok=False
            if xyh[i][2]>0 and xyh[i][2]!=t_height:
                ok=False
        if ok:
            print(cx,cy,H)

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

xyh = [list(map(int,input().split()))for i in range(n)]
i = 0
while i<n:
    if xyh[i][2]==0:
        xyh.pop(i)
        n -= 1
    else: i += 1

if(n==1):
    print(*xyh[0])
    exit()

for i in range(101):
    for j in range(101):
        base = xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for k in range(1, n):
            if base!=xyh[k][2]+abs(xyh[k][0]-i)+abs(xyh[k][1]-j): break
        else:
            print(i, j, base)
            exit()

Solution (Python):
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
for _ in range(N):
  A[_][0], A[_][1], A[_][2] = A[_][2], A[_][0], A[_][1]
A.sort(reverse=True)
if sum(A[_][0] for _ in range(N)) == 0:
  print(0, 0, 1)
else:
  for i in range(101):
    for j in range(101):
      H = abs(A[0][1] - i) + abs(A[0][2] - j) + A[0][0]
      flg = 1
      for k in range(N):
        if max(H - abs(A[k][1] - i) - abs(A[k][2] - j), 0) != A[k][0]:
          flg = 0
          break
      if flg == 1:
        Cx, Cy, cerH = i, j, H
        break
    if flg == 1:
      break
  print(Cx, Cy, cerH)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
information = [list(map(int, input().split())) for _ in range(n)]
information.sort(key=lambda x: x[2])

for c_x in range(101):
    for c_y in range(101):
        x, y, h = information[-1]
        H = h + abs(x - c_x) + abs(y - c_y)
        judge = 1
        for w in information[:-1]:
            x, y, h = w
            if h == max(0, H - abs(x - c_x) - abs(y - c_y)):
                continue
            else:
                judge -= 1
                break
        if judge:
            print(c_x, c_y, H)
            sys.exit()
        else:
            continue

Solution (Python):
from sys import setrecursionlimit
from operator import itemgetter

def main():
    N = int(input())
    XYH = [list(map(int,input().split())) for _ in range(N)]
    XYH.sort(key = itemgetter(2),reverse = True)
    ansx = -1
    ansy = -1
    for cx in range(0,101):
        for cy in range(0,101):
            H = -1
            flag = True
            for x,y,h in XYH:
                if H >= 0:
                    if h != max(H - abs(x - cx) - abs(y - cy),0):
                        flag = False
                        break
                elif h > 0:
                    H =  h + abs(x - cx) + abs(y - cy)
            if flag:
                ansx = cx
                ansy = cy
                print(ansx,ansy,H)
                return
    return   

if __name__ == "__main__":
    main()

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

s = 0

for index, i in enumerate(li):
  if i[2] > 0:
    s = index
    break
  
for x in range(101):
  for y in range(101):
    h = li[s][2] + abs(x - li[s][0]) + abs(y - li[s][1])
    ok = True

    for i in li:
      if i[2] > 0 and h != i[2] + abs(x - i[0]) + abs(y - i[1]):
        ok = False
      if i[2] == 0 and h > i[2] + abs(x - i[0]) + abs(y - i[1]):
        ok = False

    if ok:
      ans = [x, y, h]

print("{} {} {}".format(ans[0], ans[1], ans[2]))

Solution (Python):
N=int(input())
x=[0]*N
y=[0]*N
h=[0]*N

ti=0

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



flag=0
for tx in range(101):
    if flag==1:
        break
    for ty in range(101):
        th=h[ti]+abs(tx-x[ti])+abs(ty-y[ti])
        flag=1
        for i in range(N):
            nh=h[i]+abs(tx-x[i])+abs(ty-y[i])
            if (h[i]!=0 and nh!=th) or (h[i]==0 and nh<th ):
                flag=0
                break
        if flag==1:
            ans=[tx,ty,th]
            break

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

Solution (Python):
def Hr(h, x, y, cx, cy):
    return h+abs(x-cx)+abs(y-cy)
def H(h, x, y, cx, cy):
    return max(h-abs(x-cx)-abs(y-cy),0)


N = int(input())
x = [list(map(int, input().split())) for i in range(N)]
for cx in range(0, 101):
    for cy in range(0, 101):
        judge = True
        m = [l for l in range(N) if x[l][2]!=0][0]
        H0 = Hr(x[m][2], x[m][0], x[m][1], cx, cy)
        for n in range(len(x)):
            Hn = H(H0, x[n][0], x[n][1], cx, cy)
            if(x[n][2] == Hn):
                judge = judge and True
            else:
                judge = judge and False
        if(judge):
            print(cx, cy, H0)

Solution (Python):
def H(h, x, y, cx, cy):
    return h + abs(x-cx) + abs(y-cy)
def Hr(h, x, y, cx, cy):
    return max(h-abs(x-cx)-abs(y-cy),0)


N = int(input())
x = [list(map(int, input().split())) for i in range(N)]
for cx in range(0, 101):
    for cy in range(0, 101):
        judge = True
        m = [l for l in range(N) if x[l][2]!=0][0]
        H0 = H(x[m][2], x[m][0], x[m][1], cx, cy)
        for n in range(len(x)):
            Hn = H(x[n][2], x[n][0], x[n][1], cx, cy)
            
            if(x[n][2] != 0):
                if(Hn == H0):
                    judge = judge and True
                else:
                    judge = judge and False
        if(judge):
            for n in range(len(x)):
                if(x[n][2] == 0):
                    Hm = Hr(H0, x[n][0], x[n][1], cx, cy)
                    if(Hm == 0):
                        judge = judge and True
                    else:
                        judge = judge and False
                
            if(judge):
                print(cx, cy, H0)

Solution (Python):
from collections import deque

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


def norm(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


q = deque()

P.sort(key=lambda x: -x[2])
x0, y0, h0 = P[0]
x1, y1, h1 = P[1]
for cx in range(0, 101):
    for cy in range(0, 101):
        norm0 = norm((x0, y0), (cx, cy))
        norm1 = norm((x1, y1), (cx, cy))
        if h0 - h1 == -norm0 + norm1:
            q.append((cx, cy))

t = 2

while len(q) > 1:
    x0, y0, h0 = P[t - 1]
    x1, y1, h1 = P[t]
    for i in range(len(q)):
        cx, cy = q.popleft()
        norm0 = norm((x0, y0), (cx, cy))
        norm1 = norm((x1, y1), (cx, cy))
        if h0 - h1 == -norm0 + norm1:
            q.append((cx, cy))
    t += 1
    

cx, cy = q.popleft()
x, y, h = P[0]
H = h + abs(x - cx) + abs(y - cy)

print(*[cx, cy, H])

Solution (Python):

from itertools import product

N=int(input())
px,py,ph=[],[],[]

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)
        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

for Cxi,Cyj in product(range(101),range(101)):

    if len(ph)!=1:
        preH=Calc_H(Cxi,Cyj,px[0],py[0],ph[0])
        for i in range(len(ph)):
            nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
            if nowH!=preH:
                break
            preH=nowH
        else:
            print(Cxi,Cyj,nowH)
            break
    else:
        print(px[0],py[0],ph[0])
        break

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

def get_H(cx, cy):
   for x, y, h in z:
      if h > 0:
         return abs(x - cx) + abs(y - cy) + h

def check_H(cx, cy, H):
   for x, y, h in z:
      if h != max(H - abs(x - cx) - abs(y - cy), 0):
         return False
   return True


for cx in range(101):
   for cy in range(101):
      H = get_H(cx, cy)
      if check_H(cx, cy, H):
         print(cx, cy, H)
         exit()

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

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

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

Solution (Python):

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
xyh = [input() for _ in range(n)]

for x_ in range(101):
    for y_ in range(101):
        cur_h = 0 
        for i in range(n):
            x = int(xyh[i].split()[0])
            y = int(xyh[i].split()[1])
            h = int(xyh[i].split()[2])
            h_ = h + (abs(x_ - x) + abs(y_ - y))
            if cur_h == 0 and h > 0:
                cur_h = h_  
            else:
                if h > 0:
                    if cur_h != h_: break
                elif cur_h -(abs(x_ - x) + abs(y_ - y)) > 0: break
        for i in range(n):
            x = int(xyh[i].split()[0])
            y = int(xyh[i].split()[1])
            h = int(xyh[i].split()[2])
            h_ = h + (abs(x_ - x) + abs(y_ - y))
            if cur_h == 0 and h > 0:
                cur_h = h_  
            else:
                if h > 0:
                    if cur_h != h_: break
                elif cur_h -(abs(x_ - x) + abs(y_ - y)) > 0: break   
                if i == n-1: 
                    print(x_,y_,cur_h)
                    
                    exit(0)

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

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

for x, y, h in XYH:
  if h >= 1:
    xt, yt, ht = x, y, h
    break

for cx in range(101):
  for cy in range(101):
    ch = ht + abs(cx-xt) + abs(cy-yt)
    for x, y, h in XYH:
        if h != max(ch - abs(x - cx) - abs(y - cy), 0):
          break
    else:
      print(cx, cy, ch)
      exit()

Solution (Python):
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
n = int(input())
l = [list(map(int, input().split())) for i in range(0, n) ]
 
for i in range(0, n):
    if l[i][2] != 0:
        p = l[i]
        break
 
for x in range(0, 101):
    for y in range(0, 101):
        h = p[2] + abs(x-p[0]) + abs(y-p[1])
        for i in range(0, n):
            if l[i][2] != max(h - abs(x-l[i][0]) - abs(y-l[i][1]), 0):
                break
        else:
            print(x, y, h)
            exit()

Solution (Python):

import math
import heapq
import bisect
import numpy as np


N = int(input())
Map = []
for i in range(N):
    m = tuple(map(int, input().split()))
    Map.append(m)

for X in range(101):
    for Y in range(101):
        for m in Map:
            if m[2] != 0:
                H = abs(X-m[0])+abs(Y-m[1])+m[2]
                break
        flg = 1
        for m in Map:
            if m[2] != max(H-abs(X-m[0])-abs(Y-m[1]),0):
                flg = 0
                break
        if flg:
            print(X,Y,H)

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N = cin.int()
    info = cin.intListList(N)
    X,Y,H = [0,0,0]
    for i in info:
        if i[2] > 0:
            X = i[0]
            Y = i[1]
            H = i[2]
    for x in range(101):
        for y in range(101):
            h = abs(x - X) + abs(y - Y) + H
            if h > 0:
                ok = True
                for i in range(N):
                    a = max(0,h - abs(x - info[i][0]) - abs(y - info[i][1]))
                    if info[i][2] != a:
                        ok = False
                if ok:
                    print("{} {} {}".format(x,y,h))
                    return
if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
xx = [0]*n
yy = [0]*n
hh = [0]*n
for i in range(n):
    x,y,h = map(int,input().split())
    xx[i] = x
    yy[i] = y
    hh[i] = h

for i in range(n):
    if hh[i] == 0:
        continue
    else:
        x = xx[i]
        y = yy[i]
        h = hh[i]
        break

for cx in range(101):
    for cy in range(101):
        H = abs(x-cx) + abs(y-cy) + h
        for i in range(n):
            if max(H-abs(xx[i]-cx)-abs(yy[i]-cy),0) != hh[i]:
                break
        else:
            print(cx,cy,H)
            exit()

Solution (Python):
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()

info = [na() for i in range(n)]
ix, iy, ih = 0, 1, 2

si = -1
for i in range(n):
	if info[i][2] > 0:
		si = i

ans = [-1, -1, -1]
for cx in range(101):
	for cy in range(101):
		x = abs(cx - info[si][ix])
		y = abs(cy - info[si][iy])
		h = info[si][ih] + x + y
		ok = True
		for i in range(n):
			if info[i][ih] > 0 and h - info[i][ih] != abs(cx - info[i][ix]) + abs(cy - info[i][iy]):
				ok = False
			if info[i][ih] == 0 and h > abs(cx - info[i][ix]) + abs(cy - info[i][iy]):
				ok = False
		if ok is True:
			ans[ix], ans[iy], ans[ih] = cx, cy, h

print(ans[ix], ans[iy], ans[ih])

Solution (Python):
n = int(input())
py = []
start = 0
for i in range(n):
    x,y,h = map(int, input().split())
    if start < h:
        start = h
    py.append((x,y,h))

height = lambda x,y,cx,cy,hh:max(hh -abs(x-cx) -abs(y-cy), 0)
while True:
    for i in range(101):
        for j in range(101):
            for a,b,h in py:
                if height(a,b,i,j,start) != h:
                    
                    break
            else:
                
                print(i,j,start)
                exit()
    start += 1

Solution (Python):
N = int(input())
X = []
Y = []
H = []
for i in range(N):
    x, y, h = map(int, input().split()) 
    X.append(x)      
    Y.append(y)      
    H.append(h)      

for cx in range(101):
    for cy in range(101):
        for i in range(N):
            if H[i] > 0:
                height = H[i] + abs(X[i]-cx) + abs(Y[i]-cy)
        ok = True
        for i in range(N):
            if max(height - abs(X[i]-cx) - abs(Y[i]-cy), 0) != H[i]:
                ok = False
        if ok:
            print(cx, cy, height)
            exit()

Solution (Python):
def p_c():
    from itertools import product
    N = int(input())
    xyh = [tuple(map(int, input().split())) for _ in range(N)]
    h = 0
    for i in xyh:
        if h < i[2]:
            x_, y_, h = i
    for x, y in product(range(101), repeat=2):
        high = h + abs(x_ - x) + abs(y_ - y)
        if all(h == max(0, high - abs(x - i) - abs(y - j)) for i, j, h in xyh):
            print(x, y, high)

p_c()

Solution (Python):
def is_right(i, j):
    H = None
    for h, x, y in XYH:
        if H is None:
            if h > 0:
                H = abs(x - i) + abs(y - j) + h
        else:
            if h != max(H - abs(x - i) - abs(y - j), 0):
                return -1
    return H


N = int(input())
XYH = []
for _ 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):
        res = is_right(i, j)
        if res > 0:
            print(i, j, res)
            exit()

Solution (Python):
N = int(input())
X = [0] * N
Y = [0] * N
H = [0] * N

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

for cx in range(101):
    for cy in range(101):
        H_list = []
        check_list = []
        for i in range(N):
            if H[i] == 0:
                check_list.append(i)
                continue
            H_list.append(H[i] + abs(X[i] - cx) + abs(Y[i] - cy))
        if len(set(H_list)) == 1:
            h = H_list[0]
            flag = True
            for check in check_list:
                if H[check] == max(h - abs(X[check] - cx) - abs(Y[check] - cy), 0):
                    pass
                else:
                    flag = False
                    break
            if flag:
                print(cx, cy, h)
                exit()

Solution (Python):
n=int(input())
xi,yi,hi=[],[],[]
for i in range(n):
    num=[int(j) for j in input().split()]
    xi+=[num[0]]
    yi+=[num[1]]
    hi+=[num[2]]
ans=[0,0,0]
for i in range(101):
    for j in range(101):
        hoge=10**9+10
        for k in range(n):
            hight=hi[k]+abs(xi[k]-i)+abs(yi[k]-j)
            if(hi[k]==0):
                continue
            if(i==xi[k] and j==yi[k]):
                hight=hi[k]
            if(hoge==10**9+10):
                hoge=hight
            elif(hoge!=hight):
                break
        else:
            flg=True
            for k in range(n):
                hight=max(hoge-abs(xi[k]-i)-abs(yi[k]-j),0)
                if(hi[k]!=hight):
                    flg=False
                    break
            if(flg):
                ans=[i,j,hoge]
print(*ans,sep=" ")

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
h = 0
for i in xyh:
  if i[2] > h:
    x, y, h = i[0], i[1], i[2]
CXY = [[i,j] for i in range(0,100+1) for j in range(0,100+1)]
for cxy in CXY:
  ans=True
  H = h + abs(x - cxy[0]) + abs(y - cxy[1])
  for i in xyh:
    if max( H - abs(i[0] - cxy[0]) - abs(i[1] - cxy[1]) ,0) != i[2]:
      ans = False
  if ans:
    print(cxy[0],cxy[1],H)

Solution (Python):
import itertools

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


for i in range(N):
    x, y, h = xyh[i]
    if h > 0:
        x_t, y_t, h_t = x, y, h
        break

for c_x, c_y in itertools.product(range(0, 100+1), repeat=2):
    H = h_t + abs(x_t - c_x) + abs(y_t - c_y)
    for i in range(N):
        x_i, y_i, h_i = xyh[i]
        if h_i != max(H - abs(x_i - c_x) - abs(y_i - c_y), 0):
            break
    else:
        print(c_x, c_y, H)
        exit()

Solution (Python):
N = int(input())
x = [0]*N
y = [0]*N
h = [0]*N
for i in range(N):
    x[i], y[i], h[i] = map(int,input().split())
    if h[i] != 0:
        nonzero = [x[i], y[i], h[i]]

for cx in range(101):
    for cy in range(101):
        ch = nonzero[2] + abs(cx-nonzero[0]) + abs(cy-nonzero[1])
        cnt = 0
        for i in range(N):
            if h[i] == max(ch-abs(x[i]-cx)-abs(y[i]-cy), 0):
                cnt += 1
        if cnt == N:
            print(cx,cy,ch)
            exit()

Solution (Python):
from itertools import product


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

    xt, yt, ht = -1, -1, -1
    for i in range(N):
        if h[i] != 0:
            xt, yt, ht = x[i], y[i], h[i]
            break
    
    for cx, cy in product(range(101), repeat=2):
        ans_h = ht + abs(cx - xt) + abs(cy - yt)
        flg = True
        for i in range(len(x)):
            if h[i] != max(ans_h - abs(x[i] - cx) - abs(y[i] - cy), 0):
                flg = False
                break
        if flg:
            print(cx, cy, ans_h)
            exit()


if __name__ == '__main__':
    solve()

Solution (Python):
n=int(input())
p=[]
for i in range(n):
    p.append(tuple(map(int,input().split())))
p.sort(key=lambda x:-x[2])
for j in range(101):
    for k in range(101):
        H=None
        f=1
        for x,y,h in p:
            if h>0 and H==None:
                H=h+abs(x-j)+abs(y-k)
            else:
                if max(0,H-abs(x-j)-abs(y-k))!=h:
                    f=0
        if f:
            print(j,k,H)
            exit()

Solution (Python):
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    x,y,h=[0]*N,[0]*N,[0]*N
    for i in range(N):
        x[i],y[i],h[i]=map(int,input().split())
    for cx in range(101):
        for cy in range(101):
            ch=-1
            queue=deque()
            for X,Y,H in zip(x,y,h):
                queue.append((X,Y,H))
            while queue:
                X,Y,H=queue.popleft()
                if ch==-1:
                    if H>0:
                        ch=H+abs(X-cx)+abs(Y-cy)
                    else:
                        queue.append((X,Y,H))
                elif ch!=-1 and ((ch-abs(X-cx)-abs(Y-cy)>0 and H!=ch-abs(X-cx)-abs(Y-cy)) or (ch-abs(X-cx)-abs(Y-cy)<=0 and H!=0)):
                    break
            else:
                print(cx,cy,ch)
                exit()
                    
        

if __name__ == '__main__':
    main()

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

for cx in range(101):
    for cy in range(101):
        H = set()
        for x, y, h in xyh:
            if h != 0:
                H.add(h + abs(x - cx) + abs(y - cy))
        if len(H) == 1:
            H = list(H)[0]
            flag = True
            for x, y, h in xyh:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    flag = False
                    break
            if flag:
                print(cx, cy, H)

Solution (Python):
import sys
N=int(input())
po = []
zp = []
for i in range(N):
    x, y, h = map(int, input().split())
    if h == 0:
        zp.append( [x,y] )
    else:
        po.append( [x,y,h] )
for yt in range(101):
    for xt in range(101):
        k = -1
        for p in po:
            tmpH = p[2] + abs(p[0]-xt) + abs(p[1]-yt)
            if k == -1:
                k = tmpH
            else:
                if k != tmpH:
                    k = -1
                    break
        if k == -1:
            continue
        for p in zp:
            if (k - abs(p[0]-xt) - abs(p[1]-yt)) > 0:
                k = -1
                break
        if k != -1:
            print(xt,yt,k)
            sys.exit

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

for x in range(101):
    for y in range(101):
        h_memo = 0
        for i in range(n):
            if xy[i][2] != 0:
                h_memo = xy[i][2] + abs(xy[i][0]-x) + abs(xy[i][1]-y)
                break
        for i in range(n):
            if xy[i][2] != max(0,h_memo-abs(xy[i][0]-x)-abs(xy[i][1]-y)):
                break

        else:               
            

            print(x,y,h_memo)
            break