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
n = int(input())

xyhl = []
for _ in range(n):
    x,y,h = map(int,input().split())
    xyhl.append((x,y,h))
    
for x in range(101):
    for y in range(101):
        heightl = []
        for x1,y1,h1 in xyhl:
            hh = abs(x1-x)+abs(y1-y)+h1
            heightl.append(hh)
        height = min(heightl)
        for x1,y1,h1 in xyhl:
            check = max(height - abs(x1-x) - abs(y1-y), 0)
            if check != h1:
                break
        else:
            print(x)
            print(y)
            print(height)
            sys.exit()

Solution (Python):
def main():
    N = int(input())
    xyh = [[int(i) for i in input().split()] for _ in range(N)]
    sx, sy, sh = [(x, y, h) for x, y, h in xyh if h != 0][0]
    for cx in range(101):
        for cy in range(101):
            H = sh + abs(sx - cx) + abs(sy - cy)
            if all(max(H-abs(x - cx)-abs(y - cy), 0) == h for x, y, h in xyh):
                return print(cx, cy, H)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
X, Y, H = [], [], []
X_zero, Y_zero = [], []
C_x, C_y = None, None

for _ in range(N):
	x, y, h = map(int, input().split())
	if h > 0:
		X.append(x)
		Y.append(y)
		H.append(h)
	else:
		X_zero.append(x)
		Y_zero.append(y)
	

end = 0
for i in range(0, 100 + 1):
	if end: break
	for j in range(0, 100 + 1):
		if end: break
		cur = None
		ok = 1
		for n in range(len(X)):
			if cur == None:
				cur = H[n] + abs(i - X[n]) + abs(j - Y[n])
				C_x = i
				C_y = j
			else:
				if cur != H[n] + abs(i - X[n]) + abs(j - Y[n]):
					ok = 0
					break
		if ok:
			end = 1
			for n in range(len(X_zero)):
				if not abs(i - X_zero[n]) + abs(j - Y_zero[n]) >= cur:
					end = 0
					break
			
print(C_x, C_y, cur)

Solution (Python):

N = int(input())

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

cx_candidates = range(101)
cy_candidates = range(101)

candidates = []
for cx in cx_candidates:
    for cy in cy_candidates:
        chs = set()
        for x, y, h in x_y_hs:
            if h == 0:
                continue
            else:
                ch = h + abs(x - cx) + abs(y - cy)
                chs.add(ch)

        if len(chs) == 1:
            ch = list(chs)[0]
            candidates.append([cx, cy, ch])


for cx, cy, ch in candidates:
    solved = True
    for x, y, h in x_y_hs:
        if h != max(ch - abs(x - cx) - abs(y - cy), 0):
            solved = False
            break
    if solved:
        print(cx, cy, ch)
        exit()

Solution (Python):
N = int(input())
lis = []
lstipt = []
cnt = 0
h = 0
while h == 0:
    x, y, h = map(int, input().split())
    if h == 0:
        lstipt.append([x,y,h])
    cnt += 1

for Cx in range(101):
    for Cy in range(101):
        Ph = abs(x-Cx) + abs(y-Cy) + h
        lis.append([Cx,Cy,Ph])

for _ in range(N-cnt):
    x, y, h = map(int, input().split())
    newlis = []
    if h == 0: 
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h >= l[2]:
                newlis.append(l)
    else:
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h == l[2]:
                newlis.append(l)
    lis = newlis

for ipt in lstipt:
    x, y, h = ipt[0], ipt[1], ipt[2]
    newlis = []
    if h == 0: 
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h >= l[2]:
                newlis.append(l)
    else:
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h == l[2]:
                newlis.append(l)
    lis = newlis

print(" ".join(map(str,lis[0])))

Solution (Python):
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(101):
    for j in range(101):
        H=[]
        for k in range(n):
            if l[k][2]>0:
                H.append(l[k][2]+abs(l[k][0]-i)+abs(l[k][1]-j))
            else:
                continue
        if len(set(H))==1:
            for k in range(n):
                if l[k][2]==0:
                    if H[0]-abs(l[k][0]-i)-abs(l[k][1]-j)>0:
                        break
            else:
                print(i,j,H[0])

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

x = xyh[0][0]
y = xyh[0][1]
h = xyh[0][2]

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

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

Solution (Python):

import sys

def sample_index_not_zero_in_all_h(h):
    for i in range(len(h)):
        if h[i] != 0:
            return i

def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    h_isnot_zero = sample_index_not_zero_in_all_h(h)
    for cx in range(0, 101):
        for cy in range(0, 101):
            
            H_is_true = True
            H = h[h_isnot_zero] + abs(x[h_isnot_zero] - cx) + abs(y[h_isnot_zero] - cy)
            for i in range(N):
                if max(H - abs(x[i] - cx) - abs(y[i] - cy) , 0) != h[i]:
                    H_is_true = False
                    break
            if H_is_true == True:
                print(cx, cy, H)
                return



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

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
data=[list(map(int,input().split())) for i in range(n)]
data.sort(key=lambda x:x[2],reverse=True)
def cal(y,x,datum,height):
  return max(height-(abs(y-datum[1])+abs(x-datum[0])),0)==datum[2]
for i in range(101):
  for j in range(101):
    height=abs(i-data[0][1])+abs(j-data[0][0])+data[0][2]
    flag=0
    for k in data[1:]:
      if not cal(i,j,k,height):
        flag=1
        break
    if flag:pass
    else:print(j,i,height);exit()

Solution (Python):
n = int(input())
xs = []
zs = []
for i in range(n):
    x,y,h = list(map(int,input().split()))
    if h == 0:
        zs.append((x,y,h))
    else:
        xs.append((x,y,h))

for i in range(101):
    for j in range(101):
        top = -1
        ans = True
        for x,y,h in xs:
            if top == -1:
                top = h + abs(x-i) + abs(y-j)
            if top != h + abs(x-i) + abs(y-j):
                ans = False
                break
        for x,y,h in zs:
            if top - abs(x-i) - abs(y-j) > 0:
                ans = False
                break
        if ans:
            break
    if ans:
        break
if top == -1:
    top = 1
print(i,j,top)

Solution (Python):
N = int(input())
xyz = []

for _ in range(N):
    temp = list(map(int, input().split()))
    xyz.append(temp)


if N == 1:
    ans = [str(xyz[0][0]), str(xyz[0][1]), str(xyz[0][2])]
else:
    for i in range(101):
        for j in range(101):
            for k in range(N):
                if xyz[k][2] >= 1:      
                    h = max(xyz[k][2] + abs(xyz[k][0] - i) + abs(xyz[k][1] - j),0)

                    count = N
                    for n in range(0,N):
                        g = max(h - abs(i - xyz[n][0]) - abs(j - xyz[n][1]),0)
                        if g == xyz[n][2]:
                            count -= 1
                    
                    if count == 0:
                        ans = [str(i), str(j), str(h)]
                        break
                    break

ans_s = ' '.join(ans)
print(ans_s)

Solution (Python):

import sys










def main():
    n = int(sys.stdin.readline().rstrip())
    info = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]
    
    
    for i in range(n):
        if info[i][2] >= 1:
            x0, y0, h0 = info[i][0], info[i][1], info[i][2]
            break
    

    for x in range(101):
        for y in range(101):
            H = h0 + abs(x - x0) + abs(y - y0)
            for i in range(n):   
                h = max(H - abs(x - info[i][0]) - abs(y - info[i][1]), 0)
                if h != info[i][2]: 
                    break     
            else:  
                res = [x, y, H]
                for i in range(3):
                    res[i] = str(res[i])
                print(' '.join(res))
                sys.exit() 
    
            

if __name__ == "__main__":
    main()

Solution (Python):

import sys










def main():
    n = int(sys.stdin.readline().rstrip())
    info = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]
    
    
    for i in range(n):
        if info[i][2] >= 1:
            x0, y0, h0 = info[i][0], info[i][1], info[i][2]
            break
    

    for x in range(101):
        for y in range(101):
            H = h0 + abs(x - x0) + abs(y - y0)
            for i in range(n):   
                h = max(H - abs(x - info[i][0]) - abs(y - info[i][1]), 0)
                if h != info[i][2]: 
                    break     
            else:  
                res = [x, y, H]
                break 
    
    for i in range(3):
        res[i] = str(res[i])
    
    print(' '.join(res))
            

if __name__ == "__main__":
    main()

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
ind = h.index(max(h))
for cx in range(0, 101):
  for cy in range(0, 101):
    H_calc = h[ind] + abs(x[ind]-cx) + abs(y[ind]-cy)
    for i in range(n):
      if max((H_calc - abs(x[i]-cx) -abs(y[i]-cy)), 0) != h[i]:
        break
    else:
      print(cx, cy, H_calc)
      sys.exit()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    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())

    def check(x0,y0):
        
        for i in range(n):
            if(H[i]==0): continue
            h=H[i]+abs(X[i]-x0)+abs(Y[i]-y0)
            break
        
        for i in range(n):
            if(H[i]!=max(0,h-abs(X[i]-x0)-abs(Y[i]-y0))):
                return False
        return x0,y0,h

    from itertools import product
    for x0,y0 in product(range(101),repeat=2):
        A=check(x0,y0)
        if(A):
            print(*A)
            return
resolve()

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 >= 1:
        xt = a
        yt = b
        ht = c

for Cx in range(101):
    for Cy in range(101):
        H = max(ht + abs(Cx - xt) + abs(Cy - yt), 0)
        for i in range(N):
            Z = max(H - abs(Cx - x[i]) - abs(Cy - y[i]), 0)
            if h[i] != Z:
                break
        else:
            res = [str(Cx), str(Cy), str(H)]

print(" ".join(res))

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

for i in range(101):
    for j in range(101):
        ch = []
        z = []
        for x, y, h in l:
            if h == 0: z.append((x, y))
            else: ch.append(abs(x - j) + abs(y - i) + h)
        if len(set(ch)) == 1:
            for x, y in z:
                if ch[0] - abs(j - x) - abs(i - y) > 0: break
            else:
                print(j, i, ch[0])
                exit()

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


def height(H,X,CX,Y,CY):
    tmp=max(H-abs(X-CX)-abs(Y-CY),0)
    return  tmp

for cx in range(101):
    for cy in range(101):
        H=h[cnt]+abs(x[cnt]-cx)+abs(y[cnt]-cy)
        flag = True
        for k in range(n):
            if h[k] != height(H,x[k],cx,y[k],cy):
                flag=False

        if flag:
            ans=[cx,cy,H]
            print(*ans)
            exit()

Solution (Python):
n=int(input())
 
L=[list(map(int,input().split())) for i in range(n)]
LSort=sorted(L,key=lambda x:x[2])
x,y,h=LSort[-1]

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

Solution (Python):
N=int(input())
XYH=[tuple(map(int,input().split())) for i in range(N)]
XYH.sort(key=lambda x:x[2])
a,b,c=XYH[-1]

import sys
for x in range(101):
    for y in range(101):
        H=abs(x-a)+abs(y-b)+c
        F=1
        for i in range(N):
            if max(H-abs(x-XYH[i][0])-abs(y-XYH[i][1]),0)!=XYH[i][2]:
                F=0
                break
        if F:
            print(x,y,H)
            sys.exit()

Solution (Python):
def calc_h(cx,cy,xyh_item):
  res=abs(cx-xyh_item[0])+abs(cy-xyh_item[1])+xyh_item[2]
  return res

n=int(input())
xyh=[[int(x) for x in input().split()] for _ in range(n)]



xyh0=[]
xyh1=[]
for item in xyh:
  if item[2]==0:
    xyh0.append(item)
  else:
    xyh1.append(item)

xyh=xyh1

for item0 in xyh0:
  if any([calc_h(item1[0],item1[1],item0)==item1[2] for item1 in xyh1]):
    xyh.append(item0)
n=len(xyh)


anslist=[]
xyh.sort(key=lambda x:x[0],reverse=True)
for x in range(101):
  for y in range(101):
    c=0
    tmp=calc_h(x,y,xyh[0])
    for i in range(1,n):
      if tmp!=calc_h(x,y,xyh[i]):
        break
      else:
        c+=1
    
    
    anslist.append([c,x,y,tmp])


anslist.sort(key=lambda x:x[0])
print(*anslist[-1][1:])

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

    for i in range(101):
        for j in range(101):
            k = 0
            while True:
                if l[k][2] == 0:
                    k += 1
                else:break
            h = l[k][2] + abs(l[k][0] - i) + abs(l[k][1] - j)
            flag = 0
            for sl in l:
                if max(h - abs(sl[0] - i) - abs(sl[1] - j),0) == sl[2]:
                    flag += 1
                else: break
            if flag == n:
                return [i,j,h]
    
    return False

print(" ".join(map(str,main())))

Solution (Python):
import sys

N = int(input())

xyh = []
minh = 0

for i in range(N):

    x,y,h = map(int,input().split())
    xyh.append([x,y,h])
    minh = max(minh,h)


for cx in range(101):

    for cy in range(101):

        for ch in range(201):

            flag = True
            ch += minh 

            for i in range(N):

                if xyh[i][2] == 0 and ch - abs(xyh[i][0] - cx) - abs(xyh[i][1] -cy) > 0:
                    flag = False
                    break

                elif xyh[i][2] != 0 and ch - abs(xyh[i][0] - cx) - abs(xyh[i][1] -cy) != xyh[i][2]:
                    flag = False
                    break

            if flag:
              print (cx,cy,ch)
              sys.exit()

Solution (Python):
xyh = []
n = int(input())
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):
		h = 0
		judge = 1
		for k in range(n):
			if xyh[k][2] > 0:
				h = xyh[k][2] + abs(cx-xyh[k][0]) + abs(cy-xyh[k][1])
				break
		for k in range(n):
			if max(h - abs(cx-xyh[k][0]) - abs(cy-xyh[k][1]), 0) != xyh[k][2]:
				judge = 0
				break
		if judge:
			print(cx, cy, h)
			exit(0)

Solution (Python):
N = int(input())
xs = []
ys = []
hs = []
for i in range(N):
	x, y, h = map(int, input().split())
	xs.append(x)
	ys.append(y)
	hs.append(h)
for cx in range(101):
	for cy in range(101):
		h = 0
		for i in range(N):
			if hs[i] > 0:
				h = hs[i] + abs(cx - xs[i]) + abs(cy - ys[i])
				break
		ok = True
		for i in range(N):
			if max(h - abs(cx - xs[i]) - abs(cy - ys[i]), 0) != hs[i]:
				ok = False
				break
		if ok:
			print(cx, cy, h)
			exit(0)

Solution (Python):
N = int(input().strip())
data = [[int(str) for str in input().strip().split()] for _ in range(N)]

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

for cx in range(101):
    for cy in range(101):
        H = abs(data[0][0] - cx) + abs(data[0][1] - cy) + data[0][2]
        flag = True
        for x, y, h in data:
            if h > 0 and h != H - abs(x - cx) - abs(y - cy):
                flag = False
                break
            if h == 0 and H > abs(x - cx) + abs(y - cy):
                flag = False
                break
        
        if flag:
            print(cx, cy, 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())
a=0
i=0
while h[i]==0:
  a=a+1
  i=i+1
for i in range(101):
  for j in range(101):
    H=abs(i-x[a])+abs(j-y[a])+h[a]
    b=0
    for k in range(n):
      if h[k]!=max(H-(abs(i-x[k])+abs(j-y[k])),0):
        break
      else:
        b=b+1
        if b==n:
          print(i,j,H)
    else:
      continue

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

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

p = points[0][0]
q = points[0][1]
r = points[0][2]

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

for i in range(0,101):
  for j in range(0,101):
    H= points[0][2] + abs(points[0][0] - i) + abs(points[0][1] - j)
    for x,y,z in points:
      if z != max(H - abs(x - i) - abs(y - j),0):
        break
    else:
      print(i,j,H)

Solution (Python):
n = int(input()) 
  
data = []
p, q, r = (0, 0, 0)
for _ in range(n):
    (l, m, n) = map(int, input().split())
    data.append([l, m, n])
    if n:
        p = l
        q = m
        r = n
 
 
for x in range(101):
    for y in range(101):
        h = r + abs(p - x) + abs(q - y)
        if all(c == max(h - abs(a - x) - abs(b - y), 0) for a, b, c in data):
            print("{} {} {}".format(x, y, h))
            exit(0)

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

xyh1 = [] 
xyh2 = [] 
for _ in range(N) :
    x, y, h = map(int, input().split())
    if h > 0 :
        xyh1.append((x, y, h))
    else :
        xyh2.append((x, y, h))

def solve() :
    for Cx in range(0, 101) :
        for Cy in range(0, 101) :
            
            x, y, h = xyh1[0]
            H = h + abs(x-Cx) + abs(y-Cy)
            
            flag = False
            for x, y, h in xyh1[1:] :
                if H != h + abs(x-Cx) + abs(y-Cy) :
                    flag = True
                    break
                    
            if flag :
                continue
                
            for x, y, h in xyh2 :
                if H - abs(x-Cx) - abs(y-Cy) > 0 :
                    flag = True
                    break
                    
            if flag :
                continue
                
            return (Cx, Cy, H)
            
print(*solve())

Solution (Python):
import sys


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    xyh = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    xyh.sort(key=lambda x: x[2], reverse=True)
    for x in range(101):
        for y in range(101):
            b = True
            h = 0
            for i in range(n):
                xx, yy, hh = xyh[i]
                if i == 0:
                    h = hh + abs(xx - x) + abs(yy - y)
                else:
                    if hh != max(h - abs(xx - x) - abs(yy - y), 0):
                        b = False
                        break
            if b:
                print(x, y, h)
                exit()


if __name__ == '__main__':
    slove()

Solution (Python):
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
flag=False
for cx in range(101):
    if flag:
        break
    for cy in range(101):
        count=0
        if flag:
            break
        for i in range(N):
            if a[i][2]!=0:
                if count==0:
                    H=a[i][2]+abs(cx-a[i][0])+abs(cy-a[i][1])
                    count+=1
                if H!=a[i][2]+abs(cx-a[i][0])+abs(cy-a[i][1]):
                    break
            if i==N-1:
                x=cx
                y=cy
                flag=True
                for k in range(N):
                    if a[k][2]!=max(H-abs(x-a[k][0])-abs(y-a[k][1]),0):
                        flag=False
print(x,y,H)

Solution (Python):
def main():
  n=int(input())
  x=[]
  y=[]
  h=[]
  for i in range(n):
    i,j,k=map(int,input().split())
    x.append(i)
    y.append(j)
    h.append(k)
  h,x,y=zip(*reversed(sorted(zip(h,x,y))))
  for i in range(101):
    for j in range(101):
      h0=h[0]+abs(i-x[0])+abs(j-y[0])
      c=1
      for k in range(1,n):
        if max(h0-abs(i-x[k])-abs(j-y[k]),0)==h[k]:
          c+=1
        else:
          break
      if c==n:
        print(i,j,h0)
        return
main()

Solution (Python):
N=int(input())
x,y,h=[],[],[]
for i in range(0,N):
  x1,y1,h1=map(int,input().split())
  x.append(x1)
  y.append(y1)
  h.append(h1)
for cx in range(0,101):
  for cy in range(0,101):
    ans=1
    m=0
    for i in range(0,N):
      if(h[i]!=0):
        m=abs(x[i]-cx)+abs(y[i]-cy)+h[i]
        break
    for j in range(0,N):
      if(max(m-abs(x[j]-cx)-abs(y[j]-cy),0)!=h[j]):
        ans=0
    if(ans):
      print(cx,cy,m)
      break

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    xyh = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    xyh.sort(key=lambda x: x[2], reverse=True)
    for i in range(101):
        for j in range(101):
            th = -1
            b = True
            for x, y, h in xyh:
                if th == -1:
                    th = h + abs(x - i) + abs(y - j)
                else:
                    if h != max(th - abs(x - i) - abs(y - j), 0):
                        b = False
                        break
            if b:
                print(i, j, th)
                exit()


if __name__ == '__main__':
    slove()

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

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

seikai = True
for yc in range(101):
    seikai = False
    for xc in range(101):
        valid = True
        h, x, y = Q[0]
        hc = abs(x-xc) + abs(y-yc) + h
        for (h, x, y) in Q:
            if h == 0:
                if hc > abs(x-xc) + abs(y-yc) + h:
                    valid = False
                    break
            else:
                if hc != abs(x-xc) + abs(y-yc) + h:
                    valid = False
                    break
        if not valid:
            continue
        seikai = True
        break
    if seikai:
        break

print(xc, yc, hc)

Solution (Python):
N = int(input())
hxy = []
for _ in range(N):
    x, y, h = map(int, input().split())
    hxy.append((h, x, y))
hxy.sort(reverse=True)
for x in range(101):
    for y in range(101):
        H = abs(hxy[0][1] - x) + abs(hxy[0][2] - y) + hxy[0][0]
        for j in range(1, N):
            if max(0, H - abs(x - hxy[j][1]) - abs(y - hxy[j][2])) == hxy[j][0]:
                continue
            else:
                break
        else:
            print(x, y, H)

Solution (Python):
N=int(input())
X,Y,H=[],[],[]
for i in range(N):
  XX,YY,HH=map(int,input().split())
  X.append(XX)
  Y.append(YY)
  H.append(HH)
for i in range(101):
  for j in range(101):
    ans=1
    m=0
    for l in range(N):
      if(H[l]!=0):
        m=abs(X[l]-i)+abs(Y[l]-j)+H[l]
        break
    for k in range(N):
      if(max(m-abs(X[k]-i)-abs(Y[k]-j),0)!=H[k]):
        ans=0
    if(ans):
      print(i,j,m)
      break

Solution (Python):

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

Solution (Python):
def solve():
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            h_cand = None
            for x, y, h in xyh:
                if h == 0:
                    continue
                h_calced = h + abs(x - cx) + abs(y - cy)
                if (h_cand is None) or (h_cand == h_calced):
                    h_cand = h_calced
                else:
                    h_cand = None
                    break

            if h_cand is None:
                continue

            for x, y, h in xyh:
                if h != 0:
                    continue
                if h_cand - abs(x - cx) - abs(y - cy) > 0:
                    h_cand = None
                    break

            if h_cand is None:
                continue

            return cx, cy, h_cand
    return None


n = int(input())
xyh = tuple(tuple(map(int, input().split())) for _ in range(n))

print(*solve())

Solution (Python):

from operator import itemgetter as gt


def main():
    N, *XYH = map(int, open(0).read().split())
    A = [(x, y, h) for x, y, h in zip(*[iter(XYH)] * 3)]
    A.sort(key=gt(2), reverse=1)
    for x in range(101):
        for y in range(101):
            i, j, k = A[0]
            h = k + abs(i - x) + abs(j - y)
            for i, j, k in A[1:]:
                if k != max(h - abs(i - x) - abs(j - y), 0):
                    break
            else:
                print(x, y, h)
                return


if __name__ == "__main__":
    main()

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:
        g=i

for i in range(101):
    for j in range(101):
        t=h[g]+abs(x[g]-i)+abs(y[g]-j)
        f=0
        for k in range(0,n):
            if h[k]==max(0,t-abs(x[k]-i)-abs(y[k]-j)):
                f+=1
        if f==n:
            print(i,j,t)
            exit()

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

def ok(cx, cy):
    x, y, h = xyh[0]
    H1 = h + abs(x - cx) + abs(y - cy)
    for x, y, h in xyh[1:]:
        H2 = h + abs(x - cx) + abs(y - cy)
        if h > 0 and H1 != H2:
            return -1
        if H1 > H2:
            return -1
    return H1

for cx in range(101):
    for cy in range(101):
        H = ok(cx, cy)
        if H >= 0:
            print(cx, cy, H)
            exit(0)

Solution (Python):
N = int(input())
l = []
for i in range(N):
    x, y, h = list(map(int, input().split(' ')))
    l.append((x, y, h))
if len(l) == 1:
    print('%d %d %d' % (l[0][0], l[0][1], l[0][2]))
    exit()
l = sorted(l, key=lambda x: x[2])[::-1]
for cx in range(101):
    for cy in range(101):
        takasa = None
        correct = True
        for x, y, h in l:
            if takasa is None:
                takasa = h + (abs(cx - x) + abs(cy - y))
            elif h != max(takasa - (abs(cx - x) + abs(cy - y)), 0):
                correct = False
                break
        if correct:
            print('%d %d %d' % (cx, cy, l[0][2] + abs(l[0][0] - cx) + abs(l[0][1] - cy)))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
xyh = [LIST() for _ in range(N)]

ins = (-1,-1,-1)
for x, y, h in xyh:
	if h >= 1:
		ins = (x, y, h)

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

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

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

    H = xyh[0][2]+abs(xyh[0][0]-cx)+abs(xyh[0][1]-cy)
            
    for xxyyhh in xyh[1:]:
      x = xxyyhh[0]
      y = xxyyhh[1]
      height = xxyyhh[2]
      
      if height == max(H -abs(x-cx) - abs(y-cy),0):
        continue
      else:
        break  
    else:
      print(cx,cy,H)
      sys.exit()

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


def f(points):
    for x in range(0, 101):
        for y in range(0, 101):
            p = points[0]
            h = abs(x - p[0]) + abs(y - p[1]) + p[2]
            same = True
            for i in range(1, len(points)):
                p = points[i]
                h_p = max(0, h - abs(x - p[0]) - abs(y - p[1]))
                if h_p != p[2]:
                    same = False
                    break
            if same:
                return x, y, h
    return -1,-1,-1


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

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

for x in range(101):
  for y in range(101):
    for i in range(n):
       if v[i][2]:
         H=v[i][2]+abs(v[i][0]-x)+abs(v[i][1]-y)
         break
    for i in range(n):
      if v[i][2]:
         if H != v[i][2]+abs(v[i][0]-x)+abs(v[i][1]-y):
           break
      else:
        if H>abs(v[i][0]-x)+abs(v[i][1]-y):
          break
    else:
      print(x,y,H)
      exit