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:
import sys

n, *xyh = map(int, sys.stdin.read().split())
xyh = list(zip(*[iter(xyh)] * 3))

def conflict(cx, cy, ch, x, y, h):
    return h != max(ch - abs(x - cx) - abs(y - cy), 0)

def main():
    for x, y, h in xyh:
        if h >= 1:
            xt, yt, ht = x, y, h
            break
    
    for cx in range(101):
        for cy in range(101):
            ch = ht + abs(cx - xt) + abs(cy - yt)
            for x, y, h in xyh:
                if conflict(cx, cy, ch, x, y, h):
                    break
            else:
                return cx, cy, ch

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    X,Y,H = [],[],[]
    xyh = [list(map(int, input().split())) for _ in range(n)]
    xyh = sorted(xyh, key=lambda x:x[2], reverse=True)
    for i in range(n):
        X.append(xyh[i][0])
        Y.append(xyh[i][1])
        H.append(xyh[i][2])

    for cx in range(101):
        for cy in range(101):
            judge = True
            h = H[0]+abs(X[0]-cx)+abs(Y[0]-cy)
            for i in range(n):
                if H[i] != max(h-abs(X[i]-cx)-abs(Y[i]-cy),0):
                    judge = False
                    break
            if judge:
                print(cx,cy,h)
                return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter


def main():
    N = int(input())
    xyh = []
    for _ in range(N):
        xyh.append([int(x) for x in input().split()])

    xyh = sorted(xyh, key=itemgetter(2), reverse=True)

    for cx in range(101):
        for cy in range(101):
            x, y, h = xyh[0]
            H = h + abs(x - cx) + abs(y - cy)
            for x, y, h in xyh:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                print(cx, cy, H)
                return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter


def main():
    N = int(input())
    xyh = []
    for _ in range(N):
        xyh.append([int(x) for x in input().split()])

    xyh = sorted(xyh, key=itemgetter(2), reverse=True)

    for cx in range(101):
        for cy in range(101):
            x, y, h = xyh[0]
            H = h + abs(x - cx) + abs(y - cy)
            is_correct = True
            for x, y, h in xyh:
                if h == 0:
                    if H - abs(x - cx) - abs(y - cy) > 0:
                        is_correct = False
                        break
                elif H != h + abs(x - cx) + abs(y - cy):
                    is_correct = False
                    break

            if is_correct:
                print(cx, cy, H)
                return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:


N = int(input())

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

for cx in range(101):
  for cy in range(101):

    for i in range(N):
      x, y, h = map(int, edges[i])
      if h > 0:
        htop = abs(x-cx) + abs(y-cy) + h

    for i in range(N):
      x, y, h = map(int, edges[i])
      if h == 0:
        if htop - (abs(x-cx) + abs(y-cy)) > 0:
          break
      if h > 0:
        if htop - (abs(x-cx) + abs(y-cy)) != h:
          break
    else:
      print(cx, cy, htop)
      exit()

Submission status: Accepted

Solution code:

N = int(input())
C = []

for i in range(N):
  x, y, z = map(int, input().split())
  C.append((x, y, z))

for X in range(101):
  for Y in range(101):

    for i in range(N):
      x, y, h = map(int, C[i])
      if h > 0:
        htop = abs(x-X) + abs(y-Y) + h
    
    for i in range(N):
      x, y, h = map(int, C[i])
      if h == 0:
        if htop - (abs(x-X) + abs(y-Y)) > 0:
          break
      if h > 0:
        if htop - (abs(x-X) + abs(y-Y)) != h:
          break
    else:
      print(X, Y, htop)
      exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++
		
def main():
	n = int(input())
	pl=101
	
	ff=[0]*pl
	for i in range(pl):
		ff[i]=[0]*pl
	
	v=[]
	v0=[]
	for i in range(n):
		x, y, h = map(int, input().split())
		if h > 0:
			v.append([x,y,h])
		else:
			v0.append([x,y,h])
		
	
	tt=0
	for i, [xi, yi, hi] in enumerate(v):
		for [xj, yj, hj] in v[i+1:]:
			tt+=1
			for px in range(pl):
				for py in range(pl):
					ihp=hi+abs(px-xi)+abs(py-yi)
					jhp=hj+abs(px-xj)+abs(py-yj)
					if ihp==jhp:
						ff[px][py]+=1
	
	for i, [xi, yi, hi] in enumerate(v):
		for [xj, yj, hj] in v0:
			tt+=1
			for px in range(pl):
				for py in range(pl):
					ihp=hi+abs(px-xi)+abs(py-yi)
					jhp=hj+abs(px-xj)+abs(py-yj)
					if ihp<=jhp:
						ff[px][py]+=1
								
	for i, vl in enumerate(ff):
		for j, va in enumerate(vl):
			if va == tt:
				[x,y,h]=v[0]
				rh=h+abs(x-i)+abs(y-j)
				print(i,j,rh)
				return
	if len(v)	== 0:		
		raise NameError('HiThere')
	print(0,0,1)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
N = int(input())
XYH = [tuple(map(int, input().split())) for _ in range(N)]
if len([h for _,_,h in XYH if h > 0]) == 1:
    print(*max(XYH, key=lambda xyh: xyh[2]))
    exit()
for cx in range(101):
    for cy in range(101):
        H = -1
        for x, y, h in XYH:
            if h:
                if H == -1:
                    H = h + abs(x-cx)+abs(y-cy)
                else:
                    if H != h + abs(x-cx)+abs(y-cy):
                        break
        else:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc112/tasks/abc112_c


# ピラミッドの中心は必ず0-100の中にある
# Hは1以上
# 与えられる情報だけで一意に定まる

# 中心座標をa,bと置いたとき、ある点x,yにおける高さは
# h(x,y; a,b)=max(H-|x-a|-|y-b|,0)である。
# ここで、真の高さとの誤差としてe(x,y;a,b)=|h(x,y;a,b) - h(x,y;Cx,Cy)|とすると。
# 任意のx,yでe=0となるa,bが答え。しかしHはわからないので0とする。
# そうすると任意のx,yでe(x,y;a,b)=constとなるa,bが答え。(ただしmaxの扱いが面倒なのでh==0は無視して処理を行う)
# またその定数constはHである

# 座標は10**4点。Nはたかだか100なので 最悪10**6回計算。間に合う。
# あー結局全探索してるんだから問題の定義を借りて素直に実装すればバグらせずに済んだな

import numpy as np
from itertools import product

N = int(input())
X, Y, H = [], [], []
for n in range(N):
    x, y, h = list(map(int, input().split()))
    if h == 0:
        continue
    X.append(x)
    Y.append(y)
    H.append(h)

if len(H) == 1:
    print(X[-1], Y[-1], H[-1])
    exit()

X = np.array(X)
Y = np.array(Y)
H = np.array(H)


def is_ok(X, Y, H, a, b):
    height = H + np.abs(X - a) + np.abs(Y - b)
    if (height == height[-1]).all():
        return True, height[-1]
    else:
        return False, False


for a, b in product(range(101), range(101)):
    flg, ansH = is_ok(X, Y, H, a, b)
    if flg:
        ans = (a, b, ansH)

print(*ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc112/tasks/abc112_c


# ピラミッドの中心は必ず0-100の中にある
# Hは1以上
# 与えられる情報だけで一意に定まる

# 中心座標をa,bと置いたとき、ある点x,yにおける高さは
# h(x,y; a,b)=max(H-|x-a|-|y-b|,0)である。
# ここで、真の高さとの誤差としてe(x,y;a,b)=|h(x,y;a,b) - h(x,y;Cx,Cy)|とすると。
# 任意のx,yでe=0となるa,bが答え。しかしHはわからないので0とする。
# そうすると任意のx,yでe(x,y;a,b)=constとなるa,bが答え。(ただしmaxの扱いが面倒なのでh==0は無視して処理を行う)
# またその定数constはHである

# 座標は10**4点。Nはたかだか100なので 最悪10**6回計算。間に合う。
# あー結局全探索してるんだから問題の定義を借りて素直に実装すればバグらせずに済んだな

import numpy as np
from itertools import product

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

if N == 1:
    print(x, y, h)
    exit()

X = np.array(X)
Y = np.array(Y)
H = np.array(H)


def is_eq_loss(X, Y, H, a, b):
    loss = np.abs(- np.abs(X - a) - np.abs(Y - b) - H)
    mask = (H == 0)  # 高さがない疑いのところは最小値に合わせる
    if np.any(mask):
        loss[mask] = loss.min()
    if (loss[-1] == loss).all():
        return True, loss[-1]
    else:
        return False, False


# for a, b in product(range(101), range(101)):
#     flg, ansH = is_eq_loss(X, Y, H, a, b)
#     if flg:
#         ans = (a, b, ansH)

# print(*ans)

# バグらせずに実装したい


def is_ok(X, Y, H, a, b):
    height = H + np.abs(X - a) + np.abs(Y - b)  # minの扱いどうする?
    if (height == height[-1]).all():
        return True, height[-1]
    else:
        return False, False


for a, b in product(range(101), range(101)):
    flg, ansH = is_eq_loss(X, Y, H, a, b)
    if flg:
        ans = (a, b, ansH)

print(*ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc112/tasks/abc112_c


# ピラミッドの中心は必ず0-100の中にある
# Hは1以上
# 与えられる情報だけで一意に定まる

# 中心座標をa,bと置いたとき、ある点x,yにおける高さは
# h(x,y; a,b)=max(H-|x-a|-|y-b|,0)である。
# ここで、真の高さとの誤差としてe(x,y;a,b)=|h(x,y;a,b) - h(x,y;Cx,Cy)|とすると。
# 任意のx,yでe=0となるa,bが答え。しかしHはわからないので0とする。
# そうすると任意のx,yでe(x,y;a,b)=constとなるa,bが答え。(ただしmaxの扱いが面倒なのでh==0は無視して処理を行う)
# またその定数constはHである

# 座標は10**4点。Nはたかだか100なので 最悪10**6回計算。間に合う。

import numpy as np
from itertools import product

N = int(input())
X, Y, H = [], [], []
for n in range(N):
    x, y, h = list(map(int, input().split()))
    # if h == 0:
    #     continue
    X.append(x)
    Y.append(y)
    H.append(h)

if N == 1:
    print(x, y, h)
    exit()

X = np.array(X)
Y = np.array(Y)
H = np.array(H)


def is_eq_loss(X, Y, H, a, b):
    loss = np.abs(- np.abs(X - a) - np.abs(Y - b) - H)
    mask = (H == 0)  # 高さがない疑いのところは最小値に合わせる
    if np.any(mask):
        loss[mask] = loss.min()
    # print(loss[-1])
    if (loss[-1] == loss).all():
        return True, loss[-1]
    else:
        return False, False


for a, b in product(range(101), range(101)):
    flg, ansH = is_eq_loss(X, Y, H, a, b)
    if flg:
        ans = (a, b, ansH)

print(*ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=[LI() for _ in range(n)]

  l=sorted(l,key=lambda x:x[2],reverse=True)

  ans=[]
  for Cx in range(101):
    for Cy in range(101):
      H=l[0][2]+abs(l[0][0]-Cx)+abs(l[0][1]-Cy)
      f=True
      for x,y,h in l[1:]:
        if h!=max(H-abs(x-Cx)-abs(y-Cy),0):
          f=False
          break
      if f:
        ans.append(str(Cx)+' '+str(Cy)+' '+str(H))
  if len(ans)==1:
    return ans[0]

# main()
print(main())

Submission status: Accepted

Solution code:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
ok=False
for i in range(n):
  if a[i][2]==0:
    ok=True
for cx in range(101):
  for cy in range(101):
    s=float('inf')
    d={}
    for k in range(n):
      if a[k][2]==0:
        s=min(s,abs(a[k][0]-cx)+abs(a[k][1]-cy))
      else:
        if a[k][2]+abs(a[k][0]-cx)+abs(a[k][1]-cy) not in d:
          d[a[k][2]+abs(a[k][0]-cx)+abs(a[k][1]-cy)]=1
    if len(list(d))==1:
      c=list(d)
      if ok:
        if 1<=c[0]<=s:
          print(cx,cy,c[0])
          exit()
      else:
        if 1<=c[0]:
          print(cx,cy,c[0])
          exit()

Submission status: Accepted

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

fa=False
for CX in range(101):
    if fa:
        break
    for CY in range(101):
        f=lambda xi,yi,hi:hi+abs(xi-CX)+abs(yi-CY)
        H=f(xyh[0][0],xyh[0][1],xyh[0][2])
        fc=True
        for i in range(1,N):
            xi,yi,hi=xyh[i]
            if (hi>0 and H!=f(xi,yi,hi)) or (hi==0 and H>abs(xi-CX)+abs(yi-CY)):
                fc=False
                break
        if fc:
            print(CX,CY,H)
            fa=True
            break

Submission status: Accepted

Solution code:
n = int(input())
X, Y, H = [], [], []
for _ in range(n):
    x, y, h = map(int, input().split())
    X.append(x); Y.append(y); H.append(h)

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

Submission status: Accepted

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

candidates =[]

for cx in range(101):
    for cy in range(101):
        ch = None
        for x,y,h in xyh:
            if h == 0:

                continue
            if ch == None:
                ch = h + abs(x-cx) + abs(y-cy)
                continue

            if ch != h + abs(x-cx) + abs(y-cy):
                break

        else:
            xyh_c = (cx, cy, ch)
            candidates.append(xyh_c)

for xyh_c in candidates:
    cx, cy, ch = xyh_c
    for x,y,h in xyh:
        if h != max(ch - abs(x-cx) - abs(y-cy) ,0):
            break
    else:
        print(cx, cy, ch)
        exit()

Submission status: Accepted

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

def calcH(x,y,h,Cx,Cy):
    if h>0:
        return(h+abs(x-Cx)+abs(y-Cy))
    return -1

for Cx in range(100+1):
    for Cy in range(100+1):
        H=-1
        check=[]
        for x,y,h in xyh:
            Hi=calcH(x,y,h,Cx,Cy)
            if Hi==-1:
                check.append(abs(x-Cx)+abs(y-Cy))
                continue
            if H==-1:
                H=Hi
            elif Hi!=H:
                break
        else:
            for c in check:
                if H>c:
                    break
            else:
                print(Cx,Cy,H)
                exit()

Submission status: Accepted

Solution code:
import itertools
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
X, Y, H = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))
X = np.array(X, dtype=int)
Y = np.array(Y, dtype=int)
H = np.array(H, dtype=int)

# ゼロのやつ使いたくない
idx = np.where(H > 0)[0][0]

# 全探索して矛盾がないのを探す
for x, y in itertools.product(range(101), range(101)):
    height = H[idx] + abs(X[idx] - x) + abs(Y[idx] - y)
    ok = np.all(np.maximum(0, height - (np.abs(X - x) + np.abs(Y - y))) == H)
    if ok:
        print(x, y, height)
        exit()

Submission status: Accepted

Solution code:
import itertools
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
X, Y, H = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))
X = np.array(X, dtype=int)
Y = np.array(Y, dtype=int)
H = np.array(H, dtype=int)

# ゼロのやつ使いたくない
idx = (H > 0).argmax()
# 全探索して矛盾がないのを探す
for x, y in itertools.product(range(101), range(101)):
    height = H[idx] + abs(X[idx] - x) + abs(Y[idx] - y)
    ok = np.all(np.maximum(0, height - (np.abs(X - x) + np.abs(Y - y))) == H)
    if ok:
        print(x, y, height)
        exit()

Submission status: Accepted

Solution code:
n = int(input())
data = []
for i in range(n):
    x, y, h = map(int, input().split())
    data.append([x,y,h])
data.sort(reverse=True, key = lambda x:x[2])
for Cx in range(0,101):
    for Cy in range(0,101):
        height = data[0][2] + abs(Cx - data[0][0]) + abs(Cy - data[0][1])
        for i in range(1,n):
            if data[i][2] != max(height - abs(Cx - data[i][0]) - abs(Cy - data[i][1]), 0):
                break
            if i == n - 1:
                print("{} {} {}".format(Cx,Cy,height))
                exit()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    xn = []
    yn = []
    hn = []
    for i in range(N):
        xi, yi, hi = map(int, input().split())
        xn.append(xi)
        yn.append(yi)
        hn.append(hi)
    for Cx in range(101):
        for Cy in range(101):
            last = None
            flg = True
            for i in range(N):
                if 0 == hn[i]:
                    continue
                H = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]
                if H < 1:
                    flg = False
                    break
                if last:
                    if H != last:
                        flg = False
                        break
                last = H
            if not flg:
                continue
            for i in range(N):
                if 0 == hn[i]:
                    h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                    if h < H:
                        flg = False
                        break
            if not flg:
                continue
            print(Cx, Cy, H)
            return


main()

Submission status: Accepted

Solution code:
# 全探索を試みるもWAを解決できず
# ゼロの扱いに対する思考が足りなかった

N = int(input())
C = []

for i in range(N):
  x, y, z = map(int, input().split())
  C.append((x, y, z))

for X in range(101):
  for Y in range(101):

    for i in range(N):
      x, y, h = map(int, C[i])
      if h > 0:
        htop = abs(x-X) + abs(y-Y) + h
    
    for i in range(N):
      x, y, h = map(int, C[i])
      if h == 0:
        if htop - (abs(x-X) + abs(y-Y)) > 0:
          break
      if h > 0:
        if htop - (abs(x-X) + abs(y-Y)) != h:
          break
    else:
      print(X, Y, htop)
      exit()

Submission status: Accepted

Solution code:
n = int(input())
xyh = []
for i in range(n):
    xyh.append(list(map(int,input().split())))
flag = False
for cx in range(101):
    if flag:
        break
    for cy in range(101):
        h1 = set()
        zero = []
        for x,y,h in xyh:
            if h != 0:
                h1.add(h + abs(cx-x)+abs(cy-y))
            else:
                zero.append([x,y])

        if len(h1) == 1:
            ah = list(h1)[0]
            f = True
            for zx,zy in zero:
                if ah - abs(cx-zx) - abs(cy-zy) > 0:
                    f = False
            if f:
                ax = cx
                ay = cy
                flag = True
                break
print(ax,ay,ah)

Submission status: Accepted

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

k = 0
while li[k][2] == 0:
    k += 1
 
for x in range(101):
    for y in range(101):

        H = li[k][2]+abs(li[k][0]-x)+abs(li[k][1]-y)
        f = True

        for i in range(N):
            # CxとCyを決め打ちした後の十分性の確認は、問題文の式を利用
            if li[i][2] != max(H-abs(li[i][0]-x)-abs(li[i][1]-y),0):
                f = False
                break
        if f:
            print(x,y,H)
            break
    else:
        continue
    break

Submission status: Accepted

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

k = 0
while li[k][2] == 0:
    k += 1
 
for x in range(101):
    for y in range(101):

        H = li[k][2]+abs(li[k][0]-x)+abs(li[k][1]-y)
        f = True

        for i in range(N):
            if li[i][2] != max(H-abs(li[i][0]-x)-abs(li[i][1]-y),0):
                f = False
                break
        if f:
            print(x,y,H)
            break
    else:
        continue
    break

Submission status: Accepted

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

k = 0
while li[k][2] == 0:
    k += 1
 
for x in range(101):
    for y in range(101):

        H = li[k][2]+abs(li[k][0]-x)+abs(li[k][1]-y)
        f = True

        for i in range(N):
            if li[i][2] > 0 and H != li[i][2]+abs(li[i][0]-x)+abs(li[i][1]-y):
                f = False
                break
            # 下2行を書き忘れていた
            elif li[i][2] == 0 and H > abs(li[i][0]-x)+abs(li[i][1]-y):
                f = False
                break
        if f:
            print(x,y,H)
            break
    else:
        continue
    break

Submission status: Accepted

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

k = 0
while li[k][2] == 0:
    k += 1
 
for x in range(101):
    for y in range(101):

        H = li[k][2]+abs(li[k][0]-x)+abs(li[k][1]-y)
        f = True

        for i in range(N):
            if li[i][2] > 0 and H != li[i][2]+abs(li[i][0]-x)+abs(li[i][1]-y):
                f = False
                break
            # 下2行を書き忘れていた
            elif li[i][2] == 0 and H > abs(li[i][0]-x)+abs(li[i][1]-y):
                f = False
                break
        if f == 1:
            print(x,y,H)
            break
    else:
        continue
    break

Submission status: Accepted

Solution code:
n = int(input())

lis = []

for i in range(n):
    array = list(map(int, input().split()))
    lis.append(array)

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

for i in range(101):
    for j in range(101):
        h = abs(i-lis[0][0]) + abs(j-lis[0][1]) + lis[0][2]
        flag = True
        for k in range(1, n):
            dist = abs(i - lis[k][0]) + abs(j - lis[k][1])
            if h - dist == lis[k][2]:
                continue
            elif h - dist <= 0 and lis[k][2] == 0:
                continue
            else:
                flag = False
                break
        if flag is True:
            print(i, j, h)

Submission status: Accepted

Solution code:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()

x = []
y = []
h = []
for i in range(n):
    xx,yy,hh = MAP()
    x.append(xx)
    y.append(yy)
    h.append(hh)

kk = h.index(max(h))
k = 0

for i in range(101):
    for j in range(101):
        ass = h[kk] + abs(x[kk]-i) + abs(y[kk]-j)
        for r in range(n):
            if h[r]==0:
                if ass-abs(x[r]-i)-abs(y[r]-j)>0:
                    ass = -1
                    break
            else:
                if ass != abs(x[r]-i)+abs(y[r]-j)+h[r]:
                    ass = -1
                    break
        if ass!=-1:
            print(i,j,ass)
            break

Submission status: Accepted

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

for cx in range(101):
  for cy in range(101):
    ch = 0
    for _ in range(2):
      for x, y, h in xyh:
        if x==cx and y==cy:
          if ch!=0:
            if h!=ch:
              break
          else:
            ch = h
        else:
          nh = abs(x-cx) + abs(y-cy)
          if h == 0:
            if nh < ch:
              break
          else:
            nh += h
            if ch == 0:
              ch = nh
            else:
              if ch != nh:
                break
      else:
        continue
      break
    else:
      print(cx, cy, ch)
      exit()

Submission status: Accepted

Solution code:
n = int(input())
a = [list(map(int, input().split(' '))) for i in range(n)]
for x in range(101):
    for y in range(101):
        for i in range(n):
            if a[i][2] > 0:
                htop = a[i][2] + abs(x-a[i][0]) + abs(y-a[i][1])
                break
        for i in range(n):
            if a[i][2] == 0:
                if htop - (abs(x-a[i][0]) + abs(y-a[i][1])) > 0:
                    break
            if a[i][2] > 0:
                if htop - (abs(x-a[i][0]) + abs(y-a[i][1])) != a[i][2]:
                    break
        else:
            print(x,y,htop)
            exit()

Submission status: Accepted

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


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    for cx in range(0,101):
        for cy in range(0,101):
            H= 0
            for i in range(N):
                if h[i] != 0:
                    H = h[i] + abs(x[i]-cx) + abs(y[i]-cy)
            for i in range(N):
                if max(H - abs(x[i]-cx) - abs(y[i]-cy),0) != h[i]:
                        break
                else:
                    continue
            else:
                print(cx,cy,H)
                return

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    h = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        h[i] = int(next(tokens))
    solve(N, x, y, h)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [list(map(int, input().split(' '))) for i in range(n)]
for x in range(101):
    for y in range(101):
        for i in range(n):
            if a[i][2] > 0:
                htop = a[i][2] + abs(x-a[i][0]) + abs(y-a[i][1])
                break
        for i in range(n):
            if a[i][2] == 0:
                if htop - (abs(x-a[i][0]) + abs(y-a[i][1])) > 0:
                    break
            if a[i][2] > 0:
                if htop - (abs(x-a[i][0]) + abs(y-a[i][1])) != a[i][2]:
                    break
        else:
            print(x,y,htop)
            exit()

Submission status: Accepted

Solution code:
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
cnt=0
for a in A:
    if a[2]!=0:
        cnt+=1
        ans=a
if cnt==1:
    print(*ans)
    exit()
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True

        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)

            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        #print(i,j,hi)
        if flg:
            ans=[i,j,hi[0]]

print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = []
for _ in range(n):
  x, y, h = map(int, input().split())
  if h != 0:
    lst.append([x, y, h])
if len(lst) == 1:
  print(*lst[0])
  quit()
for cx in range(101):
  for cy in range(101):
    a = True
    preh = abs(lst[0][0] - cx) + abs(lst[0][1] - cy) +lst[0][2]
    for x, y, h in lst[1:]:
      H = abs(x - cx) + abs(y - cy) + h
      if H != preh:
        a = False
        break
    if a:
      print(cx, cy, H)
      quit()

Submission status: Accepted

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

for cx in range(0, 101):
    for cy in range(0, 101):
        flag = 0
        H = 1
        for idx, x_y_h in enumerate(x_y_h_list):
            if H == 1:
                H = x_y_h[2] + abs(cx - x_y_h[0]) + abs(cy - x_y_h[1])
            else:
                if x_y_h[2] != max(H - abs(cx-x_y_h[0]) - abs(cy-x_y_h[1]), 0):
                    flag = 1
                    break
        if flag == 0:
            print(cx, cy, H)

Submission status: Accepted

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

from itertools import product
for cx, cy in product(range(101), repeat=2):
    H = None
    for x, y, h in xyh:
        if H is None:
            H = h + abs(x-cx) + abs(y-cy)
        else:
            if h != max(H - abs(x-cx) - abs(y-cy), 0):
                break
    else:
        print(cx, cy, H)
        exit()

Submission status: Accepted

Solution code:
import sys
N = int(input())
pyramids = [tuple(map(int,input().split())) for _ in range(N)]
for i in range(101):
  for j in range(101):
    H_set = set()
    keep = []
    for k in range(len(pyramids)):
      x,y,h = pyramids[k]
      if h == 0:
        keep.append((x,y))
        continue
      H_set.add(h + abs(x - j) + abs(y - i))
    if len(H_set) == 1:
      if len(keep) != 0:
        is_suitable = True
        for x,y in keep:
          if list(H_set)[0] - abs(j - x) - abs(i - y) > 0:
            is_suitable = False
            break
        if is_suitable:
          print(j,i,list(H_set)[0])
          sys.exit()
        else:
          continue
      else:
        print(j,i,list(H_set)[0])
        sys.exit()

Submission status: Accepted

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

hi = -1
for i in range(N):
  if h[i] > 0:
    hi = i
    break
if hi == -1:
  exit()

for X in range(101):
  for Y in range(101):
    H = h[hi] + abs(X - x[hi]) + abs(Y - y[hi])
    flag = 1
    for i in range(N):
      if h[i] != max(H - abs(X - x[i]) - abs(Y - y[i]), 0):
        flag = 0
        break
    if flag:
      break
  if flag:
    break
print(X, Y, H)