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:
# coding: utf-8

# https://atcoder.jp/contests/abc112


def main():
    N = int(input())

    x, y, h = [None] * N, [None] * N, [None] * N

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

    for cx in range(0, 101):
        for cy in range(0, 101):
            first = True
            notans = False
            for i in range(N):
                # print(cx, cy, i)
                if h[i] > 0:
                    H = h[i] + abs(x[i]-cx) + abs(y[i]-cy)
                    if first:
                        first = False
                        pre_H = H
                    else:
                        if H != pre_H:
                            break
            if H == pre_H:
                for i in range(N):
                    if h[i] == 0:
                        if H - abs(x[i]-cx) - abs(y[i]-cy) > 0:
                            notans = True
                            break

                if notans:
                    continue

                print(cx, cy, H)
                return None


main()
# print(main())

Submission status: Accepted

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

def solve(N: int, X: "List[int]", Y: "List[int]", H: "List[int]"):
    def calc_h(cx, cy):
        h = None
        for xx, yy, hh in filter(lambda xyh: xyh[2]>0, zip(X, Y, H)):
            th = hh + abs(cx - xx) + abs(cy - yy)
            if h is not None and th != h:
                return None
            h = th
        h = h if h else 1
        for xx, yy, _ in filter(lambda xyh: xyh[2]==0, zip(X, Y, H)):
            if abs(cx - xx) + abs(cy - yy) < h:
                return None
        return h

    for cx in range(101):
        for cy in range(101):
            h = calc_h(cx, cy)
            if h is not None:
                return cx, cy, h


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    h = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        h[i] = int(next(tokens))
    print(*solve(N, x, y, h))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
def k(H,cx,cy,f):
    for x,y,h in f:
        if h==max(H-abs(x-cx)-abs(y-cy),0):
            continue
        else:
            return
    print(cx,cy,H)
    exit()
for x,y,h in f:
    if h==0:
        continue
    for cx in range(101):
        for cy in range(101):
            H=h+abs(x-cx)+abs(y-cy)
            k(H,cx,cy,f)

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
data = []
for _ in range(n):
    x,y,h = map(int,input().split())
    data.append((x,y,h))
data.sort(key=itemgetter(2),reverse=True)
for x in range(101):
    for y in range(101):
        c = -1
        for a,b,h in data:
            if c == -1:
                c = h+abs(a-x)+abs(b-y)
            else:
                if h != max(c-abs(a-x)-abs(y-b),0):
                    break
        else:
            print(x,y,c)
            exit()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    
    P = set()
    for i in range(n):
        x,y,h = map(int,input().split())
        if h != 0:
            P.add((x,y,h))
    x,y,h = P.pop()
    if not P:
        return x,y,h
    for cx in range(101):
        for cy in range(101):
            H = h + abs(x-cx) + abs(y-cy)
            for p in P:
                if H != p[2] + abs(p[0]-cx) + abs(p[1]-cy):
                    break
            else:
                return cx,cy,H
        
if __name__ == '__main__':
    print(*(solve()))

Submission status: Accepted

Solution code:
N = int(input())

d = {}
l = []
p = 0

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

while True:
  if(l[0][2] == 0):
    l.append(l[0])
    del l[0]
  else:
    x, y, h= l[0]
    for i in range(101):
      for j in range(101):
        d[(i, j)] = abs(i- x)+ abs(j- y)+ h
    break

for k in range(N- 1):
  x, y, h = l[k+ 1]
  if(h == 0):
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)]- abs(i- x)- abs(j- y)> 0):
            del d[(i, j)]
  else:
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)] != abs(i- x)+ abs(j- y)+ h):
            del d[(i, j)]

zahyou, height = list(d.items())[0]
  
print("{0[0]} {0[1]} {1}".format(zahyou, height))

Submission status: Accepted

Solution code:
n = int(input())
low = 0
hi = 10**9

li = []
lin = []

for _ in range(n):
    x,y,h = map(int,input().split())
    if h != 0:
        li.append((x,y,h))
    lin.append((x,y,h))

for i in range(101):
    for j in range(101):
        flag = True
        h = li[0][2]+abs(i-li[0][0])+abs(j-li[0][1])
        for a,b,c in lin:
            if max(h-abs(i-a)-abs(j-b),0) != c:
                flag = False
                break
        if flag:
            print(i,j,h)
            exit()

Submission status: Accepted

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

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

for i in range(101):
    for j in range(101):
        ref = l[-1][2] + abs(l[-1][0] - i) + abs (l[-1][1] - j)
        for k in range(n):
            if l[k][2] == max(0, ref - abs(l[k][0] - i) - abs (l[k][1] - j)):
                continue
            else:
                break
        else:
            print(i, j, ref)
            exit()

Submission status: Accepted

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

for x, y, h in xyh:
    if h!= 0:
        x0, y0, h0 = (x, y, h)
        break

for i in range(101):
    for j in range(101):
        res = 1
        for x, y, h in xyh:
            if h == max(h0+abs(x0-i)+abs(y0-j)-abs(x-i)-abs(y-j), 0):
                res *= 1
            else:
                res *= 0
        if res:
            print(i, j, h0 + abs(x0-i) + abs(y0-j))
            exit()

Submission status: Accepted

Solution code:
import sys

# 解説カンニング済み

N = int(input())
xs = []
ys = []
hs = []
reference = None
for i in range(N):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)
    # 地面でないことが分かっている(ピラミッド内のサンプル)を1つ選ぶ
    if h > 0:
        reference = (x, y, h)

for cx in range(0, 100+1):
    for cy in range(0, 100+1):
        # サンプルの高さを求める
        rx, ry, rh = reference
        ref_H = rh + abs(rx-cx) + abs(ry-cy)
        # 他のデータも全てサンプルと合致するか検証する
        ok = True
        for i in range(N):
            calc_H = max(ref_H - abs(xs[i]-cx) - abs(ys[i]-cy), 0)
            if calc_H != hs[i]:
                ok = False
                break
        if ok:
            print(cx, cy, ref_H)
            sys.exit(0)

Submission status: Accepted

Solution code:
N=int(input())
x=[]
y=[]
h=[]
for i in range(N):
  a,b,c=map(int,input().split())
  x.append(a)
  y.append(b)
  h.append(c)
field=[[-1 for i in range(101)] for i in range(101)]
for i in range(N):
  for j in range(101):
    for k in range(101):
      if(h[i]!=0):
        if(field[j][k]==-1):
          field[j][k]=h[i]+abs(j-x[i])+abs(k-y[i])
        elif(field[j][k]!=h[i]+abs(j-x[i])+abs(k-y[i])):
          field[j][k]=-2
      else:
        if(field[j][k]>h[i]+abs(j-x[i])+abs(k-y[i])):
          field[j][k]=-2
cx=0
cy=0
H=0
for i in range(101):
  for j in range(101):
    if(field[i][j]>=0):
      cx=i
      cy=j
      H=field[i][j]
print(cx,cy,H)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
xyh = LI(n)

xyh = mysort(xyh,2,True)
# pprint(xyh)

for i in range(101):
    for j in range(101):
        flag = True
        for k in range(n):
            x = xyh[k][0]
            y = xyh[k][1]
            h = xyh[k][2]
            if k==0: 
                H = h + abs(x-i) + abs(y-j)
            elif k==(n-1):
                l = max( H - abs(x-i) - abs(y-j), 0 )
                if l==h:
                    ans = [i,j,H]
                else:
                    flag = False
            else:
                l = max( H - abs(x-i) - abs(y-j), 0 )
                if l==h:
                    pass
                else:
                    flag = False
        if flag:
            myoutput(ans,True)
            exit()
        else:
            continue
exit()

Submission status: Accepted

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

xyh.sort(key=lambda x:x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        H = abs(x - cx) + abs(y - cy) + h
        f = True

        for i in range(1, n):
            x, y, h = xyh[i]
            h2 = max(0, H - abs(x - cx) - abs(y - cy))
            if h != h2:
                f = False
                break

        if f:
            ans = (cx, cy, H)

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

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x:x[2],reverse=True)
sx,sy,sh=l[0]
for xx in range(0,101):
  for yy in range(0,101):
    hh=sh+abs(sx-xx)+abs(sy-yy)
    for ll in l[1:]:
      if ll[2]!=max(0,hh-abs(ll[0]-xx)-abs(ll[1]-yy)):
        break
    else:
      print(xx,yy,hh)

Submission status: Accepted

Solution code:
n=int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
max_h = 0
max_x = 0
max_y = 0
for p,q,h in xy:
    if max_h < h:
        max_h = h
        max_x = p
        max_y = q

for top_x in range(101):
    for top_y in range(101):
        top_h = abs(max_x-top_x)+abs(max_y-top_y)+max_h
        for x,y,h in xy:
            if max(top_h-abs(top_x-x)-abs(top_y-y),0) != h:
                break
        else:
            print(top_x,top_y,top_h)
            exit()

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
P = []
for _ in range(N):
    x, y, h = list(map(int, input().split()))
    P.append([x, y, h])
    if h != 0:
        tx, ty, th = x, y, h


for cx in range(101):
    for cy in range(101):
        H = th + abs(tx-cx)+abs(ty-cy)
        if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P):
            print(cx, cy, H)
            exit(0)

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


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

for i in range(N):
    x, y, h = P[i]
    for cx in range(101):
        for cy in range(101):
            H = h + abs(x-cx)+abs(y-cy)
            if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P):
                print(cx, cy, H)
                exit(0)

Submission status: Accepted

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

found = False
for i in range(len(P)):
    x, y, h = P[i]
    for cy in range(101):
        for cx in range(101):
            H = h + abs(x - cx) + abs(y - cy)
            if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in P):
                print(cx, cy, H)
                found = True
                break
        if found:
            break
    if found:
        break

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
XYZ = [list(map(int, input().split())) for _ in range(N)]

XYZ.sort(key=itemgetter(2), reverse=True)

for x in range(101):
    for y in range(0, 101):
        H = XYZ[0][2]+abs(XYZ[0][0]-x)+abs(XYZ[0][1]-y)
        judge = True
        for xyz in XYZ[1:]:
            if xyz[2] == max(H-abs(xyz[0]-x)-abs(xyz[1]-y),0):
                pass
            else:
                judge = False
                break
        if judge:
            X = x
            Y = y
            break
    if judge:
        break
print(X, Y, H)

Submission status: Accepted

Solution code:
n = int(input())

x = []
y = []
h = []
u = 0
for i in range(n):
    a = list(map(int, input().split(' ')))
    x.append(a[0])
    y.append(a[1])
    h.append(a[2])
    if h[i] > 0:
        u = i

for cx in range(101):
    for cy in range(101):
        H = abs(cx - x[u]) + abs(cy - y[u]) + h[u]
        ok = True
        for i in range(n):
            ok &= max(H - abs(cx - x[i]) - abs(cy - y[i]), 0) == h[i]
        if ok:
            print(cx, cy, H)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
xyh = []
for _ in range(n):
    xyh.append(list(map(int, input().split())))
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = None
        maxh = 10**10
        for x, y, h in xyh:
            if h == 0:
                maxh = min(maxh, abs(x - cx) + abs(y - cy))
            else:
                if H is None:
                    H = h + abs(x - cx) + abs(y - cy)
                    if H > maxh:
                        flag = 0
                        break
                else:
                    if H != h + abs(x - cx) + abs(y - cy):
                        flag = 0
                        break
        if flag and H <= maxh:
            print(cx, cy, H)
            sys.exit()

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

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

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
x = [];y=[];h=[]
sh = -1
for i in range(n):
    xa,ya,ha = readInts()
    x.append(xa);y.append(ya);h.append(ha);
    if ha > 0:
        sh = i
# CxとCyを特定しておく すべてにおいて合致するかを考える
resx = -1;resy =-1;resh=-1;
for Cx in range(101):
    for Cy in range(101):
        ok = True
        H = h[sh] + abs(x[sh] - Cx) + abs(y[sh] - Cy)
        # 全操作して合致するようにする
        for i in range(n):
            if h[i] == 0:
                if H > abs(x[i] - Cx) + abs(y[i] - Cy):
                    ok = False
                    break
            elif h[i] > 0:
                if H -h[i] !=  abs(x[i] - Cx) + abs(y[i] - Cy):
                    ok = False
                    break
        if ok:
            resx = Cx;resy = Cy;resh = H;

print(resx,resy,resh)

Submission status: Accepted

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

cands = []
for cx in range(101):
    for cy in range(101):
        ch = None
        for x,y,h in XYH:
            if h==0: continue
            d = abs(cx-x) + abs(cy-y)
            if ch is None:
                ch = h + d
            else:
                if h + d != ch:
                    break
        else:
            cands.append((cx,cy,ch))

for cx,cy,ch in cands:
    for x,y,h in XYH:
        d = abs(cx-x) + abs(cy-y)
        if h != max(ch - d, 0):
            break
    else:
        print(cx,cy,ch)
        exit()

Submission status: Accepted

Solution code:
def check(X,Y):
    Hs = []
    for x,y,h in xyh:
        if h > 0:
            H = h + abs(x-X) + abs(y-Y)
            Hs.append(H)
        else:
            H = Hs[0]
            if abs(x-X) + abs(y-Y) < H:
                return False
    
    if len(set(Hs)) == 1:
        print(X,Y,Hs[0])
        return True
    else:
        return False

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

for i in range(101):
    for j in range(101):
        if check(i,j):
            exit()

Submission status: Accepted

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

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

for cx in range(101):
    for cy in range(101):
        x0, y0, h0 = xyh[0]
        H = h0+abs(x0-cx)+abs(y0-cy)
        flag = True
        
        for x, y, h in xyh:
            h2 = max(H-abs(x-cx)-abs(y-cy), 0)
            
            if h!=h2:
                flag = False
                
        if flag:
            print(cx, cy, H)
            exit()

Submission status: Accepted

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

for h in range(P[0][2],P[0][2]+201):
    for x in range(101):
        for y in range(101):
            f = 1
            for e in P:
                if e[2] != max(0,h-abs(e[0]-x)-abs(e[1]-y)):
                    f = 0
                    break
            if f == 1:
                print(x,y,h)
                exit(0)

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 i in range(101):
    for j in range(101):
        H = -1
        for k in range(n):
            h, x, y = HXY[k]
            if h > 0:
                temp = h + abs(x-i) + abs(y-j)
                if H > 0:
                    if H != temp:
                        break
                else:
                    H = temp
            else:
                if H - abs(x-i) - abs(y-j) > 0:
                    break
        else:
            if H > 0:
                print(i, j, H)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[2],reverse=True)
for x in range(101):
    for y in range(101):
        a,b,h = A[0]
        H = h+abs(x-a)+abs(y-b)
        flag = 1
        for i in range(1,N):
            a,b,h = A[i]
            if max(0,H-abs(x-a)-abs(y-b))==h:continue
            else:
                flag = 0
                break
        if flag==1:
            cx = x
            cy = y
            break
    if flag==1:break
print(cx,cy,H)

Submission status: Accepted

Solution code:
n = int(input())
lst = []
for i in range(n):
    xi, yi, hi = map(int, input().split())
    lst.append([xi, yi, hi])

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

for cx in range(101):
    for cy in range(101):
        h = -1
        for i in range(n):
            xi, yi, hi = lst[i]
            if h == -1:
                h = hi + abs(xi-cx) + abs(yi-cy)
                continue
            if hi != max(h - abs(xi-cx) - abs(yi-cy), 0):
                h = -1
                break
        if h != -1:
            print(cx, cy, h)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
XYH = [tuple(map(int, input().split())) for _ in range(N)]
bx, by, bh = [xyh for xyh in XYH if xyh[2] > 0][0]

def solve(cx, cy):
    H = abs(cx - bx) + abs(cy - by) + bh

    for x, y, h in XYH:
        D = max(0, H - abs(cx - x) - abs(cy - y))
        if D != h:
            return 0
    return H

for x in range(101):
    for y in range(101):
        h = solve(x, y)
        if h > 0:
            print(x, y, h)
            exit()

print(-1)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
xyh = [LIST() for _ in range(N)]

for x, y, h in xyh:
	if h >= 1:
		tmp = (x, y, h)

for i in range(101):
	for j in range(101):
		x_, y_, h_ = tmp
		H = h_ + abs(i-x_) + abs(j-y_)

		for x, y, h in xyh:
			if max(H-abs(x-i)-abs(y-j), 0) != h:
				break
		else:
			print(i, j, H)
			exit()

Submission status: Accepted

Solution code:
n = int(input())
kouho = [list(map(int,input().split())) for i in range(n)]
kouho = sorted(kouho,key=lambda x :x[2],reverse=True)

for cx in range(101):
    for cy in range(101):
        h = kouho[0][2] + abs(kouho[0][0]-cx) + abs(kouho[0][1]-cy)
        flag = False
        for i in range(1,n):
            now = max(h - abs(kouho[i][0]-cx) - abs(kouho[i][1]-cy),0)
            if now != kouho[i][2]:
                flag = True
                break
        if not flag:
            print(str(cx) + " " + str(cy) + " " + str(h))
            exit()

Submission status: Accepted

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

flag=0
for Cx in range(101):
    for Cy in range(101):
        Hcands = []
        for i in range(N):
            X = XYH[i][0]
            Y = XYH[i][1]
            h = XYH[i][2]
            if h>0:
                Hcand = abs(Cx-X)+abs(Cy-Y)+h
                break
        for i in range(N):
            X = XYH[i][0]
            Y = XYH[i][1]
            h = XYH[i][2]
            if h != max(Hcand-abs(Cx-X)-abs(Cy-Y), 0):
                flag=0
                break
            else:
                flag=1
        if flag==1:
            print(Cx,Cy,Hcand)
            break
    if flag==1:
        break

Submission status: Accepted

Solution code:
n = int(input())
info = [list(map(int, input().split())) for _ in range(n)]
for i in info:
    if i[2] > 0:
        x, y, h = i[0], i[1], i[2]
        break
for i in range(101):
    for j in range(101):
        H = h + abs(x - i) + abs(y - j)
        if all(max(H - abs(k[0] - i) - abs(k[1] - j), 0) == k[2] for k in info):
            print(i, j, H)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
xyh = [LIST() for _ in range(N)]
ins = (-1, -1, -1)

for x, y, h in xyh:
	if h >= 1:
		ins = (x, y, h)

x1, y1, h1 = ins   # h>=1 の条件中の任意の(x, y, h)

for Cx in range(101):
	for Cy in range(101):
		H = h1 + abs(x1-Cx) + abs(y1-Cy)  #Hは条件中の任意の(x, y, h)で決定できる。
		for x, y, h in xyh:
			if max(H-abs(x-Cx)-abs(y-Cy), 0) != h:
				break
		else:
			print(Cx, Cy, H)
			exit()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
xyh = [LIST() for _ in range(N)]
xyh.sort(key = lambda x:[x[0], x[1]])

for Cx in range(101):
	for Cy in range(101):
		H = 0
		H_max = INF
		for x, y, h in xyh:
			if h == 0:
				H_max = min(H_max, h + abs(x-Cx) + abs(y-Cy))
			else:
				if H == 0:
					H = h + abs(x-Cx) + abs(y-Cy)
				else:
					if H != h + abs(x-Cx) + abs(y-Cy):
						break
		else:
			if H <= H_max:
				print(Cx, Cy, H)
				break
	else:
		continue
	break

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
xyh = [LIST() for _ in range(N)]

h_dict = defaultdict(int)
xyh.sort(key = lambda x:[x[0], x[1]])

for Cx in range(101):
	for Cy in range(101):
		H = 0
		H_max = INF
		for x, y, h in xyh:
			if h == 0:
				H_max = min(H_max, h + abs(x-Cx) + abs(y-Cy))
			else:
				if H == 0:
					H = h + abs(x-Cx) + abs(y-Cy)
				else:
					if H != h + abs(x-Cx) + abs(y-Cy):
						break

		else:
			if H <= H_max:
				print(Cx, Cy, H)
				break
	else:
		continue
	break

Submission status: Accepted

Solution code:
n = int(input())
xyh = []
for _ in range(n):
    x, y, h = map(int, input().split())
    xyh.append((x, y, h))
for cx in range(101):
    for cy in range(101):
        H = None
        maxH = 10**12
        for x, y, h in xyh:
            if h>0:
                if H is None:
                    H = h+abs(x-cx)+abs(y-cy)
                elif H!=h+abs(x-cx)+abs(y-cy):
                    break
                if H>maxH:
                    break
            else:
                maxH = min(maxH, abs(x-cx)+abs(y-cy))
                if H is not None and H>maxH:
                    break
        else:
            print(cx, cy, H)
            exit()