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:
import math

N = int(input())

field = [[-1 for i in range(101)] for j in range(101)]

tmp = []
for i in range(N):
	x,y,h = map(int,input().split())
	if h == 0:
		tmp.append([x,y,h])
		continue
	for j in range(101):
		for k in range(101):
			if h == 0:
				if field[j][k] - abs(x-j) - abs(y-k) > 0:
					field[j][k] = -2
			else:
				if field[j][k] == -1:
					field[j][k] = h + abs(x-j) + abs(y-k)
				elif field[j][k] != h + abs(x-j) + abs(y-k):
					field[j][k] = -2

for x,y,h in tmp:
	for j in range(101):
		for k in range(101):
			if h == 0:
				if field[j][k] - abs(x-j) - abs(y-k) > 0:
					field[j][k] = -2
			else:
				if field[j][k] == -1:
					field[j][k] = h + abs(x-j) + abs(y-k)
				elif field[j][k] != h + abs(x-j) + abs(y-k):
					field[j][k] = -2

for i in range(101):
	for j in range(101):
		if field[i][j] > 0:
			print(i,j,field[i][j])

Submission status: Accepted

Solution code:
def solve(n):
    can = [[[-1, float('inf')] for _ in range(101)] for _ in range(101)]
    for k in range(n):
        x, y, h = map(int, input().split())
        for i in range(101):
            for j in range(101):
                if can[i][j] is None:
                    continue
                hh = h + abs(x - i) + abs(y - j)
                hl = 1 if h == 0 else hh
                nl, nh = max(can[i][j][0], hl), min(can[i][j][1], hh)
                if nl > nh:
                    can[i][j] = None
                else:
                    can[i][j][0] = nl
                    can[i][j][1] = nh

    for i in range(101):
        for j in range(101):
            if can[i][j] is None:
                continue
            return i, j, can[i][j][0]


n = int(input())
print(*solve(n))

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())
L = tuple(tuple(map(int,input().split())) for _ in range(N))

for xc,yc in product(range(101), repeat=2):
  s = set(abs(xc-x)+abs(yc-y)+h for x,y,h in L if h != 0)
  if len(s) == 1:
    H = next(iter(s))
    if all(abs(xc-x)+abs(yc-y) >= H for x,y,h in L if h == 0):
      print(xc,yc,H)
      break

Submission status: Accepted

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

for i in range(101):
    for j in range(101):
        height = -1
        Z = []
        for x, y, h in XYH:
            hi = abs(x - i) + abs(y - j) + h
            if h == 0:
                Z.append([x, y])
                continue
            if height == -1:
                height = hi
            else:
                if height == hi:
                    pass
                else:
                    break
        else:
            for x, y in Z:
                if abs(x - i) + abs(y - j) >= height:
                    continue
                else:
                    break
            else:
                print(i, j, height)
                exit()

Submission status: Accepted

Solution code:

from operator import itemgetter

N = int(input())

XYH = []

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

XYH.sort(key=itemgetter(2))
XYH.reverse()

for i in range(101):
    for j in range(101):
        
        H = XYH[0][2]+abs(XYH[0][0]-i)+abs(XYH[0][1]-j)
        flag = 1
        
        for k in range(1, N):
            if not max(H-abs(XYH[k][0]-i)-abs(XYH[k][1]-j), 0) == XYH[k][2]:
                flag = -1
                break
        
        if flag > 0:
            break
    if flag > 0:
        break    

ans = str(i)+' '+str(j)+' '+str(H)
  
print(ans)

Submission status: Accepted

Solution code:
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
xyh = []
xyh.sort(key=lambda x: x[2])
for _ in range(n):
    xyh.append(ai())

for cx in range(101):
    for cy in range(101):
        H = []
        d = []
        for x,y,h in xyh:
            H.append(h+abs(cx-x)+abs(cy-y))
            d.append(abs(cx-x)+abs(cy-y))
        hh = min(H)
        f = 0
        for i in range(n):
            if H[i] == d[i] > hh or (d[i] <= hh and H[i] == hh):
                continue
            else:
                f = 1
                break
        if f == 0:
            print(cx,cy,hh)
            exit()

Submission status: Accepted

Solution code:
n = int(input())
info = [[int(i) for i in input().split()] for j in range(n)]
info.sort(key=lambda x:x[2])
if n == 1:
    print(info[0][0], info[0][1], info[0][2])
else:
    for i in range(n):
        if info[i][2] > 0:
            r = i
    for x in range(101):
        for y in range(101):
            h = info[r][2] + abs(x - info[r][0]) + abs(y - info[r][1])
            for i in range(n):
                if i < n-1 :
                    if info[i][2] == 0:
                        if h > abs(x - info[i][0]) + abs(y - info[i][1]):
                            break
                    else:
                        if h != info[i][2] + abs(x - info[i][0]) + abs(y - info[i][1]):
                            break
                elif i == n-1:
                    if h == info[i][2] + abs(x - info[i][0]) + abs(y - info[i][1]):
                        cx = x
                        cy = y
                        ch = h
    print(cx, cy, ch)

Submission status: Accepted

Solution code:
n = int(input())

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

ext = lambda x: list(x)[0]

def check(zero, h):
    for xy in zero:
        if h - xy > 0:
            return False
    return True

for xcand in range(101):
    for ycand in range(101):
        values = set()
        zero = list()
        for x, y, h in xyh:
            if h == 0:
                zero.append(abs(xcand - x) + abs(ycand - y))
            else:
                values.add(abs(xcand - x) + abs(ycand - y) + h)
        if len(values) == 1:
            v = ext(values)
            if check(zero, v):
                print(xcand, ycand, v)
                exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import itertools

N = int(input())
ta = [list(map(int,input().split())) for _ in range(N)]
for Cx, Cy in itertools.product(range(101),range(101)):
    # もしcx,cyが決まっていた場合矛盾が起こらないか
    # H = abs(x-cx)+abs(y-cy) + h
    H = None
    for [x,y,h] in ta:
        if h == 0:
            pass
        else:
            if H is None:
                H = h + abs(x-Cx)+abs(y-Cy)
            else:
                if H != h + abs(x-Cx)+abs(y-Cy):
                    break
    for [x,y,h] in ta:
        if h != max(H - abs(x-Cx) - abs(y-Cy),0):
            break
    else:
        break
print(Cx,Cy,H)

Submission status: Accepted

Solution code:
n = int(input())
cx,cy = 0,0
list_xyh = []
for i in range(n):
    list_xyh.append(list(map(int, input().split())))
for cx in range(0,101):
    for cy in range(0,101):
        for i in range(n):
            if list_xyh[i][2] != 0:
                H = abs(cx - list_xyh[i][0]) + abs(cy - list_xyh[i][1]) + list_xyh[i][2]
                break
        for i in range(n):
            if max(H - abs(cx - list_xyh[i][0]) - abs(cy - list_xyh[i][1]),0) == list_xyh[i][2]:
                continue
            else:
                break
        else:
            print(cx,cy,H)
            break
    else:
        continue
    break

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
h = []
for i in range(N):
    x_i, y_i, h_i = map(int, input().split())
    x.append(x_i)
    y.append(y_i)
    h.append(h_i)

#i:情報番号 j:求めるx座標 k:求めるy座標 l:求める高さ
for j in range(101):
    for k in range(101):
        for l in range(h[0], h[0] + 200):
            flag = 1
            for i in range(N):
                h_i_test = max(l - abs(x[i] - j) - abs(y[i] - k), 0)
                if h_i_test != h[i]:
                    flag = 0
                    break
            if flag == 1:
                print(str(j)+ " " + str(k) + " " + str(l))
                break
        if flag == 1:
            break
    if flag == 1:
        break

Submission status: Accepted

Solution code:
N = int(input())
Info = [list(map(int, input().split())) for i in range(N)]
Info_nonzero = []
highest = 0
for x, y, h in Info:
    if h != 0:
        Info_nonzero.append([x, y, h])

for x, y, h in Info:
    if h == 0:
        highest = max(highest, x + y)

for Cx in range(101):
    for Cy in range(101):
        candidate_set = set()
        for x, y, h in Info_nonzero:
            H = abs(Cx - x) + abs(Cy - y) + h
            candidate_set.add(H)

        ans_H = list(candidate_set)[0]
        if len(candidate_set) == 1:
            for x, y, h in Info:
                H = abs(Cx - x) + abs(Cy - y) + h
                if h == 0:
                    if not H >= ans_H:
                        break

                if h != 0:
                    if not H <= ans_H:
                        break
            else:
                print(Cx, Cy, abs(Cx - Info_nonzero[0][0]) + abs(Cy - Info_nonzero[0][1]) + Info_nonzero[0][2])
                exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

N = d_in()

cand = [[i,j,0] for i in range(0, 101) for j in range(0, 101)]

info = []
for _ in range(N):
    info.append(ds_in())

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

for i in range(len(cand)):
    x, y, h = info[0]
    cand[i][2] = h + abs(x-cand[i][0]) + abs(y-cand[i][1])

if N > 1:
    idx = 1
    while len(cand) > 1 and idx < N:
        temp = []
        x, y, h = info[idx]
        for c in cand:
            if h == max(0, c[2] - abs(x-c[0]) - abs(y-c[1])):
                temp.append(c)
        cand = temp.copy()
        idx += 1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, XYH):
    XYH.sort(key=lambda x: x[2], reverse=True)
    MM = 101
    M = [[1] * MM for _ in range(MM)]
    for r, (x, y, h) in enumerate(XYH):
        if h == 0:
            M[x][y] = 0
            continue
        for i in range(MM):
            for j in range(MM):
                t = abs(i-x) + abs(j - y) + h
                if r == 0:
                    M[i][j] = t
                else:
                    if M[i][j] != t:
                        M[i][j] = 0

    

    for i in range(MM):
        for j in range(MM):
            if M[i][j] != 0:
                if i > 0 and M[i-1][j] != 0:
                    continue
                if i < MM -1 and M[i+1][j] != 0:
                    continue
                if j > 0 and M[i][j-1] != 0:
                    continue
                if j < MM -1 and M[i][j+1] != 0:
                    continue
                return '%d %d %d' % (i, j, M[i][j])

    assert False


def main():
    N = read_int()
    XYH = [read_int_n() for _ in range(N)]
    print(slv(N, XYH))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
h = []
for i in range(N):
    (tmp_x, tmp_y, tmp_h) = map(int, input().split())
    x.append(tmp_x)
    y.append(tmp_y)
    h.append(tmp_h)

def CalcHigh(cx, cy, px, py, ph):
    ch = ph + abs(cx-px) + abs(cy-py)
    return ch

for i in range(101):
    for j in range(101):
        ch = 0
        for k in range(N):
            if h[k] > 0:
                ch = CalcHigh(i, j, x[k], y[k], h[k])

        flag = True
        for k in range(N):
            if ch > 0:
                if h[k] == 0:
                    if CalcHigh(i, j, x[k], y[k], h[k]) < ch:
                        flag = False
                        break
                else:
                    if CalcHigh(i, j, x[k], y[k], h[k]) != ch:
                        flag = False
                        break

        if flag == True:
            ans = (i, j, ch)
            break

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

Submission status: Accepted

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

INF = float('inf')
for cx in range(0,101):
    for cy in range(0,101):
        tmph = None
        maxh = INF
        for x,y,h in src:
            if h > 0:
                tmp = h + abs(x-cx) + abs(y-cy)
                if tmph is None:
                    tmph = tmp
                else:
                    if tmp != tmph:
                        break
                if tmph > maxh:
                    break
            else:
                maxh = min(maxh, abs(x-cx) + abs(y-cy))
                if maxh == 1:
                    tmph = 1
        else:
            for x,y,h in src:
                if max(tmph - abs(x-cx) - abs(y-cy), 0) != h:
                    break
            else:
                print(cx,cy,tmph)
                exit()

Submission status: Accepted

Solution code:
n=int(input())
data = []
for i in range(n):
    data.append(list(map(int,input().split())))
data.sort(key=lambda x:x[2],reverse=True)
ansflg = False
for xpos in range(101):
    for ypos in range(101):
        high = data[0][2] + abs(data[0][0]-xpos) + abs(data[0][1]-ypos)
        check = True
        for k in range(1,n):
            if data[k][2] != max(0,high - abs(data[k][0]-xpos) - abs(data[k][1]-ypos)):
                check = False
                break
        if check:
            print('{} {} {}'.format(xpos,ypos,high))
            ansflg = True
            break
    if ansflg:
        break

Submission status: Accepted

Solution code:
def big(a,b):
    if a >= b:
        return a
    else:
        return b

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

info.sort(key = lambda x: x[2])
info.reverse()

check = False
for cx in range(101): 
    for cy in range(101):
        high = info[0][2] + abs(info[0][0]-cx) + abs(info[0][1]-cy)
        if info[0][2] == 0:
            print(info[1000])
        temp = True
        for i in range(1,n):
            if info[i][2] != big(high-abs(info[i][0]-cx)-abs(info[i][1]-cy),0):
                temp = False
        if temp:
            check = True
            break
    if check:
        break
print(cx,cy,high)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
  x,y,h = map(int,input().split())
  a.append([x,y,h])
a.sort(key=lambda x:  -x[2])
def test(t,b,c):
  for k in a:
    if c - (abs(t - k[0]) + abs(b-k[1])) != k[2]:
      if (c - (abs(t - k[0]) + abs(b-k[1])) < 0 and k[2] == 0):
        continue
      else:
        return False
  return True
for i in range(101):
  for j in range(101):
    h = abs(i-a[0][0]) + abs(j - a[0][1]) + a[0][2]
    if test(i,j,h):
      print(i,j,h)
      exit()

Submission status: Accepted

Solution code:
import sys

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

for cx in range(100+1):
    for cy in range(100+1):
        x, y, h= coordinates[0]
        H = h + abs(x-cx) + abs(y-cy)
        i = 1
        for x, y, h in coordinates[1:]:
            if not h == max(H - abs(x-cx) - abs(y-cy), 0):
                break
            else:
                i += 1
                if i == N:
                    print(cx, cy, H)
                    sys.exit()

Submission status: Accepted

Solution code:
N=int(input())

data=[]

for _ in range(N):
    x,y,h=map(int,input().split())
    data.append([x,y,h])
 
def test():
    for cx in range(101):
        for cy in range(101):
            
            for i in range(N):
                if data[i][2]:
                    temph=data[i][2]+abs(data[i][0]-cx)+abs(data[i][1]-cy)
                    flag=True
            
            for d in data:
                if d[2] != max(temph-abs(d[0]-cx)-abs(d[1]-cy),0):
                    flag=False
                    break
                
            if flag:
                print(cx,cy,temph)
                return
            
test()

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []
h = []
ot = []
for i in range(n):
    xi, yi, hi = [int(_) for _ in input().split()]
    if hi != 0:
        x.append(xi)
        y.append(yi)
        h.append(hi)
    else:
        ot.append([xi, yi, hi])

ans = []
for cxi in range(101):
    for cyi in range(101):
        flag = True
        for i in range(len(h)):
            if i == 0:
                height = h[i] + abs(x[i]-cxi) + abs(y[i]-cyi)
            else:
                if height != h[i] + abs(x[i]-cxi) + abs(y[i]-cyi):
                    flag = False
                    continue
        if flag:
            ans.append([cxi, cyi, height])

if len(ans) == 1:
    print(ans[0][0], ans[0][1], ans[0][2])
else:
    for a in ans:
        flag = True
        for o in ot:
            if max((a[2] - abs(o[0]-a[0]) - abs(o[1]-a[1])), 0) != o[2]:
                flag = False
                continue
        if flag:
            print(a[0], a[1], a[2])

Submission status: Accepted

Solution code:
N = int(input())
x,y,h = [0]*N,[0]*N,[0]*N

j = -1
for i in range(N):
    x[i],y[i],h[i] = map(int,input().split(" "))
    if h[i] !=  0:
        j = i 
        
H = 1
if j == (-1):
    for cx in range(0,101):
        for cy in range(0,101):
            for i in range(N):
                H = min(H,(abs(x[i]-cx) + abs(y[i]-cy)))

            if H > 0:
                print("{0} {1} {2}".format(cx,cy,H))
                exit(0)

for cx in range(0,101):
    for cy in range(0,101):
        H = h[j] + abs(x[j]-cx) + abs(y[j]-cy)
        flg = True
        for i in range(N):
            if (h[i] == 0 and ((abs(x[i]-cx) + abs(y[i]-cy))) < H):
                flg = False
                break
            if (h[i] != 0 and H != (h[i] + abs(x[i]-cx) + abs(y[i]-cy))):
                flg = False
                break
        if flg:
            print("{0} {1} {2}".format(cx,cy,H))
            exit(0)

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        pt = 0
        while lines[pt][2] == 0:
            pt += 1
        x0, y0, h0 = lines[pt]
        h = h0 + abs(cx - x0) + abs(cy - y0)
        flag = True
        for x0, y0, h0 in lines:
            tmp = h0 + abs(cx - x0) + abs(cy - y0)
            if h0 > 0 and tmp != h:
                flag = False
                break
            if h0 == 0:
                if h - abs(cx - x0) - abs(cy - y0) > 0:
                    flag = False
                    break
        if flag:
            print(cx, cy, h)
            exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n=int(input())

x=[]
y=[]
h=[]
#n,T=[int(i) for i in input().split()]
A=[]
for _ in range(n):
#    x0,y0,h0=[int(i) for i in input().split()]
#    x.append(x0)
#    y.append(y0)
#    z.append(z0)
    a=[int(i) for i in input().split()]
    A.append(a)

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

ax=-1
ay=-1
ah=-1
#print(A)

zz=101
for i in range(zz):
    for j in range(zz):
        ok=1
        h=abs(A[0][0]-i)+abs(A[0][1]-j)+A[0][2]
        for k in range(n):
            c=abs(A[k][0]-i)+abs(A[k][1]-j)
#            if i==2 and j==2:
#                print(h,k,c,A[k][0],A[k][1],A[k][2])
            if max(h-c,0) != A[k][2]:
                ok=0
                break
        if ok==1:
            ax=i
            ay=j
            ah=h
        if ok==1:
            break
        
    if ok==1:
        break
print(ax,ay,ah)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8
#

def return_H(x, y, h, cx, cy):
    retval_H = h + abs(x - cx) + abs(y - cy)
    return retval_H

def main(n, l):
    for cx in range(0, 101):
        for cy in range(0, 101):
            retl = []
            maxH = []
            for x, y, h in l:
                if h != 0:
                    retl.append(return_H(x, y, h, cx, cy))
                elif h == 0:
                    maxH.append(return_H(x, y, h, cx, cy))
            if len(maxH) > 0:
                if len(set(retl)) == 1 and retl[0] <= min(maxH):
                    print('{} {} {}'.format(cx, cy, retl[0]))
                    return
            else:
                if len(set(retl)) == 1:
                    print('{} {} {}'.format(cx, cy, retl[0]))
                    return
    
if __name__ == '__main__':
    try:
        n  = int(input().strip())
        l = []
        for i in range(n):
            l.append(list(map(int, input().strip().split(' '))))
        main(n, l)
    except EOFError:
        pass

Submission status: Accepted

Solution code:
N = int(input())

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

for m in range(N):
    if l[m][2] != 0:
        break

for i in range(0, 101):
    for j in range(0, 101):
        center = [i, j]
        h = l[m][2] + abs(i - l[m][0]) + abs(j - l[m][1])
        # print(i, j, h)

        flag = True

        number = list(range(N))
        number.pop(m)
        for k in number:
            # print(l[k])
            # print(l[k][0])
            if max(h - abs(i - l[k][0]) - abs(j - l[k][1]), 0) != l[k][2]:
                flag = False

        if flag:
            print(i, j, h)
            exit()

Submission status: Accepted

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

for Cx in range(100 + 1):
    for Cy in range(100 + 1):
        flg = True
        H = -1
        max_H = float('inf')
        for x, y, h in XYHs:
            CF = abs(x - Cx) + abs(y - Cy)
            if h == 0:
                max_H = min(max_H, CF)
            else:
                t = h + CF
                if H == -1:
                    H = t
                elif H != t:
                    flg = False
                    break
        if flg and H <= max_H:
            print(Cx, Cy, H)
            exit()

Submission status: Accepted

Solution code:
n = int(input())

xs = []
ys = []
hs = []

for i in range(n):
    x, y, h = list(map(int, input().split()))
    xs.append(x)
    ys.append(y)
    hs.append(h)

count = 0
for h in hs:
    if h != 0:
        count += 1

if count == 1:
    for x, y, h in zip(xs, ys, hs):
        if h != 0:
            print(x, y, h)
            exit(0)

if count == 0:
    pairs = list([(x, y) for x, y in zip(xs, ys)])
    for x1 in range(101):
        for y1 in range(101):
            if (x1, y1) not in pairs:
                print(x1, y1, 1)
                exit(0)

x_cands = []
y_cands = []
for x1 in range(101):
    for y1 in range(101):
        h0 = None
        for x, y, h in zip(xs, ys, hs):
            if h == 0:
                continue
            if h0 is None:
                h0 = abs(x1 - x) + abs(y1 - y) + h
            elif abs(x1 - x) + abs(y1 - y) + h != h0:
                break
        else:
            x_cands.append(x1)
            y_cands.append(y1)

h_cands = []
for xc, yc in zip(x_cands, y_cands):
    for x, y, h in zip(xs, ys, hs):
        if h != 0:
            h_cands.append(h + abs(xc - x) + abs(yc - y))
            break

for xc, yc, hc in zip(x_cands, y_cands, h_cands):
    for x, y, h in zip(xs, ys, hs):
        if h != max(hc - abs(xc - x) - abs(yc - y), 0):
            break
    else:
        print(x_cands[0], y_cands[0], h_cands[0])
        exit(0)

Submission status: Accepted

Solution code:
N = int(input())

infs = []

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

for i in range(101):
    for j in range(101):
        min_dis = 300
        pre_h = 0
        ans = True
        for k in range(N):
            # 一番近いところは大丈夫
            x, y, h = infs[k]
            dx = abs(x - i)
            dy = abs(y - j)
            if min_dis > dx + dy:
                min_dis = dx + dy
                pre_h = h + dx + dy
        for k in range(N):
            # k番目大丈夫か
            x, y, h = infs[k]
            dx = abs(x - i)
            dy = abs(y - j)
            if max(pre_h - dx - dy, 0) != h:
                ans = False
                break

        if ans:
            print(i, j, pre_h)
            break

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())

info = []

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

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

for x,y in product(range(101),repeat=2):
    h=-1
    flag=True
    for i in info:
        if h==-1:
            h=abs(i[0]-x)+abs(i[1]-y)+i[2]
        else:
            if i[2] != max(0,h-abs(i[0]-x)-abs(i[1]-y)):
                flag=False
    if flag:
        X=x
        Y=y
        H=h
        break

print(X,Y,H)

Submission status: Accepted

Solution code:
n = int(raw_input())
pts = [map(int, raw_input().split()) for i in xrange(n)]

for i in xrange(105):
    for j in xrange(105):
        H = 0
        ok = True
        for k in pts:
            if max(H - abs(k[0] - i) - abs(k[1] - j), 0) == k[2]:
                continue
            elif H < 1:
                H = k[2] + abs(k[0] - i) + abs(k[1] - j)
            else:
                ok = False
        if ok and H > 0:

            for k in pts:
                if max(H - abs(k[0] - i) - abs(k[1] - j), 0) == k[2]:
                    continue
                else:
                    ok = False

            if ok:
                print i, j, H
                exit(0)

Submission status: Accepted

Solution code:
def is_correct(n, xs, ys, hs, cx, cy):
    h = abs(xs[0] - cx) + abs(ys[0] - cy) + hs[0]
    for i in range(1, n):
        if hs[i] != max(h - abs(xs[i] - cx) - abs(ys[i] - cy), 0):
            return None
    return h


def solve(n, xs, ys, hs):
    for cx in range(101):
        for cy in range(101):
            h = is_correct(n ,xs, ys, hs, cx, cy)
            if h is not None:
                print('{0} {1} {2}'.format(cx, cy, h))
                return


n = int(input())
xs = []
ys = []
hs = []

for i in range(n):
    line = [int(v) for v in input().split()]
    xs.append(line[0])
    ys.append(line[1])
    hs.append(line[2])

maxi = 0
for i in range(n):
    if hs[i] > hs[maxi]:
        maxi = i
hs[0], hs[maxi] = hs[maxi], hs[0]
xs[0], xs[maxi] = xs[maxi], xs[0]
ys[0], ys[maxi] = ys[maxi], ys[0]

solve(n, xs, ys, hs)

Submission status: Accepted

Solution code:
n = int(input())
p = [[int(i) for i in input().split()] for i in range(n)]
p.sort(key=lambda x: x[2])
a,b,c = p[-1]
f = 0
for cx in range(101):
	for cy in range(101):
		h = c+abs(a-cx)+abs(b-cy)
		if all(k==max(h-abs(i-cx)-abs(j-cy),0) for i,j,k in p): f = 1
		if f: break
	if f: break
print(cx,cy,h)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
RC112 C
"""

n = int(input())
xyhlist = [tuple(map(int,input().split())) for i in range(n)]
xyhlist0 = []
xyhlist1 = []
for x,y,h in xyhlist:
    if h == 0:
        xyhlist0.append((x,y))
    else:
        xyhlist1.append((x,y,h))

candidate = []
from itertools import product
for x,y in product(range(0,101),range(0,101)):
    test = set(map(lambda t:t[2]+abs(t[0]-x)+abs(t[1]-y),xyhlist1))
    if len(test) == 1:
        candidate.append((x,y,test.pop()))
    elif len(test) == 0:
        candidate.append((x,y,1))

for x,y,h in candidate:
    flag = True
    for x0,y0 in xyhlist0:
        if h-abs(x-x0)- abs(y-y0)>0:
            flag = False
    if flag:
        print(x,y,h)
        exit()

Submission status: Accepted

Solution code:
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
arr.sort(key=lambda l:-l[2])

for cx in range(101):
  for cy in range(101):
    ch = None
    for x, y, h in arr:
      t = h + abs(cx-x) + abs(cy-y)
      if h > 0:
        if ch is not None and t != ch:
          break
        ch = t
      else:
        if t < ch:
          break
    else:
      print(cx, cy, ch)
      exit()

Submission status: Accepted

Solution code:
N = int(input())
d = [[int(j) for j in input().split()] for i in range(N)]
ind = float('inf')
for i, (x,y,h) in enumerate(d):
    if h != 0:
        ind = i
        break

for cx in range(0, 101):
    for cy in range(0, 101):
        x,y,h = d[ind]
        H = h + abs(x - cx) + abs(y - cy)
        l = [h == max(H - abs(x - cx) - abs(y - cy), 0) for j,(x,y,h) in enumerate(d) if j != ind]
        if all(l):
            print(cx,cy,H)
            exit()