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.  



Sample input:
4
2 3 5
2 1 5
1 2 5
3 2 5


Sample output:
2 2 6

Submission status: Accepted

Solution code:
import itertools

n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
if n == 1:
    print(xyh[0])
    pass
else:
    for cx, cy in itertools.product(range(0, 101), range(0, 101)):
        flag = False
        tmp_h = 0
        for x, y, h in xyh:
            if h != 0:
                tmp_h_tmp = h + abs(cx-x) + abs(cy-y)
                if tmp_h == 0:
                    tmp_h = tmp_h_tmp
                else:
                    if tmp_h != tmp_h_tmp:
                        flag = True
                        break
        if flag:
            continue
        for x, y, h in xyh:
            if h == 0:
                if not max(tmp_h - abs(cx-x) - abs(cy-y), 0) == 0:
                    flag = True
                    break
        if flag:
            continue
        print(cx, cy, tmp_h)
        break

Submission status: Accepted

Solution code:
import itertools

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)
if n == 1:
    print(x[0], y[0], h[0])
else:
    c = [-1, -1]
    top = -1
    for cx, cy in itertools.product(range(0, 101), range(0, 101)):
        flag = False
        tmp_h = 0
        for j in range(n):
            if h[j] != 0:
                tmp_h_tmp = h[j] + abs(cx-x[j]) + abs(cy-y[j])
                if tmp_h == 0:
                    tmp_h = tmp_h_tmp
                else:
                    if tmp_h != tmp_h_tmp:
                        flag = True
                        break
        if flag:
            continue
        assert tmp_h > 0
        for j in range(n):
            if h[j] == 0:
                if not max(tmp_h - abs(cx-x[j]) - abs(cy-y[j]), 0) == 0:
                    flag = True
                    break
        if flag:
            continue
        c = [cx, cy]
        top = tmp_h
        break
    print(c[0], c[1], top)

Submission status: Accepted

Solution code:
N = int(input())
infos = [0 for i in range(N)]

for i in range(N):
    x,y,h = map(int, input().split())
    infos[i] = [x,y,h]
    if h > 0:
        x1, y1, h1 = x,y,h

for i in range(101):
    for j in range(101):
        H = h1 + abs(x1-i) + abs(y1-j)
        for info in infos:
            x,y,h = info
            if h != max(H - abs(x-i) - abs(y-j), 0):
                break
        else:
            print(i,j,H)
            exit()

Submission status: Accepted

Solution code:
import itertools
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
for cx, cy in itertools.product(range(0,101), repeat=2):
  flag = False
  hhh = []
  for i in range(n):
    if xyh[i][2] != 0:
      h = xyh[i][2] + abs(xyh[i][0]-cx) + abs(xyh[i][1]-cy)
      hhh.append(h)
  if len(set(hhh)) == 1:
    flag = True
    for i in range(n):
      if xyh[i][2] == 0:
         if hhh[0] - abs(xyh[i][0]-cx) - abs(xyh[i][1]-cy) > 0:
            flag = False
  if flag:
    print(cx, cy, hhh[0])

Submission status: Accepted

Solution code:
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]
for i in range(n):
    if s[i][2] > 0:
        a,b,c = s[i][0],s[i][1],s[i][2]
        break

for i in range(101):
    for j in range(101):
        h = abs(a-i)+abs(b-j)+ c
        co = 0
        for r in range(n):
            t = h - abs(i - s[r][0]) - abs(j - s[r][1])
            if s[r][2] != max(t,0):
                co = 1
                break
        if co == 0:
            x = i
            y = j
            break
    if co == 0:
        break

print("{} {} {}".format(x,y,h))

Submission status: Accepted

Solution code:
n=int(input())
l=[]
l1=[]
for i in range(n):
  l1=list(map(int,input().split()))
  l1=l1[::-1]
  l.append(l1)      
l=sorted(l)
for i in range(101):
  for j in range(101):
    b=True
    h=abs(i-l[-1][2])+abs(j-l[-1][1])+l[-1][0]
    for k in range(n-1):
      if max(h-abs(i-l[-2-k][2])-abs(j-l[-2-k][1]),0)!=l[-2-k][0]:
        b=False
    if b:
      print(i,j,h)
      break

Submission status: Accepted

Solution code:
N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
c = 0
H = 0
for i in range(101):
    for j in range(101):
        c = 0
        for k in range(N):
            #print(i,j,max(H - abs(L[k][0] - i) - abs(L[k][1] - j), 0))
            if L[k][2] != 0:
                H = L[k][2] + abs(L[k][0] - i) + abs(L[k][1] - j)
                break
        for k in range(N):
            #print(i,j,k)
            if max(H - abs(L[k][0] - i) - abs(L[k][1] - j), 0) != L[k][2]:
                c = 1
                break
        if c == 0:
            print(i, j, H)
            exit()
print(L)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N = 0
X, Y, H = [], [], []


def set_inputs():
    global N, X, Y, H
    N = get_int()
    X, Y, H = get_data(N, [int, int, int])
    return


def answer(cx, cy):
    x, y, h = next(itertools.dropwhile(
        lambda v: v[2] == 0,
        zip(X, Y, H)
    ))
    ch = h + abs(x - cx) + abs(y - cy)
    for x, y, h in zip(X, Y, H):
        if max(ch - abs(x - cx) - abs(y - cy), 0) != h:
            return False
    print(cx, cy, ch)
    return True


def main():
    setrecursionlimit(100000)
    set_inputs()
    for cx in range(0, 101):
        for cy in range(0, 101):
            if answer(cx, cy):
                return
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
xyh=[]
for i in range(n):
    xyh1=[int(i) for i in input().split()]
    xyh.append(xyh1)
xyh.sort(key=lambda x: x[2])
xm,ym,hm=xyh[-1]
for cx in range(101):
    for cy in range(101):
        H=hm+abs(xm-cx)+abs(ym-cy)
        if all(h==max(H-abs(x-cx)-abs(y-cy),0) for x,y,h in xyh):
            print(cx, cy, H)
            exit()

Submission status: Accepted

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

for i in range(N):
    if list[i][2]:
        x0,y0,h0 = list[i]

for Cx in range(0,101):
    for Cy in range(0,101):
        for i in range(N):
            H = max(h0+abs(x0-Cx)+abs(y0-Cy),0)
            if max(H-abs(list[i][0]-Cx)-abs(list[i][1]-Cy),0) != list[i][2]:
                break
        else:
            print(Cx,Cy,H)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int,input().split(' '))) for i in [0]*N]


ls = [[0]*101 for i in [0]*101]

cor = [[i,j] for i in range(101) for j in range(101)]


for cx,cy in cor:
	H = 0
	for x,y,h in xyh:
		if h != 0:
			hx = abs(cx-x)
			hy = abs(cy-y)
			H = h + hx + hy
			break
	ok = True 
	for x,y,h in xyh:
		hx = abs(cx-x)
		hy = abs(cy-y)
		if h != max(H-hx-hy,0):
			ok = False
			break
	if ok:
		break

print(cx,cy,H)

Submission status: Accepted

Solution code:
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)
MAX=101
for posX in range(MAX):
  for posY in range(MAX):
    needH=-1
    for i in range(N):
      if h[i]>0:
        tmp=h[i]+abs(posX-x[i])+abs(posY-y[i])
        if needH == -1:
          needH=tmp
        elif needH != tmp:
          needH=-2
          break
    if needH==-2:
      continue
    for i in range(N):
      if h[i] == 0:
        dist=abs(posY-y[i])+abs(posX-x[i])
        if needH > dist:
          needH=-2
          break
    if needH == -2:
      continue
    print(posX,posY,needH)

Submission status: Accepted

Solution code:
N = int(input())

list_inp = [list(map(int,input().split())) for _ in range(N)]
list_inp.sort(key=lambda x: x[2], reverse=True)
max_list_inp = list_inp[0]

for x in range(101):
  for y in range(101):
    flg = True
    max_h = max_list_inp[2] + abs(max_list_inp[0] - x) + abs(max_list_inp[1] - y)
    
    # 全サンプルで、結果が一致することを確認する。
    for i in list_inp:
      h = max(max_h - abs(i[0] - x) - abs(i[1] - y), 0)
      if h != i[2]:
        flg = False
        break
    
    if flg:
      ans_x, ans_y,ans_h = x,y,max_h
      break
    
  if flg:
    break
    
    
print(ans_x, ans_y,ans_h)

Submission status: Accepted

Solution code:
N = int(input())
info = [list(map(int,input().split())) for _ in range(N)]
info.sort(key=lambda x:x[2])

x,y,h = info[-1]

for cx in range(101):
  for cy in range(101):
    H = h+abs(x-cx)+abs(y-cy)
    if all(h_ == max(H-abs(x_-cx)-abs(y_-cy),0) for x_,y_,h_ in info):
      print(cx, cy, H)
      exit()

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
    a,b,c=map(int,input().split())
    l.append((a,b,c))
    if c>0:
        x,y,h=a,b,c
ma=len(l)
for s in range(101):
    for t in range(101):
        x2,y2,h2=s,t,h+abs(x-s)+abs(y-t)  #候補点
        c=0
        if all(h3==max(h2-abs(x3-x2)-abs(y3-y2),0)for(x3,y3,h3)in l):
            print(x2,y2,h2)
            exit()
print(-1,-1,-1)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [[int(i) for i in input().split()] for _ in range(N)]
xyh.sort(key = lambda x: x[2])
tx, ty, th = xyh[-1]
for Cx in range(101):
  for Cy in range(101):
    H = th+abs(tx-Cx)+abs(ty-Cy)
    if all(h == max(H-abs(x-Cx)-abs(y-Cy), 0) for x, y, h in xyh):
      print(Cx, Cy, H)
      exit()

Submission status: Accepted

Solution code:
import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    flag=True
    Z=10**18
    for i in range(n):
      x,y,h=s[i]
      if h!=0 and flag:
        H=abs(x-cx)+abs(y-cy)+h
        flag=False
      elif h!=0 and flag==False:
        if H!=abs(x-cx)+abs(y-cy)+h:
          H=10**18+1
          break
      elif h==0:
        Z=min(Z,abs(x-cx)+abs(y-cy)+h)
    if H<=Z:
      print(cx,cy,H)
      exit()

Submission status: Accepted

Solution code:
import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    Z=10**18
    flag=True
    for i in range(n):
      x,y,h=s[i]
      if h!=0:
        if flag:
          H=abs(x-cx)+abs(y-cy)+h
          flag=False
        else:
          if H!=abs(x-cx)+abs(y-cy)+h:
            H=10**18+1
            break
      else:
        Z=min(Z,abs(x-cx)+abs(y-cy))
    if H<=Z:
      print(cx,cy,H)
      exit()

Submission status: Accepted

Solution code:
import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    H=[]
    Z=[]
    for i in range(n):
      x,y,h=s[i]
      if h!=0:
        H.append(abs(x-cx)+abs(y-cy)+h)
      else:
        Z.append(abs(x-cx)+abs(y-cy))
    if len(Z)==0:
      Z.append(10**18)
    if H.count(H[0])==len(H) and min(Z)>=H[0]:
      print(cx,cy,H[0])
      exit()

Submission status: Accepted

Solution code:
from operator import itemgetter

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

xyh.sort(key = itemgetter(2))
tx, ty, th = xyh[-1]
for Cx in range(101):
  for Cy in range(101):
    H = th + abs(tx-Cx) + abs(ty-Cy)
    if all(h == max(H-abs(x-Cx)-abs(y-Cy), 0) for x, y, h in xyh):
      print(Cx, Cy, H)
      exit()

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
if N == 1:
    print(xyh[0][0],xyh[0][1],xyh[0][2])
    exit()

for cx in range(101):
    for cy in range(101):
        H = set()
        d = []
        for x,y,h in xyh:
            if h >= 1:
                H.add(abs(x-cx)+abs(y-cy)+h)
            else:
                d.append(abs(x-cx)+abs(y-cy))

        if len(H) == 1:
            if len(d) == 0 or list(H)[0] <= min(d):
                print(cx,cy,list(H)[0])
                exit()

Submission status: Accepted

Solution code:
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
if N==1:
    print(D[0][0],D[0][1],D[0][2])
    exit()
H={}
for cx in range(101):
    for cy in range(101):
        H=set()
        d = []
        for x, y, h in D:
            if h >=1:
                H.add(abs(x-cx)+abs(y-cy)+h)
            else:
                d.append(abs(x-cx)+abs(y-cy))

        if len(H)==1:
            if len(d)==0 or list(H)[0] <= min(d):
                print(cx, cy, list(H)[0])
                exit()

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
sys.setrecursionlimit(10**7)
N = int(input())
li = [[int(x) for x in input().split()] for _ in range(N)]
li.sort(key=itemgetter(2),reverse=True)
map = [[-1 for _ in range(101)] for _ in range(101)]
ans = [0]*3
for i in range(101):
    for j in range(101):
        h = -1
        flag = True
        for x in li:
            if(h == -1):
                h=x[2]+abs(x[0]-i)+abs(x[1]-j)
            else:
                if(x[2]!=0):
                    if(h!=x[2]+abs(x[0]-i)+abs(x[1]-j)):
                        flag = False
                else:
                    if(h>abs(x[0]-i)+abs(x[1]-j)):
                        flag = False
        if(flag):
            if(h>ans[2]):
                ans=[i,j,h]

print(str(ans[0])+' '+str(ans[1])+' '+str(ans[2]))

Submission status: Accepted

Solution code:
#coding: utf-8
N = int(input())
l = []
for i in range(N):
    a = list(map(int, input().split()))
    if a[2] > 0:
      l.append(a)
if len(l) >= 2:
    for i in range(len(l)-1):
        ans = []
        for cx in range(101):
            for cy in range(101):
                if l[i][2] + abs(l[i][0] - cx) + abs(l[i][1] - cy) == l[i+1][2] + abs(l[i+1][0] - cx) + abs(l[i+1][1] - cy):
                    if i == 0:
                        ans.append([cx, cy])
                    else:
                        if [cx, cy] in ansn:
                            ans.append([cx, cy])
        ansn = ans[:]
        if len(ans) == 1:
            break
    print(ans[0][0], ans[0][1], l[0][2] + abs(l[0][0] - ans[0][0]) + abs(l[0][1] - ans[0][1]))
else:
    print(l[0][0], l[0][1], l[0][2])

Submission status: Accepted

Solution code:
#coding: utf-8
N = int(input())
l = []
for i in range(N):
    a = list(map(int, input().split()))
    if a[2] > 0:
      l.append(a)
if len(l) >= 2:
    for i in range(len(l)-1):
        ans = []
        for cx in range(101):
            for cy in range(101):
                if l[i][2] + abs(l[i][0] - cx) + abs(l[i][1] - cy) == l[i+1][2] + abs(l[i+1][0] - cx) + abs(l[i+1][1] - cy) and l[i][2] != 0 and l[i+1][2] != 0:
                    if i == 0:
                        ans.append([cx, cy])
                    else:
                        if [cx, cy] in ansn:
                            ans.append([cx, cy])
        ansn = ans[:]
        if len(ans) == 1:
            break
    print(ans[0][0], ans[0][1], l[0][2] + abs(l[0][0] - ans[0][0]) + abs(l[0][1] - ans[0][1]))
else:
    print(l[0][0], l[0][1], l[0][2])

Submission status: Accepted

Solution code:
n=int(input())
l=[[] for i in range(n)]
for i  in range(n):
    l[i]=list(map(int,input().split()))
xy=[[] for i in range(101**2)]
k=0
for x in range(101):
    for y in range(101):
        xy[k]=[x,y]
        k+=1
for i in l:
    for j in l:
        tmp=[]
        if i==j:
            continue
        for z in xy:
            if abs(i[0]-z[0])-abs(j[0]-z[0])+abs(i[1]-z[1])-abs(j[1]-z[1])==j[2]-i[2] and i[2]!=0 and j[2]!=0:
                tmp.append(z)
            elif abs(i[0]-z[0])-abs(j[0]-z[0])+abs(i[1]-z[1])-abs(j[1]-z[1])>=j[2]-i[2] and i[2]==0:
                tmp.append(z)
            elif abs(i[0]-z[0])-abs(j[0]-z[0])+abs(i[1]-z[1])-abs(j[1]-z[1])<=j[2]-i[2] and j[2]==0:
                tmp.append(z)
        xy=tmp[:]
        if len(xy)==1:
            break
    if len(xy)==1:
            break
for i in l:
    if i[2]!=0:
        H=i[2]+abs(i[0]-xy[0][0])+abs(i[1]-xy[0][1])
print(xy[0][0],xy[0][1],H)

Submission status: Accepted

Solution code:
#sys.stdin.readline()
import sys
input = sys.stdin.readline

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

Cx,Cy = [],[]
for i in range(101):
  for j in range(101):
    Cx.append(i),Cy.append(j)

if(len(X) == 1):
  print(X[0],Y[0],H[0])
else:
 # H = hi+|Xi-Cx|+|Yi-Cy|
 ans_cx,ans_cy,ans_h = 0,0,0
 for i in range(101*101): 
  judge = 1 #1:全ての点が条件を満たす,0:NG
  for j in range(len(X)):
   if(j == 0): 
     ans_H = H[j] + abs(X[j]-Cx[i]) + abs(Y[j]-Cy[i])
   else:
     tmp_H = H[j] + abs(X[j]-Cx[i]) + abs(Y[j]-Cy[i])
     if(ans_H != tmp_H):
       judge = 0
       break
  if(judge == 1):
    ans_cx,ans_cy = Cx[i],Cy[i]
    break

 print(ans_cx,ans_cy,ans_H)

Submission status: Accepted

Solution code:
N = int(input())
xyh = []
X = 0
Y = 1
H = 2
for i in range(N):
    xyh.append(list(map(int, input().split())))

ng = 0
MAX = 101
estH = -1
newH = -1
for x in range(MAX):
    for y in range(MAX):
        for xyhi in xyh:
            if(xyhi[H] > 0):
                newH = xyhi[H] + abs(x - xyhi[X]) + abs(y - xyhi[Y])
#                print("x={},y={},estH={},newH={}".format(x,y,estH,newH))
                if(estH < 0):
                    estH = newH
                elif(estH != newH):
                    ng = 1
                    break
        if(1 == ng):
#            print("NG1!!!")
            ng = 0
            estH = -1
            continue
        for xyhi in xyh:
            if(xyhi[H] == 0):
                if(estH > abs(x - xyhi[X]) + abs(y - xyhi[Y])):
                    ng = 1
                    break
        if(1 == ng):
#            print("NG2!!!")
            ng = 0
            estH = -1
            continue
        print("{} {} {}".format(x, y, estH))
        exit()

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
xyh = []
for _ in range (N):
    xyh.append([int(x) for x in input().split()])

count = 0
while True:
    if xyh[count][2] > 0:
        xstd = xyh[count][0]
        ystd = xyh[count][1]
        hstd = xyh[count][2]
        break
    else:
        count += 1

for x in range (101):
    for y in range (101):
        Cx = x
        Cy = y
        H = hstd + abs(xstd-Cx) + abs (ystd - Cy)
        xyhcand = []
        for k in range (N) :
            xi = xyh[k][0]
            yi = xyh[k][1]
            h = max(H-abs(xi-Cx)-abs(yi-Cy),0)
            xyhls = [xi,yi,h]
            xyhcand.append(xyhls)
            xyhls = []
        if sorted(xyh) == sorted(xyhcand):
            ans = " ".join([str(x),str(y),str(H)])
            break
        
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
info = np.array([input().split() for _ in range(0, N)], dtype='int')
info = info[np.argsort(info[:,2])][::-1]
start_x = info[0,:][0]
start_y = info[0,:][1]
start_h = info[0,:][2]

for Cx in range(101):
    for Cy in range(101):
        H = start_h+abs(start_x-Cx)+abs(start_y-Cy)
        if all(max(0,H-abs(x-Cx)-abs(y-Cy))==h for x,y,h in info):
            print(Cx,Cy,H)
            break
        else:
            continue
        break

Submission status: Accepted

Solution code:
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
data.sort(key=lambda x:-x[2])

def get_H(data,Cx,Cy):
    x,y,h = data
    return h+abs(x-Cx)+abs(y-Cy) , h==0
def estimate_H(data,Cx,Cy):
    H,_ = get_H(data[0],Cx,Cy)
    for cur_data in data[1:]:
        tmp,isZero = get_H(cur_data,Cx,Cy)
        if isZero and H <= tmp:
            continue
        if H != tmp:
            break
    else:
        return H
    return None

for Cx in range(101):
    for Cy in range(101):
        tmp = estimate_H(data,Cx,Cy)
        if tmp != None:
            print(Cx,Cy,tmp)
            break

Submission status: Accepted

Solution code:
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
xyh = sorted(xyh,key = lambda x:-x[2])
mx,my,mh = xyh[0]
for cx in range(101):
	for cy in range(101):
		H = mh+abs(mx-cx)+abs(my-cy)
		if all(h == max(0,H-abs(x-cx)-abs(y-cy))for x,y,h in xyh):
			print(cx,cy,H)
			exit()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    a = LIR(n)
    if n == 1:
        print(*a[0])
        quit()
    for cy in range(101):
        for cx in range(101):
            for i in range(n):
                x,y,h = a[i]
                if h > 0:
                    H = abs(x-cx)+abs(y-cy)+h
                    break
            f = True
            for i in range(n):
                x,y,h = a[i]
                if max(H-abs(x-cx)-abs(y-cy),0) != h:
                    f = False
                    break
            if f:
                print(cx,cy,H)
                quit()
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
N = int(input().strip())

points = []

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

for cx in range(0,101):
    for cy in range(0,101):
        for p in points:
            if p[2] > 0:
                target = p
                break
        H = (target[2] + abs(target[0] - cx) + abs(target[1] - cy))
        if all([points[i][2] == max(H - (abs(points[i][0] - cx) + abs(points[i][1] - cy)),0) for i in range(0,N)]):
            res = [cx,cy,H]
            break


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

Submission status: Accepted

Solution code:
n=int(input())
p=[list(map(int,input().split()))for _ in range(n)] #[ax,ay,ah]をひとつの要素とする二重リスト
ax,ay,ah=list(filter(lambda x:x[2],p))[0] #x[2]がTrue、つまりahが0以外のリストの先頭の要素を取得
for x in range(101):
    for y in range(101):
        H=ah+abs(ax-x)+abs(ay-y) #Hの予測値
        if all([max(H-abs(t[0]-x)-abs(t[1]-y),0)==t[2]for t in p]): #ahのリストを生成し、予測したHから正しいかどうか判定
            print(x,y,H)

Submission status: Accepted

Solution code:
n = int(input())
XYH = []

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

flag = False
ans = XYH[0]
for i in range(101):
    for j in range(101):
        tempH = abs(XYH[0][0] - i) + abs(XYH[0][1] - j) + XYH[0][2]
        for x,y,h in XYH[1:]:
            if abs(x - i) + abs(y - j) + h != tempH:
                flag = False
                break
            else:
                flag = True
        if flag:
            ans = [i,j,tempH]
            break
    if flag:
        break

print(*ans,sep = " ")

Submission status: Accepted

Solution code:
A=abs;n=int(input());p=eval('list(map(int,input().split())),'*n);x,y,h=[x for x in p if x[2]][0]
for I in range(10201):j,i=I//101,I%101;H=h+A(x-j)+A(y-i);print(*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for s,t,u in p))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

A=abs;n=int(input());p=eval('list(map(int,input().split())),'*n);x,y,h=[x for x in p if x[2]][0]
for I in range(10201):j,i=I//101,I%101;H=h+A(x-j)+A(y-i);print(*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for s,t,u in p))

Submission status: Accepted

Solution code:

n=int(input());p=eval('list(map(int,input().split())),'*n);x,y,h=[x for x in p if x[2]][0]
for I in range(10201):j,i=I//101,I%101;H=h+abs(x-j)+abs(y-i);print(*(j,i,H)*all(u==max(H-abs(s-j)-abs(t-i),0)for s,t,u in p))

Submission status: Accepted

Solution code:

n=int(input());p=eval('list(map(int,input().split())),'*n);x,y,h=[x for x in p if x[2]][0]
for I in range(10201):j,i=I//101,I%101;H=h+abs(x-j)+abs(y-i);print(*(j,i,H)*all(max(H-abs(t[0]-j)-abs(t[1]-i),0)==t[2]for t in p))

Submission status: Accepted

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


for cx in range(0, 101):
    for cy in range(0, 101):
        flag = 1
        x, y, h = XYH[0]
        H = h + abs(x - cx) + abs(y - cy)
        for n in range(1, N):
            xn, yn, hn = XYH[n]
            if hn != max(H-abs(xn-cx)-abs(yn-cy), 0):
                flag = 0
        if flag == 1:
            print(cx, cy, H)
            quit()

Submission status: Accepted

Solution code:
N = int(input())
p = [0, 0, 0]*N

p = [list(map(int, input().split())) for _ in range(N)]
p = sorted(p, key=lambda x:-x[2])
for cx in range(101):
	for cy in range(101):
		H = abs(p[0][0]-cx)+abs(p[0][1]-cy)+p[0][2]
		for i in range(N):
			# if H != abs(x[i]-cx)+abs(y[i]-cy)+h[i]:
			if p[i][2] != max(H-abs(p[i][0]-cx)-abs(p[i][1]-cy), 0):
				break
			if i == N-1:
				ans = [cx, cy, H]
				break
print(ans[0],ans[1],ans[2])

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

point = [[int(item) for item in input().split()] for _ in range(N)]
point.sort(key=lambda x:x[2], reverse=True)

ans = np.zeros((101, 101))

for i, p in enumerate(point):
  if i == 0:
    for j in range(101):
      for k in range(101):
        H = p[2] + abs(j - p[0]) + abs(k - p[1])
        ans[j, k] = H
  else:
    for j in range(101):
      for k in range(101):
        if not ans[j,k] == 0:
          if ans[j,k] != p[2] + abs(j - p[0]) + abs(k - p[1]):
            ans[j,k] = 0
  if len(ans[ans!=0]) <= 1:
    break

x, y = np.where(ans!=0)
print(x[0], y[0], int(ans[x[0],y[0]]))

Submission status: Accepted

Solution code:
n = int(input())
xyh = sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[2])[::-1]
flag = 0
for x in range(101):
    for y in range(101):
        H = abs(xyh[0][0]-x) + abs(xyh[0][1]-y)+xyh[0][2]
        for i in range(n):
            if not((xyh[i][2] == 0 and H - abs(xyh[i][0]-x) - abs(xyh[i][1]-y) <= 0) or H - abs(xyh[i][0]-x) - abs(xyh[i][1]-y) == xyh[i][2]):
                break
            if i == n-1:
                flag = 1
        if flag == 1:
            ans = [x,y,H]
            break
    if flag == 1:
        break
print(str(ans[0])+" "+str(ans[1])+" "+str(ans[2]))

Submission status: Accepted

Solution code:
N = int( input())
X = [ list( map( int, input().split())) for _ in range(N)]
for j in range(N):
    if X[j][2] != 0:
        k = j
        break
A = X[j]


for cx in range(101):
  for cy in range(101):
    H = A[2] + abs(A[0] - cx) + abs(A[1] - cy)
    flag = True
    for i in range(N):
      if max(H - abs(X[i][0]-cx) - abs(X[i][1] - cy), 0) != X[i][2]:
        flag = False
        break
    if flag:
      print(cx,cy,H)
      break
  if flag:
    break

Submission status: Accepted

Solution code:
import sys
 
N = int(input())
infos = [list(map(int, input().rstrip().split(' '))) + [i] for i in range(N)]
infos = sorted(infos, key=lambda x: x[2])[::-1]

if N == 1:
    print(infos[0][0], infos[0][1], infos[0][2])
    sys.exit()

for cy in range(100 + 1):
    for cx in range(100 + 1):
        pseudo_h1 = abs(infos[0][0] - cx) + abs(infos[0][1] - cy) + infos[0][2]
 
        flag_assumpt = True
        for info in infos[1:]:
            pseudo_h2 = abs(info[0] - cx) + abs(info[1] - cy) + info[2]
            
            if info[2] == 0:
                if abs(info[0] - cx) + abs(info[1] - cy) < pseudo_h1:
                    flag_assumpt = False
                    break
                
            elif pseudo_h1 != pseudo_h2:
                flag_assumpt = False
                break
        
        if flag_assumpt:
            print(cx, cy, pseudo_h1)
            sys.exit()