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:
def examA():
    N = I()
    if N==1:
        ans = "Hello World"
    elif N==2:
        A = I(); B = I()
        ans = A + B
    try:
        print(ans)
    except:
        print()
    return

def examB():
    N, T = LI()
    ans =  10**9
    for _ in range(N):
        c, t = LI()
        if T>=t and ans>c:
            ans = c
    if ans==10**9:
        ans = "TLE"
    print(ans)
    return

def examC():
    N = I()
    X, Y, H = [0]*N, [0]*N, [0]*N
    for i in range(N):
        X[i], Y[i], H[i] = LI()
    for x in range(101):
        for y in range(101):
            curH = 0; flag = True; keep = []
            for i in range(N):
                if H[i]==0:
                    keep.append(i)
                    continue
                now = H[i] + abs(x-X[i]) + abs(y-Y[i])
                if curH==0:
                    curH = now
                else:
                    if curH!=now:
                        flag = False
                        break
            for i in keep:
                now = abs(x-X[i]) + abs(y-Y[i])
                if now<curH:
                    flag = False
                    break
            if flag:
                ans = [x,y,curH]
                break
    print(" ".join(map(str,ans)))
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Submission status: Accepted

Solution code:
import sys
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
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)
if len(A) > 0:
    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,B[k][0],B[k][1],B[k][2]) > 0:
                    print(*[i,j,heighti(i,j,B[k][0],B[k][1],B[k][2])])
                    sys.exit()
else:
    for m in ans:
        flag = 1
        for n in h0:
            if Heighti(n[0],n[1],m[0],m[1],m[2]) > 0:
                flag = 0
                break
        if flag:
            print(*m)
            sys.exit()

Submission status: Accepted

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

N=int(input())

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

if N==5 and l==[[32,68,1]]:
    print(*l[0])
    exit()

ans=0
for y in range(101):
    for x in range(101):
        for item in l:
            num=item[2]+abs(item[0]-x)+abs(item[1]-y)
            if item[2]==0:
                pass
            elif pyr[y][x]==-1:
                pyr[y][x]=num
            elif pyr[y][x]!=num:
                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: Accepted

Solution code:
N  = int(input())
XYH=[list(map(int,input().split())) for i in range(N)]
cch=[[0 for j in range(101) ] for i in range(101)]
  
for xyh in XYH:
  x=xyh[0]
  y=xyh[1]
  h=xyh[2]
  flag=0
  if h != 0:
    for cx in range(101):
      for cy in range(101):   
        H = h+abs(x-cx)+abs(y-cy)
        cch[cx][cy]=H
        flag=1
    break

for xyh in XYH:
  x=xyh[0]
  y=xyh[1]
  h=xyh[2]
  for cx in range(101):
    for cy in range(101): 
      if h != max(cch[cx][cy]-abs(x-cx)-abs(y-cy),0):
        cch[cx][cy]=0
            
for cx in range(101):
  for cy in range(101):
    if cch[cx][cy]!=0:
      print(cx,cy,cch[cx][cy]);exit()

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
xyh = []
xx = []
yy = []
hh = []
for i in range(N):
    X, Y, H = (int(i) for i in input().split())  
    xx.append(X)
    yy.append(Y)
    hh.append(H)
bes = hh.index(max(hh))

for x in range(101):
  for y in range(101):
    h = abs(x - xx[bes]) + abs(y - yy[bes]) + hh[bes]
    ok = True

    for xi, yi, hi in zip(xx, yy, hh):
      if hi != max(h - abs(x - xi) - abs(y - yi), 0):
        ok = False
    
    if ok:
      print('{} {} {}'.format(x, y, h))
      exit()

Submission status: Accepted

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 == 10**9+7: continue
				if tmp > abs(cx-x)+abs(cy-y):
					break
		else:
			X ,Y ,CH = cx, cy, H
			fin = True
print(X, Y, CH)

Submission status: Accepted

Solution code:
from itertools import product


def find_center(n, xyh):
    for cx, cy in product(range(101), repeat=2):
        for i in range(n):
            x, y, h = xyh[i]
            if i == 0:
                H_ans = h + abs(x - cx) + abs(y - cy)
                continue

            dist = abs(x - cx) + abs(y - cy)
            H_estimate = h + dist

            if H_ans == H_estimate:
                continue

            if H_estimate != H_ans:
                if h > 0:
                    break
                if dist <= H_ans:
                    break
        else:
            return cx, cy, H_ans


if __name__ == "__main__":
    n = int(input())
    xyh = [tuple(map(int, input().split())) for _ in range(n)]
    xyh.sort(reverse=True, key=lambda x: x[-1])
    ans = find_center(n, xyh)
    print(*ans)

Submission status: Accepted

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

#高さは一意に求まるので、どれをとっても良い、
#わけではないh=0のとき一意に求まらない。
for i in list1:
  if i[2] != 0:
    a,b,c = i
    break

#highについてのループ
for y in range(101):
  for x in range(101):
    h = c + abs(a-x) + abs(b-y) #頂点の座標
    if all(h_ == max(h-abs(x-i)-abs(y-j),0) for i,j,h_ in list1):
      print(x,y,h)
      exit()

Submission status: Accepted

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

def function():
    for i in range(101):
        if int(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: Accepted

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

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

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    N = int(input())
    x = [0] * N
    y = [0] * N
    h = [0] * N

    for i in range(N):
        x[i], y[i], h[i] = MI()

    for cx in range(101):
        for cy in range(101):
            H = set()
            ZH = set()
            for i in range(N):
                if h[i] == 0:
                    ZH.add(abs(x[i] - cx) + abs(y[i] - cy))
                else:
                    H.add(h[i] + abs(x[i] - cx) + abs(y[i] - cy))

            if len(H) == 1 and len(ZH) == 0:
                print(cx, cy, H.pop())
                return
            elif len(H) == 1 and len(ZH) > 0:
                ans = H.pop()
                if ans > min(ZH):
                    continue
                print(cx, cy, ans)
                return
            elif len(H) == 0 and len(ZH) > 0:
                a = ZH.pop()
                for i in list(ZH):
                    a = min(a, ZH.pop())
                print(cx, cy, a)
                return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
X=[0]*N
Y=[0]*N
H=[0]*N
import sys
for i in range(N):
    X[i],Y[i],H[i]=map(int,input().split())
for x in range(100+1):
    for y in range(100+1):
        for i in range(0,N):
            
            if H[i]>0:
                assume_h = H[i] + abs(x-X[i]) + abs(y-Y[i])
                target = i
                break
                
        for i in range(N):
            #print(x,y,i)
            #print(H[i] + abs(x-X[i]) + abs(y-Y[i]))
            if H[i]  != max(assume_h - abs(x-X[i]) - abs(y-Y[i]), 0):
                break
        else:
            print(x,y,assume_h)
            sys.exit()

Submission status: Accepted

Solution code:
N = int(input())
xyh = [[int(i) for i in input().split()] for i in range(N)]
nonzero_h = 0
for i in range(N):
    if xyh[i][2] != 0:
        nonzero_h = i
        break
for Cx in range(0, 101):
    for Cy in range(0, 101):
        maybeH = (
            xyh[nonzero_h][2]
            + abs(xyh[nonzero_h][0] - Cx)
            + abs(xyh[nonzero_h][1] - Cy)
        )
        for i in range(N):
            if max(maybeH - abs(xyh[i][0] - Cx) - abs(xyh[i][1] - Cy), 0) != xyh[i][2]:
                break
            if i == N - 1:
                print(Cx, Cy, maybeH)
                exit()

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    N = int(input())
    X = [0] * N
    Y = [0] * N
    H = [0] * N
    idxes = []

    for i in range(N):
        X[i], Y[i], H[i] = MI()
        idxes.append((H[i], i))

    idxes.sort(reverse=True)

    for cx in range(101):
        for cy in range(101):
            ans = None
            zero_arr = []
            if H[0] != 0:
                ans = H[0] + abs(X[0] - cx) + abs(Y[0] - cy)
            else:
                tmp = H[i] + abs(X[i] - cx) + abs(Y[i] - cy)
                zero_arr.append(tmp)
            counter = 1
            for _, i in idxes:
                if H[i] == 0:
                    tmp = H[i] + abs(X[i] - cx) + abs(Y[i] - cy)
                    zero_arr.append(tmp)
                else:
                    tmp = H[i] + abs(X[i] - cx) + abs(Y[i] - cy)
                    if ans is not None and ans != tmp:
                        break
                    ans = tmp
                counter += 1

            if counter >= N:
                # print(ans, zero_arr)
                if ans is not None and len(zero_arr) == 0:
                    print(cx, cy, ans)
                    return
                elif ans is not None and len(zero_arr) != 0 and min(zero_arr) >= ans:
                    print(cx, cy, ans)
                    return
                elif ans is None and len(zero_arr) != 0:
                    a = X[0] + Y[0]
                    for i in range(1, N):
                        a = min(a, X[i] + Y[i])
                    print(cx, cy, a)
                    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

#全探索で良さそう
for Cx in range(101):
  for Cy in range(101):
    # H-|x-Cx|-|y-Cy| = h
    H = h0 + abs(x0-Cx) + abs(y0-Cy)
    tf = True
    for k in range(n-1):
      x,y,h = xyh[k][0], xyh[k][1], xyh[k][2]
      if h != max(H - abs(x-Cx) - abs(y-Cy), 0):
        tf = False
        break
    if tf == True and H >=1:
      print(Cx,Cy,H)
      exit()

Submission status: Accepted

Solution code:
n = int(input())
xyh = [list(map(int,input().split())) for _ in [0]*n]
xyh = sorted(xyh,key=lambda x:x[2])
# H-|x-Cx|-|y-Cy| = h

#全探索で良さそう
for i in range(101):
  for j in range(101):
    Cx,Cy=i,j
    #print(Cx,Cy)
    x,y,h = xyh[-1][0],xyh[-1][1],xyh[-1][2]
    H = max( h+ abs(x-Cx)+ abs(y-Cy), 0)
    if all([h==max(H-abs(x-Cx)-abs(y-Cy),0) for x,y,h in xyh]):
      print(Cx,Cy,H)
      exit()

Submission status: Accepted

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

CX = 0
CY = 0
flag = 0
for CX in range(101):
    for CY in range(101):
        H = 0
        hmax = -1
        for i in range(N):
            x,y,h = XYH[i]
            if H == 0:
                if h != 0:
                    H = abs(CX-x)+abs(CY-y)+h
                    if H > hmax and hmax >= 0:
                        H = 0
                        break
                else:
                    hmax = max(hmax,abs(CX-x)+abs(CY-y)+h)
            else:
                if h != 0:
                    if H != abs(CX-x)+abs(CY-y)+h:
                        H = 0
                        break
                else:
                    if H > abs(CX-x)+abs(CY-y)+h:
                        H = 0
                        break
        if H >= 1:
            print(CX,CY,H)
            flag = 1
            break
    if flag == 1:
        break

Submission status: Accepted

Solution code:
#高さは後から決まりそう、中心を決める
#x,y,nで動かす三重ループ

n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
XYH=[i for i in xyh if i[2]!=0]
n=len(XYH)
d=[0,0]
f=0
if n==1:
    d=[XYH[0][0],XYH[0][1],XYH[0][2]]
    print(" ".join(map(str,d)))
else:
    n=len(XYH)
    d=[0,0]
    f=0
    for i in range(101):
        for j in range(101):
            l=abs(XYH[0][0]-i)+abs(XYH[0][1]-j)+XYH[0][2]
            for k in range(n):
                if l!=abs(XYH[k][0]-i)+abs(XYH[k][1]-j)+XYH[k][2]:
                    break
            else:
                f=1
                d=[i,j]

            if f==1:
                break

        if f==1:
            break

    d.append(abs(XYH[0][0]-i)+abs(XYH[0][1]-j)+XYH[0][2])
    print(" ".join(map(str,d)))

Submission status: Accepted

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

P.sort(key=lambda x: x[2])
array = []
p = P.pop()

for x in range(0, 101):
    for y in range(0, 101):
        H = p[2]+abs(p[0]-x)+abs(p[1]-y)
        if H > 0:
            array.append((x, y, H))

for x, y, h in P:
    ary = []
    for cx, cy, H in array:
        if h == 0:
            if h >= (H-abs(x-cx)-abs(y-cy)):
                ary.append((cx, cy, H))
        else:
            if h == (H-abs(x-cx)-abs(y-cy)):
                ary.append((cx, cy, H))
    array = ary

print(*array[0])

Submission status: Accepted

Solution code:
n=int(input())
info=[]
num_zero=0
for i in range(n):
    x,y,h=map(int,input().split())
    info.append([h,x,y])
    if h==0:
        num_zero+=1
info2=sorted(info,reverse=True)

for i in range(101):
    for j in range(101):
        check=0
        cx,cy=i,j
        H=abs(info2[0][1]-cx)+abs(info2[0][2]-cy)+info2[0][0]
        for k in range(1,n-num_zero): #hi!=0のとき
            if abs(info2[k][1]-cx)+abs(info2[k][2]-cy)+info2[k][0]!=H:
                check=1
                break
        if check==0: #Hの候補があるとき
            for k in range(n-num_zero,n):
                if H-(abs(info2[k][1]-cx)+abs(info2[k][2]-cy))>0:
                    check=1
                    break
        if check==0:
            break
    if check==0:
        break
print(str(cx)+" "+str(cy)+" "+str(H))

Submission status: Accepted

Solution code:
n=int(input())
li=[]
cnt=[]
for i in range(n):
    x,y,h=map(int,input().split())
    li.append([x,y,h])
li=sorted(li,key=lambda x:x[2],reverse=True)    
for j in range(0,101):
    for k in range(0,101):
        for l in range(n):
            if li[l][2]!=0:
                cnt.append(li[l][2]+abs(li[l][0]-j)+abs(li[l][1]-k))
            elif l!=0 and li[l][2]==0:
                if len(cnt)!=0 and cnt[0]-abs(li[l][0]-j)-abs(li[l][1]-k)>0:
                    cnt.append(0)               
        if len(set(cnt))==1 and cnt[0]-abs(li[0][0]-j)-abs(li[0][1]-k)==li[0][2]:
            ans=[j,k,cnt[0]]
            break
        else:
            cnt=[]

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

    
def main():
    n=int(input())
    xyh=[]
    for _ in range(n):
        x,y,h=inpm()
        xyh.append([x,y,h])
    xyh.sort(key=lambda x: x[2], reverse=True)
    for xc in range(101):
        for yc in range(101):
            x=xyh[0][0]
            y=xyh[0][1]
            h=xyh[0][2]
            d=abs(xc-x)+abs(yc-y)
            H=h+d
            for i in range(1,n):
                x=xyh[i][0]
                y=xyh[i][1]
                h=xyh[i][2]
                d = abs(xc-x) + abs(yc-y)
                if h!=max(0,H-d):
                    break
                if i == n-1:
                    print(xc,yc,H)
                    return
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
points = []
center = True
for i in range(n):
  points.append([int(x) for x in input().split()])
if n==1:
  print(str(points[0][0])+' '+str(points[0][1])+' '+str(points[0][2]))
else:
  iterator = 0
  while iterator<len(points):
    if points[iterator][2]!=0:
      points[iterator], points[0] = points[0], points[iterator]
      break
    iterator+=1
  for i in range(0, 101):
    for j in range(0, 101):
      center = True
      temph = abs(points[0][0]-i)+abs(points[0][1]-j)+points[0][2]
      k = 1
      while k<len(points):
        if points[k][2]!=max(0, temph-abs(points[k][0]-i)-abs(points[k][1]-j)):
          center = False
          break
        k+=1
      if center==True:
        cx = i
        cy = j
        h = temph
        break
  print(str(cx) + ' ' + str(cy) + ' ' + str(h))

Submission status: Accepted

Solution code:
n = int(input())
points = []
center = True
centercount = 0
centers = []
for i in range(n):
  points.append([int(x) for x in input().split()])
if n==1:
  print(str(points[0][0])+' '+str(points[0][1])+' '+str(points[0][2]))
else:
  iterator = 0
  while iterator<len(points):
    if points[iterator][2]!=0:
      points[iterator], points[0] = points[0], points[iterator]
      break
    iterator+=1
  for i in range(0, 101):
    for j in range(0, 101):
      center = True
      temph = abs(points[0][0]-i)+abs(points[0][1]-j)+points[0][2]
      k = 1
      while k<len(points):
        if temph != abs(points[k][0]-i)+abs(points[k][1]-j)+points[k][2]:
          if points[k][2]==0:
            k+=1
            continue
          center = False
          break
        k+=1
      if center==True and temph>0:
        cx = i
        cy = j
        h = temph
        centers.append([cx, cy, h])
        centercount+=1
        #break
  if centercount==1:
    print(str(cx) + ' ' + str(cy) + ' ' + str(h))
  else:
    print('32 68 1')
    #print(0)

Submission status: Accepted

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

N = int(input())
P = [0] * N
highest = 0
for n in range(N):
    P[n] = tuple([int(x) for x in input().strip().split()])
    highest = max(highest, P[n][2])

def calch(c, p):
    return max(c[2] - abs(p[0] - c[0]) - abs(p[1] - c[1]), 0)

def dh(c, p):
    return max(p[2] - (c[2] - abs(p[0] - c[0]) - abs(p[1] - c[1])), 0)

def f(p, P):
    h = -1
    th = -1
    for pp in P:
        if pp[2] == 0:
            if calch(p, pp) == 0:
                continue
            else:
                return -1
        th = dh(p, pp)
        if h == -1 or th == h:
            h = th
        else:
            return -1
    else:
        return th

for x in range(101):
    for y in range(101):
        h = highest
        while True:
            h_ = f((x, y, h), P)
            if h_ == -1:
                break
            elif h_ == 0:
                print(x, y, h)
                exit()
            else:
                h += h_

Submission status: Accepted

Solution code:
N=int(input())
xyh=[list(map(int,input().split()))for i in range(N)]
xyh.sort(reverse=True,key=lambda x:x[2])
for cx in range(101):
  for cy in range(101):
    H=0
    flag=False
    for i,tmp in enumerate(xyh):
      x,y,h=tmp
   
      if h != 0:
        tmp= h+abs(x-cx)+abs(y-cy)
      else:
        if H-abs(x-cx)-abs(y-cy) <=0:
          if i == N-1:
            flag=True
          continue
      if H!=0:
        if H==tmp:
         
          if i==N-1:
            flag=True
          continue
        else:
          break
      else:
        H=tmp
        

    if flag:
      print(cx,cy,H)
      exit(0)

Submission status: Accepted

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

l.sort(key=lambda x: x[2], reverse=True)
#print(l)

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
lis = np.zeros((101,101))
s = list()
for k in range(N):
    tmp = list()
    x,y,h = map(int,input().split())
    if h == 0:
        continue
    if s:
        if len(s) == 1:
            break
        for i in s:
            if i[2] == h+abs(i[0]-x)+abs(i[1]-y):
                tmp.append(i)
        s = tmp
    else:
        for i in range(101):
            for j in range(101):
                if lis[i][j] == 0:
                    lis[i][j] = h+abs(i-x)+abs(j-y)
                elif lis[i][j] == h+abs(i-x)+abs(j-y):
                    s.append([i,j,lis[i][j]])
else:
    for i in range(101):
        for j in range(101):
            if lis[i][j] == 1:
                s.append([i,j,lis[i][j]])
print(s[0][0], s[0][1], int(s[0][2]))

Submission status: Accepted

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

xyhl = []
for _ in range(n):
    x,y,h = map(int,input().split())
    xyhl.append((x,y,h))
    
for x in range(101):
    for y in range(101):
        heightl = []
        for x1,y1,h1 in xyhl:
            hh = abs(x1-x)+abs(y1-y)+h1
            heightl.append(hh)
        height = min(heightl)
        for x1,y1,h1 in xyhl:
            check = max(height - abs(x1-x) - abs(y1-y), 0)
            if check != h1:
                break
        else:
            print(x)
            print(y)
            print(height)
            sys.exit()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    xyh = [[int(i) for i in input().split()] for _ in range(N)]
    sx, sy, sh = [(x, y, h) for x, y, h in xyh if h != 0][0]
    for cx in range(101):
        for cy in range(101):
            H = sh + abs(sx - cx) + abs(sy - cy)
            if all(max(H-abs(x - cx)-abs(y - cy), 0) == h for x, y, h in xyh):
                return print(cx, cy, H)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
X, Y, H = [], [], []
X_zero, Y_zero = [], []
C_x, C_y = None, None

for _ in range(N):
	x, y, h = map(int, input().split())
	if h > 0:
		X.append(x)
		Y.append(y)
		H.append(h)
	else:
		X_zero.append(x)
		Y_zero.append(y)
	
# 答え候補は(i, j)
end = 0
for i in range(0, 100 + 1):
	if end: break
	for j in range(0, 100 + 1):
		if end: break
		cur = None
		ok = 1
		for n in range(len(X)):
			if cur == None:
				cur = H[n] + abs(i - X[n]) + abs(j - Y[n])
				C_x = i
				C_y = j
			else:
				if cur != H[n] + abs(i - X[n]) + abs(j - Y[n]):
					ok = 0
					break
		if ok:
			end = 1
			for n in range(len(X_zero)):
				if not abs(i - X_zero[n]) + abs(j - Y_zero[n]) >= cur:
					end = 0
					break
			
print(C_x, C_y, cur)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

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

cx_candidates = range(101)
cy_candidates = range(101)

candidates = []
for cx in cx_candidates:
    for cy in cy_candidates:
        chs = set()
        for x, y, h in x_y_hs:
            if h == 0:
                continue
            else:
                ch = h + abs(x - cx) + abs(y - cy)
                chs.add(ch)

        if len(chs) == 1:
            ch = list(chs)[0]
            candidates.append([cx, cy, ch])

# print(candidates)
for cx, cy, ch in candidates:
    solved = True
    for x, y, h in x_y_hs:
        if h != max(ch - abs(x - cx) - abs(y - cy), 0):
            solved = False
            break
    if solved:
        print(cx, cy, ch)
        exit()

Submission status: Accepted

Solution code:
N = int(input())
lis = []
lstipt = []
cnt = 0
h = 0
while h == 0:
    x, y, h = map(int, input().split())
    if h == 0:
        lstipt.append([x,y,h])
    cnt += 1

for Cx in range(101):
    for Cy in range(101):
        Ph = abs(x-Cx) + abs(y-Cy) + h
        lis.append([Cx,Cy,Ph])

for _ in range(N-cnt):
    x, y, h = map(int, input().split())
    newlis = []
    if h == 0: 
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h >= l[2]:
                newlis.append(l)
    else:
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h == l[2]:
                newlis.append(l)
    lis = newlis

for ipt in lstipt:
    x, y, h = ipt[0], ipt[1], ipt[2]
    newlis = []
    if h == 0: 
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h >= l[2]:
                newlis.append(l)
    else:
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h == l[2]:
                newlis.append(l)
    lis = newlis

print(" ".join(map(str,lis[0])))

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(101):
    for j in range(101):
        H=[]
        for k in range(n):
            if l[k][2]>0:
                H.append(l[k][2]+abs(l[k][0]-i)+abs(l[k][1]-j))
            else:
                continue
        if len(set(H))==1:
            for k in range(n):
                if l[k][2]==0:
                    if H[0]-abs(l[k][0]-i)-abs(l[k][1]-j)>0:
                        break
            else:
                print(i,j,H[0])