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

xyh = [list(map(int,input().split()))for i in range(n)]
i = 0
while i<n:
    if xyh[i][2]==0:
        xyh.pop(i)
        n -= 1
    else: i += 1

if(n==1):
    print(*xyh[0])
    exit()

for i in range(101):
    for j in range(101):
        base = xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for k in range(1, n):
            if base!=xyh[k][2]+abs(xyh[k][0]-i)+abs(xyh[k][1]-j): break
        else:
            print(i, j, base)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
for _ in range(N):
  A[_][0], A[_][1], A[_][2] = A[_][2], A[_][0], A[_][1]
A.sort(reverse=True)
if sum(A[_][0] for _ in range(N)) == 0:
  print(0, 0, 1)
else:
  for i in range(101):
    for j in range(101):
      H = abs(A[0][1] - i) + abs(A[0][2] - j) + A[0][0]
      flg = 1
      for k in range(N):
        if max(H - abs(A[k][1] - i) - abs(A[k][2] - j), 0) != A[k][0]:
          flg = 0
          break
      if flg == 1:
        Cx, Cy, cerH = i, j, H
        break
    if flg == 1:
      break
  print(Cx, Cy, cerH)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
information = [list(map(int, input().split())) for _ in range(n)]
information.sort(key=lambda x: x[2])

for c_x in range(101):
    for c_y in range(101):
        x, y, h = information[-1]
        H = h + abs(x - c_x) + abs(y - c_y)
        judge = 1
        for w in information[:-1]:
            x, y, h = w
            if h == max(0, H - abs(x - c_x) - abs(y - c_y)):
                continue
            else:
                judge -= 1
                break
        if judge:
            print(c_x, c_y, H)
            sys.exit()
        else:
            continue

Submission status: Accepted

Solution code:
from sys import setrecursionlimit
from operator import itemgetter

def main():
    N = int(input())
    XYH = [list(map(int,input().split())) for _ in range(N)]
    XYH.sort(key = itemgetter(2),reverse = True)
    ansx = -1
    ansy = -1
    for cx in range(0,101):
        for cy in range(0,101):
            H = -1
            flag = True
            for x,y,h in XYH:
                if H >= 0:
                    if h != max(H - abs(x - cx) - abs(y - cy),0):
                        flag = False
                        break
                elif h > 0:
                    H =  h + abs(x - cx) + abs(y - cy)
            if flag:
                ansx = cx
                ansy = cy
                print(ansx,ansy,H)
                return
    return   

if __name__ == "__main__":
    main()

Submission status: Accepted

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

s = 0

for index, i in enumerate(li):
  if i[2] > 0:
    s = index
    break
  
for x in range(101):
  for y in range(101):
    h = li[s][2] + abs(x - li[s][0]) + abs(y - li[s][1])
    ok = True

    for i in li:
      if i[2] > 0 and h != i[2] + abs(x - i[0]) + abs(y - i[1]):
        ok = False
      if i[2] == 0 and h > i[2] + abs(x - i[0]) + abs(y - i[1]):
        ok = False

    if ok:
      ans = [x, y, h]

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

Submission status: Accepted

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

ti=0

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



flag=0
for tx in range(101):
    if flag==1:
        break
    for ty in range(101):
        th=h[ti]+abs(tx-x[ti])+abs(ty-y[ti])
        flag=1
        for i in range(N):
            nh=h[i]+abs(tx-x[i])+abs(ty-y[i])
            if (h[i]!=0 and nh!=th) or (h[i]==0 and nh<th ):
                flag=0
                break
        if flag==1:
            ans=[tx,ty,th]
            break

print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
def Hr(h, x, y, cx, cy):
    return h+abs(x-cx)+abs(y-cy)
def H(h, x, y, cx, cy):
    return max(h-abs(x-cx)-abs(y-cy),0)


N = int(input())
x = [list(map(int, input().split())) for i in range(N)]
for cx in range(0, 101):
    for cy in range(0, 101):
        judge = True
        m = [l for l in range(N) if x[l][2]!=0][0]
        H0 = Hr(x[m][2], x[m][0], x[m][1], cx, cy)
        for n in range(len(x)):
            Hn = H(H0, x[n][0], x[n][1], cx, cy)
            if(x[n][2] == Hn):
                judge = judge and True
            else:
                judge = judge and False
        if(judge):
            print(cx, cy, H0)

Submission status: Accepted

Solution code:
def H(h, x, y, cx, cy):
    return h + abs(x-cx) + abs(y-cy)
def Hr(h, x, y, cx, cy):
    return max(h-abs(x-cx)-abs(y-cy),0)


N = int(input())
x = [list(map(int, input().split())) for i in range(N)]
for cx in range(0, 101):
    for cy in range(0, 101):
        judge = True
        m = [l for l in range(N) if x[l][2]!=0][0]
        H0 = H(x[m][2], x[m][0], x[m][1], cx, cy)
        for n in range(len(x)):
            Hn = H(x[n][2], x[n][0], x[n][1], cx, cy)
            #print(Hn)
            if(x[n][2] != 0):
                if(Hn == H0):
                    judge = judge and True
                else:
                    judge = judge and False
        if(judge):
            for n in range(len(x)):
                if(x[n][2] == 0):
                    Hm = Hr(H0, x[n][0], x[n][1], cx, cy)
                    if(Hm == 0):
                        judge = judge and True
                    else:
                        judge = judge and False
                
            if(judge):
                print(cx, cy, H0)

Submission status: Accepted

Solution code:
from collections import deque

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


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


q = deque()

P.sort(key=lambda x: -x[2])
x0, y0, h0 = P[0]
x1, y1, h1 = P[1]
for cx in range(0, 101):
    for cy in range(0, 101):
        norm0 = norm((x0, y0), (cx, cy))
        norm1 = norm((x1, y1), (cx, cy))
        if h0 - h1 == -norm0 + norm1:
            q.append((cx, cy))

t = 2
# print("22: print(len(q)) {}".format(len(q)))
while len(q) > 1:
    x0, y0, h0 = P[t - 1]
    x1, y1, h1 = P[t]
    for i in range(len(q)):
        cx, cy = q.popleft()
        norm0 = norm((x0, y0), (cx, cy))
        norm1 = norm((x1, y1), (cx, cy))
        if h0 - h1 == -norm0 + norm1:
            q.append((cx, cy))
    t += 1
    # print(t)

cx, cy = q.popleft()
x, y, h = P[0]
H = h + abs(x - cx) + abs(y - cy)

print(*[cx, cy, H])

Submission status: Accepted

Solution code:
#112
from itertools import product

N=int(input())
px,py,ph=[],[],[]

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)
        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

for Cxi,Cyj in product(range(101),range(101)):

    if len(ph)!=1:
        preH=Calc_H(Cxi,Cyj,px[0],py[0],ph[0])
        for i in range(len(ph)):
            nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
            if nowH!=preH:
                break
            preH=nowH
        else:
            print(Cxi,Cyj,nowH)
            break
    else:
        print(px[0],py[0],ph[0])
        break

Submission status: Accepted

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

def get_H(cx, cy):
   for x, y, h in z:
      if h > 0:
         return abs(x - cx) + abs(y - cy) + h

def check_H(cx, cy, H):
   for x, y, h in z:
      if h != max(H - abs(x - cx) - abs(y - cy), 0):
         return False
   return True


for cx in range(101):
   for cy in range(101):
      H = get_H(cx, cy)
      if check_H(cx, cy, H):
         print(cx, cy, H)
         exit()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
xyh = [input() for _ in range(n)]
#print(xyh)
for x_ in range(101):
    for y_ in range(101):
        cur_h = 0 #flga の場所をループの中に入れない
        for i in range(n):
            x = int(xyh[i].split()[0])
            y = int(xyh[i].split()[1])
            h = int(xyh[i].split()[2])
            h_ = h + (abs(x_ - x) + abs(y_ - y))
            if cur_h == 0 and h > 0:
                cur_h = h_  #決め打ちの高さ        
            else:
                if h > 0:
                    if cur_h != h_: break
                elif cur_h -(abs(x_ - x) + abs(y_ - y)) > 0: break
        for i in range(n):
            x = int(xyh[i].split()[0])
            y = int(xyh[i].split()[1])
            h = int(xyh[i].split()[2])
            h_ = h + (abs(x_ - x) + abs(y_ - y))
            if cur_h == 0 and h > 0:
                cur_h = h_  #決め打ちの高さ        
            else:
                if h > 0:
                    if cur_h != h_: break
                elif cur_h -(abs(x_ - x) + abs(y_ - y)) > 0: break   
                if i == n-1: 
                    print(x_,y_,cur_h)
                    #print("hello")
                    exit(0)

Submission status: Accepted

Solution code:
N = int(input())

XYH = [list(map(int, input().split())) for _ in range(N)]
# 高さは一意に決まるのでhi>0のものをひとつ変数に持っておく
for x, y, h in XYH:
  if h >= 1:
    xt, yt, ht = x, y, h
    break
# greedy    
for cx in range(101):
  for cy in range(101):
    ch = ht + abs(cx-xt) + abs(cy-yt)
    for x, y, h in XYH:
        if h != max(ch - abs(x - cx) - abs(y - cy), 0):
          break
    else:
      print(cx, cy, ch)
      exit()

Submission status: Accepted

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
n = int(input())
l = [list(map(int, input().split())) for i in range(0, n) ]
 
for i in range(0, n):
    if l[i][2] != 0:
        p = l[i]
        break
 
for x in range(0, 101):
    for y in range(0, 101):
        h = p[2] + abs(x-p[0]) + abs(y-p[1])
        for i in range(0, n):
            if l[i][2] != max(h - abs(x-l[i][0]) - abs(y-l[i][1]), 0):
                break
        else:
            print(x, y, h)
            exit()

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N = int(input())
Map = []
for i in range(N):
    m = tuple(map(int, input().split()))
    Map.append(m)

for X in range(101):
    for Y in range(101):
        for m in Map:
            if m[2] != 0:
                H = abs(X-m[0])+abs(Y-m[1])+m[2]
                break
        flg = 1
        for m in Map:
            if m[2] != max(H-abs(X-m[0])-abs(Y-m[1]),0):
                flg = 0
                break
        if flg:
            print(X,Y,H)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N = cin.int()
    info = cin.intListList(N)
    X,Y,H = [0,0,0]
    for i in info:
        if i[2] > 0:
            X = i[0]
            Y = i[1]
            H = i[2]
    for x in range(101):
        for y in range(101):
            h = abs(x - X) + abs(y - Y) + H
            if h > 0:
                ok = True
                for i in range(N):
                    a = max(0,h - abs(x - info[i][0]) - abs(y - info[i][1]))
                    if info[i][2] != a:
                        ok = False
                if ok:
                    print("{} {} {}".format(x,y,h))
                    return
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
xx = [0]*n
yy = [0]*n
hh = [0]*n
for i in range(n):
    x,y,h = map(int,input().split())
    xx[i] = x
    yy[i] = y
    hh[i] = h

for i in range(n):
    if hh[i] == 0:
        continue
    else:
        x = xx[i]
        y = yy[i]
        h = hh[i]
        break

for cx in range(101):
    for cy in range(101):
        H = abs(x-cx) + abs(y-cy) + h
        for i in range(n):
            if max(H-abs(xx[i]-cx)-abs(yy[i]-cy),0) != hh[i]:
                break
        else:
            print(cx,cy,H)
            exit()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()

info = [na() for i in range(n)]
ix, iy, ih = 0, 1, 2

si = -1
for i in range(n):
	if info[i][2] > 0:
		si = i

ans = [-1, -1, -1]
for cx in range(101):
	for cy in range(101):
		x = abs(cx - info[si][ix])
		y = abs(cy - info[si][iy])
		h = info[si][ih] + x + y
		ok = True
		for i in range(n):
			if info[i][ih] > 0 and h - info[i][ih] != abs(cx - info[i][ix]) + abs(cy - info[i][iy]):
				ok = False
			if info[i][ih] == 0 and h > abs(cx - info[i][ix]) + abs(cy - info[i][iy]):
				ok = False
		if ok is True:
			ans[ix], ans[iy], ans[ih] = cx, cy, h

print(ans[ix], ans[iy], ans[ih])

Submission status: Accepted

Solution code:
n = int(input())
py = []
start = 0
for i in range(n):
    x,y,h = map(int, input().split())
    if start < h:
        start = h
    py.append((x,y,h))

height = lambda x,y,cx,cy,hh:max(hh -abs(x-cx) -abs(y-cy), 0)
while True:
    for i in range(101):
        for j in range(101):
            for a,b,h in py:
                if height(a,b,i,j,start) != h:
                    # no
                    break
            else:
                # ok
                print(i,j,start)
                exit()
    start += 1

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)      

for cx in range(101):
    for cy in range(101):
        for i in range(N):
            if H[i] > 0:
                height = H[i] + abs(X[i]-cx) + abs(Y[i]-cy)
        ok = True
        for i in range(N):
            if max(height - abs(X[i]-cx) - abs(Y[i]-cy), 0) != H[i]:
                ok = False
        if ok:
            print(cx, cy, height)
            exit()

Submission status: Accepted

Solution code:
def p_c():
    from itertools import product
    N = int(input())
    xyh = [tuple(map(int, input().split())) for _ in range(N)]
    h = 0
    for i in xyh:
        if h < i[2]:
            x_, y_, h = i
    for x, y in product(range(101), repeat=2):
        high = h + abs(x_ - x) + abs(y_ - y)
        if all(h == max(0, high - abs(x - i) - abs(y - j)) for i, j, h in xyh):
            print(x, y, high)

p_c()

Submission status: Accepted

Solution code:
def is_right(i, j):
    H = None
    for h, x, y in XYH:
        if H is None:
            if h > 0:
                H = abs(x - i) + abs(y - j) + h
        else:
            if h != max(H - abs(x - i) - abs(y - j), 0):
                return -1
    return H


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

for i in range(101):
    for j in range(101):
        res = is_right(i, j)
        if res > 0:
            print(i, j, res)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
X = [0] * N
Y = [0] * N
H = [0] * N

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

for cx in range(101):
    for cy in range(101):
        H_list = []
        check_list = []
        for i in range(N):
            if H[i] == 0:
                check_list.append(i)
                continue
            H_list.append(H[i] + abs(X[i] - cx) + abs(Y[i] - cy))
        if len(set(H_list)) == 1:
            h = H_list[0]
            flag = True
            for check in check_list:
                if H[check] == max(h - abs(X[check] - cx) - abs(Y[check] - cy), 0):
                    pass
                else:
                    flag = False
                    break
            if flag:
                print(cx, cy, h)
                exit()

Submission status: Accepted

Solution code:
n=int(input())
xi,yi,hi=[],[],[]
for i in range(n):
    num=[int(j) for j in input().split()]
    xi+=[num[0]]
    yi+=[num[1]]
    hi+=[num[2]]
ans=[0,0,0]
for i in range(101):
    for j in range(101):
        hoge=10**9+10
        for k in range(n):
            hight=hi[k]+abs(xi[k]-i)+abs(yi[k]-j)
            if(hi[k]==0):
                continue
            if(i==xi[k] and j==yi[k]):
                hight=hi[k]
            if(hoge==10**9+10):
                hoge=hight
            elif(hoge!=hight):
                break
        else:
            flg=True
            for k in range(n):
                hight=max(hoge-abs(xi[k]-i)-abs(yi[k]-j),0)
                if(hi[k]!=hight):
                    flg=False
                    break
            if(flg):
                ans=[i,j,hoge]
print(*ans,sep=" ")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
h = 0
for i in xyh:
  if i[2] > h:
    x, y, h = i[0], i[1], i[2]
CXY = [[i,j] for i in range(0,100+1) for j in range(0,100+1)]
for cxy in CXY:
  ans=True
  H = h + abs(x - cxy[0]) + abs(y - cxy[1])
  for i in xyh:
    if max( H - abs(i[0] - cxy[0]) - abs(i[1] - cxy[1]) ,0) != i[2]:
      ans = False
  if ans:
    print(cxy[0],cxy[1],H)

Submission status: Accepted

Solution code:
import itertools

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


for i in range(N):
    x, y, h = xyh[i]
    if h > 0:
        x_t, y_t, h_t = x, y, h
        break

for c_x, c_y in itertools.product(range(0, 100+1), repeat=2):
    H = h_t + abs(x_t - c_x) + abs(y_t - c_y)
    for i in range(N):
        x_i, y_i, h_i = xyh[i]
        if h_i != max(H - abs(x_i - c_x) - abs(y_i - c_y), 0):
            break
    else:
        print(c_x, c_y, H)
        exit()

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        ch = nonzero[2] + abs(cx-nonzero[0]) + abs(cy-nonzero[1])
        cnt = 0
        for i in range(N):
            if h[i] == max(ch-abs(x[i]-cx)-abs(y[i]-cy), 0):
                cnt += 1
        if cnt == N:
            print(cx,cy,ch)
            exit()

Submission status: Accepted

Solution code:
from itertools import product


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

    xt, yt, ht = -1, -1, -1
    for i in range(N):
        if h[i] != 0:
            xt, yt, ht = x[i], y[i], h[i]
            break
    
    for cx, cy in product(range(101), repeat=2):
        ans_h = ht + abs(cx - xt) + abs(cy - yt)
        flg = True
        for i in range(len(x)):
            if h[i] != max(ans_h - abs(x[i] - cx) - abs(y[i] - cy), 0):
                flg = False
                break
        if flg:
            print(cx, cy, ans_h)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n=int(input())
p=[]
for i in range(n):
    p.append(tuple(map(int,input().split())))
p.sort(key=lambda x:-x[2])
for j in range(101):
    for k in range(101):
        H=None
        f=1
        for x,y,h in p:
            if h>0 and H==None:
                H=h+abs(x-j)+abs(y-k)
            else:
                if max(0,H-abs(x-j)-abs(y-k))!=h:
                    f=0
        if f:
            print(j,k,H)
            exit()

Submission status: Accepted

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    x,y,h=[0]*N,[0]*N,[0]*N
    for i in range(N):
        x[i],y[i],h[i]=map(int,input().split())
    for cx in range(101):
        for cy in range(101):
            ch=-1
            queue=deque()
            for X,Y,H in zip(x,y,h):
                queue.append((X,Y,H))
            while queue:
                X,Y,H=queue.popleft()
                if ch==-1:
                    if H>0:
                        ch=H+abs(X-cx)+abs(Y-cy)
                    else:
                        queue.append((X,Y,H))
                elif ch!=-1 and ((ch-abs(X-cx)-abs(Y-cy)>0 and H!=ch-abs(X-cx)-abs(Y-cy)) or (ch-abs(X-cx)-abs(Y-cy)<=0 and H!=0)):
                    break
            else:
                print(cx,cy,ch)
                exit()
                    
        

if __name__ == '__main__':
    main()

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):
        H = set()
        for x, y, h in xyh:
            if h != 0:
                H.add(h + abs(x - cx) + abs(y - cy))
        if len(H) == 1:
            H = list(H)[0]
            flag = True
            for x, y, h in xyh:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    flag = False
                    break
            if flag:
                print(cx, cy, H)

Submission status: Accepted

Solution code:
import sys
N=int(input())
po = []
zp = []
for i in range(N):
    x, y, h = map(int, input().split())
    if h == 0:
        zp.append( [x,y] )
    else:
        po.append( [x,y,h] )
for yt in range(101):
    for xt in range(101):
        k = -1
        for p in po:
            tmpH = p[2] + abs(p[0]-xt) + abs(p[1]-yt)
            if k == -1:
                k = tmpH
            else:
                if k != tmpH:
                    k = -1
                    break
        if k == -1:
            continue
        for p in zp:
            if (k - abs(p[0]-xt) - abs(p[1]-yt)) > 0:
                k = -1
                break
        if k != -1:
            print(xt,yt,k)
            sys.exit

Submission status: Accepted

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

for x in range(101):
    for y in range(101):
        h_memo = 0
        for i in range(n):
            if xy[i][2] != 0:
                h_memo = xy[i][2] + abs(xy[i][0]-x) + abs(xy[i][1]-y)
                break
        for i in range(n):
            if xy[i][2] != max(0,h_memo-abs(xy[i][0]-x)-abs(xy[i][1]-y)):
                break

        else:               
            #print(x+1,y+1,h[0])

            print(x,y,h_memo)
            break

Submission status: Accepted

Solution code:
N = int(input())
xyh = []

tmp = -1
for i in range(N):
    x,y,h = map(int,input().split())
    xyh.append((x,y,h))
    if h > 0: tmp = i

def check(cx,cy,H,i):
    if xyh[i][2] == max(H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy),0): return True
    else: return False

flg = False
for cx in range(101):
    for cy in range(101):
        H = xyh[tmp][2] + abs(xyh[tmp][0]-cx) + abs(xyh[tmp][1]-cy)
        if all([check(cx,cy,H,i) for i in range(N)]):
            flg = True
            break
    if flg: break

print(cx,cy,H)

Submission status: Accepted

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

t = 0
for i in range(N):
    if info[i][2] != 0:
        t = i
        break
#  print(t)

def check(Cx, Cy, H):
    for i in range(N):
        if info[i][2] != max(H - abs(info[i][0] - Cx) - abs(info[i][1] - Cy), 0):
            return False
    return True



for Cx in range(101):
    for Cy in range(101):
        H = abs(info[t][0] - Cx) + abs(info[t][1] - Cy) + info[t][2]
        if check(Cx, Cy, H):
            print('{} {} {}'.format(Cx, Cy, H))

Submission status: Accepted

Solution code:
def decide_H(Cx,Cy):
    for x,y,h in T:
        H=h+abs(x-Cx)+abs(y-Cy)
        if h>=1:
            return(H)

def check_H(Cx,Cy,H):
    for x,y,h in T:
        if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
            return False
    return True

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

for Cx in range(101):
    for Cy in range(101):
        H=decide_H(Cx,Cy)
        if check_H(Cx,Cy,H):
            print(Cx,Cy,H)
            exit(0)

Submission status: Accepted

Solution code:
def decide_H(Cx,Cy):
    for x,y,h in T:
        H=h+abs(x-Cx)+abs(y-Cy)
        if h>=1:
            return(H)

def check_H(Cx,Cy,H):
    for x,y,h in T:
        if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
            return False
    return True

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

for Cx in range(101):
    for Cy in range(101):
        H=decide_H(Cx,Cy)
        if check_H(Cx,Cy,H):
            print(Cx,Cy,H)
            exit(0)

Submission status: Accepted

Solution code:
def get_H(Cx, Cy):
    for x, y, h in L:
        if h > 0:
            return abs(x - Cx) + abs(y - Cy) + h


def check_H(Cx, Cy, H):
    for x, y, h in L:
        if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
            return False
    return True


N = int(input())

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

for Cx in range(101):
    for Cy in range(101):
        H = get_H(Cx, Cy)
        if check_H(Cx, Cy, H):
            print('{} {} {}'.format(Cx, Cy, H))
            exit(0)

Submission status: Accepted

Solution code:
N=int(input())
p=[list(map(int, input().split())) for _ in range(N)]
ax, ay, ah = list(filter(lambda x: x[2], p))[0]#ピラミッドの高さがないところを抜かないといけないんだ
for i in range(101):
  for j in range(101):
    center=[i,j,ah+abs(ax-i)+abs(ay-j)]
    if all(t[2]==max(center[2]-abs(t[0]-center[0])-abs(t[1]-center[1]),0) for t in p) :
      print(center[0],center[1],center[2])

Submission status: Accepted

Solution code:
N=int(input())
p=[list(map(int, input().split())) for _ in range(N)]
ax, ay, ah = list(filter(lambda x: x[2], p))[0]
for i in range(101):
  for j in range(101):
    center=[i,j,ah+abs(ax-i)+abs(ay-j)]
    if all(t[2]==max(center[2]-abs(t[0]-center[0])-abs(t[1]-center[1]),0) for t in p) :
      print(center[0],center[1],center[2])

Submission status: Accepted

Solution code:
N = int(input())
p = [list(map(int, input().split()))for _ in range(N)]
ax, ay, ah = list(filter(lambda x: x[2], p))[0]
for x in range(101):
    for y in range(101):
        H = ah+abs(ax-x)+abs(ay-y)
        if all(max(H-abs(t[0]-x)-abs(t[1]-y), 0) == t[2]for t in p):
            print(x, y, H)

Submission status: Accepted

Solution code:
n = int(input())
p = [list(map(int, input().split()))for _ in range(n)]
ax, ay, ah = list(filter(lambda x: x[2], p))[0]
for x in range(101):
    for y in range(101):
        H = ah+abs(ax-x)+abs(ay-y)
        if all(max(H-abs(t[0]-x)-abs(t[1]-y), 0) == t[2]for t in p):
            print(x, y, H)

Submission status: Accepted

Solution code:
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
B=sorted(A,key=lambda x: x[2])
#(i,j)が中心座標にあるとき
for i in range(101):
  for j in range(101):
    H=abs(B[-1][0]-i)+abs(B[-1][1]-j)+B[-1][2]
    for k in range(N-1):
      if max(H-abs(B[k][0]-i)-abs(B[k][1]-j),0)!=B[k][2]:
        break
    else:
      print(i,j,H)     
      exit()

Submission status: Accepted

Solution code:
N = int(input())
P = []
for i in range(N):
    x,y,h = map(int,input().split())
    P.append((x,y,h))
def f(x,y,h,i,j):
    H = h + max(x-i,i-x) + max(y-j,j-y)
    return H
for i in range(101):
    for j in range(101):
        Hi = []
        t = 1
        M = 10**100
        for k in range(N):
            x,y,h = P[k]
            if h == 0:
                H = f(x,y,h,i,j)
                M = min(M,H)
                continue
            H = f(x,y,h,i,j)
            if H > M:
                t = 0
            if H not in Hi:
                Hi.append(H)
        if len(Hi) != 1:
            t = 0
        else:
            if Hi[0] > M:
                t = 0
        if t == 1:
            print(i,j,Hi[0])
            quit()

Submission status: Accepted

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