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: Runtime Error

Solution code:
def decide_H(Cx,Cy,x,y,h):
    H=h+abs(x-Cx)+abs(y-Cy)
    if h>=1:
        return(H)
 
def check_H(Cx,Cy,H):
    for x,y,h in T:
        if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
            return False
    return True
 
N=int(input())
T=[[int(i) for i in input().split()] for _ in range(N)]
 
for Cx in range(101):
    for Cy in range(101):
        for x,y,h in T:
            H=decide_H(Cx,Cy,x,y,h)
            if check_H(Cx,Cy,H):
                print(Cx,Cy,H)
                exit()
            else:
                break

Submission status: Runtime Error

Solution code:
def decide_H(Cx,Cy,x,y,h):
    H=h+abs(x-Cx)+abs(y-Cy)
    if h>=1:
        return(H)
 
def check_H(Cx,Cy,H):
    for x,y,h in T:
        if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
        # if H==decide_H(Cx,Cy,x,y,h) and H!=None and h!=0:
        #     continue
            return False
    return True
 
N=int(input())
T=[[int(i) for i in input().split()] for _ in range(N)]
 
for Cx in range(101):
    for Cy in range(101):
        for x,y,h in T:
            H=decide_H(Cx,Cy,x,y,h)
            if check_H(Cx,Cy,H):
                print(Cx,Cy,H)
                exit()
            else:
                break
def decide_H(Cx,Cy,x,y,h):
    H=h+abs(x-Cx)+abs(y-Cy)
    if H>=1:
        return(H)

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

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

for Cx in range(101):
    for Cy in range(101):
        for x,y,h in T:
            H=decide_H(Cx,Cy,x,y,h)
            if check_H(Cx,Cy,H):
                print(Cx,Cy,H)
                exit()
            else:
                break
提出情報

Submission status: Runtime Error

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

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

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

for Cx in range(101):
    for Cy in range(101):
        for x,y,h in T:
            H=decide_H(Cx,Cy,x,y,h)
            if check_H(Cx,Cy,H):
                print(Cx,Cy,H)
                exit()
            else:
                break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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=[]
	for i in range(n):
		x, y, h = map(int, input().split())
		v.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, 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
				
	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: Runtime Error

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_ok(X, Y, H, a, b)
    if flg:
        ans = (a, b, ansH)

print(*ans)

Submission status: Runtime Error

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[mask].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: Runtime Error

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(H - np.abs(X - a) - np.abs(Y - b))
    mask = (H == 0)  # 高さがない疑いのところは最小値に合わせる
    loss[mask] = loss[mask].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: Runtime Error

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)
    if (loss[-1] == loss).all():
        return True, loss[-1]
    else:
        return False, False


# def sum_loss(X, Y, H, a, b):
#     loss = np.abs(-np.abs(X - a) - np.abs(Y - b) - H)
#     return loss.sum()


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)

# 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: Runtime Error

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==0:
          continue
        if h!=H-abs(x-Cx)-abs(y-Cy):
          f=False
          break
      if f:
        ans.append(str(Cx)+' '+str(Cy)+' '+str(H))
  if len(ans)==1:
    return ans[0]
  else:
    aaa

# main()
print(main())

Submission status: Runtime Error

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

for cx in range(101):
    for cy in range(101):
        ch = None
        okflag = True
        for x,y,h in xyh:
            if h == 0 or okflag == False:
                continue
            if ch == None:
                ch = h + abs(x-cx) + abs(y-cy)
                continue

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

        if okflag == True:
            xyh_c = (cx, cy, ch)
            candidates.append(xyh_c)

okflag = True
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):
            okflag = False
            break

    if okflag == True:
        print(cx, cy, ch)
        exit()

Submission status: Runtime Error

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

for cx in range(101):
    for cy in range(101):
        ch = None
        okflag = True
        for x,y,h in xyh:
            if h == 0:
                if ch > abs(x-cx) + abs(y-cy):
                    okflag = False
                    break
                continue
            if ch == None:
                ch = h + abs(x-cx) + abs(y-cy)
                continue

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

        if okflag == True:
            print(cx, cy, ch)
            exit()

Submission status: Runtime Error

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

for cx in range(101):
    for cy in range(101):
        ch = None
        okflag = True
        for x,y,h in xyh:
            if h == 0:
                if ch <= abs(x-cx) + abs(y-cy):
                    okflag = False
                    break
                continue
            if ch == None:
                ch = h + abs(x-cx) + abs(y-cy)
                continue

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

        if okflag == True:
            print(cx, cy, ch)
            exit()

Submission status: Runtime Error

Solution code:
n = int(input())

lis = []

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

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
            else:
                flag = False
                break
        if flag is True:
            ans_list.append([i, j, h])

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

for i in ans_list[0]:
    print(i, end=' ')

Submission status: Runtime Error

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

ans = []
x,y,h = MAP()
for i in range(101):
    for j in range(101):
        ans.append((i,j,h+abs(i-x)+abs(j-y)))

for i in range(n-1):
    tmp = []
    x,y,h = MAP()
    for j in range(101):
        for k in range(101):
            if (j,k,h+abs(j-x)+abs(k-y)) in ans:
                tmp.append((j,k,h+abs(j-x)+abs(k-y)))
    ans = tmp

print(*ans[0])

Submission status: Runtime Error

Solution code:
N=int(input())
A=[0]*N    

for i in range(N):
    A[i]=list(map(int,input().split()))
A=sorted(A,key=lambda x: (x[0],x[1]))

"""
if(N==1):
    print(A[0][0],A[0][1],A[0][2])
    exit()
H=0
x=0
y=0
for i in range(101):
    for j in range(101):
        f=0
        h=abs(i-A[0][0])+abs(j-A[0][1])+A[0][2]
        for k in range(N):
            if(h!=abs(i-A[k][0])+abs(j-A[k][1])+A[k][2]):
                f=1
                break 
        if(f==0):
            if(h>H):
                H=h
                x=i
                y=j
print(x,y,H)
"""
for cx in range(101):
    for cy in range(101):
        flag=True
        Hcand=-1
        for x,y,h in A:
            if h==0 and H>0:
                if H-abs(x-cx)-abs(y-cy)>0:
                    flag=False
                    break
            else:
                H= h+abs(x-cx)+abs(y-cy)
                if Hcand==-1:
                    Hcand=H
                else:
                    if Hcand!=H:
                        flag=False
                        break
        if flag:
            break
    if flag:
        break
print(cx,cy,H)

Submission status: Runtime Error

Solution code:
n=int(input())

zahyo=[]

for _ in range(n):
    zahyo.append(tuple(map(int,input().split())))

zahyo.sort(key=lamda x:x[2])

for x in range(101):
    for y in range(101):


        H=zahyo[0][2]+abs(zahyo[0][0]-x)+abs(zahyo[0][1]-y)
        flag=0
        saisho=10**9+1
        H=0
        for item in zahyo[1:]:
                if item[2]==0:
                    if H>abs(item[0]-x)+abs(item[1]-y):
                        flag=1
                        break
                else:
                    if H!=item[2]+abs(item[0]-x)+abs(item[1]-y):
                        flag=1
                        break
        if flag==0:
            print(x,y,H)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[0]*N

for i in range(N):
    A[i]=list(map(int,input().split()))
A=sorted(A,key=lambda x: (x[0],x[1]))

H=0
for i in range(101):
    for j in range(101):
        f=0
        h=abs(i-A[0][0])+abs(j-A[0][1])+A[0][2]
        for k in range(N):
            if(h!=abs(i-A[k][0])+abs(j-A[k][1])+A[k][2]):
                f=1
                break 
        if(f==0):
            if(h>H):
                H=h
                x=i
                y=j

print(x,y,H)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
for Cx in range(0,101):
    for Cy in range(0,101):
        p = 0
        ans = []
        for i in xyh:
            H = i[2]+abs(i[0]-Cx)+abs(i[1]-Cy)
            if H < 1:
                H = -3425
                break
            if i[2] != 0:
                ans.append(H)
        if len(set(ans)) == 1:
            print(Cx,Cy,ans[3])

Submission status: Runtime Error

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: Runtime Error

Solution code:
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True
        B=[]
        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)
            else:
                B.append(a)
            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        for b in B:
            if hi[0]-abs(a[1]-j)-abs(a[0]-i)>0:
                flg=False
        #print(i,j,hi)
        if flg:
            ans=[i,j,hi[0]]
print(*ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True
        B=[]
        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)
            else:
                if hi[0]-abs(a[1]-j)-abs(a[0]-i)>0:
                    flg=False
            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: Runtime Error

Solution code:
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True
        B=[]
        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)
            else:
                B.append([a[0],a[1]])
            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        #print(i,j,hi)
        if flg:
            flg2=True
            for b in B:
                if hi[0]-abs(a[1]-j)-abs(a[0]-i)>0:
                    flg2=False
            if flg2:
                ans=[i,j,hi[0]]
print(*ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        hi=[]
        flg=True
        B=[]
        for a in A:
            if a[2]!=0:
                hi_=a[2]+abs(a[1]-j)+abs(a[0]-i)
                hi.append(hi_)
            else:
                B.append([a[0],a[1])
            if len(hi)>=2:
                if hi[-1]!=hi[-2]:
                    flg=False
        #print(i,j,hi)
        if flg:
            flg2=True
            for b in B:
                if hi[0]-abs(a[1]-j)-abs(a[0]-i)>0:
                    flg2=False
        if flg2:
            ans=[i,j,hi[0]]
print(*ans)

Submission status: Runtime Error

Solution code:
n = int(input())
lst = []
for _ in range(n):
  x, y, h = map(int, input().split())
  if h:
  lst.append(x, y, h)
if len(lst) == 1:
  print(*lst)
  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: Runtime Error

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: Runtime Error

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
N = int(input())
B = [[int(x) for x in input().split()] for _ in range(N)]
def heighti(Cx,Cy,x,y,h):
    return abs(x-Cx) + abs(y-Cy) + h
ans = []
h0 = []
A = []
for l in B:
    if l[2] == 0:
        h0.append([l[0],l[1]])
    else:
        A.append(l)
for i in range(101):
    for j in range(101):
        tempH = heighti(i,j,A[0][0],A[0][1],A[0][2])
        if tempH < 0:
            break
        else:
            flag = 1
            for k in range(1,len(A)):
                if A[k][2] != 0 and heighti(i,j,A[k][0],A[k][1],A[k][2]) != tempH:
                    flag = 0
                    break
            if flag:
                ans.append([i,j,tempH])
if len(ans) == 1:
    print(*ans[0])
elif len(ans) == 0:
    for i in range(101):
        for j in range(101):
            for k in range(N):
                if heighti(i,j,A[k][0],A[k][1],A[k][2]) > 0:
                    print(*[i,j,heighti(i,j,A[k][0],A[k][1],A[k][2])])
                    sys.exit()
else:
    for m in ans:
        for n in h0:
            if heighti(n[0],n[1],m[0],m[1],m[2]) > 0:
                break
        print(*m)
        sys.exit()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
pyr=[[-1]*101 for i in range(101)]

N=int(input())

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

ans=0
for y in range(101):
    for x in range(101):
        for item in l:
            if item[2]==0:
                if pyr[y][x]==-1:
                    pyr[y][x]=item[2]+abs(item[0]-x)+abs(item[1]-y)
                else:
                    pass
            elif pyr[y][x]==-1:
                pyr[y][x]=item[2]+abs(item[0]-x)+abs(item[1]-y)
            elif pyr[y][x]!=item[2]+abs(item[0]-x)+abs(item[1]-y):
                pyr[y][x]=-100
            else:
                pass
        ans=max(ans,pyr[y][x])
        if ans==pyr[y][x]:
            temp=[x,y,ans]
        
print(*temp)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
pyr=[[-1]*101 for i in range(101)]

N=int(input())

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

ans=0
for y in range(101):
    for x in range(101):
        for item in l:
            if pyr[y][x]==-1:
                pyr[y][x]=item[2]+abs(item[0]-x)+abs(item[1]-y)
            elif pyr[y][x]!=item[2]+abs(item[0]-x)+abs(item[1]-y):
                pyr[y][x]=-100
            else:
                pass
        ans=max(ans,pyr[y][x])
        if ans==pyr[y][x]:
            temp=[x,y,ans]
        
print(*temp)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
pyr=[[-1]*101 for i in range(101)]

N=int(input())

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

ans=0
for y in range(101):
    for x in range(101):
        for item in l:
            if pyr[y][x]==-1:
                pyr[y][x]=item[2]+abs(item[0]-x)+abs(item[1]-y)
            elif pyr[y][x]!=item[2]+abs(item[0]-x)+abs(item[1]-y):
                pyr[y][x]=-100
            else:
                pass
        ans=max(ans,pyr[y][x])
        if ans==pyr[y][x]:
            temp=[x,y]
        
print(*temp,ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = [MAP() for _ in range(N)]

fin = False
for cx in range(101):
	for cy in range(101):
		tmp = 10**9+7
		for a in A:
			x, y, h = a
			if h != 0:
				H = abs(cx-x)+abs(cy-y)+h
				if tmp == 10**9+7:
					tmp = H
				else:
					if tmp != H:
						break
			else:
				if tmp > abs(cx-x)+abs(cy-y):
					break
		else:
			X ,Y ,CH = cx, cy, H
			fin = True
print(X, Y, CH)

Submission status: Runtime Error

Solution code:
n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    for i in range(101):
        if map_list[i][2] > 0:
            x = int(map_list[i][0])
            y = int(map_list[i][1])
            h = int(map_list[i][2])
            break
        else:
            continue

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
            
            for data in map_list:
                xx, yy, hh = map(int, data)
                if hh != max(H - abs(xx - i) - abs(yy - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)

Submission status: Runtime Error

Solution code:

n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    x = int(map_list[0][0])
    y = int(map_list[0][1])
    h = int(map_list[0][2])

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
            
            for k in range(n):
                xx = int(map_list[k][0])
                yy = int(map_list[k][1])
                hh = int(map_list[k][2])

                if hh != max(H - abs(xx - i) - abs(yy - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)

Submission status: Runtime Error

Solution code:

n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    x = int(map_list[0][0])
    y = int(map_list[0][1])
    h = int(map_list[0][2])

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
            
            for k in range(n):
                x = int(map_list[k][0])
                y = int(map_list[k][1])
                h = int(map_list[k][2])

                if h != max(H - abs(x - i) - abs(y - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)

Submission status: Runtime Error

Solution code:

n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    x = int(map_list[-1][0])
    y = int(map_list[-1][1])
    h = int(map_list[-1][2])

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
            
            for k in range(n-1):
                x = int(map_list[k][0])
                y = int(map_list[k][1])
                h = int(map_list[k][2])

                if h != max(H - abs(x - i) - abs(y - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)

Submission status: Runtime Error

Solution code:

n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    x = int(map_list[-1][0])
    y = int(map_list[-1][1])
    h = int(map_list[-1][2])

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
            
            for k in range(n):
                x = int(map_list[k][0])
                y = int(map_list[k][1])
                h = int(map_list[k][2])

                if h != max(H - abs(x - i) - abs(y - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)