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 sys
n = int(input())
P = [0] * n
for i in range(n):
    P[i] = list(map(int, input().split()))
P = sorted(P, key=lambda x: x[2], reverse=True)

max_h = P[0][2]

for hh in range(max_h+200, max_h-1, -1):
    for cx in range(101):
        for cy in range(101):
            for x, y, h in P:
                th = max(hh-abs(cx-x)-abs(cy-y),0)
                if h == th:
                    continue
                else:
                    break
            else:
                print('%d %d %d' % (cx, cy, hh))
                sys.exit(0)

Submission status: Accepted

Solution code:
n=int(input())
e = [[int(i) for i in input().split()] for i in range(n)]
h=0
for a in range(n):
    if e[a][2]>0:
        s=a
        break
for x in range(0,101):
    for y in range(0,101):
            k=abs(x-e[s][0])+abs(y-e[s][1])+e[s][2]
            for i in range(0,n):
                if e[i][2]!=max(k-abs(x-e[i][0])-abs(y-e[i][1]),0):
                    break
            else:
                print(x,y,k)

Submission status: Accepted

Solution code:
N = int(input())
points = [[int(s) for s in input().split()] for i in range(N)]
h_max = max(h for x, y, h in points)

for H in range(h_max, h_max + 1000):
    for Cx in range(101):
        for Cy in range(101):
            ok = True
            for x, y, h in points:
                h_calc = max(H - abs(x - Cx) - abs(y - Cy), 0)
                if h != h_calc:
                    ok = False
                    break
            if ok:
                print('{} {} {}'.format(Cx, Cy, H))
                exit()

Submission status: Accepted

Solution code:
N = int(input())
xyz = []
for i in range(N):
    xyz.append(list(map(int, input().split())))
H = 0
h = 0
flag = False
maxz = xyz[0][2]
maxy = xyz[0][1]
maxx = xyz[0][0]
for k in range(N):
    if xyz[k][2] > maxz:
        maxz = xyz[k][2]
        maxx = xyz[k][0]
        maxy = xyz[k][1]
for i in range(101):
    for j in range(101):
        H = maxz + abs(maxx-i) + abs(maxy-j)
        for k in xyz:
            h = H -abs(k[0]-i)-abs(k[1]-j)
            if h < 0:
                h = 0
            if h == k[2]:
                continue
            else:
                break
        else:
            if H != 0:
                flag = True
                print("{} {} {}".format(i, j, H))
                break
    if flag:
        break

Submission status: Accepted

Solution code:
#coding:utf-8
import numpy as np
import collections
N = int(input())
arr = []
for n in range(N):
    arr.append(list(map(int,input().split())))
narr = np.array(arr)
x_min  = narr[:,0].min()
x_max = narr[:,0].max()
y_min = narr[:,1].min()
y_max =  narr[:,1].max()
mx = narr[:,2].max()
for k in range(mx+100,mx-1,-1):
    for i in range(x_min,x_max+1):
        for j in range(y_min,y_max+1):
            for x,y,h in arr:
                h_ = max(k-abs(i-x)-abs(j-y),0)
                if h_ != h:
                    break
            else:
                print (i,j,k)
                exit()

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))

import numpy as np

N = int(input())
X = np.zeros(N, dtype=np.int64)
Y = np.zeros(N, dtype=np.int64)
H = np.zeros(N, dtype=np.int64)

# Hの降順でリストに入れてる
Q = sorted([inpl() for _ in range(N)], key=lambda x: x[2], reverse=True)

for i, q in enumerate(Q):
    X[i], Y[i], H[i] = q

for cx in range(101):
    for cy in range(101):
        cH = H[0] + np.abs(X[0] - cx) + np.abs(Y[0] - cy)
        if np.all(H == np.maximum(cH - np.abs(X - cx) - np.abs(Y - cy), 0)):
            print(cx, cy, cH)

Submission status: Accepted

Solution code:
n = int(input())
data = [[int(j) for j in input().split()] for i in range(n)]
data.sort(key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        x0, y0, h0 = data[0][0], data[0][1], data[0][2]
        h = h0 + abs(x0 - cx) + abs(y0 - cy)
        for i in range(1, n):
            xi, yi, hi = data[i][0], data[i][1], data[i][2]
            if hi == 0 and h < abs(xi - cx) + abs(yi - cy):
                continue
            if h != hi + abs(xi - cx) + abs(yi - cy):
                break
        else:
            print(cx, cy, h)
            exit()

Submission status: Accepted

Solution code:
import sys
N = input()
x = []
y = []
h = []
for i in range(N):
	_x, _y, _h = map(int, raw_input().split())
	x.append(_x)
	y.append(_y)
	h.append(_h)

for _x in range(101):
	for _y in range(101):
		candH = -1
		for i in range(N):
			if h[i] > 0:
				tmp = h[i] + abs(x[i] - _x) + abs(y[i] - _y)
				if candH == -1:
					candH = tmp
				elif candH == tmp:
					continue
				else:
					candH = -2
					break
		if candH == -2:
			continue
		for i in range(N):
			if h[i] == 0:
				dist = abs(x[i] - _x) + abs(y[i] - _y)
				if dist < candH:
					candH = -2
					break
					
		if candH == -2:
			continue
		print _x, _y, candH
		sys.exit()

Submission status: Accepted

Solution code:
N = int(input())
XYH = [0] * N
for i in range(N):
  x, y, h = map(int, input().split())
  XYH[i] = [x, y, h]
XYH.sort(key=lambda x: x[2], reverse=True)
H = 0
for cx in range(101):
  for cy in range(101):
    _H = abs(cx - XYH[0][0]) + abs(cy - XYH[0][1]) + XYH[0][2]
    for x, y, h in XYH[1:]:
      if h != max(_H - abs(cx - x) - abs(cy - y), 0):
        break
    else:
      Cx = cx
      Cy = cy
      H = _H
    if H:
      break
  if H:
    break
print(Cx, Cy, H)

Submission status: Accepted

Solution code:
N = int(input())

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

h_max = max([h for x, y, h in points])

for H in range(h_max + 100, h_max - 1, -1):
    for Cx in range(101):
        for Cy in range(101):
            ok = True
            for X, Y, h1 in points:
                h2 = max(H - abs(X - Cx) - abs(Y - Cy), 0)
                if h1 != h2:
                    ok = False
                    break
            if ok:
                print('{} {} {}'.format(Cx, Cy, H))
                exit()

Submission status: Accepted

Solution code:

import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    N = int(input_raw[0])
    info_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [x, y, h] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
        info_list.append((h, x, y))

    info_list.sort(reverse = True)
    for Cx in range(101):
        for Cy in range(101):
            pre_H = -1
            is_all_eq = True
            for info in info_list:
                x = info[1]
                y = info[2]
                h = info[0]
                if h == 0:
                    if pre_H - abs(Cx - x) - abs(Cy - y) > 0:
                        is_all_eq = False
                        break
                else:
                    H =  h + abs(Cx - x) + abs(Cy - y)

                    if pre_H == -1 or H == pre_H:
                        pre_H = H
                    else:
                        is_all_eq = False
                        break;
            if is_all_eq == True:
                break
        if is_all_eq == True:
                break

    print Cx, Cy, H

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def get_cands(x, y, h):
    for xc in range(100 + 1):
        for yc in range(100 + 1):
            hc = h + abs(xc - x) + abs(yc - y)
            yield (xc, yc, hc)

def is_valid(top, view):
    xt, yt, ht = top
    xv, yv, hv = view
    return hv == max(0, ht - abs(xt - xv) - abs(yt - yv))

cand = set(get_cands(*next(filter(lambda x: x[2] > 0, XYH))))
ans = filter(lambda x: all(is_valid(x, v) for v in XYH), cand)

print(*next(ans))

Submission status: Accepted

Solution code:
import sys


n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]


for i in range(0, 101):
    for j in range(0, 101):
        ans = 1
        for k in range(n):
            if l[k][2] != 0:
                h = l[k][2] + abs(i - l[k][0]) + abs(j - l[k][1])
                break
        for k in range(n):
            if l[k][2] != max(h - abs(i - l[k][0]) - abs(j - l[k][1]), 0):
                ans = 0
        if ans:
            print(i, j, h)
            sys.exit()

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for w in range(n):
   if l[w][2]>0:
     k=w
     break
for x in range(101):
  for y in range(101):
    a=l[k][2]+abs(l[k][0]-x)+abs(l[k][1]-y)
    c=0
    for z in range(n):
      if max((a-abs(l[z][0]-x)-abs(l[z][1]-y)),0)==l[z][2]:c+=1
      if c==n:
        print(x,y,a)

Submission status: Accepted

Solution code:
def c_pyramid(N, Pos):
    from itertools import product
    # 中心座標を全探索
    for cx, cy in product(range(101), repeat=2):
        # ピラミッドの高さを求める
        for x, y, h in Pos:
            if h > 0:
                height = h + abs(cx - x) + abs(cy - y)
        # ピラミッドの高さが得られた情報に適合するか調べる
        for x, y, h in Pos:
            if h != max((height - abs(cx - x) - abs(cy - y)), 0):
                break
        else:
            ans = [cx, cy, height]
            break
    ans = '{0} {1} {2}'.format(*ans)
    return ans

N = int(input())
Pos = [[int(i) for i in input().split()] for j in range(N)]
print(c_pyramid(N, Pos))

Submission status: Accepted

Solution code:
import numpy as np

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

for j in range(101):
    for k in range(101):
        needH = -1
        for i in range(N):
            if a[i][2] > 0:
                temp = a[i][2] + np.abs(a[i][0] - j) + np.abs(a[i][1] - k)
                if needH == -1:
                    needH = temp
                else:
                    if needH != temp:
                        needH = -2
                        break
        if needH == -2:
            continue
            
        for i in range(N):
            if a[i][2] == 0:
                dist = np.abs(a[i][0] - j) + np.abs(a[i][1] - k)
                if needH > dist:
                    needH = -2
                    break
        if needH == -2:
            continue
            
        print("{} {} {}\n".format(j, k, needH))

Submission status: Accepted

Solution code:
n = int(input())

# maxH - |Cx - x| - |Cy - y| = H
# maxH = H + |Cx - x| + |Cy - y|

xyh = []
for i in range(n):
    px, py, h = list(map(int, input().split()))
    d = {
        'px': px,
        'py': py,
        'h': h
    }
    xyh.append(d)

# 高さ0でない情報を探す
t = {}
for d in xyh:
    if d['h'] >= 1:
        t = d
        break

# 全座標を探索
for cx in range(101):
    for cy in range(101):
        # 仮決めした中心座標で頂点の高さを出す
        max_h = (
            abs(t['px'] - cx) + abs(t['py'] - cy) + t['h']
        )
        # 全ての条件でこの頂点が適切かチェック
        is_ok = True
        for d in xyh:
            if d['h'] != max(
                max_h - abs(d['px'] - cx) - abs(d['py'] - cy), 0
            ):
                is_ok = False
                break
        if is_ok:
            print(cx, cy, max_h)

Submission status: Accepted

Solution code:
def solve(C):
    C.sort(key=lambda x: x[2], reverse=True)
    for xi in range(0, 101):
        for yi in range(0, 101):
            h = C[0][2] + abs(xi - C[0][0]) + abs(yi - C[0][1])
            if all(max(h - abs(xi - c[0]) - abs(yi - c[1]), 0) == c[2] for c in C):
                return [str(xi), str(yi), str(h)]


if __name__ == "__main__":
    N = int(input())
    C = []
    for n in range(N):
        d = input().split(" ")
        C.append((int(d[0]), int(d[1]), int(d[2])))
    print(" ".join(solve(C)))

Submission status: Accepted

Solution code:
n=int(input())
xymap=[[-1 for j in range(101)] for i in range(101)]
inlist=[]
for i in range(n):
    xi,yi,hi=map(int,input().split())
    inlist.append([xi,yi,hi])
inlist.sort(key=lambda x :-x[2])
for i in range(n):
    xi,yi,hi=inlist[i]
    if hi==0:
        xymap[xi][yi]=-2
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]<=a:
                    pass
                else:
                    xymap[x][y]=-2
    else:
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]==a or xymap[x][y]==-1 :
                    xymap[x][y]=a
                else:
                    xymap[x][y]=-2
for x in range(101):
    for y in range(101):
        if xymap[x][y]!=-2:
            print(x,y,xymap[x][y])

Submission status: Accepted

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

idx = 0
while(xyhs[idx][2] == 0):
    idx+=1

for i in range(101):
    for j in range(101):
        nowh = xyhs[idx][2] + abs(i-xyhs[idx][0]) +abs(j-xyhs[idx][1])
        isCorrect = True
        for k in range(n):
            calch = max(nowh - abs(i-xyhs[k][0]) - abs(j-xyhs[k][1]),0)
            if calch != xyhs[k][2]:
                isCorrect = False
        
        if isCorrect:
            print(i,j,nowh)

Submission status: Accepted

Solution code:
N = int(input())
Q = [0]*N
H=0
for j in range(N):
    Q[j] = [ int(i) for i in input().split()]

for x in range(101):
    for y in range(101):
        h_kouho = {-1}
        for i in range(N):
            if  Q[i][2] != 0:
                H1 = Q[i][2] + abs(Q[i][0]- x) + abs(Q[i][1] - y)
                if h_kouho =={-1}:
                    h_kouho = {H1}
                else:
                    h_kouho = h_kouho & {H1}
            else:
                continue
        if h_kouho != set() :
            u = 0
            for i in range(N):
                if Q[i][2] != max({0,max(h_kouho)- abs(Q[i][0]- x) - abs(Q[i][1] - y)}):
                    u = 1
            if u == 0:
                print(x,y,max(h_kouho))
                break
                break
            else:
                continue
        else:
            continue

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
h = []
for _ in range(N):
    xx,yy,hh = map(int,input().split())
    x.append(xx)
    y.append(yy)
    h.append(hh)
cm = 100
def dist(cx,cy,x,y):
    return(abs(cx-x)+abs(cy-y))
for cx in range(cm+1):
    for cy in range(cm+1):
        H = -1
        Hm = 10000000000
        contra = False
        for i in range(N):
            Hi = h[i] + dist(cx,cy,x[i],y[i])
            if h[i] == 0:
                Hm = min(Hi,Hm)
            else:
                if H == -1:
                    H = Hi
                else:
                    if H!=Hi:
                        contra = True
                        break
            if H > Hm:
                contra = True
                break
        if contra == False:
            print(cx,cy,H)                
            exit()

Submission status: Accepted

Solution code:
N = int(input())

X = []
Y = []
h = []
for i in range(N):
    a,b,c = map(int,input().split())

    if c > 0:
        p = i
    X.append(a)
    Y.append(b)
    h.append(c)

for Cx in range(101):
    for Cy in range(101):
        works = True
        H = h[p] + abs(X[p] - Cx) + abs(Y[p] - Cy)
        for i in range(N):
            if h[i] != max(H - abs(X[i] - Cx) - abs(Y[i] - Cy), 0):
                works = False
                break
        
        if works:
            print(Cx,Cy,H)
            quit()

Submission status: Accepted

Solution code:
N=int(input())
L=100
x=[0 for i in range(N)]
y=[0 for i in range(N)]
h=[0 for i in range(N)]
p=(-1,-1,-1)
for i in range(N):
    x[i],y[i],h[i]=map(int,input().split())
for i in range(N):
    if h[i]!=0:
        p=(x[i],y[i],h[i])
        break
if p[2]==-1:
    print("Baka")
    exit()
for Cx in range(L+1):
    for Cy in range(L+1):
        H=p[2]+abs(Cx-p[0])+abs(Cy-p[1])
        flag=1
        for i in range(N):
            hd=max([H-abs(x[i]-Cx)-abs(y[i]-Cy),0])
            if h[i]!=hd:
                flag=0
                break
        if flag==1:
            print(Cx,Cy,H)
            exit()

Submission status: Accepted

Solution code:
n = int(input())

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

#高さが0でない情報を探す
for i in range(n):
    if xyh[i][2] != 0:
        x_ex, y_ex, h_ex = xyh[i]
        break

for cx in range(101): #Cx 0~100
    for cy in range(101): #Cy 0~100
        h = abs(x_ex - cx) + abs(y_ex - cy) + h_ex #高さHを求める

        #先程出した高さHが他の例にも当てはまるか確認
        flag = 0
        for i in range(n):
            x_i, y_i, h_i = xyh[i]
            if h_i == max(h - abs(x_i - cx) - abs(y_i - cy), 0):
                flag += 1
            else:
                break

        if flag == n:
            print(cx, cy, h)
            exit()

Submission status: Accepted

Solution code:
N=int(input())

data=[]

for _ in range(N):
    x,y,h=map(int,input().split())
    data.append([x,y,h])
 
def test():
    for cx in range(101):
        for cy in range(101):
            
            for i in range(N):
                if data[i][2]:
                    temph=data[i][2]+abs(data[i][0]-cx)+abs(data[i][1]-cy)
                    flag=True
                    break
            
            for d in data:
                if d[2] != max(temph-abs(d[0]-cx)-abs(d[1]-cy),0):
                    flag=False
                    break
                
            if flag:
                print(cx,cy,temph)
                return
            
test()

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        for r in xyh:
            if r[2] > 0:
                ch = r[2] + abs(r[0] - cx) + abs(r[1] - cy)
                break
        j = False
        for r in xyh:
            if r[2] != max((ch - abs(r[0] - cx) - abs(r[1] - cy)),0):
                j = True
                break
        if not j:
            print(cx,cy,ch)

Submission status: Accepted

Solution code:
from sys import exit
n=int(input())
z=[]
for i in range(n):
	x,y,h=map(int,input().split())
	z.append((x,y,h))
for i in range(101):
	for j in range(101):
		pp=-1
		ff=True
		for k in range(n):
			if(pp==-1 and z[k][2]>0):
				pp=z[k][2]+abs(z[k][0]-i)+abs(z[k][1]-j)
			else:
				zk=max(pp-abs(z[k][0]-i)-abs(z[k][1]-j),0)
				if(zk!=z[k][2]):
					ff=False
					break
		if(ff):
			for k in range(n):
				zk=max(pp-abs(z[k][0]-i)-abs(z[k][1]-j),0)
				if(zk!=z[k][2]):
					ff=False
					break
			if(ff):
				print(i,j,pp)
				exit(0)

Submission status: Accepted

Solution code:
n = int(input())

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

#高さが0でない情報を探す
for i in range(n):
    if xyh[i][2] != 0:
        x_ex, y_ex, h_ex = xyh[i]
        break

for cx in range(101): #Cx 0~100
    for cy in range(101): #Cy 0~100
        h = abs(x_ex - cx) + abs(y_ex - cy) + h_ex #高さHを求める

        #先程出した高さHが他の例にも当てはまるか確認
        flag = 0
        for i in range(n):
            x_i, y_i, h_i = xyh[i]
            if h_i == max(h - abs(x_i - cx) - abs(y_i - cy), 0):
                flag += 1
            else:
                break

        if flag == n:
            print(cx, cy, h)

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
h = []

for _ in range(N):
    xx, yy, hh = map(int, input().split())
    x.append(xx)
    y.append(yy)
    h.append(hh)

V_MAX = 100

for cx in range(V_MAX + 1):
    for cy in range(V_MAX + 1):
        # 頂上がどのくらいの高さであって欲しいか
        # -1: 未定, 0以上は確定しているとき
        # -2: 不可能だと分かったとき
        needH = - 1

        for i in range(N):
            if h[i] > 0:
                dist = abs(x[i] - cx) + abs(y[i] - cy)
                # この頂点から見て, 頂上がcx, cyのときに, どの位の高さがあって欲しいか
                tmp = h[i] + dist
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break

        if needH == -2:
            continue # ダメだったら別の場所を探す

        for i in range(N):
            if h[i] == 0:
                dist = abs(x[i] - cx) + abs(y[i] - cy)
                if needH > dist:
                    needH = - 2
                    break

        if needH == -2:
            continue # ダメだったら別の場所を探す

        print(cx, cy, needH)

Submission status: Accepted

Solution code:
import sys
Input = sys.stdin.readline

N = int(Input())
x_y_h = [list(map(int, Input().split())) for _ in range(N)]
 
if N == 1:
    print("{0} {1} {2}".format(x_y_h[0][0], x_y_h[0][1], x_y_h[0][2]))
else:
    for c_x in range(0, 100+1):
        for c_y in range(0, 100+1):
            for x, y, h in x_y_h:
                if h > 0:
                    H = h + abs(c_x - x) + abs(c_y - y)
                    break
            for x, y, h in x_y_h:
                if h != max(H - abs(c_x - x) - abs(c_y - y), 0):
                    break
            else:
                print("{0} {1} {2}".format(c_x, c_y, H))
                sys.exit()

Submission status: Accepted

Solution code:
N = int(input())
zahyou = [list(map(int,input().split())) for i in range(N)]
 
H = -1
C_x = 0
C_y = 0
 
def height(C_x,C_y,x,y,h):
  H = h + abs(x-C_x) + abs(y-C_y)
  return H
 
def koud(C_x,C_y,H,x,y):
  h = H - abs(x-C_x) - abs(y-C_y)
  return h
 
flag = False
for i in range(0,101):
  C_x = i
  for j in range(0,101):
    C_y = j
    H = -1
    memo = []
    for k in range(N):
      if zahyou[k][2] == 0:#高度が0のとき
        memo.append(k)
        continue
      if H < 0:
        H = height(C_x,C_y,zahyou[k][0],zahyou[k][1],zahyou[k][2])
      else:
        if zahyou[k][2] != koud(C_x,C_y,H,zahyou[k][0],zahyou[k][1]):
          break
        else:
          continue        
    else:
      for l in range(len(memo)):
        if H <= height(C_x,C_y,zahyou[l][0],zahyou[l][1],zahyou[l][2]):
          continue
        else:
          break
      else:  
        flag = True
        break
    if flag:
      break
  if flag:
    break

print(C_x,C_y,H)

Submission status: Accepted

Solution code:
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)
    else:
        X.insert(0, x)
        Y.insert(0, y)
        H.insert(0, h)
x1 = X[0]
y1 = Y[0]
h1 = H[0]
for Cx in range(min(X), max(X) + 1):
    for Cy in range(min(Y), max(Y) + 1):
        h = h1 + abs(x1-Cx) + abs(y1-Cy)
        i = 1
        while i < N and H[i] == max(h - abs(X[i]-Cx) - abs(Y[i]-Cy), 0):
            i += 1
        if i == N:
            print(Cx, Cy, h)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())

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

for i in range(n): # 高さが0でない情報を探す
    if xyh[i][2] != 0:
        xyh_1 = xyh[i]
        break

for cx in range(101): #Cx 0~100
    for cy in range(101): #Cy 0~100
        h = abs(xyh_1[0] - cx) + abs(xyh_1[1] - cy) + xyh_1[2] # 高さHを求める

        flag = 0
        for i in range(n):
             # 高さHが適切であるか確認
            if xyh[i][2] == max(h - abs(xyh[i][0] - cx) - abs(xyh[i][1] - cy), 0):
                flag += 1

        if flag == n:
            print(cx, cy, h)

Submission status: Accepted

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

# 中心座標(Cx,Cy)を全通り試す
for Cx in range(101):
    for Cy in range(101):
        x, y, h = xyhs[-1]
        H = h + abs(Cx - x) + abs(Cy - y)
        for x, y, h in reversed(xyhs[:-1]):
            H2 = h + abs(Cx - x) + abs(Cy - y)
            if h == 0:
                if H2 < H: break
            else:
                if H != H2: break
        else:
            print(Cx, Cy, H)
            exit()

Submission status: Accepted

Solution code:
import sys
N = int(input().strip())
grid = []
ref = 0
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
    if array[2]>0:
      ref = i
x = 0
y = 0
while y <= 100:
  x = 0
  while x <= 100:
    flag = 0
    h0 = grid[ref][2]+abs(x-grid[ref][0])+abs(y-grid[ref][1])
    for arrays in grid:
      h = max(0,h0-abs(x-arrays[0])-abs(y-arrays[1]))
      if h != arrays[2]:
        flag = 1
    if flag == 0:
      print(x,y,h0)
      sys.exit()
    x += 1
  y += 1

Submission status: Accepted

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

max_h = P[0][2]

P2 = set()
for i in range(101):
    for j in range(101):
        P2.add((i, j))
for hh in range(max_h+200, max_h-1, -1):
    P3 = P2.copy()
    for x, y, h in P:
        for xx, yy in P3.copy():
            dx = abs(xx - x)
            dy = abs(yy - y)
            th = max(hh-dx-dy, 0)
            if th != h:
                P3.remove((xx, yy))
    if len(P3) == 1:
        xx, yy = P3.pop()
        print('%d %d %d' % (xx, yy, hh))

Submission status: Accepted

Solution code:
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
h = [0 for i in range(n)]
height_tmp = 0
X = 0
Y = 0
for i in range(n):
    x[i], y[i], h[i] = [int(i) for i in input().split()]
    if h[i] != 0:
        height_tmp = h[i]
        X = x[i]
        Y = y[i]
for i in range(101):
    for j in range(101):
        flag = 0
        okFlag = 1
        H = height_tmp + abs(X - i) + abs(Y - j)
        if H < 0:
            continue
        for k in range(n):
            if h[k] != max(H - abs(x[k] - i) - abs(y[k] - j), 0):
                okFlag = 0
                break
        if okFlag == 1:
            print("{} {} {}".format(i, j, H))
            exit()
"""
        flag = 0
        okFlag = 1
        height_tmp = 0
        output = [0, 0, 0]
        for k in range(n):
            if h[k] == 0:
                continue
            if flag == 0:
                height_tmp = h[k] + abs(x[k] - i) + abs(y[k] - j)
                flag = 1
            else:
                if height_tmp != h[k] + abs(x[k]-i) + abs(y[k]-j):
                    okFlag = 0
                    break
                elif k == n-1:
                    if height_tmp == h[k] + abs(x[k] - i) + abs(y[k] - j):
                        output = [i, j, height_tmp]
                        okFlag = 1
                        #print("{} {} {}".format(i, j, height_tmp))
                        #exit()
        if okFlag == 1:
            print("{} {} {}".format(i, j, height_tmp))
            exit()
"""

Submission status: Accepted

Solution code:
N = int(input())
R = [_ for _ in range(N)]
for i in range(N):
    x, y, h = [int(_) for _ in input().split()]
    R[i] = (h, x, y)

R.sort(reverse=True)

def solve():
    for cx in range(101):
        for cy in range(101):
            h, x, y = R[0]
            H = h + abs(x - cx) + abs(y - cy)
            for i in range(1, N):
                h, x, y = R[i]
                if h == 0 and H < abs(x - cx) + abs(y - cy):
                    continue

                tempH = h + abs(x - cx) + abs(y - cy)
                if tempH != H:
                    break
            else:
                print(cx, cy, H)
                return

solve()

Submission status: Accepted

Solution code:
N = int(input())
data = []
for _ in range(N):
    x, y, h = map(int, input().split())
    data.append((x, y, h))

data = sorted(data, key=lambda x: x[2], reverse=True)
    
halt = False
for i in range(100+1):
    for j in range(100+1):
        x, y, h = data[0]
        H = h + abs(x - i) + abs(y - j)
        for x, y, h in data[1:]:
            if h != max(0, H - abs(x- i) - abs(y - j)):
                break
        else:
            print(i, j, H)
            halt = True
        if halt:
            break
    if halt:
        break

Submission status: Accepted

Solution code:
N = input().strip()
import copy

import sys
loop = []
cccs = set()
first = True
for line in sys.stdin:
    x, y, h = [int(x) for x in line.strip().split(' ')]
    if h != 0 and first:
        for cx in range(101):
            for cy in range(101):
                H = h + abs(x-cx) + abs(y-cy)
                cccs.add((cx,cy,H))
        first = False
    else:
        loop.append((x,y,h))
ncc = set()
for x,y,h in loop:
    for cx, cy, H in cccs:
        if h == max(H - abs(x-cx) - abs(y-cy), 0):
            ncc.add((cx,cy,H))
    cccs = ncc
    ncc = set()

for i in cccs:
    print(i[0], i[1], i[2])

Submission status: Accepted

Solution code:
N = int(input())

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

ans = []
ans_c = 0
for i in range(101):
    for j in range(101):
        H = -1
        judge = True
        for k in range(N):
            if info[k][2] == 0:
                continue
            dis = abs(i - info[k][0]) + abs(j - info[k][1])
            if H == -1:
                H = info[k][2] + dis
            else:
                if H != (info[k][2] + dis):
                    judge = False
        if judge == True:
            for k in range(N):
                if info[k][2] == 0:
                    h = max(H - (abs(i - info[k][0]) + abs(j - info[k][1])), 0)
                    if h != 0:
                        judge = False
        if judge == True:
            print("{} {} {}".format(i,j,H))
            exit()