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:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
XYH = [tuple(map(int,input().split())) for _ in range(N)]

# 高さの降順にソートしておく
#  -> これをしないと 高さ 0 を基準に中心の高さを決めてしまう可能性があるので
XYH.sort(key=lambda x:x[2], reverse=True)

# 中心座標で全探索
for xi in range(101):
    for yi in range(101):
        flg = True
        x,y,h = XYH[0]
        # 中心の高さ
        hh0 = abs(xi-x) + abs(yi-y) + h
        for i in range(1,N):
            x,y,h = XYH[i]
            if h == 0:
                hhi = abs(xi-x) + abs(yi-y) + h
                if hh0 > hhi:
                    flg = False
                    break
            else:
                hhi = abs(xi-x) + abs(yi-y) + h
                if hh0 != hhi:
                    flg = False
                    break
        if flg:
            print(xi,yi,hh0)
            sys.exit()

Submission status: Accepted

Solution code:
n = int(input())
XYH = [tuple(map(int, input().split())) for _ in range(n)]
for cx in range(101):
    for cy in range(101):
        H = set()
        for x, y, h in XYH:
            if h == 0:
                continue
            H.add(h + abs(x - cx) + abs(y - cy))
        if len(H) != 1:
            continue
        H = list(H)[0]
        flag = True
        for x, y, h in XYH:
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                flag = False
                break
        if flag:
            print(cx, cy, H)

Submission status: Accepted

Solution code:
n = int(input())
XYH = [list(map(int, input().split())) for _ in range(n)]
XYH.sort(key=lambda x:x[2])
X, Y, H = XYH[-1]
for cx in range(101):
    for cy in range(101):
        h = H + abs(cx-X) + abs(cy-Y)
        flag = False
        for xyh in XYH:
            if xyh[2] != max(h-abs(cx-xyh[0])-abs(cy-xyh[1]), 0):
                flag = True
        if flag: continue
        print(cx, cy, h)

Submission status: Accepted

Solution code:
n = int(input())
XYH = [list(map(int, input().split())) for _ in range(n)]
XYH.sort(key=lambda x:x[2])
X, Y, H = XYH[-1]
for cx in range(101):
    for cy in range(101):
        h = H + abs(cx-X) + abs(cy-Y)
        flag = False
        for xyh in XYH:
            if xyh[2] != max(h-abs(cx-xyh[0])-abs(cy-xyh[1]), 0):
                flag = True
        if flag: continue
        print(cx, cy, h)
        exit()

Submission status: Accepted

Solution code:
N = int(input())
xyh = []
si = 0
for i in range(N):
    x, y, h = map(int, input().split())
    xyh.append([x,y,h])
    if h > 0:
        si = i

for cx in range(101):
    for cy in range(101):
        H = xyh[si][2] + abs(cx - xyh[si][0]) + abs(cy - xyh[si][1])
        ok = True
        for x,y,h in xyh:
            if h > 0 and H - h != abs(cx - x) + abs(cy - y):
                ok = False
            if h == 0 and H > abs(cx - x) + abs(cy - y):
                ok = False
        if ok:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh = sorted(xyh, key=lambda x:x[2])
ans = []
for i in range(101):
    for j in range(101):
        pre = xyh[-1][2] + abs(i-xyh[-1][0]) + abs(j-xyh[-1][1])
        valid = True
        for k in range(N):
            x, y, h = xyh[k]
            a = abs(x-i) + abs(y-j)
            if max(pre-a, 0) != h:
                valid = False

        if valid and pre >= 1:
            print(i, j, pre)
            exit()

Submission status: Accepted

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


def main():
    N = int(input())
    info0 = []
    info1 = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        if h == 0: info0.append((x, y))
        if h != 0: info1.append((x, y, h))

    for cx in range(101):
        for cy in range(101):
            H = -1
            for x, y, h in info1:
                wrong = False
                if h > 0 and H == -1:
                    H = h + abs(cx - x) + abs(cy - y)
                elif h > 0:
                    if H != h + abs(cx - x) + abs(cy - y):
                        wrong = True
                        break
            if wrong: continue
            for x, y in info0:
                wrong = False
                if abs(cx - x) + abs(cy - y) < H:
                    wrong = True
                    break
            if wrong: continue
            print("{} {} {}".format(cx, cy, H))
            exit()

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
ans=[[None]*101 for _ in range(101)] 
a=[[0]*3 for _ in range(n)] 

for i in range(n):
    a[i][0],a[i][1],a[i][2]=map(int,input().split())
a=sorted(a,key=lambda x: x[2],reverse=True)

for i in range(n):
    for cx in range(101):
        for cy in range(101):
            height=a[i][2]+abs(a[i][0]-cx)+abs(a[i][1]-cy)
            if a[i][2]>0:
                if ans[cx][cy]==None or ans[cx][cy]==height:
                    ans[cx][cy]=height
                else:
                    ans[cx][cy]=-1
            else:
                if ans[cx][cy]!=None:
                    if ans[cx][cy]>abs(a[i][0]-cx)+abs(a[i][1]-cy):
                        ans[cx][cy]=-1
                else:
                    ans[a[i][0]][a[i][1]]=-1
        

for cx in range(101):
    for cy in range(101):
        if ans[cx][cy]!=-1:
            if ans[cx][cy]==None: 
                ans[cx][cy]=1
            print(cx,cy,ans[cx][cy])

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()

data = []
for i in range(N):
  x,y,h = IL()
  data.append((x,y,h))

data = sorted(data, lambda x:x[2])

import itertools
x,y,h = data.pop()
dic = {(i,j):h+(abs(i-x)+abs(j-y))  for i,j in itertools.product(range(101),repeat=2)}

while len(dic)>1:
  x,y,h = data.pop()
  for i,j in itertools.product(range(101),repeat=2):
    if (i,j) in dic:
      if h > 0:
        if dic[(i,j)] != h+(abs(i-x)+abs(j-y)):
          dic.pop((i,j))
      else:
        if dic[(i,j)] > h+(abs(i-x)+abs(j-y)):
          dic.pop((i,j))

ans = [k for k in dic][0]

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

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda f:f[2])
p=xyh[-1]
for cx in range(0,101):
  for cy in range(0,101):
    h=p[2]+abs(p[0]-cx)+abs(p[1]-cy)
    for u in xyh:
      if u[2]!=max(0,h-abs(u[0]-cx)-abs(u[1]-cy)):
        break
    else:
      print(cx,cy,h)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [tuple(map(int, input().split())) for _ in range(N)]
for x in xyh:
    if x[2] > 0:
        base = x
        break
for i in range(101):
    for j in range(101):
        h = base[2] + abs(i-base[0]) + abs(j-base[1])
        for x in xyh:
            if x[2] != max(h-abs(i-x[0])-abs(j-x[1]),0):
                break
        else:
            print(i,j,h)
            exit()

Submission status: Accepted

Solution code:
def resolve():
    n=int(input())
    xyh=[[0]*3 for _ in range(n)]
    for i in range(n):
        x,y,h=map(int,input().split())
        xyh[i][0],xyh[i][1],xyh[i][2]=h,x,y
    xyh.sort(reverse=True)
    ans,flg=0,0
    for cx in range(101):
        for cy in range(101):        
            ans,flg=0,0
            for h,x,y in xyh:
                if ans==0:
                    if h==0:
                        continue
                    else:
                        ans=h+abs(x-cx)+abs(y-cy)
                else:
                    if h==0:
                        if ans>abs(x-cx)+abs(y-cy):
                            flg=1
                            break
                        else:
                            continue
                    else:
                        if ans==h+abs(x-cx)+abs(y-cy):
                            continue
                        else:
                            flg=1
                            break
            if flg==0:
                break
        if flg==0:
            break
    print(cx,cy,ans)            

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
# C - Pyramid

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

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

for cx in range(101):
    for cy in range(101):
        (x, y, h) = XYH[0]
        tmp_H = h + abs(x - cx) + abs(y - cy)
        for (x, y, h) in XYH:
            if h != max(tmp_H - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            ans = (cx, cy, tmp_H)
            break

print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]
XYH.sort(key=lambda x:x[2], reverse=True)
isOk = False
cx = 0
while cx <= 100:
  cy = 0
  while cy <= 100:
    x, y, h = XYH[0]
    H = h+abs(x-cx)+abs(y-cy)
    i = 1
    isOk = True
    while i < N and isOk:
      x, y, h = XYH[i]
      if max(H-abs(x-cx)-abs(y-cy),0) != h:
        isOk = False
      i += 1
    if isOk:
      break
    cy += 1
  if isOk:
    break
  cx += 1
print(cx, cy, H)

Submission status: Accepted

Solution code:
N = int(input())

infos = []
first_info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0 and len(first_info) == 0:
        first_info = [x, y, h]
    else:
        infos.append([x, y, h])


# cxとcyを1つに絞り込む
x1, y1, h1 = first_info
for cx in range(101):
    for cy in range(101):
        isValid = True
        H = h1 + abs(x1-cx) + abs(y1-cy)
        for x2, y2, h2 in infos:
            if h2 != max(H - abs(x2-cx) - abs(y2-cy), 0):
                isValid = False

        if isValid:
            ans = [cx, cy]

cx, cy = ans
H = h1 + abs(x1-cx) + abs(y1-cy)
print(cx, cy, H)

Submission status: Accepted

Solution code:
def main():
    points = int(input())
    info = []
    for _ in range(points):
        info.append(list(map(int, input().split())))
    info.sort(key=lambda x: x[2], reverse=True)
    is_answered = False
    for x in range(101):
        if is_answered:
            break
        for y in range(101):
            now_height = abs(x - info[0][0]) + abs(y - info[0][1]) + info[0][2]
            if all(info[i][2] == max(now_height - abs(x - info[i][0]) - abs(y - info[i][1]), 0) for i in range(1, points)):
                if now_height > 0:
                    print(x, y, now_height)
                    is_answered = True
                    break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
info = [list(map(int, input().split())) for _ in range(n)]
for Cx in range(101):
    for Cy in range(101):
        flag = False
        check = []
        for x, y, h in info:
            if h == 0:
                continue
            check.append(h+abs(x-Cx)+abs(y-Cy))
        if len(set(check)) == 1:
            flag = True
            ans_h = check[0]
            for x, y, h in info:
                if h != max(ans_h-abs(x-Cx)-abs(y-Cy), 0):
                    flag = False
        if flag:
            print(Cx, Cy, ans_h)
            exit()

Submission status: Accepted

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


def main():
    N = int(input())
    x = [None] * N
    y = [None] * N
    h = [None] * N
    for i in range(N):
        x[i], y[i], h[i] = map(int, input().split())
    
    # Cx, Cyを全探索する
    for i in range(101):
        for j in range(101):
            flag = True
            maxH = 10**12
            H = set()
            for k in range(N):
                if h[k] == 0:
                    maxH = min(maxH, abs(x[k]-i) + abs(y[k]-j))
                else:
                    tmpH = h[k] + abs(x[k]-i) + abs(y[k]-j)
                    H.add(tmpH)
                    if len(H) > 1:
                        flag = False
                        break
            if flag and list(H)[0] <= maxH:
                print(i,j,list(H)[0])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
x_y_h_list = []
for i in range(n):
  x_y_h_list.append(list(map(int,input().split())))
x_y_h_list.sort(key=lambda x: x[2],reverse = True)
result = []
for x in range(101):
  for y in range(101):
    H = -1
    check = True
    for x_y_h in x_y_h_list:     
      if H == -1:
        H = x_y_h[2] + abs(x_y_h[0] - x) + abs(x_y_h[1] - y)
      else:
        if x_y_h[2] != 0:
          if H != x_y_h[2] + abs(x_y_h[0] - x) + abs(x_y_h[1] - y):
            check = False
            break
        else:
          if H > abs(x_y_h[0] - x) + abs(x_y_h[1] - y):
            check = False
            break
    if check == True:
      print(x,y,H)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
info = []
for i in range(N):
    x, y, h = getNM()
    info.append([x, y, h])
info.sort(reverse = True,key = lambda info:info[2])

ans = []
for i in range(101):
    for j in range(101):
        height = -1
        flag = True
        for k in range(N):
            minusx = abs(i - info[k][0])
            minusy = abs(j - info[k][1])
            if height == -1:
                # 上で逆順にソートしてるので確実に１以上の高さがでる
                height = info[k][2] + minusx + minusy
            else:
                # 問題の式に沿うように
                if info[k][2] != max(height - minusx - minusy, 0):
                    flag = False
                    break
        if flag:
            ans = [i, j, height]
print(*ans)

Submission status: Accepted

Solution code:



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



HXY.sort(reverse=True)

for cx in range(101):
    for cy in range(101):
        H = HXY[0][0] + abs(HXY[0][1] - cx) + abs(HXY[0][2] - cy)
        is_valid = True
        for h,x,y in HXY:
            if h == max(H - abs(x - cx) - abs(y - cy), 0):
                continue
            else:
                is_valid = False
                break
        if is_valid:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
XYH = TIR(n)
XYH.sort(key=itemgetter(2), reverse=True)
H = INF
CX = INF
CY = INF
for cx in range(100+1):
    for cy in range(100+1):
        tmp = INF
        for x, y, h in XYH:
            if tmp == INF:
                tmp = h+abs(x-cx)+abs(y-cy)
            elif h != max(tmp - abs(x-cx) - abs(y-cy), 0):
                break
        else:
            H = tmp
            CX = cx
            CY = cy
print("{} {} {}".format(CX, CY, H))

Submission status: Accepted

Solution code:
N=int(input())
lst=[0 for f in range(N)]
for i in range(N):
 lst[i]= list(map(int,input().split()))
lst.sort(key=lambda x: x[2], reverse=True)
for i in range(101):
 for j in range(101):
  h=abs(i-lst[0][0])+abs(j-lst[0][1])+lst[0][2]
  if h==10**9 and N==1:
   ans=[lst[0][0],lst[0][1],lst[0][2]]
  else:
   t=0
   for k in range(N-1):
    if max(h-abs(i-lst[k+1][0])-abs(j-lst[k+1][1]),0)==lst[k+1][2]:
     t+=1
   if t==N-1:
    ans=[i,j,h]
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
lp = []

for i in range(N):
    p = list(map(int,input().split()))
    lp.append(p)

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


def check(cx,cy, lp):
    is_center = True
    ch = lp[0][2] + abs(cx - lp[0][0]) + abs(cy - lp[0][1])
    for p in lp[1:]:
        x,y,h = p
        if h:
            chp = h + abs(cx - x) + abs(cy - y)
            if ch != chp:
                is_center = False
                break
        else:
            if (ch-abs(cx - x) - abs(cy-y)) > 0:
                is_center = False
                break

    return is_center, ch


if N == 1:
    print(p)
else:
    for i in range(101):
        for j in range(101):
            is_center, h = check(i,j, lp)
            if is_center:
                print(i,j,h)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=[]
for i in range(n):
    lis.append(LI())
lis.sort(key=lambda x:x[2],reverse=True)
x1,y1,h1,x2,y2,h2=lis[0][0],lis[0][1],lis[0][2],lis[1][0],lis[1][1],lis[1][2]
cand=[]
    
for i in range(101):
    for j in range(101):
        H=h1+abs(i-x1)+abs(j-y1)
        cand.append([i,j,H])
#print(cand)

candx=[]
for j in range(len(cand)):
    H=cand[j][2]
    count=0
    #print(H)
    for i in range(1,n):
        if max(H-abs(cand[j][0]-lis[i][0])-abs(cand[j][1]-lis[i][1]),0)==lis[i][2]:
            count+=1
    #print(count)
    if count==n-1:
        candx.append([cand[j][0],cand[j][1],H])
print(*candx[0])
'''for li in candx:
    flag=True
    for i in range(n):
        if lis[i][2]<0:
            if -abs(li[0]-lis[i][0])-abs(li[1]-lis[i][1])+li[2]>=0:
                flag=False
    if flag==True:
        print(*li)
        sys.exit()'''

Submission status: Accepted

Solution code:
n = int(input())

TABLES = []
H = []
for _ in range(n):
    x, y, h = map(int, input().split())
    TABLE = [[0] * 101 for _ in range(101)]
    for i in range(101):
        for j in range(101):
            TABLE[i][j] = h + abs(x - i) + abs(y - j)
    TABLES.append(TABLE)
    H.append(h)

for k in range(n):
    if H[k] != 0:
        a = k
        break

for i in range(101):
    for j in range(101):
        temp = TABLES[a][i][j]
        flag = True
        for k in range(n):
            if H[k] == 0:
                if TABLES[k][i][j] < temp:
                    flag = False
                    break
            else:
                if TABLES[k][i][j] != temp:
                    flag = False
                    break
        if flag:
            print(i, j, temp)
            exit()

Submission status: Accepted

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

for x in range(101):
    for y in range(101):
        hmax = 0
        for item in xyh:
            if item[2] > 0:
                hmax = item[2] + abs(x - item[0]) + abs(y - item[1])
                break
        is_ok = True
        for item in xyh:
            if max(0, hmax - abs(x - item[0]) - abs(y - item[1])) != item[2]:
                is_ok = False
        if is_ok:
            print(x, y, hmax)
            exit()

Submission status: Accepted

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

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

for i in range(101):
  for j in range(101):
    ans=[]
    for k in t:
      d = abs(k[0]-i)+ abs(k[1]-j)
      h_tmp = d + k[2]
      if ans==[]:
        ans.append(k+[d,h_tmp])
      else:
        if d>ans[-1][-1] and k[2]==0:
          pass
        else:
          if h_tmp!=ans[-1][-1]:
            break
    else:
      print(i,j,ans[-1][-1])
      exit()

Submission status: Accepted

Solution code:
n=int(input())
data=[list(map(int,input().split())) for i in range(n)]
data.sort(key=lambda x:x[2],reverse=True)
def cal(y,x,datum,height):
  return max(height-(abs(y-datum[1])+abs(x-datum[0])),0)==datum[2]
for i in range(101):
  for j in range(101):
    height=abs(i-data[0][1])+abs(j-data[0][0])+data[0][2]
    flag=0
    for k in data[1:]:
      if not cal(i,j,k,height):
        flag=1
        break
    if flag:pass
    else:print(j,i,height);exit()

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
a=[]
for x in range(101):
  for y in range(101):
    c=[]
    for t in l:
      if t[2]:
        c.append(t[2]+abs(x-t[0])+abs(y-t[1]))
    f=0
    if len(set(c))==1:
      f=1
      h=c[0]
      for t in l:
        if t[2]==0:
          if h-abs(x-t[0])-abs(y-t[1])>0:
            f=0
    if f:
      print(x,y,h)
      exit()

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
XYH=[tuple(map(int,input().split())) for i in range(n)]
XYH.sort(key=itemgetter(2),reverse=True)
for cy in range(101):
    for cx in range(101):
        hc=XYH[0][2]+abs(cx-XYH[0][0])+abs(cy-XYH[0][1])
        for x,y,h in XYH[1:]:
            if h!=max(0,hc-abs(x-cx)-abs(y-cy)):
                break
        else:
            print(cx,cy,hc)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from operator import itemgetter
def main():
    n=int(input())
    XYH=[tuple(map(int,input().split())) for i in range(n)]
    XYH.sort(key=itemgetter(2),reverse=True)
    for cy in range(101):
        for cx in range(101):
            hc=XYH[0][2]+abs(cx-XYH[0][0])+abs(cy-XYH[0][1])
            for x,y,h in XYH[1:]:
                if h!=max(0,hc-abs(x-cx)-abs(y-cy)):
                    break
            else:
                print(cx,cy,hc)
                sys.exit()

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from operator import itemgetter
def main():
    n=int(input())
    XYH=[tuple(map(int,input().split())) for i in range(n)]
    XYH.sort(key=itemgetter(2),reverse=True)
    for cy in range(101):
        for cx in range(101):
            hc=XYH[0][2]+abs(cx-XYH[0][0])+abs(cy-XYH[0][1])
            for x,y,h in XYH:
                if h!=max(0,hc-abs(x-cx)-abs(y-cy)):
                    break
            else:
                print(cx,cy,hc)
                sys.exit()

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
z = [[0] * 101 for _ in range(101)]
xyh = [tuple(map(int, input().split())) for _ in range(n)]
xyh = sorted(xyh, key=lambda x: x[2], reverse=True)

for xi in range(101):
    for yi in range(101):
        hi = 0
        allok = True
        for i in range(n):
            x,y,h = xyh[i]
            if i == 0:
                hi = abs(xi - x) + abs(yi - y) + h
            if max(hi - abs(xi - x) - abs(yi - y), 0) != h:
                allok = False
        if allok:
            print(xi, yi, hi)
            exit()

Submission status: Accepted

Solution code:
n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]
xyh.sort(key=lambda x: x[2], reverse=True)
#print(xyh)
for cx in range(101):
    for cy in range(101):
        c = (cx, cy)
        count = 0
        H = 0
        for x, y, h in xyh:
            if count == 0:
                H = h+abs(x-cx)+abs(y-cy)
                count = 1
            else:
                if h != max(H-abs(x-cx)-abs(y-cy), 0):
                    break
        else:
            ans = [cx, cy, H]
            print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
xyh = []
for i in range(n):
    xyh.append(list(map(int,input().split())))
H = []
for cx in range(0,101):
    for cy in range(0,101):
        hantei = False
        for i in range(n):
            if xyh[i][2] > 0:
                if not H:
                    H.append(xyh[i][2] + abs(cx-xyh[i][0]) + abs(cy-xyh[i][1]))
                else:
                    hantei = True
                    if xyh[i][2] + abs(cx-xyh[i][0]) + abs(cy-xyh[i][1]) != H[0]:
                        H.pop(0)
                        break
        else:
            if hantei: 
                print(cx,cy,H[0])
                exit()
else:
    mx = 0
    for i in range(n):
        if mx < xyh[i][2]:
            ansind = i
            mx = xyh[i][2]
    print(xyh[ansind][0],xyh[ansind][1],xyh[ansind][2])

Submission status: Accepted

Solution code:
N = int(input())

Point = []
for _ in range(N):
    Point.append(tuple(map(int, input().split())))
Point.sort(key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        x, y, h = Point[0]
        H = h + abs(x-cx) + abs(y-cy)
        flag = True
        for i in range(1,N):
            nx, ny, nh = Point[i]
            if max(H - abs(nx-cx) - abs(ny-cy),0) != nh:
                flag = False
                break
        if flag:
            print(cx, end=' ')
            print(cy, end=' ')
            print(H, end=' ')
            exit()