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:
n = int(input())
s_list = []
ans = 0
zero_list = []
for _ in range(n):
    x, y, s = map(int, input().split())
    if s > 0:
        s_list.append([x, y, s])
    else:
        zero_list.append([x, y, s])
for x in range(101):
    for y in range(101):
        t = []
        for i in range(len(s_list)):
            x_, y_, h = s_list[i]
            if h > 0:
                t.append(h + abs(x_ - x) + abs(y_ - y))
        if (len(set(t)) == 1):
            if len(zero_list) > 0:
                zero_p = max([list(t)[0] - abs(x - x_zero) - abs(y - y_zero) for (x_zero, y_zero, s_zero) in zero_list])
                if zero_p <= 0:
                    ttt = h + abs(x_ - x) + abs(y_ - y)
                    ans = str(x) + " " + str(y) + " " + str(ttt)
                    break
            else:
                ttt = h + abs(x_ - x) + abs(y_ - y)
                ans = str(x) + " " + str(y) + " " + str(ttt)
                break
                
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
N = int(input())
XYH = [tuple(map(int,input().split(' '))) for _ in range(N)]
XYH.sort(key=lambda y:y[2],reverse=True)
x,y,h = XYH[0]
#i,jでありうるすべての中心座標を表現
for i,j in itertools.product(range(101),repeat=2):
  #座標(x,y)における高さと中心座標における高さの関係
  H = h + abs(x-i) + abs(y-j)
  if all(max(H-abs(a-i)-abs(b-j),0)==c for a,b,c in XYH):
    print(i,j,H)
    break

Submission status: Accepted

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

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())

for i in range(n):
    if h[i] != 0:
        s = i
        break
        
for cx in range(101):
    for cy in range(101):
        H = h[s] + abs(x[s] - cx) + abs(y[s] - cy)
        Flag = True
        for k in range(n):
            if h[k] != max(H - abs(x[k] - cx) - abs(y[k] - cy), 0):
                Flag = False
                break  
        if Flag:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
for j in range(N):
    if X[j][2] != 0:
        k = j
        break
A = X[j]
for cx in range(101):
    for cy in range(101):
        H = A[2] + abs(A[0] - cx) + abs(A[1] - cy)
        Flag = True
        for i in range(N):
            if max(H - abs(X[i][0] - cx) - abs(X[i][1] - cy), 0) != X[i][2]:
                Flag = False
                break
        if Flag:
            print(cx, cy, H)
            break
    if Flag:
        break

Submission status: Accepted

Solution code:
N=int(input())
XYH = [[int(a) for a in input().split(" ")] for i in range(N)]
for cx in range(0, 101):
    for cy in range(0, 101):
        Hp = [abs(x-cx)+abs(y-cy)+h for x, y, h in XYH if h>0]
        Hz = [Hp[0]-abs(x-cx)-abs(y-cy) for x,y,h in XYH if h==0] 
        if all([h==Hp[0] for h in Hp]) and all([h<=0 for h in Hz]):
            print(" ".join([str(cx),str(cy),str(Hp[0])]))

Submission status: Accepted

Solution code:
import math
N = int( input())
di = [[-1] * 101 for i in range(101)]



ps = []
basep=0
for k in range(N):
    temp = list(map(int,input().split(" ")))
    ps.append(temp)
    if temp[2] != 0:
        basep = temp
# print(ps)
basex = basep[0]
basey = basep[1]
baseh = basep[2]
# print(basep)
flag = True
for i in range(101):
    for j in range(101):
        flag = True
        X = i
        Y = j
        H = abs(basex - X) + abs(basey - Y) + baseh
        for l,p in enumerate(ps):
            x = p[0]
            y = p[1]
            h = p[2]
        #     print(l,":",p)       
            if max(H -abs(X-x)-abs(Y-y),0) != h: 
                flag = False
                # print("x,y,h:",x,y,h)
                # print("X,Y,H:",X,Y,H)

                # print("break")
                break
        if flag:
                print(X,Y,H)
                break
    if flag:
        break

#         di[i][j].append(h + abs(x-i)  + abs(y-j))
#         print
# for i in range(0,101):
# for j in range(0,101):
#         if len(list(set(di[i][j]))) == 1:
#         print(i,j,di[i][j][0])

Submission status: Accepted

Solution code:
###############################################################################

from bisect import bisect_left as binl
from copy import copy, deepcopy

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


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


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * sy) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()
    xyhlist = intinl(n)

    for x_sample, y_sample, h_sample in xyhlist:
        if h_sample > 0:
            break

    for cx in range(101):
        for cy in range(101):
            h_ans = h_sample + abs(x_sample - cx) + abs(y_sample - cy)
            for x, y, h in xyhlist:
                if h != max(h_ans - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                print('%d %d %d' % (cx, cy, h_ans))
                return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product

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())

max_i = h.index(max(h))
for cx, cy in product(range(101), repeat=2):
    H = h[max_i] + abs(x[max_i] - cx) + abs(y[max_i] - cy)
    ok = True
    for i in range(N):
        if h[i] != max(H - abs(x[i] - cx) - abs(y[i] - cy), 0):
            ok = False
            break
    if ok:
        print(cx, cy, H)
        break

Submission status: Accepted

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

xyh=[[int(l) for l in k] for k in [j.split() for j in [i.strip() for i in sys.stdin.readlines()]]]
xyh=sorted(xyh, key= lambda x : x[2], reverse=True)
#print(xyh)
ef=0

def hgh(c,p):
    return abs(c[0]-p[0])+abs(c[1]-p[1])+p[2]

#ans=[]

for x in range(101):
    if ef:
        break
    for y in range(101):
        th = -1
        c=1
        for plc in xyh:
            #if not plc[2]:
            #    continue
            h = hgh([x,y],plc)
            #print(x,y,h)
            if th<0:
                th = h
                continue
            if h==th:
                continue
            if  h >= th:
                if not plc[2]:
                    continue
            c=0
            break
        if c:
            ef=1
            ans=[str(s) for s in [x,y,th]]
            break

print(" ".join(ans))

Submission status: Accepted

Solution code:
n=int(input())
import sys
place=[]
place_0=[]
place_all=[]
for i in range(n):
    x,y,h=map(int,input().split())
    place_all.append((x,y,h))
    if h==0:
        place_0.append((x,y,h))
    else:
        place.append((x,y,h))
for x in range(0,101):
    for y in range(0,101):
        if not place==[]:
            H=abs(place[0][0]-x)+abs(place[0][1]-y)+place[0][2]
        else:
            H=1
        for i in range(0,n):
            d=abs(place_all[i][0]-x)+abs(place_all[i][1]-y)
            if place_all[i][2]>0:
                if H==place_all[i][2]+d:
                    count=1
                else:
                    count=0
                    break
            else:
                if d>=H:
                    count=1
                else:
                    count=0
                    break
        if count==1:
            print(x,y,H)
            sys.exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    for i, j in product(range(0, 101), range(0, 101)):
        H = set()
        for xx, yy, hh in zip(x, y, h):
            if 0 < hh:
                ch = hh + abs(xx - i) + abs(yy - j)
                H.add(ch)
        if len(H) != 1:
            continue

        hhh = list(H)[0]
        no = False
        for xx, yy, hh in zip(x, y, h):
            if 0 == hh:
                if 0 < hhh - abs(xx - i) - abs(yy - j):
                    no = True
        if no:
            continue

        return "{} {} {}".format(i, j, hhh)


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))
    result = solve(N, x, y, h)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

for Cx in range(101):
  for Cy in range(101):
    flag = True
    H = 0
    for data in datas:
      if data[2] != 0:
        #高さをあるデータから適当に決める
        H = data[2] + abs(data[0] - Cx) + abs(data[1] - Cy)
        break
        
    #直前で適当に決めた高さがほかのデータにも適合すればOK
    for data in datas:
      if data[2] != 0:
        if H != data[2] + abs(data[0] - Cx) + abs(data[1] - Cy):
          flag = False
          break
      else:
        #hi = 0ならH-abs(data[0] - Cx)-abs(data[1] - Cy)<= 0であるあず
        if H - abs(data[0] - Cx) - abs(data[1] - Cy) > 0:
          flag = False
          break
          
    if flag:
      print(Cx, Cy, H)

Submission status: Accepted

Solution code:
n = int(input())
I = [list(map(int, input().split())) for _ in range(n)]
cands = [[x, y] for x in range(101) for y in range(101)]
for cand in cands:
    h = 0
    flag = 0
    list = []
    for i in I:
        if i[2] == 0:
            list.append(i)
            continue
        ch = i[2] + abs(i[0] - cand[0]) + abs(i[1] - cand[1])
        if h == 0:
            flag = 1
            h = ch
            continue
        if h != 0:
            if h != ch:
                flag = 0
                break
    for item in list:
        if h -  abs(item[0] - cand[0]) - abs(item[1] - cand[1]) > 0:
            flag = 0
            break
    if flag == 1:
        print(cand[0], cand[1], h)
        break

Submission status: Accepted

Solution code:
import sys
N = int(input())
data = []
for _ in range(N):
    data.append(list(map(int,input().split())))
CX = -1
CY = -1
H = -1
for cx in range(101):
    for cy in range(101):
        estimated_h = -1
        for d in data:
            x,y,h = d
            if h <= 0:
                continue

            if estimated_h < 0 :
                estimated_h = abs(x-cx) + abs(y-cy) + h
            if estimated_h != abs(x-cx) + abs(y-cy) + h:
                break
        else:
            CX = cx
            CY = cy
            H = estimated_h
            for d in data:
                x, y, h = d
                if max(H - abs(x-cx) - abs(y-cy), 0) != h:
                    H = -1
                    CX = -1
                    CY = -1
                    break
            else:
                print(cx,cy,estimated_h)
                sys.exit(0)

Submission status: Accepted

Solution code:
N = int(input())

class Position():
    def __init__(self, x, y, h):
        self.x = x
        self.y = y
        self.h = h

    def hamming_distance(self, x, y):
        return abs(self.x - x) + abs(self.y - y)

    def original_height(self, x, y):
        height = self.h + self.hamming_distance(x, y)
        if self.h == 0:
            return False, height
        else:
            return True, height

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

pos = [[x, y] for x in range(101) for y in range(101)]
for x, y in pos:
    H = 0
    for position in position_list:
        is_safe, h = position.original_height(x, y)
        if is_safe:
            H = h
            break
    if H < 1:
        continue
    is_correct = True
    for position in position_list:
        hamming = position.hamming_distance(x, y)
        if hamming > H and position.h == 0:
            continue
        _, original_height = position.original_height(x, y)
        if original_height != H:
            is_correct = False
            break
    if is_correct:
        print("{0} {1} {2}".format(x, y, H))
        break

Submission status: Accepted

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

def calc(cx, cy):
    excepth = -1
    for x, y, h in ps:
        if h > 0:
            tmph = h + abs(x - cx) + abs(y - cy)
            if excepth == -1:
                excepth = tmph
            elif excepth != tmph:
                return -1
    for x, y, h in ps:
        if h == 0:
            tmpd = abs(x - cx) + abs(y - cy)
            if excepth - tmpd > 0:
                return -1
    return excepth

for cy in range(101):
    for cx in range(101):
        resh = calc(cx, cy)
        if resh != -1:
            print(cx, cy, resh)
            break

Submission status: Accepted

Solution code:
N = int(input())
XYH = [[int(i) for i in input().split()] for j in range(N)]
search = 0
while XYH[search][2] == 0:
    search += 1

for X in range(101):
    for Y in range(101):
        H = XYH[search][2] + abs(X-XYH[search][0]) + abs(Y-XYH[search][1])
        for x,y,h in XYH:
               if h != max(H - abs(X-x) -abs(Y-y),0):
                    break
        else:
            print(X,Y,H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
xyh = []
xyh1 = []
for _ in range(N):
	x0, y0, h0 = map(int, input().split())
	xyh.append([x0,y0,h0])
	if h0 > 0:
		xyh1.append([x0,y0,h0])

def absum(x, y, h, Cx, Cy):
	return abs(x - Cx) + abs(y - Cy) + h

if len(xyh1) > 1:
	for Cx in range(101):
		for Cy in range(101):
			for i in range(len(xyh1)-1):
				if absum(xyh1[i][0], xyh1[i][1], xyh1[i][2], Cx, Cy) != absum(xyh1[i+1][0], xyh1[i+1][1], xyh1[i+1][2], Cx, Cy):
					break
			else:
				H = absum(xyh1[i][0], xyh1[i][1], xyh1[i][2], Cx, Cy)
				print(Cx, Cy, H)
else:
	print(xyh1[0][0], xyh1[0][1], xyh1[0][2])

Submission status: Accepted

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

n = int(input())
l = []
for _ in range(n):
    x, y, h = map(int, input().split())
    if h >= 1:
        l.append([x, y, h])

result = None
for i in range(101):
    for j in range(101):
        judge = True
        x, y, h = l[0]
        highest = abs(i - x) + abs(j - y) + h
        if len(l) == 1:
            result = (x, y, h)
            break
        for x, y, h in l[1:]:
            if abs(i - x) + abs(j - y) + h != highest:
                judge = False
                break
        if judge:
            result = (i, j, highest)
            break
    if result:
        break

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

Submission status: Accepted

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


first = True
record = {}
target = None
for x, y, h in nums:
    if h != 0:
        target = x, y, h

if target is not None:
    x, y, h = target
    for i in range(0,101):
        for j in range(0, 101):
            if abs(x - i) + abs(x - j) + h >= 1:
                record[(i,j)] = abs(x - i) + abs(y - j) + h
    
    for x, y, h in nums:
        for (i, j) in list(record.keys()):
            if max(record[(i, j)] - abs(x-i) - abs(y-j), 0) != h:
                record.pop((i,j))
    key = list(record.keys())[0]

    print(key[0],key[1], record[key])
else:
    for x, y, h in nums:
        record[(x,y)] = True
    ndone = True
    for i in range(101):
        for j in range(101):
            if (i, j) not in record and ndone:
                print(i, j, 1)
                ndone = False

Submission status: Accepted

Solution code:
import itertools

n=int(input())
# x1,y1,h1
test_data = []
for _ in range(n):
     check=[int(i) for i in input().split()]
     test_data.append(check)
     if check[2]!=0:
         a,b,c=check

for cx, cy in itertools.product(range(100 + 1), range(100+1)):
    blnCorrect=True
    H=c + abs(a - cx) + abs(b - cy)
    for coord in test_data:
        if  coord[2]!=max(H-abs(coord[0] - cx) - abs(coord[1] - cy),0):
            blnCorrect = False
            break
    if blnCorrect:
        print(cx,cy,H)
        break

Submission status: Accepted

Solution code:
N = int(input())

xyh = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h != 0:
        xx, yy, hh = x, y, h
    xyh.append((x, y, h))

# print(xyh)

# h = max(H - |x - Cx| - |y - Cy|, 0)

'''
  0 1 2 3
0
1     5
2   5   5
3     5

   99 100
0 192
1 191 192
'''


def f():
    for tx in range(101):
        for ty in range(101):
            th = hh + abs(xx - tx) + abs(yy - ty)
            if all(h == max(th - abs(tx - x) - abs(ty - y), 0) for x, y, h in xyh):
                return tx, ty, th

print(*f())

Submission status: Accepted

Solution code:
N = int(input())
XYH = []
for i in range(N):
    tmp = list(map(int, input().split()))
    if tmp[2] != 0:
        xyh = tmp
    XYH.append(tmp)

def calc(XYH, xyh):
    for tarx in range(101):
        for tary in range(101):
            tarh = xyh[2] + abs(xyh[0] - tarx) + abs(xyh[1] - tary)
            if all(h==max(tarh - abs(tarx - x) - abs(tary - y), 0) for x, y, h in XYH):
                return list(map(str, [tarx, tary, tarh]))
    
print(" ".join(calc(XYH, xyh)))

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
    x,y,h=map(int,input().split())
    l.append([x,y,h])
    if h!=0:
        a,b,c=x,y,h
for x in range(101):
    for y in range(101):
        h=c+abs(x-a)+abs(y-b)
        if all(r==max(h-abs(x-s)-abs(y-t),0)for s,t,r in l):
            print(x,y,h)
            exit()

Submission status: Accepted

Solution code:
import sys

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):
        H =xyh[0][2] + abs(xyh[0][0] - cx) + abs(xyh[0][1] - cy)
        for idx in range(1,N):
            if xyh[idx][2] != max(0,H-(abs(xyh[idx][0] - cx) + abs(xyh[idx][1] - cy))):
                break
        else:
            print(cx,cy,H)
            sys.exit()

Submission status: Accepted

Solution code:

N = int(input())

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

X.sort(key = lambda item: item[2] ,reverse = True)

for i in range(101):
    for j in range(101):
        h = X[0][2] + abs(X[0][0] - i) + abs(X[0][1] - j)

        ok = True
        for k in range(N):
            if X[k][2] != max((h - abs(X[k][0] - i) - abs(X[k][1] - j)), 0):
                ok = False

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

Submission status: Accepted

Solution code:
def dist(a, b, x, y, h):
    return h + abs(a - x) + abs(b - y)

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

for i in range(101):
    for j in range(101):
        H = dist(i, j, P[0][1], P[0][2], P[0][0])
        for p in P[1:]:
            if max(H - abs(p[1] - i) - abs(p[2] - j), 0) != p[0]:
                break
        else:
            print(i, j, H)
            break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 18 22:48:00 2019

@author: Yamazaki Kenichi
"""
import sys

N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
A.sort(key = lambda x:x[2], reverse = True)
ans = [-1,-1,1]
if A[0][2] == 1:
    print(' '.join(map(str,A[0])))
    sys.exit()

for i in range(101):
    for j in range(101):
        h = A[0][2] + abs(A[0][0]-i) + abs(A[0][1]-j)
        counta = 0
        for c in A:
#            print(i,j,h)
            if h == c[2] + abs(c[0]-i) + abs(c[1]-j) or c[2] == 0:
                counta += 1
            else:
                break
            if counta == N:
                if h > ans[2]:
                    ans = [i,j,h]
print(' '.join(map(str,ans)))

Submission status: Accepted

Solution code:

def check(x, y, data, num):
    high = 0
    check_data = []
    for i in range(num):
       if data[i][2] == 0:
           check_data.append(data[i])
           continue
       if high == 0:
           high = abs(x - data[i][0]) + abs(y - data[i][1]) + data[i][2]
       else:
           if high != abs(x - data[i][0]) + abs(y - data[i][1]) + data[i][2]:
               return 0
    for i in range(len(check_data)):
        high_now = high - abs(x - check_data[i][0]) - abs(y - check_data[i][1])
        if high_now > 0:
            return 0

    return high



if __name__ == '__main__':
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]

    if len(data) == 1:
        print(data[0][0], data[0][1], data[0][2])
    else:

        for i in range(101):
            for j in range(101):
                flg = check(i, j, data, num)
                if flg:
                    print(i, j, flg)
                    break
            if flg:
                break

Submission status: Accepted

Solution code:
n=int(input())
p=[list(map(int,input().split()))for i in range(n)]
d=[]
for i in range(n):
  if p[i][2]==0:
    d.append(i)
d.sort(reverse=1)
for i in d:
  del p[i]
if len(p)==1:
  print(p[0][0],p[0][1],p[0][2])
else:
  for i in range(0,101):
    for j in range(0,101):
      k=1
      l=p[0][2]+abs(i-p[0][0])+abs(j-p[0][1])
      for x,y,h in p:
        if h==0:
          continue
        m=h+abs(i-x)+abs(j-y)
        if l!=m:
          k=0
      if k:
        ans=[i,j,l]
  print(ans[0],ans[1],ans[2])

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

point = [[int(item) for item in input().split()] for _ in range(N)]
point.sort(key=lambda x:x[2], reverse=True)

ans = np.zeros((101,101))

for i,p in enumerate(point):
  if i == 0:
    for j in range(101):
      for k in range(101):
        H = p[2] + abs(j - p[0]) + abs(k - p[1])
        ans[j,k] = H
      #  print(ans[j,k])
  else:
    for j in range(101):
      for k in range(101):
        if not ans[j,k] == 0:
          if ans[j,k] != p[2] + abs(j - p[0]) + abs(k - p[1]):
            ans[j,k] = 0
  if len(ans[ans!=0]) <= 1:
    break
x,y = np.where(ans!=0)
print(x[0],y[0],int(ans[x[0],y[0]]))

Submission status: Accepted

Solution code:
import sys
n = int(input())
data = []
for i in range(n):
    data.append([ int(i) for i in input().split() ])
for x in range(101):
    for y in range(101):
        h = set()
        le = 1e18
        for pt in data:
            xcx = abs(x-pt[0])
            ycy = abs(y-pt[1])
            if pt[2] > 0:
                h.add(pt[2] + xcx + ycy )
            elif pt[2] == 0:
                le = min( le, xcx + ycy )
        if len(h) == 1:
            for i in h:
                if i <= le:
                    print(x,y,i)
                    sys.exit(0)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    points = []
    for i in range(n):
        points.append(list(map(int, input().split())))

    for c_x in range(101):
        for c_y in range(101):
            is_correct = True
            estimated_height = 0
            for point in points:
                x = point[0]
                y = point[1]
                h = point[2]
                if h != 0:
                    estimated_height = abs(c_x - x) + abs(c_y - y) + h
                    break

            for point in points:
                x = point[0]
                y = point[1]
                h = point[2]
                if h != 0:
                    if estimated_height != abs(c_x - x) + abs(c_y - y) + h:
                        is_correct = False
                        break
                else:
                    if estimated_height - abs(c_x - x) - abs(c_y - y) > 0:
                        is_correct = False
                        break

            if is_correct:
                # outputの形式を確認する
                print(c_x, c_y, estimated_height)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
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)
 
for i in range(n):
  if h[i]!=0:
      s=i
      break
 
for cx in range(101):
  for cy in range(101):
    H=h[s]+abs(x[s]-cx)+abs(y[s]-cy)
    for i in range(n):
      if h[i]!=max(0,H-abs(x[i]-cx)-abs(y[i]-cy)):break
      if i==n-1:print(cx,cy,H);exit()

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())

xyh = []
for _ in range(N):
    xyh.append(list(map(int, input().split())))
xyh = np.array(xyh)
xyh = xyh[np.argsort(xyh[:, 2])[::-1]]

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

Hdict = [[] for i in range(101)]
for i in range(len(cxylist)):
    x, y, h =xyh[0]
    H = h + abs(x-cxylist[i][0]) + abs(y-cxylist[i][1])
    Hdict[cxylist[i][0]].append(H)

def calh(cxylist, x, y, h):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        H = h + abs(x-cx) + abs(y-cy)
        if Hdict[cx][cy] == H:
            newcxylist.append([cx, cy])
    return newcxylist

def checkh(cxylist, x, y):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        if Hdict[cx][cy] - abs(x-cx) - abs(y-cy) <= 0:
            newcxylist.append([cx, cy])
    return newcxylist

for n in range(N-1):
    if xyh[n+1][2] != 0:
        cxylist = calh(cxylist, xyh[n+1][0], xyh[n+1][1], xyh[n+1][2])
    else:
        cxylist = checkh(cxylist, xyh[n+1][0], xyh[n+1][1])

print(cxylist[0][0], cxylist[0][1], Hdict[cxylist[0][0]][cxylist[0][1]])

Submission status: Accepted

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

for cx in range(100 + 1):
    for cy in range(100 + 1):
        # すべての中心候補に対して
        H = -1
        for x, y, h in xyh:
            if h > 0:
                t = h + abs(x - cx) + abs(y - cy)
                if H == -1:
                    H = t
                else:
                    if H != t:
                        # 適切な中心を選んでいるときは、すべてのHが一致する
                        break
        else:
            for x, y, h in xyh:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                if H >= 1:
                    print(cx, cy, H)
                    exit()

Submission status: Accepted

Solution code:
n = int(input())
xyhs = [list(map(int, input().split())) for _ in range(n)]
ans_cx = 0
ans_cy = 0
ans_h = 0

if n == 1:
    ans_cx, ans_cy, ans_h = xyhs[0]
elif all([xyh[2] == 0 for xyh in xyhs]):
    ans_cx = 0
    ans_cy = 0
    for x, y, h in xyhs:
        ans_cx += x
        ans_cy += y
    ans_cx //= n
    ans_cy //= n
    ans_h = abs(xyhs[0][0] - ans_cx) + abs(xyhs[0][1] - ans_cy)
else:
    for cx in range(101):
        for cy in range(101):
            h_set = set([h + abs(x - cx) + abs(y - cy) for x, y, h in xyhs if h != 0])
            if len(h_set) > 1:
                continue
            h_ = list(h_set)[0]
            if all([max(h_ - abs(x - cx) - abs(y - cy), 0) == h for x, y, h in xyhs]):
                ans_cx = cx
                ans_cy = cy
                ans_h = h_

print(ans_cx, ans_cy, ans_h)