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:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
X = []
Y = []
H = []
ans = ()
for i in range(n):
    x, y, h = LI()
    if h:
        r = i
    X += [x]
    Y += [y]
    H += [h]




for cx in range(101):
    for cy in range(101):
        x0, y0, h0 = X[r], Y[r], H[r]
        h = h0 + abs(cx - x0) + abs(cy - y0)
        for i in range(n):
            if H[i] != max(h - abs(cx - X[i]) - abs(cy - Y[i]), 0):
                break
        else:
            print(cx, cy, h)
            exit()

Submission status: Accepted

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

# 高度が0ではない任意の点を1つ定める
sx, sy, sh = sorted(xyh, key=lambda x: x[-1])[-1]

# 全探索
for cx in range(101):
    for cy in range(101):
        H = abs(sx - cx) + abs(sy - cy) + sh
        for x, y, h in xyh:            
            if max(H - abs(x - cx) - abs(y - cy), 0) != h:
                break
        else:
            ans = cx, cy, H
print(*ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())
point = [[int(i) for i in input().split()] for _ in range(N)]
point.sort(key=lambda x:x[2],reverse=True)
#print(point)
for cx in range(101):
    for cy in range(101):
        H = point[0][2]+abs(cx-point[0][0])+abs(cy-point[0][1])
        OK = True
        for i in range(N):
            if not point[i][2]==max(H-abs(cx-point[i][0])-abs(cy-point[i][1]),0):
                OK = False
                break
        if OK:
            print(cx,cy,H)
            sys.exit(0)

Submission status: Accepted

Solution code:
def check_h(x, y, xy_):
    difference_h = abs(x-xy_[0]) + abs(y-xy_[1])
    return difference_h

def main():
    n = int(input())
    xyh = [list(map(int, input().split())) for _ in range(n)]
    get_h = [xyh[i][2] for i in range(n)]
    X, Y, H = xyh[get_h.index(max(get_h))]

    for i in range(101):
        for j in range(101):
            xy = [i, j]
            h = H + check_h(X, Y, xy)
            if h >= H:
                if all(xyh[s][2]==max(h-check_h(xyh[s][0], xyh[s][1], xy), 0) for s in range(n)):
                    print(i, j, h)
                    break
    return 0

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def check_h(x, y, xy_):
    difference_h = abs(x-xy_[0]) + abs(y-xy_[1])
    return difference_h

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

    for x_, y_, h_ in xyh:
        if h_ != 0:
            X, Y, H = x_, y_, h_
            break

    for i in range(101):
        for j in range(101):
            xy = [i, j]
            h = H + check_h(X, Y, xy)
            if h >= H:
                if all(xyh[s][2]==max(h-check_h(xyh[s][0], xyh[s][1], xy), 0) for s in range(n)):
                    print(i, j, h)
                    break
    return 0

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
xyh = [list(map(int,input().split())) for _ in range(n)]
#h != 0 であるようなｈをさがし、そのときのx,y.hを変数に保存(このようなｈが少なくとも一つ存在)
for i in range(n):
    if(xyh[i][2]!= 0):
        x = xyh[i][0]
        h = xyh[i][2]
        y = xyh[i][1]
        break
for i in range(101):
    for j in range(101):
        #中心座標を(i,j)で決め打つ
        H = h+ abs(x - i)+abs(y - j)#さっきの(x,y,h)をつかうと、ピラミッドの高さはこうなる
        ok = True#フラグをTrueで初期化、もし条件を満たさないものが一つでもあればダメなので、ok= Falseしてbreak
        #すべての(x,y,h)が条件を満たすものがあれば、それが答え。出力してbreak
        for k in range(n):
            nowx = xyh[k][0]
            nowy = xyh[k][1]
            nowh = xyh[k][2]
            if nowh != max(H - abs(nowx - i) - abs(nowy - j),0):
                ok = False
                break
        if ok :
            print(i,j,H)
            break

Submission status: Accepted

Solution code:
n = int(input())
xyh = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    if(xyh[i][2]!= 0):
        x = xyh[i][0]
        h = xyh[i][2]
        y = xyh[i][1]
        break
for i in range(101):
    for j in range(101):
        H = h+ abs(x - i)+abs(y - j)
        ok = True
        for k in range(n):
            nowx = xyh[k][0]
            nowy = xyh[k][1]
            nowh = xyh[k][2]
            if nowh != max(H - abs(nowx - i) - abs(nowy - j),0):
                ok = False
                break
        if ok :
            print(i,j,H)
            break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def main():
	N = inputInt()
	xyz = []
	for i in range(N):
		x,y,h = inputMap()
		xyz.append((x,y,h))

	for ansY in range(0,101):
		for ansX in range(0,101):
			ansH = -1
			for i,val in enumerate(xyz):
				x,y,h = val
				if h > 0:
					tmp = h + abs(ansX-x) + abs(ansY-y)
					if ansH == -1:
						ansH = tmp
					else:
						if tmp != ansH:
							ansH = -2
							break
			#print(ansH)
			if ansH == -2:
				continue

			for i,val in enumerate(xyz):
				x,y,h = val
				if h == 0:
					tmp = abs(ansX-x) + abs(ansY-y)
					if ansH > tmp:
						ansH = -2
						break
			if ansH == -2:
				continue

			print("{} {} {}".format(ansX,ansY,ansH))


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Accepted

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

def get_H(Cx, Cy):
    for x, y, h in L:
        if h == 0:
            continue
        H = h + abs(x - Cx) + abs(y - Cy)
        if H >= 1:
            return H

def check(Cx, Cy, H):
    for x, y, h in L:
        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(Cx, Cy, H):
            print(Cx, Cy, 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)

for x in range(101):
    for y in range(101):
        ans=True
        H=xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
        for n in range(1,N):
            if H!=xyh[n][2]+abs(x-xyh[n][0])+abs(y-xyh[n][1]) and xyh[n][2]!=0:
                ans=False
                break
        if ans:
            for n in range(1,N):
                if max(H-abs(x-xyh[n][0])-abs(y-xyh[n][1]),0)!=xyh[n][2]:
                    ans=False
                    break
            if ans:
                print(x,y,H)
                exit()

Submission status: Accepted

Solution code:
import sys

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

cx=0
cy=0
H=0
for i in range(0,101):
    for j in range(0,101):
        flag=0
        cx=i
        cy=j
        for k in range(N):
            if h[k]!=0:
                H=h[k]+abs(cx-x[k])+abs(cy-y[k])
                break
        for k in range(N):
            test=max(0,H-abs(cx-x[k])-abs(cy-y[k]))
            if test!=h[k]:
                flag=1
                break
        if flag==0:
            print(cx,cy,H)
            sys.exit()

Submission status: Accepted

Solution code:
def High(cx, cy, x, y, h):
    return h + abs(x-cx) + abs(y-cy)

def high(cx, cy, x, y, High):
    return max(High - abs(x-cx) - abs(y-cy), 0)

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

from operator import itemgetter
l = sorted(l, key=itemgetter(2) , reverse=1)

for i in range(101):
    for j in range(101):
        H = High(l[0][0], l[0][1], i, j, l[0][2])
        for k in l[1:]:
            if high(k[0], k[1], i, j, H) != k[2]:
                break
        else:
            print(i, j, H)
            break

Submission status: Accepted

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

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

for i in range(101):
    for j in range(101):
        h = abs(l[0][0] - i) + abs(l[0][1] - j) + l[0][2]
        if h<=0:
            continue

        ok=True
        for k in range(len(l)):
            tmp_h = max(h - abs(l[k][0] - i) - abs(l[k][1] - j),0)
            if tmp_h != l[k][2]:
                ok=False
                break
        if ok:
            print(i,j,h)
            exit()

Submission status: Accepted

Solution code:
arr = []
n = int(input())

for i in range(n):
    arr.append([int(s) for s in input().split(" ")])



import math

def calculate(n, arr):
    for i in range(101):
        for j in range(101):

            centerH = -100

            for ar in arr:
                posX = ar[0]
                posY = ar[1]
                posH = ar[2]

                if posH > 0:

                    if centerH == -100:
                        centerH = posH + int(math.fabs(i - posX)) + int(math.fabs(j - posY))
                        continue

                    tmp = posH + int(math.fabs(i - posX)) + int(math.fabs(j - posY))

                    if tmp != centerH:
                        centerH = -2
                        break

            for ar in arr:
                posX = ar[0]
                posY = ar[1]
                posH = ar[2]
                if posH == 0:
                    if int(math.fabs(i - posX)) + int(math.fabs(j - posY)) < centerH:
                        centerH = -2
                        break

            if centerH != -2:
                print(i, j, centerH)





calculate(n, arr)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
for x in range(101):
    for y in range(101):
        b = True
        for i in range(N):
            if xyh[i][2] != 0:
                H = abs(xyh[i][0]-x) + abs(xyh[i][1]-y) + xyh[i][2]
                break
        for j in range(N):
            if xyh[j][2] != max(H - abs(xyh[j][0]-x) - abs(xyh[j][1]-y), 0):
                b = False
                break
        if b:
            break
    if b:
        break
print(x,y,H)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
for x in range(101):
    for y in range(101):
        b = True
        H = 1
        for i in range(N):
            if xyh[i][2] != 0:
                H = abs(xyh[i][0]-x) + abs(xyh[i][1]-y) + xyh[i][2]
                break
        for j in range(N):
            if xyh[j][2] != max(H - abs(xyh[j][0]-x) - abs(xyh[j][1]-y), 0):
                b = False
                break
        if b:
            break
    if b:
        break
print(x,y,H)

Submission status: Accepted

Solution code:
import sys
n = int(input())
plot = []
for i in range(n):
    x, y, h = map(int, input().split())
    plot.append([x,y,h])

for cx in range(101):
    for cy in range(101):
        d = set()
        for i in range(n):
            h = 0
            if plot[i][2] > 0:
                h = abs(plot[i][0] - cx) + abs(plot[i][1] - cy) + plot[i][2]
                d.add(h)
        if len(d) == 1:
            flag = True
            for i in range(n):
                H = list(d)[0]
                h = max(H - abs(plot[i][0] - cx) - abs(plot[i][1] - cy), 0)
                if h != plot[i][2]:
                    flag = False
            if flag:
                print(cx,cy,H)
                sys.exit(0)

Submission status: Accepted

Solution code:
N = int(input())
ls = [None]*N
ind = None
for i in range(N):
    ls[i] = tuple(map(int,input().split()))
    if ls[i][2] > 0:
        ind = i
for cx in range(101):
    for cy in range(101):
        flag = True
        x,y,h = ls[ind]
        H = h+abs(x-cx)+abs(y-cy)
        for i in range(N):
            x,y,h = ls[i]
            if h != max(0,H-abs(x-cx)-abs(y-cy)):
                flag = False
                break
        if flag:
            print(cx,cy,H)
            exit(0)

Submission status: Accepted

Solution code:
N = int(input())
X, Y, H = [], [], []
target = (-1, -1, -1)
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    if h >= 1:
        target = (x, y, h)

for cx in range(101):
    for cy in range(101):
        v = target[2] + abs(target[0] - cx) + abs(target[1] - cy)
        v = max(v, 0)
        flag = True
        for x, y, h in zip(X, Y, H):
            vv = v - abs(x - cx) - abs(y - cy)
            vv = max(vv, 0)
            if h != vv:
                flag = False
                break
        if flag:
            print(cx, cy, v)
            exit()

Submission status: Accepted

Solution code:
#112_C
N=int(input())
pyramid=[]
for i in range(N):
    x,y,h=map(int,input().split())
    pyramid.append((x,y,h))
pyramid=sorted(pyramid,key=lambda x:x[2])[::-1]

Ans=[]
#全探索
for cx in range(0,101):
    for cy in range(0,101):
        flg=True
        H=pyramid[0][2]+abs(cx-pyramid[0][0])+abs(cy-pyramid[0][1])
        for i in range(1,N):
            h=max(H-abs(cx-pyramid[i][0])-abs(cy-pyramid[i][1]),0)
            if h!=pyramid[i][2]:
                flg=False
        if flg:
            Ans=[cx,cy,H]
            break
print(*Ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
XYH = np.array([input().split() for _ in range(N)], dtype=np.int64)
x, y, h = XYH[XYH[:, 2] != 0][0].T
X, Y, H = XYH.T

for Cx in range(101):
    for Cy in range(101):
        estimated_heights = h + abs(x - Cx) + abs(y - Cy)
        if (np.clip(estimated_heights - np.abs(X - Cx) - np.abs(Y - Cy), 0, None) == H).all():
            print(Cx, Cy, estimated_heights)
            quit()

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
data=[]
for i in range(n):
    x0,y0,h0=map(int,input().split())
    data.append([h0,x0,y0])
data.sort(reverse=True)
if n==1 or data[1][0]==0:
    print(data[0][1],data[0][2],data[0][0])
else:
    x=0
    y=0
    buf=0
    for cx in range(101):
        buf=0
        for cy in range(101):
            buf=0
            h=data[0][0]+abs(data[0][1]-cx)+abs(data[0][2]-cy)
            for i in range(1,n):
                if data[i][0]==0:
                    break
                else: 
                    h_i=data[i][0]+abs(data[i][1]-cx)+abs(data[i][2]-cy)
                    if h_i!=h:
                        buf=1
                        break
            if buf==0:
                x=cx
                y=cy
                break
        if buf==0:
            break
    print(x,y,h)

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    A=[list(map(int,input().split())) for i in range(n)]
    A.sort(key=lambda x:x[2],reverse=True)
    for cx in range(101):
        for cy in range(101):
            flag=True
            h=abs(A[0][0]-cx)+abs(A[0][1]-cy)+A[0][2]
            for i in range(1,n):
                if A[i][2]>0:
                    if h!=abs(A[i][0]-cx)+abs(A[i][1]-cy)+A[i][2]:
                        flag=False
                        break
                else:
                    if h-abs(A[i][0]-cx)-abs(A[i][1]-cy)>0:
                        flag=False
                        break
            if flag:
                print(cx,cy,h)
                exit()
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []
h = []
I = 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:
        I = i
H = 0
X = Y = 0
flag = 0
cnt = 0
for i in range(101):
    for j in range(101):
        tmp = abs(x[I]-i) + abs(y[I]-j) + h[I]
        for k in range(n):
            if h[k] > 0:
                cnt += 1
                if tmp != abs(x[k]-i) + abs(y[k]-j) + h[k]:
                    break
        else:
            if cnt == 1:
                print(x[I], y[I], h[I])
                exit(0)
            else:
                H = tmp
                X = i
                Y = j
print(X, Y, H)

Submission status: Accepted

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

for e in xyh:
    if e[2] != 0:
        t = e

candidates = []
for cy in range(101):
    for cx in range(101):
        candidates.append((cx, cy, t[2] + abs(t[0] - cx) + abs(t[1] - cy)))

for e in xyh:
    nc = []
    for c in candidates:
        if e[2] == max(c[2] - abs(e[0] - c[0]) - abs(e[1] - c[1]), 0):
            nc.append(c)
    candidates = nc

print(*candidates[0])

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    H = -1
    for x in range(0, 101):
        for y in range(0, 101):
            for xi, yi, hi in XYH:
                abs_xy = abs(x - xi) + abs(y - yi)
                if H < 0 and hi > 0:
                    H = hi + abs_xy
                elif hi != max(H - abs_xy, 0):
                    H = -1
                    break
            else:
                if H > 0:
                    print(x, y, H)
                    exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ll = [list(map(int,input().split())) for _ in range(int(input()))]
x,y,h = list(filter(lambda k:k[2],ll))[0]
for cx in range(101):
  for cy in range(101):
    ch = h+abs(x-cx)+abs(y-cy)
    if all(max(ch-abs(x-cx)-abs(y-cy),0)==h for x,y,h in ll): print(cx,cy,ch); exit()

Submission status: Accepted

Solution code:
ll = sorted([list(map(int,input().split())) for _ in range(int(input()))],key=lambda k:k[2])
x,y,h = ll[-1]
for cx in range(101):
  for cy in range(101):
    ch = h+abs(x-cx)+abs(y-cy)
    if all(max(ch-abs(x-cx)-abs(y-cy),0)==h for x,y,h in ll): print(cx,cy,ch); exit()

Submission status: Accepted

Solution code:
ll = [list(map(int,input().split())) for _ in range(int(input()))]
ll.sort(key=lambda k:k[2],reverse=1)
x,y,h = ll[0]
for cx in range(101):
  for cy in range(101):
    ch = h+abs(x-cx)+abs(y-cy)
    for x,y,h in ll:
      if max(ch-abs(x-cx)-abs(y-cy),0) != h:
        break
    else:
      print(cx,cy,ch)
      break
  else:
    continue
  break

Submission status: Accepted

Solution code:
n = int(input())
ll = sorted([list(map(int,input().split())) for _ in range(n)],key=lambda k:k[2])[::-1]
for cx in range(101):
  for cy in range(101):
    ch = ll[0][2]+abs(ll[0][0]-cx)+abs(ll[0][1]-cy)
    for x,y,h in ll:
      if max(ch-abs(x-cx)-abs(y-cy),0) != h:
        break
    else:
      print(cx,cy,ch)
      break
  else:
    continue
  break

Submission status: Accepted

Solution code:
def abs(x1,x2):
    if x1>x2:
        return x1-x2
    else:
        return x2-x1
    
n=int(input())
x=[]
y=[]
h=[]

for i in range(n):
    xi,yi,hi=map(int,input().split())
    x.append(xi)
    y.append(yi)
    h.append(hi)

hmax=h[0]
xhmax=x[0]
yhmax=y[0]
ihmax=0

for i in range(n):
    if hmax<h[i]:
        hmax=h[i]
        xhmax=x[i]
        yhmax=y[i]
        ihmax=i
    
for cx in range(101):
    for cy in range(101):
        hh=hmax+abs(xhmax,cx)+abs(yhmax,cy)
        yesno="yes"
        for i in range(n):
            if h[i]!=max(hh-abs(x[i],cx)-abs(y[i],cy),0):
                yesno="no"
                break
        if yesno=="yes":
            print(cx,cy,hh)
            break
    if yesno=="yes":
        break

Submission status: Accepted

Solution code:
def abs(x1,x2):
    if x1>x2:
        return x1-x2
    else:
        return x2-x1
    
n=int(input())
x=[]
y=[]
h=[]

for i in range(n):
    xi,yi,hi=map(int,input().split())
    x.append(xi)
    y.append(yi)
    h.append(hi)

hmax=h[0]
xhmax=x[0]
yhmax=y[0]
ihmax=0

for i in range(n):
    if hmax<h[i]:
        hmax=h[i]
        xhmax=x[i]
        yhmax=y[i]
        ihmax=i
    
for cx in range(101):
    for cy in range(101):
        hh=hmax+abs(xhmax,cx)+abs(yhmax,cy)
        yesno="yes"
        for i in range(n):
            if h[i]!=max(hh-abs(x[i],cx)-abs(y[i],cy),0):
                yesno="no"
                break
        if yesno=="yes":
            print(cx,cy,hh)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
info = []
for i in range(N):
    info.append(list(map(int, input().split())))
# s = False
info.sort(key=lambda x: x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        flag = True
        s = False
        for i in range(N):
            x, y, h = info[i]
            # if x < 0 or y < 0 or h <= 0:
            #     continue
            if not s:
                H = h + abs(cx - x) + abs(cy - y)
                s = True
                continue
            else:
                if h != max(H - abs(cx - x) - abs(cy - y), 0):
                    flag = False
        if flag:
            print(cx, cy, H)
            exit()
ans = info[0]
for i in range(1, N):
    if ans[2] > info[i][2]:
        ans = info[i]
print(*ans)

Submission status: Accepted

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

for x in range(101):
    for y in range(101):
        flg = True
        H = xyh[-1][2] + abs(xyh[-1][0] - x) + abs(xyh[-1][1] - y)
        X = x
        Y = y
        
        for i in range(N):
            if xyh[i][2] != max(H - abs(xyh[i][0]-x) - abs(xyh[i][1] - y),0):
                flg=False
                break
        
        if flg:
            break
    if flg:
        break
print(X,Y,H)

Submission status: Accepted

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


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


def check(cx, cy, H):
    for x, y, h in xyh:
        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(cx, cy)
        if check(cx, cy, H):
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())

xyh = []
not_zero = -100
flag_zero = True

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

for i in range(101):
    for j in range(101):

        Cx = i
        Cy = j
        H = xyh[not_zero][2] + abs(Cx-xyh[not_zero][0]) + abs(Cy-xyh[not_zero][1])
        ans = True

        for x,y,h in xyh:
            tmp_h = h+abs(Cx-x)+abs(Cy-y)
            if h>0:
                if tmp_h != H:
                    ans = False
                    break
            else:
                if H - abs(Cx-x) -abs(Cy-y) > 0:
                    ans = False
                    break
            
        if ans:
            print(Cx,Cy,H)
            exit()

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
point = 0
for i in range(101):
    for j in range(101):
        flag = True
        kizyun = False
        count = 0
        for a,b,c in li:
            if c != 0:
                count += 1
                if kizyun == False:
                    h = c+abs(a-i)+abs(b-j)
                    ha = a
                    hb = b
                    hc = c
                    kizyun = True
                else:
                    k = c+abs(a-i)+abs(b-j)
                    if h != k:
                        flag = False
        if count == 1:
            print(ha,hb,hc)
            exit()
        if flag == True:
            point += 1
            print(i,j,h)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
point = 0
for i in range(101):
    for j in range(101):
        flag = True
        kizyun = False
        count = 0
        for a,b,c in li:
            if c != 0:
                count += 1
                if kizyun == False:
                    h = c+abs(a-i)+abs(b-j)
                    if h-abs(a-i)-abs(b-j) != c:
                        flag = False
                    kizyun = True
                else:
                    k = c+abs(a-i)+abs(b-j)
                    if h != k and kizyun == True:
                        flag = False
        if count == 1:
            print(a,b-1,c+1)
            exit()
        if flag == True:
            point += 1
            print(i,j,h)

Submission status: Accepted

Solution code:
from operator import itemgetter
def main():
    N = int(input())
    xyh = sorted([list(map(int,input().split())) for _ in range(N)],key=itemgetter(2),reverse = True)
    for px in range(101):
        for py in range(101):
            X,Y,H = xyh[0][0],xyh[0][1],xyh[0][2]
            ph = H + abs(X-px) + abs(Y-py)
            for i in range(N):
                X,Y,H = xyh[i][0],xyh[i][1],xyh[i][2]
                tmp = max(ph - abs(X-px) - abs(Y-py),0)
                if tmp != H:
                    break
                if i == N-1:
                    print(px,py,ph)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# ABC100 C - Pyramid
n=int(input())
xyh=[]
idx=-1
for i in range(n):
    x,y,h=map(int,input().split())
    xyh.append([x,y,h])
    if h>=1:
        idx=i
for cx in range(101):
    for cy in range(101):
        H=abs(xyh[idx][0]-cx)+abs(xyh[idx][1]-cy)+xyh[idx][2]
        H=max(H,0)
        ok=True
        for i in range(n):
            t_height=H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)
            if xyh[i][2]==0 and t_height>0:
                ok=False
            if xyh[i][2]>0 and xyh[i][2]!=t_height:
                ok=False
        if ok:
            print(cx,cy,H)