Problem:
 Score: 300 points    Problem Statement  In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc. The pyramid had center coordinates  (C_X, C_Y) and height  H . The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0) .  Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:   C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1 .  Additionally, he obtained N pieces of information. The i -th of them is: "the altitude of point (x_i, y_i) is h_i ."   This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.      Constraints   N is an integer between 1 and 100 (inclusive).  x_i and y_i are integers between 0 and 100 (inclusive).  h_i is an integer between 0 and 10^9 (inclusive).  The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.  The center coordinates and the height of the pyramid can be uniquely identified.         Input  Input is given from Standard Input in the following format:  N  x_1  y_1  h_1  x_2  y_2  h_2  x_3  y_3  h_3  :  x_N  y_N  h_N       Output  Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.        Sample Input 1 4
2 3 5
2 1 5
1 2 5
3 2 5      Sample Output 1 2 2 6  In this case, the center coordinates and the height can be identified as (2, 2) and 6 .       Sample Input 2 2
0 0 100
1 1 98      Sample Output 2 0 0 100  In this case, the center coordinates and the height can be identified as (0, 0) and 100 . Note that C_X and C_Y are known to be integers between 0 and 100 .       Sample Input 3 3
99 1 191
100 1 192
99 0 192      Sample Output 3 100 0 193  In this case, the center coordinates and the height can be identified as (100, 0) and 193 .

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

A=[]
cnt,add=0,[0,0]
for i in range(101):
    for j in range(101):
        for x,y,h in XYH:
            H=h+abs(x-i)+abs(y-j)
            A.append([H,i,j])

for H,cx,cy in A:
    flag=1
    for x,y,h in XYH:
        if max(H-abs(x-cx)-abs(y-cy),0)!=h:flag=0
        if not flag:break
    if flag:print(cx,cy,H);exit()

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

A=[]
cnt,add=0,[0,0]
for i in range(101):
    for j in range(101):
        for x,y,h in XYH:
            H=h+abs(x-i)+abs(y-j)
            A.append([H,i,j])

for H,cx,cy in A:
    flag=1
    for x,y,h in XYH:
        if max(H-abs(x-cx)-abs(y-cy),0)!=h:flag=0
        if not flag:break
    if flag:
        print(cx,cy,H);exit()

Solution (Python):
N=int(input())
xyh=[list(map(int,input().split(' '))) for i in range(N)]
for i in range(101):
    for j in range(101):
        H_0=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh])
        H_1=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh if h!=0])
        if len(H_0)==1:
            print(i,j,max(H_0))
            exit()
        if len(H_1)==1:
            cx,cy,H=i,j,max(H_1)
print(cx,cy,H)

Solution (Python):
import sys


from collections import Counter, deque, defaultdict





from operator import attrgetter, itemgetter





readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    hbase = 0
    idx = 0

    while hbase == 0:
        xbase = xyh[idx][0]
        ybase = xyh[idx][1]
        hbase = xyh[idx][2]
        idx += 1

    for x in range(101):
        for y in range(101):
            h = hbase + (abs(xbase - x) + abs(ybase - y))
            for i in range(n):
                htemp = max((h - (abs(xyh[i][0] - x) + abs(xyh[i][1] - y)), 0))
                if htemp != xyh[i][2]:
                    break
            else:
                print(x, y, h)
                sys.exit()


if __name__ == '__main__':
    main()

Solution (Python):
import sys
N = int(input())
points = [list(map(int, input().split())) for _ in range(N)]

for a,b,c in points:
  if c>0:
    a,b,c
    break

f = lambda x, y: abs(a-x) + abs(b-y)

for i in range(101):
  for j in range(101):
    height = f(i, j) + c
    flg = True
    for x, y, h in points:
      if h != max(height - abs(x-i) - abs(y-j) , 0):
        flg = False
        break
    if flg:
      print(i, j, height)
      sys.exit()

Solution (Python):
n=int(input())
inf=[list(map(int,input().split())) for i in range(n)]
for a,b,c in inf:
    if c>0:
        x,y,h=a,b,c
        break
def hei(a,b):
    return h+abs(a-x)+abs(b-y)
for i in range(101):
    for j in range(101):
        flag=True
        H=hei(i,j)
        
        
        for k in range(n):
            
            
            if max(H-abs(inf[k][0]-i)-abs(inf[k][1]-j),0)!=inf[k][2]:
                flag=False
                break
        if flag:
            print(i,j,H)
            exit()

Solution (Python):
N=int(input())
xyh=[list(map(int,input().split(' '))) for i in range(N)]
for i in range(101):
    for j in range(101):
        H_0=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh])
        H_1=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh if h!=0])
        if len(H_0)==1:
            print(i,j,max(H_0))
            exit()
        if len(H_1)==1:
            cx,cy,H=i,j,max(H_1)
print(cx,cy,H)

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

def d(a,b,c,d):
  return abs(c-a)+abs(d-b)


for i in range(101):
  for j in range(101):
    H0 = d(i,j,X,Y)+H
    flag = 1
    for l in arr:
      if l[2] != max(0,H0-d(i,j,l[0],l[1])):
        flag = 0
        break
    if flag == 1:
      print(i,j,H0)
      quit()

Solution (Python):
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
for i in range(101):
    for j in range(101):
        H = []
        MIN = float('inf')
        for k in range(n):
            if a[k][2] == 0:
                MIN = min(MIN, abs(a[k][0] - i) + abs(a[k][1] - j))
            else:
                H.append(a[k][2] + abs(a[k][0] - i) + abs(a[k][1] - j))
        if len(set(H)) == 1 and H[0] <= MIN:
            print(i, j, H[0])
            exit()

Solution (Python):
def main():
    N = int(input())
    points = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        points.append((x, y, h))
        if h >= 1:
            hint = (x, y, h)

    for px in range(101):
        for py in range(101):
            H = hint[2] + abs(px-hint[0]) + abs(py-hint[1])
            clearflag = True
            for point in points:
                x, y, h = point
                val = max([H - abs(px-x) - abs(py-y), 0])
                if val != h:
                    clearflag = False

            if clearflag:
                print(px, py, H)
                return
if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
xyh=[]
for i in range(n):
	x,y,h=map(int,input().split())
	xyh.append((x,y,h))
def dis(a,b):
	return abs(a[0]-b[0])+abs(a[1]-b[1])
for i in range(101):
	for j in range(101):
		for k in range(n):
			if xyh[k][2]!=0:
				kari=dis(xyh[k],(i,j))+xyh[k][2]
				break
		f=1
		for k in range(n):
			if xyh[k][2]!=max(kari-dis(xyh[k],(i,j)),0):
				f=0
				break
		if f:
			print(i,j,kari)
			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())

import sys

for cx in range(0,101):
    for cy in range(0,101):
        H = [0]*N
        for i in range(N):
            H[i] = h[i] + abs(x[i]-cx) + abs(y[i]-cy)
        for i in range(N):
            if h[i] == 0:
                H[i] = min(H)
        if max(H) == min(H):
            print(cx,cy,max(H))
            sys.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()))

for i in range(101):
    for j in range(101):
        
        for k in range(N):
            if h[k] == 0:
                continue
            H = abs(i-x[k]) + abs(j-y[k]) + h[k]
            break

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

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

for x,y,h in lst:
    if h != 0:
        break

for cx in range(101):
    for cy in range(101):
        H = abs(cx-x) + abs(cy-y) + h
        if all(hi == max(H-abs(cx-xi)-abs(cy-yi),0) for xi,yi,hi in lst):
            print(cx,cy,H)
            exit()

Solution (Python):
def main():
    N = int(input())
    x = [0]*N
    y = [0]*N
    h = [0]*N
    k = N
    
    for i in range(N):
        x[i], y[i], h[i] = map(int, input().split())
        if(h[i] > 0):
            k = min(k, i)
    
    for Cx in range(101):
        for Cy in range(101):
            tmp = abs(x[k]-Cx)+abs(y[k]-Cy)+h[k]
            for i in range(N):
                if(h[i] != max(tmp-abs(x[i]-Cx)-abs(y[i]-Cy), 0)):
                    break
                if(i == N-1 and tmp > 0):
                    print(Cx, Cy, tmp)
                    quit()               
main()

Solution (Python):
import sys

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


for cx in range(101):
  for cy in range(101):
    ch=-1
    for h,x,y in hxylist:
      if h==0:
        max_ch=h+abs(x-cx)+abs(y-cy)
        if max_ch<ch:
          break
      elif ch==-1:
        ch=h+abs(x-cx)+abs(y-cy)
        
      else:
        ch2=h+abs(x-cx)+abs(y-cy)
        if ch!=ch2:
          break
    else:
      print(cx,cy,ch)
      sys.exit(0)

Solution (Python):








import sys
sys.setrecursionlimit(10 ** 5 + 10)


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

    def height(X,Y,Cx,Cy,H):
        return max(H-abs(X-Cx)-abs(Y-Cy),0)
    def main():
        for i in range(101):
            for j in range(101):
                H = data[0][2] + abs(data[0][0] - i) + abs(data[0][1] - j)
                for k in range(1,N):
                    if height(data[k][0],data[k][1],i,j,H)!=data[k][2]:
                        break
                    elif k==N-1:
                        print(i,j,H)
                        return None

    main()

resolve()

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

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

X0,Y0,H0 = XYH[0]
if N == 1:
    print(X0,Y0,H0)
    exit()

for Cx in range(101):
    for Cy in range(101):
        H = H0 + abs(X0 - Cx) + abs(Y0 - Cy)
        flag = True
        for X,Y,h in XYH[1:]:
            if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                continue
            flag = False
        if flag:
            print(Cx,Cy,H)
            exit()

Solution (Python):
import sys
import copy

N = int(input())

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

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

for cx in range(101):
    for cy in range(101):
        beforeH = ""
        roop = 0
        minH = float('inf')
        for i in range(len(XYH)):
            if XYH[i][2] == 0:
                minH = min(minH, abs(cx-XYH[i][0])+abs(cy-XYH[i][1]))
                roop += 1
            else:
                calced_H = calcH(XYH[i][0], XYH[i][1], XYH[i][2], cx, cy)
                if beforeH == "":
                    beforeH = calced_H
                elif calced_H > minH:
                    break
                elif beforeH != calced_H:
                    break
                roop += 1
        if roop == N and calced_H <= minH:
            print(str(cx)+" "+str(cy)+" "+str(beforeH))
            sys.exit()

Solution (Python):
N=int(input())
field=[[0 for _ in range(101)] for _ in range(101)]

p=[list(map(int,input().split())) for _ in range(N)]
for x,y,h in p:
    if h!=0:
        tem_x=x
        tem_y=y
        tem_h=h
        break

for i in range(101):
    for k in range(101):
        flag=True
        H=tem_h+abs(tem_x-i)+abs(tem_y-k)
        for x,y,h in p:
            if h==max(H-abs(x-i)-abs(y-k),0):
                pass
            else:
                flag=False
        if flag:
            print(i,k,H)
            exit()

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

xyh_list = list()

for i in range(N):
    x,y,h = map(int, input().split())
    xyh_list.append((x,y,h))
    
for i in range(N):
    h = xyh_list[i][2]
    if h != 0:
        no_zero_h = i
        break


break_flag = 0

for i in range(0,101):
    for j in range(0,101):
        
        x = xyh_list[no_zero_h][0]
        y = xyh_list[no_zero_h][1]
        h = xyh_list[no_zero_h][2]
        H = h + abs(x-i) + abs(y-j)
        
        if 1 <= H:
            for k in range(0,N):
                x = xyh_list[k][0]
                y = xyh_list[k][1]
                h = xyh_list[k][2]
                
                if (h != 0 and h + abs(x-i) + abs(y-j) != H) or (h == 0 and H - abs(x-i) - abs(y-j) > 0):
                    break
            else:
                print(i,j,H)
                break_flag = 1
                
        if break_flag == 1:
            break
            
    if break_flag == 1:
        break

Solution (Python):
from operator import itemgetter
N=int(input())

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

xyh.sort(key=itemgetter(2),reverse=True)
for h in xyh:
    if h[2]==0:
        count+=1
for px in range(101):
    for py in range(101):
        judge=0
        base=0
        for i in xyh:
            if i[2]>=1:
                if base==0:
                    base=i[2]+abs(i[0]-px)+abs(i[1]-py)
                    judge+=1
                elif base==i[2]+abs(i[0]-px)+abs(i[1]-py):
                    judge+=1
            else:
                if max(base-abs(i[0]-px)-abs(i[1]-py),0)==0:
                    judge+=1

        if judge==N:
            print(px,py,base)
            break

Solution (Python):

n = int(input())

data = [list(map(int, input().split())) for _ in range(n)]
result = [0] * n
flag = 1

for i in range(n):
    if data[i][2] != 0:
        start = i
        break
for i in range(100 + 1):
    for j in range(100 + 1):
        flag = 1
        h = data[start][2] + abs(data[start][0] - i) + abs(data[start][1] - j)
        for k in range(n):
            if data[k][2] != max(h - abs(data[k][0] - i) - abs(data[k][1] - j), 0):
                flag = 0
                break
        if flag == 1:
            print("{0} {1} {2}".format(i, j, h))
            exit()

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N=int(readline())
    x=[0]*N
    y=[0]*N
    h=[0]*N
    for i in range(N):
        a,b,c=map(int,readline().split())
        x[i]=a
        y[i]=b
        h[i]=c

    ok=False
    for Cx in range(101):
        for Cy in range(101):
            for i in range(N):
                if h[i]==0:
                    continue
                else:
                    H=h[i]+abs(x[i]-Cx)+abs(y[i]-Cy)
                    break
            for i in range(N):
                if h[i]!=max(H-abs(x[i]-Cx)-abs(y[i]-Cy),0):
                    break
            else:
                ok=True

            if ok: break
        if ok: break
    
    print(Cx,Cy,H)

if __name__=="__main__":
    main()

Solution (Python):
N = int(input())
data = []
for _ in range(N):
    x, y, h = map(int,input().split())
    data.append([h, x, y])
data.sort(reverse=True)
end = False
for x in range(101):
    if end:
        break
    for y in range(101):
        if end:
            break
        hi, xi, yi = data[0]
        H = hi + abs(x - xi) + abs(y - yi)
        for i in range(1, N):
            hi, xi, yi = data[i]
            if max(H - abs(x - xi) - abs(y - yi), 0) != hi:
                break
            if i == N - 1:
                print(x, y, H)
                end = True
                break

Solution (Python):
n = int(input())
XYH = list(tuple(map(int, input().split())) for _ in range(n))


for x, y, h in XYH:
    if h != 0:
        x_, y_, h_ = x, y, h
        break

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

        H = abs(x_ - cx) + abs(y_ - cy) + h_

        if all([max(H - abs(x - cx) - abs(y - cy), 0) == h for x, y, h in XYH]):
            print(cx, cy, H)
            exit()

Solution (Python):
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
x, y, h = list(filter(lambda x: x[2], p))[0]

for i in range(101):
  for j in range(101):
    H = h + abs(x-i) + abs(y-j)
    if all(max(H-abs(t[0]-i)-abs(t[1]-j), 0) == t[2] for t in p):
      print(i,j,H)

Solution (Python):
import sys
from collections import Counter
n = int(input())
x,y,h = [0]*n , [0]*n , [0]*n
q = 0
ze = 0

for i in range(n):
    x[i] ,y[i] ,h[i] = map(int,input().split())
    
ss = Counter(h)
if ss[0] >= n-1:
    ze = 1

for xx in range(101):
    for yy in range(101):
        fl = 1
        a = []
        for i in range(n):
            if h[i] != 0 or ze == 1:
                temp = abs(x[i]-xx) + abs(y[i]-yy) + h[i]
                a.append(temp)
                le = len(a)
                
                if le > 1:
                    if a[le-1] != a[le-2]:
                        fl = 0
                        
        if fl == 1:
            print(xx,yy,max(a))
            sys.exit()

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

def to_getH(cx,cy):
    for x, y, h in data:
        if h > 0: 
            return abs(x - cx) + abs(y - cy) + h
def to_checkH(cx,cy,H):
    for x, y, h in data:
        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 = to_getH(cx, cy)
        if to_checkH(cx, cy, H):
            print(cx, cy, H)
            exit()

Solution (Python):




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

    XYH.sort(key=lambda i: i[2], reverse=True)

    for cx in range(101):
        for cy in range(101):
            x, y, h = XYH[0]
            ch = h + abs(cy - y) + abs(cx - x)

            if all([h == max(ch - abs(cy - y) - abs(cx - x), 0) for x, y, h in XYH[1:]]):
                print(cx, cy, ch)
                exit()

    print(XYH)


if __name__ == "__main__":
    main()

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


def set_height(i,x,y):
	ans = z[i][2] + abs(z[i][0] - x) + abs(z[i][1] - y)
	return ans


answer = 0
for j in range(0,101):
	for k in range(0,101):
		flag = 1
		for l in range(0,n):
			if z[l][2] != 0:
				answer = set_height(l,j,k)
				break

		for l in range(0,n):
			if z[l][2] == 0:
				if answer > set_height(l,j,k):	
					flag = 0
					break
			else:
				if answer != set_height(l,j,k):
					flag = 0
					break
		if flag == 1 and answer > 0 :
			test = map(str,(j,k,answer))
			print(" ".join(test))

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

marker = [0]*101
for Cx in range(101):
  marker[Cx] = [True]*101
  for Cy in range(101):
    h = -1
    for i in range(N):
      X,Y,H = query[i]
      if H==0:
        if h > abs(Cx-X)+abs(Cy-Y):
          marker[Cx][Cy] = False
          break
      else:
        a = H+abs(Cx-X)+abs(Cy-Y)
        if h == -1:
          h = a
        elif h != a:
          marker[Cx][Cy] = False
          break
    if marker[Cx][Cy] == True:
      ans = [Cx,Cy,h]
      print(*ans)
      exit()

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

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

X0,Y0,H0 = XYH[0]

if N == 1:
    print(X0,Y0,H0)
    exit()

for Cx in range(101):
    for Cy in range(101):
        H = H0 + abs(X0 - Cx) + abs(Y0 - Cy)
        flag = True
        for X,Y,h in XYH[1:]:
            if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                continue
            flag = False
        if flag:
            print(Cx,Cy,H)

Solution (Python):
from itertools import product

n = int(input())
data = [[int(i) for i in input().split()] for _ in range(n)]
for d in data:
    if d[2] > 0:
        sample = d
        break

for cx, cy in product(range(101), repeat=2):
    ch = sample[2] + abs(sample[0]-cx) + abs(sample[1]-cy)
    for x, y, h in data:
        val = h + abs(x-cx) + abs(y-cy)
        if h != max(ch - abs(x-cx) - abs(y-cy), 0):
            break
    else:
        print(cx, cy, ch)
        break

Solution (Python):
import itertools
n = int(input())
query = []
for _ in range(n):
    x,y,h = map(int,input().split())
    if h != 0:
        query.append((x,y,h))
tx = query[0][0]
ty = query[0][1]
th = query[0][2]
if len(query) == 1:
    print(tx,ty,th)
    exit()
query.pop(0)
c = [i for i in range(101)]
cc = list(itertools.product(c, repeat=2))
for X,Y in cc:
    H = th + abs(tx-X) + abs(ty-Y)
    Flag = True
    for x,y,h in query:
        if max(H - abs(x-X) - abs(y-Y),0) != h:
            Flag = False
            break
    if Flag:
        print(X,Y,H)
        exit()

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

for cx in range(101):
    for cy in range(101):
        H_upper = info[0][2]+abs(info[0][0]-cx)+abs(info[0][1]-cy)
        H_lower = info[0][2]+abs(info[0][0]-cx)+abs(info[0][1]-cy) if info[0][2] != 0 else 0
        for i in range(1,N):
            H_upper = min(H_upper,info[i][2]+abs(info[i][0]-cx)+abs(info[i][1]-cy))
            H_lower = max(H_lower,info[i][2]+abs(info[i][0]-cx)+abs(info[i][1]-cy) if info[i][2] != 0 else 0)
        if H_upper == H_lower and 0 < H_lower:
            print(cx,cy,H_upper)
            break
    else:
        continue
    break

Solution (Python):
N = int(input())
xyh0 = []
xyh1 = []
for i in range(N):
  x, y, h = map(int, input().split())
  if h:
    xyh1.append([x, y, h])
  else:
    xyh0.append([x, y, h])

cands = []
for cx in range(101):
  for cy in range(101):
    H = -1
    for x, y, h in xyh1:
      _h = h + abs(x-cx) + abs(y-cy)
      if H < 0:
        H = _h
      else:
        if H != _h:
          break
    else:
      cands.append([cx, cy, H])

if cands:
  for cx, cy, H in cands:
    for x, y, h in xyh0:
      if H > abs(x-cx) + abs(y-cy):
        break
    else:
      print(cx, cy, H)

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(input = sys.stdin.readline):
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())

    N = II()
    info = []
    for _ in range(N):
        xi, yi, hi = LMIIS()
        if hi != 0:
            xt, yt, ht = xi, yi, hi
        info.append((xi, yi, hi))

    for Cy in range(101):
        for Cx in range(101):
            H = ht + abs(xt - Cx) + abs(yt - Cy)
            found = True
            for xi, yi, hi in info:
                tmp_h = max(H - abs(Cy-yi) - abs(Cx-xi), 0)
                if tmp_h != hi:
                    found = False
                    break
            if found:
                print('{} {} {}'.format(Cx,Cy,H))
                return



if __name__ == '__main__':
    main()

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

for cx in range(101):
    for cy in range(101):
        for k in range(n):
            x, y, h = xyh[k]
            if h:
                H = h + abs(x - cx) + abs(y - cy)
                break

        ans = True
        for k in range(n):
            x, y, h = xyh[k]
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                ans = False
                break
        if ans:
            print(cx, cy, H)
            exit()

Solution (Python):
INF=10**20
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
xyh=sorted(xyh,key=lambda xyh:xyh[2],reverse=True)
for i in range(101):
    for j in range(101):
        res=-INF
        T=True
        for k in range(N):
            tmp=xyh[k][2]+abs(xyh[k][0]-i)+abs(xyh[k][1]-j)
            if(xyh[k][2]>0):
                if(res==-INF):
                    res=tmp
                elif(res!=tmp):
                    T=not T
                    break
            elif(xyh[k][2]==0):
                if(tmp<res):
                    T=not T
                    break
        if T:
            print(i,j,res)
            exit()

Solution (Python):


def read_input():
    n = int(input())
    conds = []
    for _ in range(n):
        x, y, h = map(int, input().split())
        conds.append(((x, y), h))

    return n, conds


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


def satisfy(cond, center):
    c, ch = center
    p, h = cond
    return ch == h + manhattan(p, c)


def zero_satisfy(cond, center):
    c, ch = center
    p, h = cond
    return ch <= manhattan(p, c)


def submit():
    n, conds = read_input()    

    if n == 1:
        p, h = conds[0]
        print("{} {} {}".format(p[0], p[1], h))
        return

    plus_conds = [c for c in conds if c[1] > 0]
    zero_conds = [c for c in conds if c[1] == 0]
    st = plus_conds[0]

    center_cands = []
    for i in range(101):
        for j in range(101):
            t = (i, j)
            th = st[1] + manhattan(st[0], t) 
            center_cands.append((t, th))
    
    
    for cond in plus_conds[1:]:
        center_cands = [c for c in center_cands if satisfy(cond, c)]

    
    for cond in zero_conds:
        center_cands = [c for c in center_cands if zero_satisfy(cond, c)]

    
    center, h = center_cands[0]
    print("{} {} {}".format(center[0], center[1], h))
            

if __name__ == "__main__":
    submit()

Solution (Python):
N = int(input())
x = []
y = []
h = []
for i in range(N) :
    p, q, r = map(int,input().split())
    x.append(p)
    y.append(q)
    h.append(r)

for Cx in range(101) :
    for Cy in range(101) :
        for i in range(N) :
            if h[i] :
                H = h[i] + abs(x[i] - Cx) + abs(y[i] - Cy)
                break
        ans = True
        for i in range(N) :
            if h[i] != max(H - abs(x[i] - Cx) - abs(y[i] - Cy), 0) :
                ans = False
        if ans :
            print(Cx, Cy, H)

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

def check(x,y):

    count = 0
    while l[count][2] == 0:
        count += 1
    h = l[count][2] + abs(x-l[count][0])+abs(y-l[count][1])

    for i,j,k in l[count:]:
        if k != max(h-abs(x-i)-abs(y-j),0):
            return False

    return x,y,h

for i in range(101):
    for j in range(101):
        if check(i,j):
            print(*check(i,j))

Solution (Python):
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)
for cx in range(0,101):
  for cy in range(0,101):
    x0,y0,h0=xyh[0]
    H=h0+abs(x0-cx)+abs(y0-cy)
    if H==0:
      continue
    flag=True
    for x,y,h in xyh:
      if h!=max(H-abs(x-cx)-abs(y-cy),0):
        flag=False
    if flag:
      print(cx,cy,H)
      exit()

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


for i in range(N):
    if xyh[i][2] > 0:
        xx, yy, hh = xyh[i][0], xyh[i][1], xyh[i][2]
        break

for cx in range(101):
    for cy in range(101):
        H = hh + abs(cx-xx) + abs(cy-yy)
        count = 0
        for i in range(N):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            if max(H - abs(x - cx) - abs(y - cy), 0) == h:
                count += 1
        if count == N:
            print(cx, cy, H)
            exit()

Solution (Python):
def main():
    n = int(input())
    XYH = [[int(e) for e in input().split()] for i in range(n)]

    for xi in range(101):
        for yi in range(101):
            top = 1
            for x, y, h in XYH:
                if h > 0:
                    top = h + abs(xi - x) + abs(yi - y)
                    break

            topf = True
            for x, y, h in XYH:
                if (h == 0 and top > abs(xi - x) + abs(yi - y)) \
                        or (h > 0 and top != h + abs(xi - x) + abs(yi - y)):
                    topf = False
                    break

            if(topf):
                print(xi, yi, top)
                exit()

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
L = [list(map(int,input().split())) for k in range(N)]
m = 0
for e in L:
    m = max(m,e[2])

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

for x in range(101):
    for y in range(101):
        for h in range(m,m+101):
            if check(x,y,h) == True:
                print(x,y,h)
                exit(0)

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

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

        else:
            if H>=1:
                print(cx,cy,H)
                exit()

Solution (Python):
N = int(input())
p = list(list(map(int,input().split()))for _ in range(N))

for i in range(N):
    if p[i][2]:
        tmp = i
        break

for Cx in range(101):
    for Cy in range(101):
        H = p[tmp][2] + abs(Cx-p[tmp][0]) + abs(Cy-p[tmp][1])
        flag = True
        for x,y,h in p:
            if h != max(H -abs(Cx-x) - abs(Cy-y), 0):
                flag = False
                break
        if flag:
            print(Cx,Cy,H)

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    xyh = [tuple(map(int, input().split())) for _ in range(N)]
    xyh.sort(reverse=True, key=lambda x:x[2])

    def check(cx, cy):
        def dist(x, y): return abs(x-cx) + abs(y-cy)
        tmp = 0
        for x, y, h in xyh:
            d = dist(x,y)
            if h == 0:
                if tmp > d: return -1
            else:
                if tmp != 0 and tmp != h+d: return -1
                tmp = h+d
        return tmp
    
    for x in range(101):
        for y in range(101):
            H = check(x,y)
            if H >= 0:
                print('{} {} {}'.format(x,y,H))
                return

if __name__ == '__main__':
    main()

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

L = [[0, 0, 0] for _ in range(n)]
for i in range(n):
    x, y, h = map(int, input().split())
    L[i][0] = x
    L[i][1] = y
    L[i][2] = h

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

for i in range(0, 101):
    for j in range(0, 101):
        temp = []
        border = float('inf')
        for k in range(n):
            x = L[k][0]
            y = L[k][1]
            h = L[k][2]
            if h > 0:
                H = abs(i-x)+abs(j-y)+h
                temp.append(H)
            else:
                border = min(border, abs(i-x)+abs(j-y))
        temp = list(set(temp))
        if len(temp) == 1 and temp[0] <= border:
            ans = [i, j, H]
print(*ans)