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 solve():
    for i in range(N):
        if xyh[i][2] > 0:
            x,y,h = xyh[i][0], xyh[i][1], xyh[i][2]
            break

    for i in range(101):
        for j in range(101):
            H = h + abs(x-i) + abs(y-j)
            a = 0
            for k in range(N):
                if xyh[k][2] == max(H-abs(xyh[k][0]-i) - abs(xyh[k][1]-j), 0):
                    continue
                else:
                    a = 1
                    break
            if a == 0:
                print(i,j,H, sep=" ")
                break
        else:
            continue


if __name__ == "__main__":
    N = int(input())
    xyh = [list(map(int, input().split())) for _ in range(N)]
    solve()

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xyh = [None]*n
for i in range(n):
    x,y,h = map(int, input().split())
    xyh[i] = (x,y,h)
ans = []
bx,by,bh = max(xyh, key=lambda p: p[2])
for i in range(101):
    for j in range(101):
        H = bh + abs(bx-i) + abs(by-j)
        bad = False
        for x,y,h in xyh:
            if max(0, H - abs(x-i) - abs(y-j))!=h:
                bad = True
                break
        if bad:
            pass
        else:
            ans = (i,j,H)
            break
    if not bad:
        break
print(" ".join(map(str, ans)))

Submission status: Accepted

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

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


for x in range(0, 101):
    for y in range(0, 101):
        H_less = 10**10
        H = -1
        flag = 0
        for x_, y_, h_ in xyh:
            if h_ == 0:
                H_less = min(abs(x_-x)+abs(y_-y), H_less)
            else:
                h_tmp = h_ + abs(x_-x) + abs(y_-y)
                if H != -1:
                    if H != h_tmp:
                        flag = 1
                        break
                H = h_tmp
        if flag == 1:
            continue
        # print(H, H_less)
        if H > H_less:
            continue
        print(x, y, H)
        exit()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    l = []
    for _ in range(N):
        x,y,h = map(int, input().split())
        l.append((x,y,h))
    l.sort(key=lambda x:x[2], reverse=True)
    for i in range(101):
        for j in range(101):
            H = l[0][2] +  abs(l[0][0] - i) + abs(l[0][1] - j)
            for k in range(N):
                if max(H-abs(l[k][0]-i) - abs(l[k][1] - j), 0) != l[k][2]:
                    break
            else:
                return i, j, H
i, j, H = main()
print(i,j,H)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    t = in_na()
    xyh = list(zip(t, t, t))

    for cx in range(101):
        for cy in range(101):
            hmax = 10**9 + 7
            pred_h = -1
            for i in range(N):
                x, y, h = xyh[i]
                xy = abs(x - cx) + abs(y - cy)
                if h == 0:
                    hmax = min(hmax, xy)
                    if pred_h > hmax:
                        break
                else:
                    if pred_h == -1:
                        pred_h = h + xy
                    elif pred_h != h + xy:
                        break
            else:
                print(cx, cy, pred_h)
                exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(input())

l = []

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

    # 高さ0の時は下で使う式変形が成り立たないので、高さがある時のものを使う。
    # 全部0のパターンはありえない。なぜなら全部0としたとき、高さが1で調査していない座標を中心としたものが複数条件を
    # 満たしてしまうので、中心が一個に特定されるという条件に反するため。
    if v[2]:
        x,y,h = v[0], v[1], v[2]

for X in range(101):
    for Y in range(101):
        H = h + abs(x-X) + abs(y-Y)
        if all(h == max(H - abs(x-X) - abs(y-Y), 0) for x,y,h in l):
            print(X,Y,H)
            exit()

Submission status: Accepted

Solution code:
N, *XYH = map(int, open(0).read().split())
XYH = [(x, y, h) for x, y, h in zip(*[iter(XYH)] * 3)]
pos_i = -1
for i, (_, _, h) in enumerate(XYH):
    if h > 0:
        pos_i = i
        break
for i in range(101):
    for j in range(101):
        t_x, t_y, t_h = XYH[pos_i]
        tmp_summit = t_h + abs(i - t_x) + abs(j - t_y)
        for x, y, h in XYH:
            if h > 0 and tmp_summit - h != abs(i - x) + abs(j - y):
                break
            elif h == 0 and tmp_summit > abs(i - x) + abs(j - y):
                break
        else:
            print(i, j, tmp_summit)
            exit()

Submission status: Accepted

Solution code:
n = int(input())
coord = []

for i in range(n):
    x, y, h = map(int, input().split())
    coord.append([h, x, y])
    if h > 0:
        x0, y0, h0 = x, y, h

flag = False


for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True

        H = h0 + abs(x0 - cx) + abs(y0 - cy)

        for i in range(n):
            if coord[i][0] != max(H - abs(coord[i][1] - cx) - abs(coord[i][2] - cy), 0):
                flag = False
                break

        if flag is True:
            res_x = cx
            res_y = cy
            res_h = H

print(res_x, res_y, res_h)

Submission status: Accepted

Solution code:
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] = map(int, input().split())
    ans = []
    for x in range(101):
        for y in range(101):
            tmp = 0
            for i in range(N):
                if H[i] == 0:
                    continue
                else:
                    tmp = H[i] + abs(X[i] - x) + abs(Y[i] - y)
                    break
            for i in range(N):
                if not (H[i] == max(tmp - abs(X[i] - x) - abs(Y[i] - y),0)):
                    break
            else:
                ans = [x,y,tmp]
                break
    if N == 1:
        if H[0] == 0:
            print(X[0],Y[0],H[0])
            exit()
    print(*ans)
            



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
xx = [0] * n
yy = [0] * n
hh = [0] * n
for i in range(n):
    x, y, h = map(int, input().split())
    xx[i], yy[i], hh[i] = x, y, h
    if h > 0:
        x0, y0, h0 = x, y, h

for cx in range(101):
    for cy in range(101):
        f = True
        h = h0 + abs(x0 - cx) + abs(y0 - cy)
        for i in range(n):
            if hh[i] != max(h - abs(xx[i] - cx) - abs(yy[i] - cy), 0):
                f = False
                break
        if f:
            print("{} {} {}".format(cx, cy, h))
            exit(0)

Submission status: Accepted

Solution code:
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
xyh = [tuple(map(int, input().split())) for _ in range(n)]
# print(xyh)


def get_H(Cx, Cy):
    for x, y, h in xyh:
        if h == 0:  # 高度が0のときは何もしない
            continue
        H = abs(x-Cx)+abs(y-Cy)+h  # H-|X-Cx|-|Y-Cy|=hの式変形
        if h >= 1:
            return H


def check(Cx, Cy, H):
    for x, y, h in xyh:
        if h != max(H-abs(x-Cx)-abs(y-Cy), 0):
            return False
    return True


for Cx in range(101):
    for Cy in range(101):
        H = get_H(Cx, Cy)
        if (check(Cx, Cy, H)):
            print(Cx, Cy, H)
            quit()

Submission status: Accepted

Solution code:
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  if X[i][2] > 0:
    x, y, h = X[i][0], X[i][1], X[i][2]
    break
for i in range(0, 101):
  for j in range(0, 101):
    H = h + abs(x-i) + abs(y-j)
    a = 0
    for k in range(N):
      if X[k][2] == max(H - abs(X[k][0]-i) - abs(X[k][1]-j), 0):
        continue
      else:
        a = 1
        break
    if a == 0:
      print(i, j, H, sep=' ')
      break
  else:
    continue
  break

Submission status: Accepted

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

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

for x in range(101):
    for y in range(101):
        tmp_h = pyramid_height[0][2] + abs(x - pyramid_height[0][0]) + abs(y - pyramid_height[0][1])
        for i in range(1, N):
            if pyramid_height[i][2] != max(tmp_h - abs(x - pyramid_height[i][0]) - abs(y - pyramid_height[i][1]), 0):
                break
        else:
            print(x, y, tmp_h)
            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,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
#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
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
X = [];Y = [];H = []
for i in range(n):
    x,y,h = readInts()
    X.append(x)
    Y.append(y)
    H.append(h)
    if h > 0:
        si = i
resx=-1;resy=-1;resh=-1;
for cx in range(101):
    for cy in range(101):
        judge = True
        h = H[si] + abs(X[si] - cx) + abs(Y[si] - cy)
        for i in range(n):
            if H[i] == 0:
                if h > abs(X[i] - cx) + abs(Y[i] - cy):
                    judge ^=True
                    break
            else:
                if h - H[i] != abs(X[i]-cx) + abs(Y[i]-cy):
                    judge ^= True
                    break
        if judge:
            resx =cx;resy=cy;resh=h;
print(resx,resy,resh)

Submission status: Accepted

Solution code:
def dist(X,Y):
    return abs(X[0]-Y[0])+abs(X[1]-Y[1])
N = int(input())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[2],reverse=True)
for i in range(101):
    for j in range(101):
        flag=0
        x0,y0,h0 = A[0]
        H = h0+dist((i,j),(x0,y0))
        for k in range(1,N):
            x,y,h = A[k]
            if h>0 and H==h+dist((i,j),(x,y)):
                continue
            elif h>0 and H!=h+dist((i,j),(x,y)):
                flag=1
                break
            elif h==0 and H<=dist((i,j),(x,y)):
                continue
            elif h==0 and H>dist((i,j),(x,y)):
                flag = 1
                break
        if flag==0:
            Cx = i
            Cy = j
            break
    if flag==0:break
print(Cx,Cy,H)

Submission status: Accepted

Solution code:
import sys
MOD = 10**9 + 7
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    p = [list(map(int,input().split())) for _ in range(n)]
    p = sorted(p,key=lambda x: -x[2])
    for x in range(0,101):
        for y in range(0,101):
            h = p[0][2] + abs(x-p[0][0]) + abs(y-p[0][1])
            flag = 1
            for (a,b,c) in p:
                if c != max(0,h-abs(x-a)-abs(y-b)):
                    flag = 0
                    break
            if flag == 1:
                print(x,y,h)
                exit(0)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

XYH.sort(reverse=True)


for i in range(101):
    for j in range(101):
        H = -1
        flag = True
        for k in range(n):
            h, x, y = XYH[k]
            if H == -1:
                H = abs(x-i)+abs(y-j)+h
            else:
                if max(H-abs(x-i)-abs(y-j), 0) != h:
                    flag = False
        if flag:
            print(i, j, H)
            exit()

Submission status: Accepted

Solution code:
n=int(input())
info=[]
import sys
for i in range(n):
  x,y,h=map(int,input().split())
  info.append([x,y,h])
for x in range(0,101):
  for y in range(0,101):
    for A in info:
      if A[2]!=0:
        h=A[2]+abs(x-A[0])+abs(y-A[1])
        break
    failflag=0
    for A in info:
      if A[2]!=max(0,h-abs(x-A[0])-abs(y-A[1])):
        failflag=1
        break
    if failflag==0:
      print(x)
      print(y)
      print(h)
      sys.exit()

Submission status: Accepted

Solution code:
from sys import exit

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

for cx in range(101):
    for cy in range(101):
        correct_flag = True
        for i in range(n):
            x, y, h = l[i]
            if h > 0:
                res_h = abs(x - cx) + abs(y - cy) + h
                break
        for i in range(n):
            x, y, h = l[i]
            if max(res_h - abs(x - cx) - abs(y - cy), 0) != h:
                correct_flag = False
                break
        if correct_flag:
            print(cx, cy, res_h)
            exit()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    x = [0 for _ in range(n)]
    y = [0 for _ in range(n)]
    h = [0 for _ in range(n)]
    for i in range(n):
        x[i], y[i], h[i] = map(int, input().split())
        if h[i]:
            xn, yn, hn = x[i], y[i], h[i]

    for cx in range(101):
        for cy in range(101):
            H = hn + abs(xn - cx) + abs(yn - cy)
            if all(h[i] == max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) for i in range(n)):
                print(cx, cy, H)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    XYH = [list(map(int, input().split())) for _ in range(n)]

    info = []
    for x, y, h in XYH:
        if h == 0:
            continue
        info.append([x, y, h])

    if len(info) == 1:
        print(*info[0])
        exit()

    for Cx in range(100 + 1):
        for Cy in range(100 + 1):
            tmp = set()
            for x, y, h in info:
                if h == 0:
                    continue
                H = h + abs(x - Cx) + abs(y - Cy)
                tmp.add(H)
            if len(tmp) == 1:
                print(Cx, Cy, *list(tmp))
                exit()


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import numpy as np
from itertools import product

N = int(input())

points = []
non_zero_point = None
for _ in range(N):
    x, y, h = map(int, input().split(' '))
    points.append((x, y, h))
    if non_zero_point is None and h > 0:
        non_zero_point = (x, y, h)

points = np.array(points)
zeros = np.zeros(shape=N, dtype=np.int64)

for cx, cy in product(range(0, 101), repeat=2):
    H = abs(non_zero_point[0] - cx) + abs(non_zero_point[1] - cy) + non_zero_point[2]
    h = np.maximum(H - np.abs(points[:, 0] - cx) - np.abs(points[:, 1] - cy), zeros)
    if np.all(h == points[:, 2]):
        print(cx, cy, H)
        break

Submission status: Accepted

Solution code:
N, *_XYH = map(int, open(0).read().split())
XYH = list(zip(*[iter(_XYH)]*3))

C = [(x, y) for x in range(101) for y in range(101)]

for c in C:
    for i, xyh in enumerate(sorted(XYH, key=lambda x: x[2], reverse=True)):
        if i==0:
            H = xyh[2] + abs(xyh[0] - c[0]) + abs(xyh[1] - c[1])
        elif max(H - abs(xyh[0] - c[0]) - abs(xyh[1] - c[1]), 0) == xyh[2]:
            is_ans = True
        else:
            is_ans = False
            break
        
    if is_ans:
        break

print(*c, H)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


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


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N = z()
X, Y, H = [], [], []
Cx, Cy, Hc = 0, 0, 0
for i in range(N):
    x, y, h = zz()
    if (h != 0):
        x_t, y_t, h_t = x, y, h
    X.append(x)
    Y.append(y)
    H.append(h)
for Cx, Cy in itertools.product(range(0, 101), repeat=2):
    Hc = h_t + abs(Cx-x_t) + abs(Cy - y_t)
    # print(Cx, Cy, Hc)
    ok_count = 0
    for x, y, h in zip(X, Y, H):
        tmp = Hc - abs(Cx - x) - abs(Cy - y)
        if (h == max(tmp, 0)):
            ok_count += 1
        else:
            break
    if (ok_count == N):
        print(Cx, Cy, Hc)
        exit()

Submission status: Accepted

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

ans = []
for i in range(101):
  for j in range(101):
    h.sort(key=lambda x: -x[2])
    hmax = h[0][2] + abs(i-h[0][0]) + abs(j-h[0][1])
    for k in range(1,n):

      if max(hmax - abs(h[k][0] - i) - abs(h[k][1] - j) , 0) != h[k][2]:
        break

    else:
      ans = [i,j,hmax]
    
    if(len(ans)):
      break
  if(len(ans)):
    break

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

Submission status: Accepted

Solution code:
# 参考:https://atcoder.jp/contests/abc112/submissions/14491766
import sys
input = lambda: sys.stdin.readline().rstrip()
 
l = []
for _ in range(int(input())):
    t = list(map(int,input().split()))
    l.append(t)
    if t[2]: 
        x,y,h = t[0], t[1], t[2]
        
for X in range(101):
    for Y in range(101):
        H = h + abs(x - X) + abs(y - Y)
        if all(h==max(H - abs(x-X) - abs(y-Y), 0) for x,y,h in l): print(X, Y, H)

Submission status: Accepted

Solution code:
l=[]
for _ in range(int(input())):
  t=[*map(int,input().split())]
  l+=[t]
  if t[2]: x,y,h=t
for X in range(101):
  for Y in range(101):
    H=h+abs(x-X)+abs(y-Y)
    if all(h==max(H-abs(x-X)-abs(y-Y),0) for x,y,h in l): print(X,Y,H)

Submission status: Accepted

Solution code:
l=sorted([[*map(int,input().split())] for _ in range(int(input()))],key=lambda k:-k[2])
x,y,h=l[0]
for X in range(101):
  for Y in range(101):
    H=h+abs(x-X)+abs(y-Y)
    if all(h==max(H-abs(x-X)-abs(y-Y),0) for x,y,h in l): print(X,Y,H)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
n=int(input())
lh,lz=[],[]
for _ in range(n):
  x,y,h=f()
  if h: lh+=[(x,y,h)]
  else: lz+=[(x,y)]
for X in range(101):
  for Y in range(101):
    x,y,h=lh[0]
    H=h+abs(x-X)+abs(y-Y)
    for x,y,h in lh:
      if H!=h+abs(x-X)+abs(y-Y): break
    else:
      if all(H-abs(x-X)-abs(y-Y)<1 for x,y in lz):
        print(X,Y,H)

Submission status: Accepted

Solution code:
n = int(input())
dat = []
for _ in range(n):
    a,b,c = map(int,input().split())
    dat.append( [a,b,c] )
can = True

for x in range(101):
    for y in range(101):
        for i in range(n):
            h = None
            can = True
            xx, yy, hh = dat[i]
            h = hh + abs(xx - x) + abs(yy - y)
            for j in range(n):
                xx, yy, hh = dat[j]
                canh = h - abs(xx - x) - abs(yy - y)
                canh = max(canh, 0)
                if canh != hh:
                    can = False
            if can:
                break
        if can:
            break
    if can:
        break
print(x, y, h)

Submission status: Accepted

Solution code:
N=int(input())
x=[list(map(int,input().split())) for _ in range(N)]
x.sort(key=lambda x:-x[2])
dp=[[0]*101 for i in range(101)]
bp=[[0]*101 for i in range(101)]
for j in range(101):
  for k in range(101):
    a,b,c=x[0]
    r=0
    asa=abs(a-j)+abs(b-k)+c
    for i in range(N):
      count=abs(x[i][0]-j)+abs(x[i][1]-k)
      if x[i][2]==max(asa-count,0):
        r+=1
    if r==N:
      print(j,k,asa)
      exit()

Submission status: Accepted

Solution code:
import sys
import numpy as np

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]
        tmp_h = abs(cy - y) + abs(cx - x) + h
        H = np.zeros(n, dtype=np.bool)
        for i, a in enumerate(xyh):
            H[i] = a[2] == max(tmp_h - abs(cx - a[0]) - abs(cy - a[1]), 0)
        if np.all(H):
            print(cx, cy, tmp_h)
            sys.exit()

Submission status: Accepted

Solution code:
N = int(input())

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

for cx in range(101):
    for cy in range(101):
        needH = -1
        for x, y, h in H:
            if h > 0:
                tmp = h+abs(x-cx)+abs(y-cy)
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break
        if needH == -2:
            continue
        f = 1
        for x, y, h in H:
            if h == 0:
                if max(needH-abs(x-cx)-abs(y-cy), 0) != 0:
                    f = 0
                    break
        if f:
            print(cx, cy, needH)
            exit()

Submission status: Accepted

Solution code:
N=int(input())
q=[list(map(int,input().split())) for _ in range(N)]
for i in range(101):
    for j in range(101):
        F=1
        r=[]
        for k in range(101):
            x,y,h=q[k]
            if h > 0:
              break
            r.append([x,y])
        s=h+abs(x-i)+abs(y-j)
        for x,y,h in q[1:]:
            if h==0:
                r.append([x,y])
                continue
            y=h+abs(x-i)+abs(y-j)
            if s!=y:
              F=0
              break
        if r:
          for x,y in r:
            if s-abs(x-i)-abs(y-j) > 0:
              F=0
              break
        if F==1:
          print(i,j,s)
          exit()

Submission status: Accepted

Solution code:
n = int(input())
L = []
for _ in range(n):
    x, y, h = map(int, input().split())
    if h > 0:
        sx, sy, sh = x, y, h
    L.append((x, y, h))
for cy in range(101):
    for cx in range(101):
        d = abs(sx - cx) + abs(sy - cy)
        H = sh + d
        for x, y, h in L:
            if h == 0:
                if H > abs(x - cx) + abs(y - cy):
                    break
            else:
                if H - abs(x - cx) - abs(y - cy) != h:
                    break
        else:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
A.sort(key=lambda x: x[2], reverse=True)
for c_x in range(101):
    for c_y in range(101):
        H = -1
        H_upper = 10**9
        for i, v in enumerate(A):
            if v[2] == 0:
                H_upper = min(H_upper, abs(c_x - v[0]) + abs(c_y - v[1]))
                if H_upper < H:
                    break
            else:
                tmp_H = abs(c_x - v[0]) + abs(c_y - v[1]) + v[2]
                if H == -1:
                    H = tmp_H
                elif H != tmp_H:
                    break
            if i == N-1:
                if H == -1:
                    print(c_x, c_y, H_upper)
                else:
                    print(c_x, c_y, H)

Submission status: Accepted

Solution code:
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
c = 0
for x,y,h in xyh:
    if h==0:
        c += 1
    else:ans = [x,y,h]
if c==n-1:
    print(*ans)
    exit()

for i in range(101):
    for j in range(101):
        a = -1
        ok = True
        for x,y,h in xyh:
            if h>0:
                if a==-1:
                    a = h+abs(x-i)+abs(y-j)
                elif h+abs(x-i)+abs(y-j)!=a:
                    ok = False
        if ok:
            print(i,j,a)
            exit()

Submission status: Accepted

Solution code:
from itertools import product
def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(list(map(int, input().split())))
    for a in A:
        if a[2] > 0:
            t = a
            break
    for x, y in product(range(0, 101), repeat = 2):
        H = t[2] + abs(t[0] - x) + abs(t[1] - y)
        for a in A:
            if a[2] == 0 and H > abs(a[0] - x) + abs(a[1] - y):
                break
            elif a[2] != 0 and a[2] != H - abs(a[0] - x) - abs(a[1] - y):
                break
        else:
            ansx, ansy = x, y
            break
    H = t[2] + abs(t[0] - ansx) + abs(t[1] - ansy)
    print('{} {} {}'.format(ansx, ansy, H))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
lis = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        sx, sy, sh = x, y, h
    lis.append((x, y, h))
for i in range(101):
    for j in range(101):
        high = sh + abs(sx - i) + abs(sy - j)
        judge = True
        for x, y, h in lis:
            if h > 0 and high != h + abs(x - i) + abs(y - j):
                judge = False
                break
            if h == 0 and high > abs(x - i) + abs(y - j):
                judge = False
                break
        if judge:
            print(i, j, sh + abs(sx - i) + abs(sy - j))
            exit()

Submission status: Accepted

Solution code:
N = int(input())
lis = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        sx, sy, sh = x, y, h
    lis.append((x, y, h))
for i in range(101):
    for j in range(101):
        high = sh + abs(sx - i) + abs(sy - j)
        judge = -1
        for x, y, h in lis:
            if h > 0 and high != h + abs(x - i) + abs(y - j):
                judge = 0
                break
        if judge == 0:
            continue
        for x, y, h in lis:
            if h == 0 and high > abs(x - i) + abs(y - j):
                judge = 0
                break
        if judge == 0:
            continue
        
        print(i, j, sh + abs(sx - i) + abs(sy - j))
        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)

def esth(x, y, h, cx, cy):
    return h + abs(x-cx) + abs(y-cy)


for cx in range(101):
    for cy in range(101):
        f = True
        ch = 0
        for x, y, h in xyh:
            if ch == 0 and h > 0:
                ch = esth(x, y, h, cx, cy)
            elif h > 0:
                if ch != esth(x, y, h, cx, cy):
                    f = False
                    break
            else:
                if max(ch - abs(x-cx) - abs(y-cy), 0) != h:
                    f = False
                    break
        if f:
            print('{} {} {}'.format(cx, cy, ch))
            break

Submission status: Accepted

Solution code:
n = int(input())
xyh = []
for i in range(n):
    temp = list(map(int,input().split()))
    if temp[2] > 0:
        x,y,h = temp[0],temp[1],temp[2]
    xyh.append(temp)
for i in range(101):
    for j in range(101):
        for k in xyh:
            if k[2] > 0 and k[2]+abs(k[0]-j)+abs(k[1]-i) != h+abs(x-j)+abs(y-i):
                break
            elif k[2]+abs(k[0]-j)+abs(k[1]-i) < h+abs(x-j)+abs(y-i):
                break
        else:
            print(j,i,h+abs(x-j)+abs(y-i))
            exit()

Submission status: Accepted

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def main():
    n = int(input())
    a = [0] * n
    b = [0] * n
    c = [0] * n
    for i in range(n):
        a[i],b[i],c[i] = readInt()
    for i in range(101):
        for j in range(101):
            for k in range(max(c),max(c)+105):
                res = False
                for l in range(n):
                    if max(k-abs(a[l]-i)-abs(b[l]-j),0)!=c[l]:
                        res = True
                        break
                if res:
                    continue
                else:
                    print(i,j,k)
                    return
    return

if __name__=='__main__':
    main()