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
input = sys.stdin.readline  
N = int(input())
xyh =[0]*N
h_list =[0]*N

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

from bisect import bisect_right
xyh.sort(key =lambda x:x[2])
h_list.sort()
ind =bisect_right(h_list,0)
from collections import defaultdict
H =defaultdict(set)

for x,y,h in xyh[ind:]:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                H[(cx,cy)].add( (h -xx -yy) )
            


if len(xyh[ind:]) ==1:
    print(*xyh[-1])
else:
    for k,v in H.items():
    
        if len(v)==1:
            vv =v.pop()
            if 0 <= vv :
                print(*k,vv)
            elif vv <0:
                print(*k,0)

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
xyh = [lr() for i in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)
for i in range(0,101):
    for j in range(0,101):
        H = abs(xyh[0][0]-i)+abs(xyh[0][1]-j)+xyh[0][2]
        flag = True
        for k in range(1,n):
            h = abs(xyh[k][0]-i)+abs(xyh[k][1]-j)+xyh[k][2]
            if not ((h>H and xyh[k][2]==0) or h==H):
                flag = False
                break
        if flag:
            print(i,j,H)
            sys.exit()

Solution (Python):

N=int(input())
XYH = [None]*N
for i in range(N):
    XYH[i] = list(map(int,input().split()))

for cx in range(101):
    for cy in range(101):
        found=False
        for i in range(N):
            d = abs(XYH[i][0]-cx)+abs(XYH[i][1]-cy)
            if XYH[i][2]>0 and not found:
                h = XYH[i][2]+d
                break
        for i in range(N):
            d = abs(XYH[i][0]-cx)+abs(XYH[i][1]-cy)
            if XYH[i][2]!= max(0,h-d):
                break
        else:
            print(cx,cy,h)

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
xyh = []
for i in range(N):
    x, y, h = LI()
    xyh.append([x, y, h])


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2], reverse=True)


ans = (0,0,0)
for c_x in range(101):
    for c_y in range(101):
        H = 0
        flag = True
        for i, (x, y, h) in enumerate(xyh):
            if i == 0:
                H = h + abs(x - c_x) + abs(y - c_y)
            if h != max(H - abs(x - c_x) - abs(y - c_y), 0):
            
                flag = False
        if flag:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

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

ans = False
for cy in range(101):
    for cx in range(101):
        x0, y0, h0 = xyh[0]
        H = abs(x0-cx) + abs(y0-cy) + h0
        
        for x, y, h in xyh[1:]:
            hh = max(H-abs(x-cx)-abs(y-cy), 0)
            if h != hh:
                break
        else:
            
            ans = True
            print(cx, cy, H)
            break
        if ans:
            break
    if ans:
        break

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

for xi in range(0, 101):
    for yi in range(0, 101):
        tmpH = 0
        for k in range(N):
            x,y,h = XYH_list[k]
            if k == 0:
                tmpH =h + abs(x - xi) + abs(y - yi)
            if h == max((tmpH - abs(x - xi) - abs(y - yi)), 0):
                if k == N - 1:
                    ans = [str(xi), str(yi), str(tmpH)]
                continue
            else:
                break
print(' '.join(ans))

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[]
for i in range(n):
  x,y,h=nii()
  l.append([x,y,h])
  if h!=0:
    ini_x=x
    ini_y=y
    ini_h=h

for tx in range(101):
  for ty in range(101):
    n_h=abs(tx-ini_x)+abs(ty-ini_y)+ini_h
    for x,y,h in l:
      t_h=max(n_h-(abs(tx-x)+abs(ty-y)),0)
      if h!=t_h:
        break
    else:
      print(tx,ty,n_h)
      exit()

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    XYH = [NLI() for _ in range(N)]
    XYH.sort(key= lambda x: x[2], reverse=True)
    H = 10**10
    for cx in range(101):
        for cy in range(101):
            is_badc = False
            for i, xyh in enumerate(XYH):
                x, y, h = xyh
                if i == 0:
                    H = h + abs(cx - x) + abs(cy - y)
                else:
                    if max(H - abs(cx-x) - abs(cy-y), 0) != h:
                        is_badc = True

            if not is_badc:
                print(cx, cy, H)
                exit()



if __name__ == "__main__":
    main()

Solution (Python):
def solve():
    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):
            res = []
            for x, y, h in zip(X, Y, H):
                if h == 0:
                    continue
                hh = h + abs(x - cx) + abs(y - cy)
                res.append(hh)
            if len(set(res)) == 1:
                flg = True
                for x, y, h in zip(X, Y, H):
                    if h != max(res[0] - abs(x - cx) - abs(y - cy), 0):
                        flg = False
                if flg:
                    print(cx, cy, res[0])

solve()

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter



import bisect
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh=sorted(xyh,key=lambda x:x[2])
for cx in range(101):
    for cy in range(101):
        h_a=h_b=10**10
        minh=10**10
        for i in range(n):
            x,y,h=xyh[i]
            if h!=0:
                h_a=h+abs(cx-x)+abs(cy-y)
                if h_a>minh:
                  break
                elif h_b!=10**10 and h_a!=h_b:
                    break
                else:
                    h_b=h_a
            else:
                minh=min(minh,abs(cx-x)+abs(cy-y))
                if minh==0:
                  break
        else:
            if minh==1 and h_a==10**10:
              print(cx,cy,1)
              exit()
            else:
                print(cx,cy,h_a)
                exit()

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)
  if c!=0:q=[a,b,c]
for i in range(101):
  for j in range(101):
    H=q[2]+abs(q[0]-i)+abs(q[1]-j)
    for a,b,c in zip(x,y,h):
      if c!=max(H-abs(a-i)-abs(b-j),0):break
    else:
      print(i,j,H)
      exit()

Solution (Python):
n=int(input())
lst=[None]*n
for i in range(n):
    a,b,c=map(int,input().split())
    lst[i]=[a,b,c]
lst=sorted(lst,key=lambda x:x[2],reverse=True)
for i in range(101):
    for j in range(101):
        switch=0
        x,y,z=lst[0]
        height=z+abs(i-x)+abs(j-y)
        for k in range(1,n):
            x,y,z=lst[k]
            if z==0:
                if abs(i-x)+abs(j-y)<height:
                    switch=1
                    break
            elif abs(i-x)+abs(j-y)+z!=height:
                switch=1
                break
        if switch==0:
            print(i,j,height)

Solution (Python):
n=int(input())
query=[]
for _ in range(n):
    a,b,c=map(int,input().split())
    query.append((a,b,c))
query=sorted(query, key=lambda x:x[2], reverse=True)

for cx in range(101):
  for cy in range(101):
      h=None
      flg=True
      for q in query:
        if h==None:
          h=q[2]+abs(cx-q[0])+abs(cy-q[1])
        elif q[2]!=0 and h!=q[2]+abs(cx-q[0])+abs(cy-q[1]):
          flg=False
          break
        elif q[2]==0 and h-abs(cx-q[0])-abs(cy-q[1])>0:
          flg=False
          break
      if flg: 
        print(cx,cy,h)
        exit()

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

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

if N==1:
    print(xyh[0],xyh[1],xyh[2])
else:
    for cx in range(101):
        for cy in range(101):
            flag = 0
            dx = abs(cx - xyh[0][0])
            dy = abs(cy - xyh[0][1])
            hmax = xyh[0][2]+dx+dy
            for i in range(1,N):
                if max(hmax -( abs(cx - xyh[i][0])+abs(cy - xyh[i][1])),0) !=  xyh[i][2]:
                    flag = 1
                    break
            if flag == 0:
                print(cx,cy,hmax)
                exit()

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

for xi in range(101):
    for yi in range(101):
        hi=0
        flag=True
        for i in range(n):
            x=xyh[i][0]
            y=xyh[i][1]
            h=xyh[i][2]
            if i==0:
                hi=abs(xi-x)+abs(yi-y)+h
            if max(hi-abs(xi-x)-abs(yi-y),0)!=h:
                flag=False
        if flag:
            print(xi, yi, hi)
            break
    else:
        continue
    break

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

for cx in range(101):
    for cy in range(101):
        candidates = set()
        for x, y, h in A:
            h += abs(x - cx) + abs(y - cy)
            candidates.add(h)
        for H in candidates:
            for x, y, h in A:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                print(cx, cy, H)
                exit()

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

xyh = [list(map(int, input().split())) for i in range(n)]
if xyh[0][2]:
    x,y,h = xyh[0]
if xyh[1][2]:
    x,y,h = xyh[1]
if xyh[-1][2]:
    x,y,h = xyh[-1]
for i in range(101):
    for j in range(101):
        k = h + abs(i - x) + abs(j - y)
        if all(h == max(k - abs(i - x) - abs(j - y), 0) for x, y, h in xyh):
            print(i, j, k)

Solution (Python):
import collections
n = int(raw_input())
pts = [map(int , raw_input().split()) for _ in range(n)]

def f(pts):
	for cx,cy in [(ii,jj) for ii in range(100+1) for jj in range(100+1)]:	
		H = min([abs(cx - x) + abs(cy - y) for x,y,h in pts if h == 0] or [+float('inf')])
		
		cc = collections.Counter()
		for x,y,h in pts:
			q = abs(cx - x) + abs(cy - y)
			if h > 0:
				Y = h + q
				if 1<=Y <= H:
					cc[Y]+=1
				else:
					cc[-1] += 1
		if len(cc) == 1:
			for k in cc:
				if 1<=k <= H:
					return k,cx,cy

h,x,y = f(pts)

print x,y,h

Solution (Python):
n = int(input())
l = []
for i in range(n):
    xyh = list(map(int, input().split()))
    l.append(xyh)
    if xyh[2]:
        x, y, h = xyh
for i in range(101):
    for j in range(101):
        k = h + abs(i - x) + abs(j - y)
        if all(h == max(k - abs(i - x) - abs(j - y), 0) for x, y, h in l):
            print(i, j, k)

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

h_range = {}
for cx in range(0, 101):
    for cy in range(0, 101):
        h_range[(cx, cy)] = [1, 10000000000]

for i in range(n):
    for (cx, cy) in h_range.keys():
        ch_max = h[i] + (abs(cx - x[i]) + abs(cy - y[i]))
        if h[i] == 0:
            ch_min = 0
        else:
            ch_min = ch_max
        ch_range = h_range[(cx, cy)]
        h_range[(cx, cy)] = [max(ch_min, ch_range[0]), min(ch_max, ch_range[1])]

for (cx, cy) in h_range.keys():
    ch_range = h_range[(cx, cy)]
    if ch_range[0] <= ch_range[1]:
        for ch in range(ch_range[0], ch_range[1] + 1):
            print('{} {} {}'.format(cx, cy, ch))

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

def chech(Cx,Cy,x,y,h):
    if h > 0:
        H = h + abs(x-Cx) + abs(y-Cy)
        c_list.append(H)
    return 
    
for Cx in range(101):
    for Cy in range(101):
        c_list=[]
        c_list_zero=[]
        for i in info:
            x,y,h=i
            c_=chech(Cx,Cy,x,y,h)

        if len(set(c_list))==1:
            check_zero=True
            for i in info:
                x,y,h=i
                H = c_list[0]
                h_=max(H - (abs(x-Cx) + abs(y-Cy)),0)
                if h_ != h:
                    check_zero=False
                
            if check_zero==True:
                print(Cx,Cy,c_list[0])

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

ans = [None] * 3
for cx in range(101):
    for cy in range(101):
        top = h0 + abs(x0 - cx) + abs(y0 - cy)
        bl = True
        for x, y, h in xyh[1:]:
            h_calc = max(top - abs(x - cx) - abs(y - cy), 0)
            if h_calc != h:
                bl = False
                break

        if bl:
            ans = [cx, cy, top]

print(*ans)

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

xyh.sort(key=lambda x: x[2], reverse=True)
ans = [None] * 3
for cx in range(101):
    for cy in range(101):
        x0, y0, h0 = xyh[0]
        top = h0 + abs(x0 - cx) + abs(y0 - cy)
        bl = True
        for x, y, h in xyh[1:]:
            h_calc = max(top - abs(x - cx) - abs(y - cy), 0)
            if h_calc != h:
                bl = False
                break

        if bl:
            ans = [cx, cy, top]

print(*ans)

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

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


for cx in range(0, 101):
    for cy in range(0, 101):

        prev = None
        flg = False
        zeros = []
        for x, y, h in XYH:
            if h == 0:
                zeros.append((x, y, h))
                continue

            cur_h = h + abs(x - cx) + abs(y - cy)

            if prev is not None:
                if prev != cur_h:
                    flg = True
                    break

            prev = cur_h

        if not flg:
            for x, y, h in zeros:
                if max(0, cur_h - abs(x - cx) - abs(y - cy)) != 0:
                    flg = True
                    break

            if not flg:
                print(cx, cy, cur_h)
                exit()

Solution (Python):
abalable_H = []
N = int(input())
x = []
y = []
h = []
first =-1
for i in range(0,N,1):
    tmpx,tmpy,tmph = map(int,input().split())
    x.append(tmpx)
    y.append(tmpy)
    h.append(tmph)
    if tmph !=0 and first == -1:
        first = i

for cx in range(0,101,1):
    for cy in range(0,101,1):
        H = h[first]+abs(x[first]-cx)+abs(y[first]-cy)
        ok = True
        for i in range(0,N,1):
            if h[i] != max(H-abs(cx-x[i])-abs(cy-y[i]),0):
                ok =False
        if ok == True:
            print(cx,cy,H)
            break

Solution (Python):

def solve():
    for i in range(N):
        if xyh[i][2] > 0:
            x,y,h = xyh[i][0], xyh[i][1], xyh[i][2]
            break

    for i in range(101):
        for j in range(101):
            H = h + abs(x-i) + abs(y-j)
            a = 0
            for k in range(N):
                if xyh[k][2] == max(H-abs(xyh[k][0]-i) - abs(xyh[k][1]-j), 0):
                    continue
                else:
                    a = 1
                    break
            if a == 0:
                print(i,j,H, sep=" ")
                break
        else:
            continue


if __name__ == "__main__":
    N = int(input())
    xyh = [list(map(int, input().split())) for _ in range(N)]
    solve()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xyh = [None]*n
for i in range(n):
    x,y,h = map(int, input().split())
    xyh[i] = (x,y,h)
ans = []
bx,by,bh = max(xyh, key=lambda p: p[2])
for i in range(101):
    for j in range(101):
        H = bh + abs(bx-i) + abs(by-j)
        bad = False
        for x,y,h in xyh:
            if max(0, H - abs(x-i) - abs(y-j))!=h:
                bad = True
                break
        if bad:
            pass
        else:
            ans = (i,j,H)
            break
    if not bad:
        break
print(" ".join(map(str, ans)))

Solution (Python):


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


for x in range(0, 101):
    for y in range(0, 101):
        H_less = 10**10
        H = -1
        flag = 0
        for x_, y_, h_ in xyh:
            if h_ == 0:
                H_less = min(abs(x_-x)+abs(y_-y), H_less)
            else:
                h_tmp = h_ + abs(x_-x) + abs(y_-y)
                if H != -1:
                    if H != h_tmp:
                        flag = 1
                        break
                H = h_tmp
        if flag == 1:
            continue
        
        if H > H_less:
            continue
        print(x, y, H)
        exit()

Solution (Python):
def main():
    N = int(input())
    l = []
    for _ in range(N):
        x,y,h = map(int, input().split())
        l.append((x,y,h))
    l.sort(key=lambda x:x[2], reverse=True)
    for i in range(101):
        for j in range(101):
            H = l[0][2] +  abs(l[0][0] - i) + abs(l[0][1] - j)
            for k in range(N):
                if max(H-abs(l[k][0]-i) - abs(l[k][1] - j), 0) != l[k][2]:
                    break
            else:
                return i, j, H
i, j, H = main()
print(i,j,H)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    t = in_na()
    xyh = list(zip(t, t, t))

    for cx in range(101):
        for cy in range(101):
            hmax = 10**9 + 7
            pred_h = -1
            for i in range(N):
                x, y, h = xyh[i]
                xy = abs(x - cx) + abs(y - cy)
                if h == 0:
                    hmax = min(hmax, xy)
                    if pred_h > hmax:
                        break
                else:
                    if pred_h == -1:
                        pred_h = h + xy
                    elif pred_h != h + xy:
                        break
            else:
                print(cx, cy, pred_h)
                exit()


if __name__ == '__main__':
    main()

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

N = int(input())

l = []

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

    
    
    
    if v[2]:
        x,y,h = v[0], v[1], v[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)
            exit()

Solution (Python):
N, *XYH = map(int, open(0).read().split())
XYH = [(x, y, h) for x, y, h in zip(*[iter(XYH)] * 3)]
pos_i = -1
for i, (_, _, h) in enumerate(XYH):
    if h > 0:
        pos_i = i
        break
for i in range(101):
    for j in range(101):
        t_x, t_y, t_h = XYH[pos_i]
        tmp_summit = t_h + abs(i - t_x) + abs(j - t_y)
        for x, y, h in XYH:
            if h > 0 and tmp_summit - h != abs(i - x) + abs(j - y):
                break
            elif h == 0 and tmp_summit > abs(i - x) + abs(j - y):
                break
        else:
            print(i, j, tmp_summit)
            exit()

Solution (Python):
n = int(input())
coord = []

for i in range(n):
    x, y, h = map(int, input().split())
    coord.append([h, x, y])
    if h > 0:
        x0, y0, h0 = x, y, h

flag = False


for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True

        H = h0 + abs(x0 - cx) + abs(y0 - cy)

        for i in range(n):
            if coord[i][0] != max(H - abs(coord[i][1] - cx) - abs(coord[i][2] - cy), 0):
                flag = False
                break

        if flag is True:
            res_x = cx
            res_y = cy
            res_h = H

print(res_x, res_y, res_h)

Solution (Python):
def main():
    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())
    ans = []
    for x in range(101):
        for y in range(101):
            tmp = 0
            for i in range(N):
                if H[i] == 0:
                    continue
                else:
                    tmp = H[i] + abs(X[i] - x) + abs(Y[i] - y)
                    break
            for i in range(N):
                if not (H[i] == max(tmp - abs(X[i] - x) - abs(Y[i] - y),0)):
                    break
            else:
                ans = [x,y,tmp]
                break
    if N == 1:
        if H[0] == 0:
            print(X[0],Y[0],H[0])
            exit()
    print(*ans)
            



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], yy[i], hh[i] = x, y, h
    if h > 0:
        x0, y0, h0 = x, y, h

for cx in range(101):
    for cy in range(101):
        f = True
        h = h0 + abs(x0 - cx) + abs(y0 - cy)
        for i in range(n):
            if hh[i] != max(h - abs(xx[i] - cx) - abs(yy[i] - cy), 0):
                f = False
                break
        if f:
            print("{} {} {}".format(cx, cy, h))
            exit(0)

Solution (Python):
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
xyh = [tuple(map(int, input().split())) for _ in range(n)]



def get_H(Cx, Cy):
    for x, y, h in xyh:
        if h == 0:  
            continue
        H = abs(x-Cx)+abs(y-Cy)+h  
        if h >= 1:
            return H


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_H(Cx, Cy)
        if (check(Cx, Cy, H)):
            print(Cx, Cy, H)
            quit()

Solution (Python):
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  if X[i][2] > 0:
    x, y, h = X[i][0], X[i][1], X[i][2]
    break
for i in range(0, 101):
  for j in range(0, 101):
    H = h + abs(x-i) + abs(y-j)
    a = 0
    for k in range(N):
      if X[k][2] == max(H - abs(X[k][0]-i) - abs(X[k][1]-j), 0):
        continue
      else:
        a = 1
        break
    if a == 0:
      print(i, j, H, sep=' ')
      break
  else:
    continue
  break

Solution (Python):
N = int(input())
pyramid_height = []
for _ in range(N):
    val = list(map(int, input().split()))
    pyramid_height.append(val)

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

for x in range(101):
    for y in range(101):
        tmp_h = pyramid_height[0][2] + abs(x - pyramid_height[0][0]) + abs(y - pyramid_height[0][1])
        for i in range(1, N):
            if pyramid_height[i][2] != max(tmp_h - abs(x - pyramid_height[i][0]) - abs(y - pyramid_height[i][1]), 0):
                break
        else:
            print(x, y, tmp_h)
            exit()

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
X = [];Y = [];H = []
for i in range(n):
    x,y,h = readInts()
    X.append(x)
    Y.append(y)
    H.append(h)
    if h > 0:
        si = i
resx=-1;resy=-1;resh=-1;
for cx in range(101):
    for cy in range(101):
        judge = True
        h = H[si] + abs(X[si] - cx) + abs(Y[si] - cy)
        for i in range(n):
            if H[i] == 0:
                if h > abs(X[i] - cx) + abs(Y[i] - cy):
                    judge ^=True
                    break
            else:
                if h - H[i] != abs(X[i]-cx) + abs(Y[i]-cy):
                    judge ^= True
                    break
        if judge:
            resx =cx;resy=cy;resh=h;
print(resx,resy,resh)

Solution (Python):
def dist(X,Y):
    return abs(X[0]-Y[0])+abs(X[1]-Y[1])
N = int(input())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[2],reverse=True)
for i in range(101):
    for j in range(101):
        flag=0
        x0,y0,h0 = A[0]
        H = h0+dist((i,j),(x0,y0))
        for k in range(1,N):
            x,y,h = A[k]
            if h>0 and H==h+dist((i,j),(x,y)):
                continue
            elif h>0 and H!=h+dist((i,j),(x,y)):
                flag=1
                break
            elif h==0 and H<=dist((i,j),(x,y)):
                continue
            elif h==0 and H>dist((i,j),(x,y)):
                flag = 1
                break
        if flag==0:
            Cx = i
            Cy = j
            break
    if flag==0:break
print(Cx,Cy,H)