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:
# -*- coding: utf-8 -*-

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


for cx in range(101):
    for cy in range(101):
        H = -1
        for _,cond in enumerate(conditions):
            if cond[2] > 0:
                H_tmp = cond[2] + abs(cond[0]-cx) + abs(cond[1]-cy)
                if H == -1:
                    H = H_tmp
                else:
                    if H_tmp != H:
                        H = -2
                        break

        if H == -2:
            continue

        for _,cond in enumerate(conditions):
            if cond[2] == 0:
                if H > abs(cond[0]-cx) + abs(cond[1]-cy):
                    H = -2
                    break
        
        if H == -2:
            continue
        
        print(cx,cy,H)

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        x, y, h = sXYH[0]
        H = h + abs(x-cx) + abs(y-cy)
        res = []
        for x, y, h in sXYH[1:]:
            temp = (h == max(H-abs(x-cx)-abs(y-cy), 0))
            res.append(temp)
        if all(res):
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
n = int(input())

xyhs = [list(map(int, input().split())) for _ in range(n)]
xyhs.sort(key=lambda i: i[2], reverse=True)

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

num_cnd = len(conditions)
if num_cnd==1:
    print(conditions[0][0],conditions[0][1],conditions[0][2])
    exit(0)

for cx in range(101):
    for cy in range(101):
        cnt = 0
        h = 0
        for i,cnd in enumerate(conditions):
            h_tmp = getH(cnd[0], cx, cnd[1], cy, cnd[2])
            if h_tmp >= 1:
                if i==0:
                    h = h_tmp
                    cnt += 1
                elif h == h_tmp:
                    cnt += 1
                    if cnt == num_cnd:
                        print(cx,cy,h)
                        exit(0)
                else:
                    break
            else:
                break
        

print('No')

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.buffer.readline

def main():
    n = int(input())
    x = [-1] * n; y = [-1] * n; h = [-1] * n
    for i in range(n):
        x[i], y[i], h[i] = map(int, input().split())

    # full search
    for i in range(n):
        if h[i] > 0:
            ind = i
            break

    for cx in range(101):
        for cy in range(101):
            try:
                height = h[ind] + abs(x[ind] - cx) + abs(y[ind] - cy)
            except:
                # h == [0] * n
                height = 1

            flag = True
            for i in range(n):
                if h[i] == 0:
                    if height - abs(x[i] - cx) - abs(y[i] - cy) > 0:
                        flag = False
                        break
                else:
                    if height - abs(x[i] - cx) - abs(y[i] - cy) != h[i]:
                        flag = False
                        break
            if flag:
                print(cx, cy, height)
                exit()

main()

Submission status: Accepted

Solution code:

def resolve():
    N = int(input())
    P = [list(map(int, input().split())) for _ in range(N)]
    X, Y, H = zip(*P)

    # Cx, Cyを固定して式に当てはめる
    # 逆算している形になっている為、情報Hと矛盾してないのが答え
    # h[i]=0になっているものは距離が分からないので、中心の高さを求めるのには使わない。
    for cx in range(101):
        for cy in range(101):
            h = 1
            for i in range(N):
                if H[i] > 0:
                    h = H[i] + abs(cx - X[i]) + abs(cy - Y[i])
            ok = True
            for i in range(N):
                res = max(h - abs(cx - X[i]) - abs(cy - Y[i]), 0)
                if res != H[i]:
                    ok = False
            if ok:
                print(cx, cy, h)
                return


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
P = []
for _ in range(n):
  x, y, h = map(int, input().split())
  P.append([h, x, y])
P.sort(reverse=True)

for cx in range(101):
  for cy in range(101):
    H = P[0][0] + abs(P[0][1]-cx) + abs(P[0][2]-cy)
    for i in range(1,n):
      if max(H-abs(P[i][1]-cx)-abs(P[i][2]-cy), 0) != P[i][0]:
        break
    else:
      print(cx, cy, H)
      exit()

Submission status: Accepted

Solution code:
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
L.sort(key=lambda x:x[2],reverse=True)
for i in range(101):
  for j in range(101):
    s=L[0][2]+abs(i-L[0][0])+abs(j-L[0][1])
    for l in L[1:]:
      h=l[2]+abs(i-l[0])+abs(j-l[1])
      if s==h:
        continue
      elif l[2]==0 and s<h:
        continue
      else:
        break
    else:
      print(i,j,s)
      exit()

Submission status: Accepted

Solution code:
#
# abc112 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
2 3 5
2 1 5
1 2 5
3 2 5"""
        output = """2 2 6"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
0 0 100
1 1 98"""
        output = """0 0 100"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3
99 1 191
100 1 192
99 0 192"""
        output = """100 0 193"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """4
59 3 0
64 94 56
5 62 11
3 93 14"""
        output = """55 80 79"""
        self.assertIO(input, output)


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

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

    print(f"{CX} {CY} {H}")


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
xyh = [tuple(map(int,input().split())) for i in range(n)]
for xi,yi,hi in xyh:
    if hi:
        xt,yt,ht = xi,yi,hi

for i in range(101):
    for j in range(101):
        a = ht+abs(i-xt)+abs(j-yt)
        for xi,yi,hi in xyh:
            x = max(a - abs(xi-i)-abs(yi-j),0)
            if hi != x:
                break
        else:
            print(i,j,a)
            exit(0)

Submission status: Accepted

Solution code:
n=int(input())
info=[list(map(int,input().split())) for i in range(n)]
for cx in range(0,101):
    for cy in range(0,101):
        H=-10**20
        lim=10**20
        for l in info:
            x,y,h=l 
            if h==0:
                 lim=min(lim,abs(x-cx)+abs(y-cy))
                 
            else:
                if H!=-10**20 and H!=abs(x-cx)+abs(y-cy)+h :break
                H=abs(x-cx)+abs(y-cy)+h 
            if H>lim:break
        else:
            print(cx,cy,H);exit()

Submission status: Accepted

Solution code:
n = int(input())
if n == 1:
    x, y, h = map(int, input().split())
    print(x, y, h)
    exit()
s = [list(map(int, input().split())) for _ in range(n)]
for i in range(101):
    for j in range(101):
        h = -1
        ok = 1
        for t in s:
            if t[2] == 0:
                ok += 1
            elif h == -1:
                h = abs(t[0] - i) + abs(t[1] - j) + t[2]
            else:
                h0 = abs(t[0] - i) + abs(t[1] - j) + t[2]
                if h == h0:
                    ok += 1
        if ok == n:
            for t in s:
                if abs(t[0] - i) + abs(t[1] - j) <= h:
                    if not h == abs(t[0] - i) + abs(t[1] - j) + t[2]:
                        ok = 0
                else:
                    if not t[2] == 0:
                        ok = 0
            if ok == n:
                print(i, j, h)
                exit()

Submission status: Accepted

Solution code:
N=int(input())
l=[list(map(int,input().split())) for i in range(N)]
for i,j,k in l:
   if k>0:
      fx,fy,fh=i,j,k
for i in range(0,101):#x
   for j in range(0,101):#y
      sw=0
      cer_h=fh+abs(fx-i)+abs(fy-j)
      for x,y,h in l:
         if max(cer_h-abs(i-x)-abs(j-y),0)!=h:
            sw=1
            break
      if sw==0:
         print(i,j,cer_h)
         exit()

Submission status: Accepted

Solution code:
n=int(input())
data=[]
for i in range(n):
    data.append(list(map(int,input().split())))
    
first_h_index=0
for i in range(n):
    if data[i][2] > 0:
        first_h_index=i
        break
    
for i in range(101):
    for j in range(101):
        h=data[first_h_index][2]+abs(data[first_h_index][0]-i)+abs(data[first_h_index][1]-j)
        for k in range(n):
            if data[k][2] != max(h-abs(data[k][0]-i)-abs(data[k][1]-j),0):
                break
        else:
            print(i,j,h)
            break

Submission status: Accepted

Solution code:
n=int(input())
data=[]
for i in range(n):
    data.append(list(map(int,input().split())))
    
first_h_index=0
for i in range(n):
    if data[i][2] > 0:
        first_h_index=i
        break
    
for i in range(101):
    for j in range(101):
        h=data[first_h_index][2]+abs(data[first_h_index][0]-i)+abs(data[first_h_index][1]-j)
        for k in range(n):
            if data[k][2] != max(h-abs(data[k][0]-i)-abs(data[k][1]-j),0):
                break
        else:
            print(i,j,h)
            exit()

Submission status: Accepted

Solution code:
# vim: fileencoding=utf-8


def main():

    n = int(input())
    li = []
    for i in range(n):
        x, y, h = map(int, input().split())
        li.append({"x": x, "y": y, "h": h})
    li.sort(key=lambda x: x["h"], reverse=True)

    tops = []
    for i in range(101):
        for j in range(101):
            h = li[0]["h"] + abs(li[0]["x"] - i) + abs(li[0]["y"] - j)
            tops.append({"x": i, "y": j, "h": h})

    for i in range(1, n):
        tmp = []
        for j in range(len(tops)):
            x = li[i]["x"]
            y = li[i]["y"]
            h = li[i]["h"]
            topX = tops[j]["x"]
            topY = tops[j]["y"]
            topH = tops[j]["h"]
            if h == max(topH - abs(topX - x) - abs(topY - y), 0):
                tmp.append(tops[j])
        tops = tmp
    print(f"{tops[0]['x']} {tops[0]['y']} {tops[0]['h']}")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

XYH.sort(key = lambda x: x[2], reverse = True)
for x in range(101):
    for y in range(101):
        diff_x = abs(XYH[0][0] - x)
        diff_y = abs(XYH[0][1] - y)
        H = XYH[0][2] + diff_x + diff_y
        for xyh in XYH[1:]:
            if xyh[2] != max(H - abs(xyh[0] - x) - abs(xyh[1] - y), 0):
                break
        else:
            print(x, y, H)
            exit()

Submission status: Accepted

Solution code:
def dist(h,xi, yi, cx, cy):
    return h + abs(xi - cx) + abs(yi - cy)

N = int(input())
P = []
for i in range(N):
    xi, yi, h= map(int, input().split())
    P.append([h, xi, yi])
P.sort(reverse = True)

for i in range(101):
    for j in range(101):
        H = dist(P[0][0], P[0][1], P[0][2],i, j)
        for p in P[1:]:
            if max(H - abs(p[1]-i)-abs(p[2]-j), 0) != p[0]:
                break
        else:
            print(i, j, H)
            break

Submission status: Accepted

Solution code:
def dist(a, b, x, y, h):
    return h + abs(a - x) + abs(b - y)

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

for i in range(101):
    for j in range(101):
        H = dist(i, j, P[0][1], P[0][2], P[0][0])
        for p in P[1:]:
            if max(H - abs(p[1]-i)-abs(p[2]-j), 0) != p[0]:
                break
        else:
            print(i, j, H)
            break

Submission status: Accepted

Solution code:
n = int(input())
x_list = []
y_list = []
h_list = []

for i in range(n):
    a, b, c = map(int, input().split())
    x_list.append(a)
    y_list.append(b)
    h_list.append(c)

k = h_list.index(max(h_list))

for x in range(101):
    for y in range(101):
        h_max = h_list[k] + abs(x_list[k] - x) + abs(y_list[k] - y)
        
        for j in range(n):
            if h_list[j] == 0 :
                if h_max - (abs(x_list[j] - x) + abs(y_list[j] - y)) > 0 :
                    h_max = -1
            else:
                if h_max != abs(x_list[j] - x) + abs(y_list[j] - y) + h_list[j]:
                    h_max = -1
        
        if h_max != -1:
            print(str(x)+' '+str(y)+ ' '+ str(h_max))
            break

Submission status: Accepted

Solution code:
N = int(input())
xs, ys, hs = [],[],[]
for _ in range(N):
    x,y,h = map(int,input().split())
    if h != 0:
        xx,yy,hh = x,y,h
    xs.append(x)
    ys.append(y)
    hs.append(h)
for cx in range(101):
    for cy in range(101):
        H = hh+abs(xx-cx)+abs(yy-cy)
        if all([hs[i] == max(0,H-abs(cx-xs[i])-abs(cy-ys[i])) for i in range(N)]):
            print(cx,cy,H)
            exit(0)

Submission status: Accepted

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

for _ in range(0,n):
    if ab[_][2] !=0:
        x = ab[_][0]
        y = ab[_][1]
        h = ab[_][2]
        break

for i in range(101):
    for j in range(101):
        f = True
        l = abs(i-x)+abs(j-y)+h
        for k in range(0,n):
            dx = ab[k][0]
            dy = ab[k][1]
            dh = ab[k][2]
            if max(l-abs(i-dx)-abs(j-dy),0) ==dh:
                pass
            else:
                f = False
        if f:
            ansx =i
            ansy =j
            ansr = l
            break
print(str(ansx)+" "+str(ansy)+" "+str(ansr))

Submission status: Accepted

Solution code:

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

ans = []
X.sort(key=lambda x: x[2])
for c_x in range(0, 101):
    for c_y in range(0, 101):
        height = X[-1][2] + abs(X[-1][0] - c_x) + abs(X[-1][1] - c_y)
        flag = True
        for x, y, h in X:
            flag &= h == max(height - abs(x - c_x) - abs(y - c_y), 0)

        if flag:
            print(c_x, c_y, height)
            exit()

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]), reverse=True)

ans = -1, -1, -1
for cx in range(101):
    for cy in range(101):
        flg = True
        x, y, h = xyh[0][0], xyh[0][1], xyh[0][2]
        ch = abs(cx-x) + abs(cy-y) + h
        for i in range(1,n):
            x, y, h = xyh[i][0], xyh[i][1], xyh[i][2]
            tmph = max(ch - abs(cx-x) - abs(cy-y), 0)
            if h != tmph:
                flg = False
                break
        if flg:
            ans = cx, cy, ch
print(*ans)

Submission status: Accepted

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

for i in range(N):
    if p[i][2] > 0:
        pp = p[i]

f = 0

for i in range(101):
    for j in range(101):
        H = pp[2] + abs(i - pp[0]) + abs(j - pp[1])
        for k in range(N):
            #print(i, j ,k)
            if p[k][2] != max(H - abs(i - p[k][0]) - abs(j - p[k][1]), 0):
                break
            if k == (N - 1):
                xa = i
                ya = j
                Ha = H
                f = 1
                break
        if f == 1:
            break
    if f == 1:
        break


print(xa, ya, Ha)

Submission status: Accepted

Solution code:
N=int(input())
L=[]
for h in range(N):
    Cx,Cy,h=map(int,input().split())
    L.append([h,Cx,Cy])
L.sort(reverse=True)

for x in range(101):
    for y in range(101):
        cond=True
        H=L[0][0]+abs(x-L[0][1])+abs(y-L[0][2])
        for i in range(1,N):
            h=L[i][0]+abs(x-L[i][1])+abs(y-L[i][2])
            if L[i][0]>0:
                if h!=H:
                    cond=False
                    break
            else:
                if h<H:
                    cond=False
                    break
        if cond:
            break
    if cond:
        break

print(x,y,H)

Submission status: Accepted

Solution code:
from itertools import product
xyh = []
xyh0 = []
N=int(input())
for _ in range(N):
    tmp1, tmp2, tmp3 = map(int, input().split())
    if tmp3 > 0:
        xyh.append((tmp1, tmp2, tmp3))
    else:
        xyh0.append((tmp1, tmp2, tmp3))
ans = None
for cx, cy in product(range(101), repeat=2):
    H = None
    H_lower = 1
    H_upper = 10**100
    is_ok = 1
    for x, y, h in xyh:
        if H is None:
            H = abs(x-cx)+abs(y-cy)+h
        else:
            if H != abs(x-cx)+abs(y-cy)+h:
                is_ok = 0
                break
    if not is_ok or H is None:
        continue
    for x, y, h in xyh0:
        H_upper = min(H_upper, abs(x-cx)+abs(y-cy))
    if H > H_upper or H < H_lower:
        continue
    ans = (cx, cy, H)
    break

print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
xyh=[]
for i in range(n):
  x,y,h=map(int,input().split())
  xyh.append([h,x,y])
xyh.sort(reverse=True)
ans=0

for cx in range(101):
  for cy in range(101):
    for N in range(n):
      if abs(xyh[0][1]-cx)+abs(xyh[0][2]-cy)+xyh[0][0]>0:
        H=abs(xyh[0][1]-cx)+abs(xyh[0][2]-cy)+xyh[0][0]
      else:
        break
      if xyh[N][0]!=max(H-abs(xyh[N][1]-cx)-abs(xyh[N][2]-cy),0):
        break
      if N == n-1:
        ans=[cx,cy,H]
print(*ans)

Submission status: Accepted

Solution code:
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def solve(info):
    for Cx in range(101):
        for Cy in range(101):
            height = abs(Cx - info[0][0]) + abs(Cy - info[0][1]) + info[0][2]
            flag = True
            for x,y,h in info[1:]:
                val = max(height - abs(Cx - x) - abs(Cy - y), 0)
                if h == val:
                    continue
                else:
                    flag = False
                    break
            if flag:
                return Cx, Cy, height

def Main():
    n = read_int()
    info = [tuple(read_ints()) for _ in range(n)]
    info.sort(key=lambda x: x[2], reverse=True)

    print(*solve(info))

if __name__ == '__main__':
    Main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3



def solve(n,queries):
    def calcTopHeight(h,x,y,cx,cy):
        return h + abs(x-cx) + abs(y-cy)
    def calcHeight(h,x,y,cx,cy):
        return max(h - abs(x-cx) - abs(y-cy), 0)
    cand = [query for query in queries if query[2] != 0][0]
    for cx in range(101):
        for cy in range(101):
            cnt = 0
            probHeight = calcTopHeight(cand[2],cand[0],cand[1],cx,cy)
            for query in queries:
                x,y,h = query
                if calcHeight(probHeight,x,y,cx,cy) == h:
                    cnt += 1
            if cnt == n:
                return cx,cy,probHeight
    return -1,-1,-1


def main():
    N = int(int(input()))
    queries = [list(map(int,input().split())) for _ in range(N)]
    print(*solve(N,queries))
    return
    # write c


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from copy import copy
N=int(input())
K=100

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

Data.sort(key=lambda x:-x[-1])
for i in range(N):
    x,y,h=Data[i]

    if i==0:
        C=[]
        for X in range(K+1):
            for Y in range(K+1):
                H=h+abs(x-X)+abs(y-Y)
                if H>0:
                    C.append((X,Y,H))
    else:
        D=[]
        for (X,Y,H) in C:
            if max(H-abs(x-X)-abs(y-Y),0)==h:
                D.append((X,Y,H))
        C=copy(D)

X,Y,H=C[0]
print(X,Y,H)

Submission status: Accepted

Solution code:
S=int(input())
L=[list(map(int,input().split())) for i in range(S)]
for i in range(S):
  if L[i][2]!=0:
    for cx in range(101):
      for cy in range(101):
        ans=0
        hpre=L[i][2]+abs(L[i][0]-cx)+abs(L[i][1]-cy)
        for j in range(S):
          if max(hpre-abs(cx-L[j][0])-abs(cy-L[j][1]),0)==L[j][2]:
            ans+=1
        if ans==S:
          print(cx,cy,hpre)
          exit()

Submission status: Accepted

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

for i in l:
    if i[2] != 0:
        x,y,h = i
# print(x,y,h)

for cx in range(101):
    for cy in range(101):
        h_pre = h+abs(x-cx)+abs(y-cy)
        flag = True
        for i in range(n):
            X,Y,H = l[i]
            if H != max(h_pre-abs(X-cx)-abs(Y-cy),0):
                flag = False
        if flag:
            print(cx,cy,h_pre)
            exit()

Submission status: Accepted

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

N = int(input())
x, y, h = zip(*[list(map(int, input().split())) for _ in range(N)])
j = -1
for i in range(N):
    if h[i] != 0:
        j = i
        break
for cx in range(101):
    for cy in range(101):
        H = h[j] + abs(x[j] - cx) + abs(y[j] - cy)
        for i in range(N):
            if h[i] != max(H - abs(x[i] - cx) - abs(y[i] - cy), 0):
                break
        else:
            print(cx, cy, H)

Submission status: Accepted

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

def main():
    for x in range(101):
        for y in range(101):
            height = hs[0][2] + abs(x-hs[0][0]) + abs(y-hs[0][1])
            for i in range(1,n):
                if max(height-(abs(x-hs[i][0]) + abs(y-hs[i][1])),0)== hs[i][2]:
                    pass
                else:
                    break
                
                if i ==n-1:
                    print(x,y,height)
                    return x,y,height
main()

Submission status: Accepted

Solution code:
N = int(input())
K = 101
D = []
for _ in range(N):
    x, y, h = map(int, input().split())
    D.append((x,y,h))
D.sort(key=lambda x:x[2], reverse=True)
for i in range(K):
    for j in range(K):
        flg = True
        H = -1
        for x, y, h in D:
            if h == 0:
                if H > abs(x-i) + abs(y-j):
                    flg = False
                    break
                continue
            if H == -1:
                H = abs(x-i) + abs(y-j) + h
                continue
            if H != abs(x-i) + abs(y-j) + h:
                flg = False
                break
        if flg:
            print(i,j,H)
            exit()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 全探索


def check(pos):
    # 2つ目以降の条件について検討
    flg = True
    for x, y, h in xyh[1:]:
        if h != max(pos[2] - abs(x - pos[0]) - abs(y - pos[1]), 0):
            flg = False
            break
    return flg


def main(xyh):
    # Aは頂点候補のリスト
    A = []
    # 1つ目の条件から高さを求める
    # 1つ目の条件の高さが0だと、頂点の高さが分からないのでソート
    xyh.sort(key=lambda x: x[2], reverse=True)
    x, y, h = xyh[0]
    for i in range(101):
        for j in range(101):
            H = h + abs(x - i) + abs(y - j)
            A.append([i, j, H])
    # 全ての頂点候補について条件に合うかチェック
    for pos in A:
        if check(pos):
            break
    top = pos
    return top


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

top = main(xyh)
print(*top)

Submission status: Accepted

Solution code:
n=int(input())
alist=[list(map(int, input().split())) for i in range(n)]
alist.sort(key=lambda x:x[2],reverse=True)
for i in range(101):
  for j in range(101):
    h=abs(alist[0][0]-i)+abs(alist[0][1]-j)+alist[0][2]
    ans=True
    for k in range(n):
      if max((h-abs(alist[k][0]-i)-abs(alist[k][1]-j)),0)!=alist[k][2]:
        ans=False 
    if ans:
      ansx=i
      ansy=j
      ansh=h
print(ansx,ansy,ansh)

Submission status: Accepted

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

for cx in range(0,101):
    for cy in range(0,101):
        flag=True
        h=abs(cx-xyh[0][0])+abs(cy-xyh[0][1])+xyh[0][2]
        for i in range(n):
            if max(h-abs(cx-xyh[i][0])-abs(cy-xyh[i][1]), 0)!=xyh[i][2]:
                flag=False
        if flag:
            print(cx,cy,h)
            exit()

Submission status: Accepted

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

ansh=-1
ans=[[]]
flag=True
for cx in range(0,101):
  if flag==False:
    break
    
  for cy in range(0,101):
    ansh = 0
    for pira in xyh:
      if ansh==0:
        ansh=pira[2]+(abs(cx-pira[0])+abs(cy-pira[1]))
        ans[0]=[cx,cy,ansh]
        
      elif len(ans[0])>0 and max(ansh -(abs(cx-pira[0])+abs(cy-pira[1])), 0) != pira[2]:
        ans[0]=[]
    if len(ans[0])>0:
      flag=False
      break
print(*ans[0])

Submission status: Accepted

Solution code:
n = int(input())

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

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

for i in range(101):
    meta = False
    for j in range(101):
        H = 0
        flag = True
        for x, y, h in xyh:
            #print(x, y, h, H)
            if H == 0:
                H = abs(x - i) + abs(y - j) + h
            elif max(H - abs(x - i) - abs(y - j), 0) != h:
                flag = False
                break
        if flag:
            print(i, j, H)
            meta = True
            break
    if meta:
        break

Submission status: Accepted

Solution code:
import sys
n = int(input())
inf_ls = [[0]*3 for _ in range(n)]
for i in range(n):
    x,y,h = map(int,input().split())
    inf_ls[i] = x,y,h
for Cx in range(101):
    for Cy in range(101):
        this_is_C = True
        H_set = set()
        zero_ls = []
        for i in range(n):
            x,y,h = inf_ls[i]
            if h > 0:
                H = abs(x-Cx) + abs(y-Cy) + h
                H_set.add(H)
            else:
                zero_ls.append([x,y])
        if len(H_set) != 1:
            this_is_C = False
            continue
        H = list(H_set)[0]
        for x,y in zero_ls:
            if H - abs(x-Cx) - abs(y-Cy) > 0:
                this_is_C = False
        if this_is_C:
            print(Cx,Cy,H)
            exit()

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())  #空白あり

N = I()
xyh = [tuple(MI()) for i in range(N)]

for i in range(101):  # ピラミッドの中心座標のx座標
    for j in range(101):  # ピラミッドの中心座標のy座標
        for k in range(N):
            x,y,h = xyh[k]
            if h != 0:
                H = h + abs(x-i) + abs(y-j)
                break
        for k in range(N):
            x,y,h = xyh[k]
            if h != max(H - abs(x-i) - abs(y-j),0):
                break
        else:
            print(i,j,H)
            exit()