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 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
XYH = []
for i in range(N):
    x, y, h = MAP()
    XYH.append((x, y, h))

# 中心候補として全座標を試す
for y1 in range(101):
    for x1 in range(101):
        H = set()
        for x2, y2, h in XYH:
            # 各座標情報から、中心の高さ(仮)を出す
            tmph = abs(x1-x2) + abs(y1-y2) + h
            # 高さ0の情報は使えないので除く
            if h > 0:
                H.add(tmph)
        # 合ってるか再確認
        if len(H) == 1:
            ansh = list(H)[0]
            for x2, y2, h in XYH:
                tmph =  ansh - (abs(x1-x2) + abs(y1-y2))
                if tmph < 0:
                    continue
                if tmph != h:
                    break
            else:
                print(x1, y1, list(H)[0])
                exit()

Submission status: Accepted

Solution code:
N, *V = map(int, open(0).read().split())
xs = V[0::3]
ys = V[1::3]
hs = V[2::3]
MAX = 101
high_cand = int()

for y in range(MAX):
  for x in range(MAX):
    high_cand = -1
    for i in range(N):
      # 最初に高さ > 0 の場合を調べる
      if(hs[i] > 0):
        tmp = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
        if(high_cand == -1):
          high_cand = tmp
        else:
          if(high_cand != tmp):
            high_cand = -2
      # その結果矛盾していれば次を見る
      if(high_cand == -2):
        continue;
    # 高さ 0 の場合を調べる
    for i in range(N):
      if(hs[i] == 0):
        a = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
        if(high_cand > a):
          high_cand = -2
          break
    # その結果矛盾していれば次を見る
    if(high_cand == -2):
      continue;
    # ここまで矛盾なければその値を出力して終了
    print(str(x) + ' ' + str(y) + ' ' + str(high_cand))

Submission status: Accepted

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

start = 0
while X[start][2] == 0:
    start += 1


def c():
    for i in range(101):
        for j in range(101):
            ng = 0
            h = X[start][2] + abs(i - X[start][0]) + abs(j - X[start][1])
            for k in range(n):
                if X[k][2] != max(0, h - abs(i - X[k][0]) - abs(j - X[k][1])):
                    ng = 1
                    break
            if ng == 0:
                return i, j, h

ans = c()
print(ans[0], ans[1], ans[2])

Submission status: Accepted

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

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


#平地の情報があると結果がバグるので捨てる
xyh0=[]
xyh1=[]
for item in xyh:
  if item[2]==0:
    xyh0.append(item)
  else:
    xyh1.append(item)

xyh=xyh1
#ただしピラミッドの根元の高さ0の地点は重要なので残す（any(~)にtrueがあれば根元の可能性がある）　
for item0 in xyh0:
  if any([calc_h(item1[0],item1[1],item0)==item1[2] for item1 in xyh1]):
    xyh.append(item0)
n=len(xyh)

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


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

Submission status: Accepted

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

n=int(input())
xyh=[[int(x) for x in input().split()] for _ in range(n)]
xyh.sort(key=lambda x:x[0],reverse=True)

#平地の情報(ピラミッドの根元を除く)は役にたたないので捨てる
xyh0=[]
xyh1=[]
for item in xyh:
  if item[2]==0:
    xyh0.append(item)
  else:
    xyh1.append(item)

xyh=xyh1

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

n=len(xyh)

anslist=[]

for x in range(101):
  for y in range(101):
    c=0
    tmp=calc_h(x,y,xyh[0])
    for i in range(1,n):
      if tmp!=calc_h(x,y,xyh[i]):
        break
      else:
        c+=1
    #if c==n-1:
    #  print(x,y,tmp)
    anslist.append([c,x,y,tmp])


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

Submission status: Accepted

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

for i in range(101):
  for j in range(101):
    H = k[2] + abs(k[0]-i) + abs(k[1]-j)
    for l in z:
      if l[2] != max(H-abs(l[0]-i)-abs(l[1]-j),0):
        break
      if l == z[-1]:
        print(i,j,H)
        exit()

Submission status: Accepted

Solution code:
### input test
"""
N = 6
rawP = [
(16,24,0),
(2,3,0),
(2,1,0),
(1,2,0),
(3,2,0),
(2,2,1),
]
# => expected(2,2,1)
###
"""
N = int(input())
rawP = [tuple(map(int, input().split())) for _ in range(N)]


###
# get 1 index where h is not 0
# N < 101*101 ==> h > 0 at least 1 point
P = []
for i in range(N):
    if rawP[i][2] > 0:
       P.append(rawP[i])
REGi = len(P)-1

# if only 1 point (h>0) given, that is the center
if len(P) == 1:
    print(*P[REGi])
    exit(0)

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

def is_correct_center(cx, cy):
    now_C = (cx, cy, 0)  # Is this the center?
    # get first sample where h is not 0
    reg_D = dist(P[REGi], now_C)
    reg_H = P[REGi][2]
    for i in range(len(P)):
        now_D = dist(P[i], now_C)
        now_H = P[i][2]
        # higher_H if nearer_D
        if (- now_D + reg_D) != (now_H - reg_H):
            return False
    return True

def get_answers(cx, cy):
    H = P[REGi][2] + dist(P[REGi], (cx, cy, 0))
    return cx, cy, H

### Start from here...
for cx in range(101):
    for cy in range(101):
        if is_correct_center(cx, cy):
            print(*get_answers(cx, cy))
            exit(0)

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
x,y,h = Line(N)

for i in range(N):
    if h[i]!=0:
        x0,y0,h0 = x[i],y[i],h[i]
        break

for cx in range(101):
    for cy in range(101):
        H = abs(x0-cx)+abs(y0-cy)+h0
        flag = True
        for i in range(N):
            if max(H-abs(x[i]-cx)-abs(y[i]-cy),0)!=h[i]:
                flag = False
                break
        if flag:
            break
    else:
        continue
    break

print(cx,cy,H)

Submission status: Accepted

Solution code:
n=int(input())
info=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:-x[2])
x0,y0,h0=info[0][0],info[0][1],info[0][2]

for i in range(101):
  for j in range(101):
    f=1
    hp=h0+abs(i-x0)+abs(j-y0)
    for k in range(n):
      x,y,h=info[k][0],info[k][1],info[k][2]
      if h>0:
        if h+abs(i-x)+abs(j-y)==hp:
          continue
        else:
          f=0
          break
      else:
        if hp-abs(i-x)-abs(j-y)<=0:
          continue
        else:
          f=0
          break
    if f==1:print(i,j,hp,sep=" ")

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
h = []
nonzero_x = 0
nonzero_y = 0
nonzero_h = 0

for _ in range(N):
    xx, yy, hh = [int(x) for x in input().split()]
    x.append(xx)
    y.append(yy)
    h.append(hh)
    if nonzero_h == 0 and hh != 0:
        nonzero_x = xx
        nonzero_y = yy
        nonzero_h = hh


def solve():
    for cx in range(101):
        for cy in range(101):
            res = True
            calc_h = nonzero_h + abs(nonzero_x-cx) + abs(nonzero_y-cy)
            for i in range(N):
                hh = max(calc_h - abs(x[i]-cx) - abs(y[i]-cy), 0)
                if hh != h[i]:
                    res = False
                    break
            if res:
                print("{} {} {}".format(cx, cy, calc_h))
                return
    return

solve()

Submission status: Accepted

Solution code:
N = int(input())
X = []
Y = []
Height =[] 
for i in range(N):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    Height.append(h)
List = []
flag = 0
for i in range(N):
    if flag ==1:
        break
    if Height[i]==0:
        continue
    else:
        for Cx in range(101):
            for Cy in range(101):
                tmp_h = Height[i]+abs((X[i]-Cx))+abs((Y[i]-Cy))
                if tmp_h >= 1 :
                    List.append([Cx,Cy,tmp_h])
        flag = 1
     
    #1個目のx,y,hからCx,Cy,Hの候補を作り(List)，他のx,y,hは候補と照らし合わせながら答えを探す．
    #制約が小さいからできる全探索

for i in range(1,N):
    for j in List[:]:
        if Height[i] == max(j[2]-abs((X[i]-j[0]))-abs((Y[i]-j[1])),0):
            continue
        else:
            List.remove(j)

print(List[-1][0],List[-1][1],List[-1][2])

Submission status: Accepted

Solution code:
import sys
n = int(input())
XYH = [list(map(int, input().split())) for _ in range(n)]
H = []
H += [H.append(XYH[i][2]) for i in range(n)]
f = H.count(0) == n-1

for i in range(102):# Cx
  for j in range(102): #Cy
    height = -100
    flg = True
    for k in range(n):
      x,y,h= XYH[k][0], XYH[k][1], XYH[k][2]
      if h <= 0:
        continue
      elif f:
        print(x,y,h)
        sys.exit()
      if height != -100:
        th = 0 if h <= 0 else max(0, h + abs(x-i) + abs(y-j))
        if height == th:
          continue
        else:
          flg = False
          break
      else:
        height = 0 if h <= 0 else max(0, h + abs(x-i) + abs(y-j))
        #height = max(0, h + abs(x-i) + abs(y-j))
        continue
    if flg and height > 0:
      print(i, j, height)
      sys.exit()

Submission status: Accepted

Solution code:
n = int(input())
z = [0] * n
for i in range(n):
  x,y,h = map(int,input().split())
  if h != 0:
    k = [x,y,h]
  z[i] = [x,y,h]
for i in range(101):
  for j in range(101):
    H = k[2] + abs(k[0]-i) + abs(k[1]-j)
    for l in z:
      if l[2] != max(H-abs(l[0]-i)-abs(l[1]-j),0):
        break
      if l == z[-1]:
        print(i,j,H)
        exit()

Submission status: Accepted

Solution code:
import itertools

n = int(input())
x, y, h = [], [], []
for _ in range(n):
    xi, yi, hi = map(int, input().split())
    if hi != 0:
        x.append(xi)
        y.append(yi)
        h.append(hi)
candidate_cx = list(range(min(x), max(x) + 1))
candidate_cy = list(range(min(y), max(y) + 1))

for cx, cy in list(itertools.product(candidate_cx, candidate_cy)):
    adapted = True
    ch = h[0] + abs(x[0] - cx) + abs(y[0] - cy)
    for xi, yi, hi in zip(x, y, h):
        if hi != ch - abs(xi - cx) - abs(yi - cy):
            adapted = False
            break
    if adapted == False:
        continue
    print(cx, cy, ch, sep = ' ')
    exit(0)

Submission status: Accepted

Solution code:
N = int(input())
ls = []
for i in range(N):
  x,y,h = map(int, input().split())
  ls += [(x,y,h)]
ls.sort(key=lambda x:x[2])
px, py, ph = ls[-1]

ans = []
flag = False
for i in range(101):
  for j in range(101):
    H = ph+abs(px-i)+abs(py-j)
    for l in ls:
      x, y, h = l
      u = max(H - abs(x-i) - abs(y-j), 0)
      if not u==h:
        break
    else:
      ans = (i,j,H)
      flag = True
      break
  if flag:
    break
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
points = 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 = -1
        for point in points:

            if point[2] > 0:
                h = abs(point[0] - cx) + abs(point[1] - cy) + point[2]
                if H == -1:
                    H = h
                elif H != h:
                    H = -2
                    break
            else:
                if H > abs(point[0] - cx) + abs(point[1] - cy) + point[2]:
                    H = -2
                    break
        if H > 0:
            print(cx, cy, h)
            exit()

Submission status: Accepted

Solution code:
#import pysnooper
import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
a=sorted([list(map(int,input().rstrip().split())) for _ in range(n)],key=lambda x:-x[2])
c=a[1:]
x,y,h=a[0]
for cx in range(101):
    for cy in range(101):
        H=h+abs(x-cx)+abs(y-cy)
        for i in c:
            nh=max(0,H-abs(i[0]-cx)-abs(i[1]-cy))
            if nh!=i[2]:
                break
        else:
            print(cx,cy,H)
            exit()

Submission status: Accepted

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

def main():

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

    I = sorted(I, key=lambda x:x[2], reverse=True)
    for cx in range(101):
        for cy in range(101):
            H = -1
            b = True
            for i in I:
                if i[2] > 0:
                    h = abs(i[0]-cx) + abs(i[1]-cy) + i[2]
                    if H == -1:
                        H = h
                    if H != h:
                        b = False
                        break
                else:
                    if abs(i[0]-cx) + abs(i[1]-cy) < H:
                        b = False
                        break
            if b:
                print(cx, cy, H)
                return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]

    kari = [[0 for i in range(101)]for j in range(101)]

    for i in range(num):
        x, y, h = data[i]
        if h > 0:
            ind = i
            break

    x, y, h = data[ind]
    for i in range(101):
        for j in range(101):
            kyori = abs(i - x) + abs(j - y)
            kari[i][j] = h + kyori


    for k in range(num):
        x, y, h = data[k]

        for i in range(101):
            for j in range(101):
                kyori = abs(i - x) + abs(j - y)
                if h == 0:
                    if kari[i][j] <= kyori:
                        pass
                    else:
                        kari[i][j] = -1
                elif h + kyori == kari[i][j]:
                    pass
                else:
                    kari[i][j] = -1

    for i in range(101):
        for j in range(101):
            if kari[i][j] >= 0:
                print(i, j, kari[i][j])




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

n = int(input())
x, y, h = [], [], []
for _ in range(n):
    xi, yi, hi = map(int, input().split())
    if hi != 0:
        x.append(xi)
        y.append(yi)
        h.append(hi)
candidate_cx = list(range(min(x), max(x) + 1))
candidate_cy = list(range(min(y), max(y) + 1))

for cx, cy in list(itertools.product(candidate_cx, candidate_cy)):
    adapted = True
    ch = 0
    for xi, yi, hi in zip(x, y, h):
        ch = max(ch, hi + abs(xi - cx) + abs(yi - cy))
    for xi, yi, hi in zip(x, y, h):
        if hi != ch - abs(xi - cx) - abs(yi - cy):
            adapted = False
            break
    if adapted == False:
        continue
    print(cx, cy, ch, sep = ' ')
    exit(0)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
x, y, h = [], [], []
for _ in range(n):
    xi, yi, hi = map(int, input().split())
    if hi != 0:
        x.append(xi)
        y.append(yi)
        h.append(hi)
candidate_cx = list(range(min(x), max(x) + 1))
candidate_cy = list(range(min(y), max(y) + 1))
candidate_ch = list(range(max(h), max(max(x) - min(x), max(y) - min(y)) + max(h) + 1))

for cx, cy, ch in list(itertools.product(candidate_cx, candidate_cy, candidate_ch)):
    adapted = True
    for xi, yi, hi in zip(x, y, h):
        if hi != ch - abs(xi - cx) - abs(yi - cy):
            adapted = False
            break
    if adapted == False:
        continue
    print(cx, cy, ch, sep = ' ')
    exit(0)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
L=[]
for i in range(n):
    x,y,h=map(int,input().split())
    L.append([x,y,h])
    if h!=0:
        Cx,Cy,Ch=x,y,h
for j in range(101):
    for k in range(101):
        H=Ch+abs(Cx-j)+abs(Cy-k)
        flag=True
        for l in L:
            if l[2]!=max(H-abs(l[0]-j)-abs(l[1]-k),0):
                flag=False
                break
        if flag:
            print(j,k,H)
            exit()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    points = sorted(
        [[int(i) for i in input().split()] for _ in range(n)],
        key=lambda x: x[2],
        reverse=True,
    )
    hoge = 101
    for cx in range(hoge):
        for cy in range(hoge):
            x, y, z = points[0]
            h = z + abs(x - cx) + abs(y - cy)

            if h < 1:
                continue
            if all([z == max(h - abs(x - cx) - abs(y - cy), 0) for x, y, z in points]):
                print(cx, cy, h)
                return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
hxy = []
for _ in range(N):
        x,y,h = map(int,input().split())
        hxy.append([h,x,y])
hxy.sort(reverse=True)
xy = [[x,y] for x in range(101) for y in range(101)]
for i in range(len(hxy) - 1):
        h1,x1,y1 = hxy[i]
        for j in range(i + 1,len(hxy)):
                h2,x2,y2 = hxy[j]
                xy_copy = xy.copy()
                if h1 == 0 and h2 == 0:
                        xy.remove([x1,y1])
                        xy.remove([x2,y2])
                        if len(xy) == 1:
                                x,y = xy[0]
                                print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                                exit()
                        continue
                elif h1 == 0:
                        for x,y in xy_copy:
                                if abs(x - x2) + abs(y - y2) - abs(x - x1) - abs(y - y1) + h2 > 0:
                                        xy.remove([x,y])
                        if len(xy) == 1:
                                x,y = xy[0]
                                print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                                exit()
                        continue
                elif h2 == 0:
                        for x,y in xy_copy:
                                if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2)  + h1 > 0:
                                        xy.remove([x,y])
                        if len(xy) == 1:
                                x,y = xy[0]
                                print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                                exit()
                        continue
                

                for x,y in xy_copy:
                        if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2) != h2 - h1:
                                xy.remove([x,y])
                if len(xy) == 1:
                        x,y = xy[0]
                        print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                        exit()

Submission status: Accepted

Solution code:
import sys

n = int(input())
data = [tuple(map(int, input().split())) for i in range(n)]

for _x, _y, _h in data:
    if _h != 0:
        break

for x in range(101):
    for y in range(101):
        h = _h + abs(_x-x) + abs(_y-y)
        for tmp_x, tmp_y, tmp_h in data:
            if tmp_h != max(h - abs(tmp_x-x) - abs(tmp_y-y), 0):
                break
        else:
            print(x, y, h)
            sys.exit(0)

Submission status: Accepted

Solution code:
import sys

n = int(input())
data = [tuple(map(int, input().split())) for i in range(n)]

for d in data:
    if d[2] != 0:
        _x = d[0]
        _y = d[1]
        _h = d[2]

for x in range(101):
    for y in range(101):
        h = _h + abs(_x-x) + abs(_y-y)
        for d in data:
            tmp_x = d[0]
            tmp_y = d[1]
            tmp_h = d[2]
            if tmp_h != max(h - abs(tmp_x-x) - abs(tmp_y-y), 0):
                break
        else:
            print(x, y, h)
            sys.exit(0)

Submission status: Accepted

Solution code:
n = int(input())
data = [list(map(int,input().split())) for _ in range(n)]
data.sort(key=lambda x:x[2],reverse=True)
for cx in range(101):
    for cy in range(101):
        hq = data[0][2] + abs(data[0][0]-cx) + abs(data[0][1]-cy)
        t = True
        for i in range(1,n):
            if data[i][2] != max(0, hq-abs(data[i][0]-cx)-abs(data[i][1]-cy)):
                t = False
                break
        if t:
            print(cx,cy,hq)
            exit()

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])

# print(xyh)

for x in range(101):
  for y in range(101):
    flg = True
    for i in range(N):
      if i == 0:
        ansh = xyh[i][2] + (abs(xyh[i][0] - x) + abs(xyh[i][1] - y))
      else:
        kouhoh = xyh[i][2] + (abs(xyh[i][0] - x) + abs(xyh[i][1] - y))
        if xyh[i][2] == 0:
          if ansh > kouhoh:
            flg = False
            break
        else:    
          if ansh != kouhoh:
            flg = False
            break
    if flg:
      print(x, y, ansh)
      exit()

Submission status: Accepted

Solution code:
def solve(xyhs):
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            cand = None
            for x, y, h in filter(lambda xyh: xyh[2] != 0, xyhs):
                t = h + abs(x - cx) + abs(y - cy)
                if cand is None:
                    cand = t
                elif cand != t:
                    break
            else:
                for x, y, h in filter(lambda xyh: xyh[2] == 0, xyhs):
                    if abs(x - cx) + abs(y - cy) < cand:
                        break
                else:
                    return cx, cy, cand

    return -1, -1, -1


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

print(*solve(xyhs))

Submission status: Accepted

Solution code:
def solve(xyhs):
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            cand = None
            for x, y, h in filter(lambda xyh: xyh[2] > 0, xyhs):
                t = h + abs(x - cx) + abs(y - cy)
                if cand is None:
                    cand = t
                elif cand != t:
                    break
            else:
                for x, y, h in filter(lambda xyh: xyh[2] == 0, xyhs):
                    if abs(x - cx) + abs(y - cy) < cand:
                        break
                else:
                    return cx, cy, cand

    return -1, -1, -1


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

print(*solve(xyhs))

Submission status: Accepted

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

cands = []
for cx in range(100 + 1):
    for cy in range(100 + 1):
        cand = None
        for x, y, h in filter(lambda xyh: xyh[2] > 0, xyhs):
            t = h + abs(x - cx) + abs(y - cy)
            if cand is None:
                cand = t
            elif cand != t:
                break
        else:
            cands.append((cx, cy, cand))

ans = None
for cx, cy, cand in cands:
    for x, y, h in filter(lambda xyh: xyh[2] == 0, xyhs):
        if abs(x - cx) + abs(y - cy) < cand:
            break
    else:
        ans = cx, cy, cand
        break

print(*ans)

Submission status: Accepted

Solution code:
N = int(input())

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

info.sort(reverse=True)

for c_x in range(101):
    for c_y in range(101):
        H = info[0][0] + abs(info[0][1] - c_x) + abs(info[0][2] - c_y)
        flag = True
        for i in range(1, N):
            if info[i][0] != max(H - abs(info[i][1] - c_x) - abs(info[i][2] - c_y), 0):
                flag = False
                break

        if flag:
            print(*[c_x, c_y, H])
            exit()

Submission status: Accepted

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

def main():
    for cx in range(101):
        for cy in range(101):
            for xi, yi, hi in info:
                if hi > 0:
                    h = abs(xi - cx) + abs(yi - cy) + hi
                    break

            success = True
            for xi, yi, hi in info:
                if hi != max(h - abs(xi - cx) - abs(yi - cy), 0):
                    success = False
                    break

            if success:
                print(cx, cy, h)
                return

main()

Submission status: Accepted

Solution code:
l=[];A=abs;r=range(101)
for _ in range(int(input())):
	*t,=map(int,input().split())
	l+=[t]
	if t[2]:a,b,c=t
for i in r:
	for j in r:
		H=c+A(i-a)+A(j-b)
		if all(h==max(0,H-A(i-x)-A(j-y))for x,y,h in l):
			print(i,j,H)

Submission status: Accepted

Solution code:
a=int(input())
b=[list(map(int,input().split())) for i in range(a)]
from operator import itemgetter
b.sort(key=itemgetter(2),reverse=True)
ans=[0,0,0]
for i in range(101):
  for j in range(101):
    h=abs(i-b[0][0])+abs(j-b[0][1])+b[0][2]      
    n=1
    while n<a:
      if max(h-abs(i-b[n][0])-abs(j-b[n][1]),0)==b[n][2]:
         n+=1
      else:
        break
    if n==a:
      ans=[i,j,h]
      print(*ans)
      exit()

Submission status: Accepted

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

l = [[l[i][2], l[i][0], l[i][1]] for i in range(n)]
l.sort(reverse=True)

for x in range(101):
    for y in range(101):
        h = l[0][0] + abs(x-l[0][1]) + abs(y-l[0][2])
        for i in range(1, n):
            if l[i][0] != max(h-abs(x-l[i][1])-abs(y-l[i][2]), 0):
                break
        else:
            print(str(x) + " " + str(y) + " " + str(h))
            exit()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

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

#ヒントの中で最大のhとその座標
x,y,h = l[-1]

#Cx,Cyの可能性を全通り試す
for i in range(101):
    for j in range(101):
        H = h + abs(i-x) + abs(j-y)
        for k in range(N-1):
            x_1,y_1,h_1 = l[k]
            H2 = max(H - abs(i-x_1) - abs(j-y_1),0)
            if not H2==h_1:
                break
        else:
            print(i,j,H)
            exit()

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)

before = 0
cnt = 0

for cx in range(101):
    for cy in range(101):
        for x,y,h in xyh:
            if cnt ==0:
                height = abs(cx-x)+abs(cy-y)+h
            
            if h != max(height-abs(cx-x)-abs(cy-y), 0):
                cnt = 0
                break

            cnt += 1
            if cnt == n:
                print(cx,cy,height)
                exit()

Submission status: Accepted

Solution code:
n = int(input());_h=0
li = []
for _ in range(n):
	x,y,h = map(int,input().split())
	li.append((x,y,h))
	if not _h:
		_x,_y,_h = x,y,h
for i in range(101):
	for j in range(101):
		H = _h + abs(i-_x) + abs(j-_y)
		if all(h==max(0,H-abs(i-x)-abs(j-y)) for (x,y,h) in li):
			print(i,j,H)
			exit()
		else:
			pass

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    L = [tuple(map(int, input().split())) for _ in range(N)]
    xx, yy, hh = next(l for l in L if l[2] >= 1)
    for Cx in range(101):
        for Cy in range(101):
            H = hh + abs(xx - Cx) + abs(yy - Cy)
            for x, y, h in L:
                if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
                    break
            else:
                print(Cx, Cy, H)
                quit()

main()