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 = []
for i in range(N):
    xyh.append(list(map(int, input().split())))

#
#すべての条件についてある入力からhを求める
#そのhについて、その他の条件をすべて満たせればOK
ans_x, ans_y, ans_h = -1,-1,-1
indexes = [i for i, x in enumerate(xyh) if x[2] > 0]

for cx in range(101):
    for cy in range(101):
        H = xyh[indexes[-1]][2] + abs(xyh[indexes[-1]][0] - cx) + abs(xyh[indexes[-1]][1] - cy)
        match = 1
        for i in range(N):
            h = H - abs(xyh[i][0] - cx) - abs(xyh[i][1] - cy)
            if xyh[i][2] > 0 and (h != xyh[i][2]):
                match = 0
            if xyh[i][2] == 0 and (H > (abs(xyh[i][0] - cx) + abs(xyh[i][1] - cy)) ):
                match = 0
        
        if match:
            ans_x = cx
            ans_y = cy
            ans_h = H
            
print(str(ans_x) + ' ' + str(ans_y) + ' ' + str(ans_h))

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]

    pos = [f() for i in range(n)]

    notz = 0
    for i in range(n):
        if pos[i][2]!=0:
            notz = i
            break


    for i in range(101):
        for j in range(101):
            d1 = abs(pos[notz][0] - i) + abs(pos[notz][1] - j)
            h = d1 + pos[notz][2]

            ok = True
            for k in range(n):
                if max(0,h - abs(pos[k][0] - i) - abs(pos[k][1] - j)) != pos[k][2]:
                    ok = False
                    break

            if ok:
                print(i,j,h)
                return




solve()

Submission status: Accepted

Solution code:
import sys

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

answer = (-1, -1, -1)
for cx in range(101):
    for cy in range(101):
        candidate = -1
        counter = 0
        for i in info:
            if i[2] != 0:
                H = i[2] + abs(i[0] - cx) + abs(i[1] - cy)
                counter += 1
                if candidate == -1:
                    candidate = H
                elif candidate != H:
                    candidate = -1
                    break
        if counter == 1:
            for i in info:
                if i[2] == 1:
                    answer = (i[0], i[1], i[2])
            break        
        elif candidate > 0:
            answer = (cx, cy, candidate)
            break
    if answer[2] > 0:
        break


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

Submission status: Accepted

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

for H in range(XYH[0][2],XYH[0][2]+110):
    for Cx in range(101):
        for Cy in range(101):
            if all(h==max(H-abs(x-Cx)-abs(y-Cy),0) for x,y,h in XYH):
                a=H;b=Cx;c=Cy
                break
print(b,c,a)

Submission status: Accepted

Solution code:
N = int(input())
x,y,h = [],[],[]
for i in range(N):
    X,Y,H = map(int,input().split())
    x += [X]
    y += [Y]
    h += [H]
a = 0
while h[a] == 0:
    a += 1 
    if a == N:
        for i in range(101):
            if i not in x:  X = i
        for i in range(101):
            if i not in y:  Y = i
        print(X,Y,1)
        exit()

for cx in range(101):
    for cy in range(101):
        H = h[a] + abs(x[a]-cx) + abs(y[a]-cy)
        ans = True
        R = list(range(N))[0:a] + list(range(N))[a+1:N]
        for i in R:
            if h[i] != max(H - abs(x[i]-cx) - abs(y[i]-cy),0):
                ans = False
                break
        if ans:
            print(cx,cy,H)
            break
    else:
        continue
    break

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
h = []
key = 0
for i in range(N):
    tmp = [int(i) for i in input().split()]
    if tmp[2] != 0:
        key = i
    x.append(tmp[0])
    y.append(tmp[1])
    h.append(tmp[2])

for Cx in range(100 + 1):
    for Cy in range(100 + 1):
        correct_flag = True
        H = abs(x[key] - Cx) + abs(y[key] - Cy) + h[key]
        for i in range(N):
            if h[i] == 0:
                if abs(x[i] - Cx) + abs(y[i] - Cy) < H:
                    correct_flag = False
                    break
            else:
                if abs(x[i] - Cx) + abs(y[i] - Cy) + h[i] != H:
                    correct_flag = False
                    break
        if correct_flag:
            print(Cx, Cy, H)
            break

Submission status: Accepted

Solution code:
def just_fit(xyh, x, y, h):
    for p in xyh:
        if max(h - abs(p[0] - x) - abs(p[1] - y), 0) == p[2]:
            pass
        else:
            return False
    return True

N = int(input())

xyh = []
highest_h = 0
for i in range(N):
    tmp = list(map(int, input().split()))
    xyh.append(tmp)
    if tmp[2] > highest_h:
        highest_h = tmp[2]

ans_x, ans_y, ans_z = -1, -1, -1
flug = 0
for highPlus in range(101):
    for x in range(101):
        for y in range(101):
            if just_fit(xyh, x, y, highest_h + highPlus):
                ans_x, ans_y, ans_z = x, y, highest_h + highPlus
                flug = 1
                break
        if flug == 1:
            break
    if flug == 1:
        break

print(ans_x, ans_y, ans_z)

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

for cx in range(101):
    for cy in range(101):
        ch = None
        for x, y, h in xyh:
            t = h + abs(cx - x) + abs(cy - y)
            if h > 0:
                if ch is not None and t != ch:
                    break
                ch = t
            else:
                if t < ch:
                    break
        else:
            print(cx, cy, ch)
            exit()

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
X.sort(key=lambda x: x[2])
a, b, c = X[-1]

for px in range(101):
    for py in range(101):
        H = abs(a - px) + abs(b - py) + c
        for k in range(N):
            if X[k][2] != max(H - abs(X[k][0] - px) - abs(X[k][1] - py), 0):
                break
            if k == N - 1:
                print(px, py, H)

Submission status: Accepted

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

for px in range(101):
    for py in range(101):
      H = abs(a - px) + abs(b - py) + c
      if all(h == max(H - abs(x - px) - abs(y - py), 0) for x, y, h in X):
        print(px, py, H)
        break

Submission status: Accepted

Solution code:
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
C_x = list(range(101))
C_y = list(range(101))
 
if sum([h for _, _, h in X]) == 1:
  for x, y, h in X:
    if h != 0:
      print(x, y, h)
else:
  for px in C_x:
    for py in C_y:
      h_list = [abs(x - px) + abs(y - py) + h for x, y, h in X if h > 0]
      if len(set(h_list)) == 1:
        print(px, py, h_list[0])
        break

Submission status: Accepted

Solution code:
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
C_x = list(range(101))
C_y = list(range(101))

if sum([h for _, _, h in X]) == 1:
  for x, y, h in X:
    if h != 0:
      print(x, y, h)
else:
  for px in C_x:
    for py in C_y:
      h_list = [abs(x - px) + abs(y - py) + h for x, y, h in X if h > 0]
      if len(set(h_list)) == 1:
        print(px, py, h_list[0])
        break

Submission status: Accepted

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

def judge(Cx,Cy):
    for x, y, h in info:
        if h != 0:
            H = abs(x-Cx) + abs(y-Cy) + h
            break
    for x, y, h in info:
        if max(H-abs(x-Cx)-abs(y-Cy),0) != h:
            return
    global ans
    ans = [Cx,Cy,H]
    
for Cx in range(101):
    for Cy in range(101):
        judge(Cx,Cy)

print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
symb = None
hints = []

for _ in range(N):
  hint = tuple(map(int, input().split()))
  if symb is None and hint[2]!=0:
    symb = hint
  else:
    hints.append(hint)


Hs = dict()
for i in range(0, 101):
  flag = False
  for j in range(0, 101):
    cand = symb[2] + abs(i-symb[0]) + abs(j-symb[1])
    contradict = False
    for x, y, h in hints:
      if max(cand - abs(x-i) - abs(y-j), 0) != h:
        contradict = True
        break
    if not contradict:
      flag = True
      print(i, j, cand)
      break
  if flag:
    break

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
Ct = [i for i in range(101)]
Cli = list(product(Ct,Ct))
XY = []
sx,sy,sh = 0,0,0
for i in range(n):
    x,y,h = map(int,input().split())
    XY.append([x,y,h])
    if h != 0: sx,sy,sh = x,y,h
for (cx,cy) in Cli:
    #cx,cyが候補。XYが実測値のリスト
    ht = sh + abs(sx-cx) + abs(sy-cy)
#    print(cx,cy,"ht=",ht)
    for i in XY:
        ht2 = max(ht-abs(i[0]-cx)-abs(i[1]-cy),0)
#        print(i[0],i[1],i[2],"ht2=",ht2,"と比較中")
        if ht2 != i[2]: break
    else:
        print(cx, cy, ht)
        break

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

flag = True

N = int(input())
pos = [0]*N
for i in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        flag = False
    pos[i] = (h, x, y)

pos = list(reversed(sorted(pos)))

def dist(p1, p2):
    (x1, y1) = p1
    (x2, y2) = p2
    return abs(x1-x2) + abs(y1-y2)

if flag:
    # dp = makelist(101, 101)
    # for (_, x, y) in pos:
    ()
else:
    for y in range(101):
        for x in range(101):
            (h1, x1, y1) = pos[0]
            H = dist((x, y), (x1, y1)) + h1

            flag = True
            for (h1, x1, y1) in pos[1:]:
                if h1 == 0:
                    if H - dist((x, y), (x1, y1)) > 0:
                        flag = False
                        break
                else:
                    if dist((x, y), (x1, y1)) + h1 != H:
                        flag = False
                        break
            if flag:
                print(" ".join(map(str, [x, y, H])))
                break

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 i in range(0,101):
    for j in range(0,101):
        for n, hn in enumerate(h):
            if hn > 0:
                tmph = hn + abs(i-x[n]) + abs(j-y[n])
                break
        count = 0
        for n in range(N):
            count += 1
            if h[n] != max(tmph - abs(i-x[n]) - abs(j-y[n]), 0):
                break
            if count == N:
                print(str(i) + ' ' + str(j) + ' ' + str(tmph))

Submission status: Accepted

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

for i in range(0, 101):
    for j in range(0, 101):
        H = -1
        check = 0
        zero_height = []
        for k in cordinate:
            if k[2] == 0:
                zero_height.append(k)
                continue
            if H == -1:
                check = 1
                H = k[2] + abs(k[0] - i) + abs(k[1] - j)
            else:
                tmp = k[2] + abs(k[0] - i) + abs(k[1] - j)
                if H == tmp:
                    check = 1
                    continue
                else:
                    check = -1
                    break
        if check == 1:
            for x in zero_height:
                if H > abs(x[0] - i) + abs(x[1] - j):
                    check = -1
                    break
            if check == 1:
                print(i, j , H)
                exit()

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 c_x in range(101):
    for c_y in range(101):
        thres = 10**10
        H = []
        for i in range(N):
            if h[i] > 0:
                H.append(h[i] + abs(x[i] - c_x) + abs(y[i] - c_y))
            elif thres > abs(x[i] - c_x) + abs(y[i] - c_y):
                thres = abs(x[i] - c_x) + abs(y[i] - c_y)

        if len(set(H)) == 1 and 0 < H[0] <= thres:
            print(str(c_x) + " " + str(c_y) + " " + str(H[0]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Pyramid
https://atcoder.jp/contests/abc112/tasks/abc112_c

"""
import sys


def solve(N, positions):
    if N == 1:
        return positions[0]
    positions.sort(key=lambda x:x[2])
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[-1]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[:-1]:
                hh = max(ph - abs(cy-y) - abs(cx-x), 0)
                if hh != h:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)

def main(args):
    N = int(input())
    positions = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, positions)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Pyramid
https://atcoder.jp/contests/abc112/tasks/abc112_c

"""
import sys


def solve(N, positions):
    if N == 1:
        return positions[0]
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[0]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[1:]:
                hh = max(ph - abs(cy-y) - abs(cx-x), 0)
                if hh != h:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[-1]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[:-1]:
                hh = max(ph - abs(cy-y) - abs(cx-x), 0)
                if hh != h:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)


def main(args):
    N = int(input())
    positions = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, positions)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
import itertools
N=int(input())
l=[]
#l:調査情報のリスト
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
M=max(item[2] for item in l)#高さの最大値(暫定)
s=list(itertools.product(range(0,101),repeat=2))
#s:中心座標の候補リスト
for A,B in itertools.combinations(range(N),2):
  #調査情報の全ての2つ組を用いて絞り込む
  if len(s)==1:
    break
  t=[]
  #t:新たな中心座標の候補リスト
  if l[A][2]<l[B][2]:
    A,B=B,A
  if l[A][2]>l[B][2]:
    #2地点の高さが異なる場合
    if l[B][2]==0:
      #B地点の高さが0ならB地点は中心から[Aの高さ]以上離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap<=abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
    else:
      #B地点の高さが0でなければA地点は中心から[Aの高さ-Bの高さ]だけ離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap==abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
  
  elif l[A][2]!=0:
    #2地点の高さが等しく0ではない場合
    #2地点からM-[Aの高さ]以上離れた地点のみ残す
    for X,Y in s:
      MM=max(1,M-l[A][2])
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]) and abs(X-l[A][0])+abs(Y-l[A][1])>=MM and abs(X-l[B][0])+abs(Y-l[B][1])>=MM:
        t.append((X,Y))
  else:
    #2地点の高さが等しく0の場合
    #2地点からM以上離れた地点のみ残す
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>=M and abs(X-l[B][0])+abs(Y-l[B][1])>=M:
        t.append((X,Y))
  s=t[:]
#sの要素は唯一だと思いたい
a,b=s[0][0],s[0][1]
i=0
while l[i][2]==0:
  i+=1

h=abs(a-l[i][0])+abs(b-l[i][1])+l[i][2]
print(a,b,h)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

XY = np.zeros((2, N))
H = np.zeros(N)
x_s, y_s, h_s = 0, 0, 0

# input
for i in range(N):
    x_tmp, y_tmp, h_tmp = map(int, input().split())

    if h_tmp > 0:
        x_s, y_s, h_s = x_tmp, y_tmp, h_tmp
    XY[:, i] = x_tmp, y_tmp
    H[i] = h_tmp

is_break = False
for c_x in range(0, 101):
    for c_y in range(0, 101):
        h_tmp = h_s + abs(x_s - c_x) + abs(y_s - c_y)
        xy = XY.copy()
        h = H.copy()
        h_tmp2 = xy - np.array([[c_x], [c_y]])
        h_tmp2 = h_tmp - np.abs(h_tmp2).sum(axis=0)
        h_tmp2 = np.clip(h_tmp2, 0, None)
        if (h == h_tmp2).all():
            print(c_x, c_y, h_tmp)
            is_break = True
            break
    if is_break:
        break

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)
tmp = max(H)
for cx in range(101):
  for cy in range(101):
    for i, h in enumerate(H):
      if h != 0:
        ch = abs(cx - X[i]) + abs(cy - Y[i]) + H[i]
        break
    for i in range(N):
      if H[i] != max(ch - abs(cx - X[i]) - abs(cy - Y[i]), 0):
        break
    else:
      print(cx, cy, ch)

Submission status: Accepted

Solution code:
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())
 
def main():
    sols = []
    for _ in range(GI()):
        x, y, h = LGIS()
        if h:
            sols.append((x, y, h))
 
    if len(sols) == 1:
        print(*sols[0])
        return
 
    for cx in range(0, 101):
        for cy in range(0, 101):
            lastH = None
            for x, y, h in sols:
                H = h + abs(x - cx) + abs(y - cy)
#                if H < 1:
#                    continue
                if lastH:
                    if H != lastH:
                        break
                lastH = H
            else:
                print(cx, cy, H)
                return
 
main()

Submission status: Accepted

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

n = int(input())
li = [list(map(int, input().split())) for i in range(n)]
li.sort(key=lambda x: x[2])
a, b, c = li[-1]
for x in range(101):
    for y in range(101):
        h = abs(x-a) + abs(y-b) + c
        if all(k == max(h-abs(x-i)-abs(y-j), 0) for i, j, k in li):
            print(x, y, h)
            exit()

Submission status: Accepted

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for x in range(n)]
l=[i for i in range(1,201)]
for i in range(101):
  for j in range(101):
    tmp1=set()
    tmp2=10**5
    for k in range(n):
      if arr[k][2]!=0:
        tmp1.add(arr[k][2]+abs(arr[k][0]-i)+abs(arr[k][1]-j))
      else:
        if abs(arr[k][0]-i)+abs(arr[k][1]-j)<tmp2:
          tmp2=abs(arr[k][0]-i)+abs(arr[k][1]-j)
    if tmp2==10**5:
      if len(list(tmp1))==1:
        print(i,j,list(tmp1)[0])
    else:
      if len(list(tmp1))==1 and len(list(tmp1&set(l[:tmp2])))==1:
        print(i,j,list(tmp1)[0])

Submission status: Accepted

Solution code:
n=int(input())
XYH=[]
for i in range(n):
  x,y,h=map(int,input().split())
  XYH.append([x,y,h])
XYH.sort(key=lambda x:x[2])
for i in range(101):
  for j in range(101):
    peak=abs(i-XYH[-1][0])+abs(j-XYH[-1][1])+XYH[-1][2]
    flag=1
    for k in range(n-1):
      if max(0,peak-abs(i-XYH[k][0])-abs(j-XYH[k][1]))!=XYH[k][2]:
        flag=0
    if flag==1:
      Ans=[i,j,peak]
print(*Ans)

Submission status: Accepted

Solution code:
N = int(input())
x,y,h = [],[],[]
for i in range(N):
    i1,i2,i3 = map(int,input().split())
    x.append(i1)
    y.append(i2)
    h.append(i3)
    if i3 != 0:
        tmp = i

for i in range(101):
    for j in range(101):
        H = h[tmp] + abs(i-x[tmp]) + abs(j-y[tmp])
        flg = True
        for n in range(N):
            if h[n] != max(H - abs(i-x[n]) - abs(j-y[n]),0):
                flg = False
                break
        if flg == True:
            print(i,j,H)

Submission status: Accepted

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

for x in range(101):
    for y in range(101):
        for n in range(N):
            if hs[n] > 0:
                h = hs[n] + abs(x - xs[n]) + abs(y - ys[n])
                break
        flg = True        
        for n in range(N):
            if hs[n] != max(0, h - abs(x - xs[n]) - abs(y - ys[n])):
                flg = False
                break
        if flg:
            print("{0} {1} {2}".format(x, y, h))

Submission status: Accepted

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

li.sort(key=lambda x: x[2])
a,b,c = li[-1]
for x in range(101):
    for y in range(101):
        h = abs(x-a) + abs(y-b) + c
        if all(k == max(h-abs(x-i)-abs(y-j),0) for i,j,k in li):
            print(x,y,h)
            exit()

Submission status: Accepted

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

X,Y=-1,-1
for x in range(101):
  for y in range(101):
    flag = True
    _h = -1
    for i,j,h in li:
      kyo = abs(i-x)+abs(j-y)
      if (h>0):
        if (_h==-1):
          _h = kyo + h
        else:
          if (_h!=kyo+h):
            flag=False
            break
      else: #h==0
        if (_h>kyo):
          flag=False
          break
    for i,j,h in li:
      kyo = abs(i-x)+abs(j-y)
      if (h>0):
        if (_h==-1):
          _h = kyo + h
        else:
          if (_h!=kyo+h):
            flag=False
            break
      else: #h==0
        if (_h>kyo):
          flag=False
          break
    if (flag):
      X = x
      break
  if (flag):
    Y = y
    break
print (X,Y,_h)

Submission status: Accepted

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


for x in range(101):
    for y in range(101):
        h = -1
        for k in xyh:
            if k[2] != 0:
                if h == -1:    
                    h = abs(k[2] + abs(k[0]-x) + abs(k[1]-y))
                elif h != abs(k[2] + abs(k[0]-x) + abs(k[1]-y)):
                    h = -2
                    break
        for k in xyh:
            if k[2] == 0:   
                tmp = abs(k[0]-x) + abs(k[1]-y)
                if h > tmp:
                    h = -2
                    break
        if h > 0:
            print(x,y,h)

Submission status: Accepted

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

xyhs = sorted(xyhs, key=lambda v: v[2], reverse=True)

anss = []
for y in range(101):
    for x in range(101):
        x0, y0, h0 = xyhs[0]
        ht = h0 + abs(x0 - x) + abs(y0 - y)

        flag = True
        for xyh in xyhs[1:]:
            xi, yi, hi = xyh
            his = max(ht - abs(xi - x) - abs(yi - y), 0)
            if his != hi:
                flag = False
                break

        if flag:
            anss.append((x, y, ht))

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

Submission status: Accepted

Solution code:
N = int(input())
IN = [list(map(int, input().split())) for i in range(N)]
# 計算に使う高さが0だと死ぬ
index = min([i for i in range(N) if IN[i][2] > 0])
for i in range(101):
  for j in range(101):
    temp_h = abs(IN[index][0]-i) + abs(IN[index][1]-j) + IN[index][2]
    check = True
    for test in IN:
      calc_h = max([temp_h - abs(test[0]-i) - abs(test[1]-j), 0])
      if calc_h != test[2]:
        check = False
        break
    if check:
      print(i, j, temp_h)
      exit()

Submission status: Accepted

Solution code:
import itertools as its

N = int(input())
P = []
on_piramid = None
for _ in range(N):
    p = tuple(map(int, input().split()))
    P.append(p)
    if on_piramid == None and p[2] >= 1:
        on_piramid = p

for x, y in its.product(range(101), range(101)):
    h = on_piramid[2] + abs(x-on_piramid[0]) + abs(y-on_piramid[1])
    for i in range(N):
        if P[i][2] != max(h - abs(x - P[i][0]) - abs(y - P[i][1]), 0):
            break
    else:
        print(x, y, h)
        exit()

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 i in range(N):
    if h[i] != 0:
        target = i
        break

for i in range(101):
    for j in range(101):
        CX = i
        CY = j
        H = h[target] + abs(x[target]-CX) + abs(y[target]-CY)
        find = True
        for k in range(N):
            if max((H-abs(x[k]-CX)-abs(y[k]-CY)), 0) != h[k]:
                find = False
                break
        if find:
            break
    if find:
        break

print(CX, CY, H)

Submission status: Accepted

Solution code:
N = int(input())
data_plus = []
data_minus = []
for i in range(N):
  datum = list(map(int, input().split()))
  if datum[2] > 0:
    data_plus.append(datum) 
  else:
    data_minus.append(datum)

finish = 0
for cx in range(101):
  for cy in range(101):
    ok = 1
    for i in range(1,len(data_plus)):
      if (abs(cx - data_plus[i][0]) - abs(cx - data_plus[0][0]) 
          + abs(cy - data_plus[i][1]) - abs(cy - data_plus[0][1])
          != data_plus[0][2] - data_plus[i][2]):
        ok = 0
        break
    if ok:
      ok2 = 1
      H = abs(cx - data_plus[0][0]) + abs(cy - data_plus[0][1]) + data_plus[0][2]
      for i in range(len(data_minus)):
        if H - abs(cx - data_minus[i][0]) - abs(cy - data_minus[i][1]) > 0:
          ok2 = 0
      if ok2:
        print(cx, cy, H)
        finish = 1
    if finish == 1:
      break
  if finish == 1:
    break

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    if xyh[i][2]>0:
        tx,ty,th=xyh.pop(i)
        break
for cx in range(101):
    for cy in range(101):
        H=th+abs(tx-cx)+abs(ty-cy)
        for x,y,h in xyh:
            if h==0 and H-abs(x-cx)-abs(y-cy)<=0: continue
            if H!=h+abs(x-cx)+abs(y-cy): break
        else:
            print(cx,cy,H)
            exit()

Submission status: Accepted

Solution code:
n = int(input())
x,y,h = [],[],[]
idx = 0
for i in range(n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    h.append(c)
    if c != 0:
        idx = i

for cx in range(101):
    for cy in range(101):
        # h[idx] = H - abs(x[idx]-cx) - abs(y[idx]-cy)
        H = h[idx] + abs(x[idx]-cx) + abs(y[idx]-cy)

        ok = True
        for i in range(n):
            if h[i] != max(H - abs(x[i]-cx) - abs(y[i]-cy), 0):
                ok = False
        if ok:
            print(cx,cy,H)

Submission status: Accepted

Solution code:
N  = int(input())
a = []
l = 0
for i in range(N):
    x,y,H = map(int,input().split())
    a.append([x,y,H])
for t in range(N):
    if a[t][2] != 0:
        break
for i in range(101):
    for j in range(101):
        l = a[t][2] + abs(a[t][0]-i)+abs(a[t][1]-j)
        for k in range(N):
            if a[k][2]!=max(0,l-abs(i-a[k][0])-abs(j-a[k][1])):
                break
            elif k == N-1:
                print(str(i)+' '+str(j)+ ' '+str(l))
                exit()

Submission status: Accepted

Solution code:
n = int(input())
inf = [list(map(int, input().split())) for i in range(n)]
inf = sorted(inf, key=lambda x : x[2])
x, y , h = inf[-1]
for cx in range(100, -1, -1):
    for cy in range(100, -1, -1):
        H = h + abs(cx - x) + abs(cy - y)
        if H < 1:
            continue
        for x1, y1, h1 in inf:
            if not h1 == max(H - abs(cx - x1) - abs(cy - y1), 0):
                break
        else:
            print(cx, cy, H, sep=' ')
            exit()

Submission status: Accepted

Solution code:
import sys
N = int(input())

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

#print (lst)

#中心座標(px, py)
for px in range(101):
    for py in range(101):
#        print ('px, py ', px, py)
        j = 0
        while lst[j][2] == 0:
            j += 1
        h = lst[j][2] + abs(px-lst[j][0]) + abs(py -lst[j][1])
#        print ('j, h ', j, h)
        k = 0
        while k < N:
            if lst[k][2] == max(h - abs(px-lst[k][0]) - abs(py -lst[k][1]), 0):
                k += 1
#                print ('A')
            else:
#                print ('B')
                k = 10 ** 9
        if k == N:
            print (px, py, h)
            sys.exit()
        else:
            pass
#            print ('C')

Submission status: Accepted

Solution code:
a=int(input())
if a==1:
    print(input())
else:
    b=[]
    k=l=0
    for i in range(a):
        x,y,h=map(int,input().split())
        b.append([x,y,h])
    for k in range(a):
        if b[k][2] != 0: break
    for i in range(101):
        for j in range(101):
            l=b[k][2]+abs(b[k][0]-i)+abs(b[k][1]-j)
            for I in range(a):
                if b[I][2]!=max(0,l-abs(i-b[I][0])-abs(j-b[I][1])):
                    break
                elif I==a-1:
                    print(str(i)+" "+str(j)+" "+str(l))
                    exit()