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

xyh = [[int(i) for i in input().split()] for j in range(n)]

xyh.sort(key=lambda x: -x[2])

cxy = 101

flag = 0

H = 0
cx = 0
cy = 0

for i in range(cxy):
    for j in range(cxy):
        flag = 0
        for k in range(n):
            if xyh[k][2] == 0:
                tmp = H - abs(xyh[k][0] - i ) - abs(xyh[k][1] - j )
                if tmp <= 0 and k == n-1:
                    print(cx,cy,H)
                    exit()
                elif tmp <= 0:
                    continue
                else:
                    break
                
            H = xyh[k][2] + abs(xyh[k][0] - i ) + abs(xyh[k][1] - j )
            
            flag += 1
            
            if flag == 1:
                H_old = H
            
            if flag > 1:
                if H != H_old:
                    break
            
            cx = i
            cy = j
            
            #print(i,j,k,H,n-1)
            
            if k == n-1:
                print(cx,cy,H)
                exit()
                break
        """
        if k == n-1:
            break
    if k == n-1:
        break
    """

#print(cx,cy,H)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [[int(i) for i in input().split()] for j in range(N)]

xyh.sort(key=lambda x: x[2])
l = xyh[-1]
Cx = 0
Cy = 0
for i in range(101):
    Cx = i
    for j in range(101):
        Cy = j
        H = abs(Cx - l[0]) + abs(Cy - l[1]) + l[2]
        for p in xyh:
            if p[2] != max(0, H - abs(Cx - p[0]) - abs(Cy - p[1])):
                break
        else:
            print(Cx, Cy, H)
            exit()

Submission status: Accepted

Solution code:
import sys
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)
if xyh[0][2]==0:
  total=0
  for i in range(n):
    total+=xyh[i][0]
  cx=total//n
  total=0
  for i in range(n):
    total+=xyh[i][1]
  cy=total//n
  ch=abs(xyh[0][0]-cx)+abs(xyh[0][1]-cy)
  print(cx,cy,ch)
  sys.exit()  
for cx in range(101):
  for cy in range(101):
    ch=abs(xyh[0][0]-cx)+abs(xyh[0][1]-cy)+xyh[0][2]
    flg=0
    for i in range(n):
      if xyh[i][2]!=max(0, ch-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)):
        flg=1
        break
    if flg==0:
      print(cx,cy,ch)
      sys.exit()

Submission status: Accepted

Solution code:
n=int(input())
hoge=[]
for i in range(n):
  x,y,z=map(int,input().split())
  if(z!=0):
    hoge.append([x,y,z])
  

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

for i in range(101):
  for j in range(101):
    h=[]
    for k in range(len(hoge)):
      h.append(hoge[k][2]+abs(hoge[k][0]-i)+abs(hoge[k][1]-j))
      
    if(h.count(h[0])==len(h)):
      print(i,j,h[0])

Submission status: Accepted

Solution code:
N = int(input())
old_dl = [list(map(int,input().split())) for _ in range(N)]
dl = []
for k in old_dl:
    if k[2] != 0:
        dl.append(k)
if len(dl) == 1:
    print(*dl[0])
else:
    for x in range(101):
        for y in range(101):
            ndl = [l[2]+abs(l[0]-x)+abs(l[1]-y) for l in dl]
            if max(ndl) == min(ndl):
                #print(ndl)
                print(x,y,max(ndl))
                exit(0)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda x: x[2])
x = [0] * N
y = [0] * N
h = [0] * N
for i in range(N):
    x[i], y[i], h[i] = xyh[i][0], xyh[i][1], xyh[i][2]

flag = False
for cx in range(101):
    for cy in range(101):
        needH = -1
        for i in range(N-1, -1, -1):
            if h[i] > 0:
                H = abs(x[i] - cx) + abs(y[i] - cy) + h[i]
                if needH == -1:
                    needH = H
                else:
                    if needH != H:
                        needH = -2
                        break
            else:
                dist = abs(x[i] - cx) + abs(y[i] - cy)
                # distの方が大きくなければいけない
                if needH > dist:
                    needH = -2
                    break

        if needH == -2:
            continue
        else:
            flag = True
        if flag:
            break
    if flag:
        break

print(cx, cy, H)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda x: x[2])
x = [0] * N
y = [0] * N
h = [0] * N
for i in range(N):
    x[i], y[i], h[i] = xyh[i][0], xyh[i][1], xyh[i][2]

flag = False
for cx in range(101):
    for cy in range(101):
        needH = -1
        for i in range(N-1, -1, -1):
            if h[i] > 0:
                H = abs(x[i] - cx) + abs(y[i] - cy) + h[i]
                if needH == -1:
                    needH = H
                else:
                    if needH != H:
                        needH = -2
                        break
            else:
                dist = abs(x[i] - cx) + abs(y[i] - cy)
                # distの方が大きくなければいけない
                if needH > dist:
                    needH = -2
                    break
                    
        if needH == -2:
            continue
        else:
            flag = True
        if flag:
            break
    if flag:
        break

print(cx, cy, H)

Submission status: Accepted

Solution code:
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())

flag = False
for cx in range(101):
    for cy in range(101):
        needH = -1
        for i in range(N):
            if h[i] > 0:
                H = abs(x[i] - cx) + abs(y[i] - cy) + h[i]
                if needH == -1:
                    needH = H
                else:
                    if needH != H:
                        needH = -2
                        break
        if needH == -2:
            continue
            
        for i in range(N):
            if h[i] == 0:
                dist = abs(x[i] - cx) + abs(y[i] - cy)
                # distの方が大きくなければいけない
                if needH > dist:
                    needH = -2
                    break
        if needH == -2:
            continue
        else:
            flag = True
        if flag:
            break
    if flag:
        break
                    
print(cx, cy, H)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    P = [None] * N
    x0, y0, h0 = 0, 0, 0
    for i in range(N):
        x, y, h = map(int, input().split())
        if h != 0 and h0 == 0:
            x0, y0, h0 = x, y, h
        P[i] = (x, y, h)
    for i in range(101):
        for j in range(101):
            H = h0 + abs(i-x0) + abs(j-y0)
            for x, y, h in P:
                dist = abs(i-x) + abs(j-y)
                if (h > 0 and dist != H-h) or (h == 0 and dist < H):
                    break
            else:
                print(i, j, H)
                return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda val: val[2])
 
for cx in range(101):
    for cy in range(101):
        check = True
        H = xyh[-1][2] + abs(xyh[-1][0] - cx) + abs(xyh[-1][1] - cy)
        for x in xyh[:-1]:
            if x[2] != max(H - abs(x[0] - cx) - abs(x[1] - cy), 0):
                check = False
                break
        if check:
            print(cx, cy, H)
            exit()

Submission status: Accepted

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


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    X = 0
    Y = 0
    hh = 0
    for i in range(0, 101):
        for j in range(0, 101):
            H =  []
            s = 0
            for k in range(N):
                if h[k] > 0:
                    s += h[k]
                    H.append(h[k] + abs(x[k] - i) + abs(y[k] - j))
            if len(H) > 1 and len(list(set(H))) == 1:
                X, Y, hh = i, j, H[-1]
            elif len(H) == 1 and H[0] == s:
                X, Y, hh = i, j, H[0]

    print(X, Y, hh)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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))
    solve(N, x, y, h)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        check = True
        H = xyh[-1][2] + abs(xyh[-1][0] - cx) + abs(xyh[-1][1] - cy)
        for x in xyh[:-1]:
            if x[2] != max(H - abs(x[0] - cx) - abs(x[1] - cy), 0):
                check = False
                break
        if check:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *

N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
xyh.sort(key = lambda z: -z[2])
for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        H = h+abs(cx-x)+abs(cy-y)
        for x, y, h in xyh[1:]:
            _h = max(H-abs(cx-x)-abs(cy-y), 0)
            if h != _h:
                break
        else:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
# 2019/07/26

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=xyh[0][0]+abs(xyh[0][1]-i)+abs(xyh[0][2]-j)
        for k in range(1,n):
            h,x,y=xyh[k]
            HH=h+abs(x-i)+abs(y-j)
            if H==HH or H-HH<0 and h==0:continue
            else:break
        else:
            print(*[i,j,H])
            exit()

Submission status: Accepted

Solution code:
N = int(input())
l = [list(map(int,input().split())) for i in range(N)]
l.sort(key = lambda x: x[2])
for x in range(101):
    for y in range(101):
        H = abs(x-l[-1][0])+abs(y-l[-1][1])+l[N-1][2]
        if all((l[i][2] == max(H-abs(x-l[i][0])-abs(y-l[i][1]),0) for i in range(N))):
            print(x,y,H)
            break
    else:
        continue
    break

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

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

		for k in range(N):
			if X[k][2] == max(H-abs(i-X[k][0])-abs(j-X[k][1]),0):
				count += 1
		
		if count == N:
			print(i,j,H)
			break
		count = 0

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ABC112C
import sys

n = int(input())

x = []
y = []
h = []
for i in range(0,n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	x.append(hoge[0])
	y.append(hoge[1])
	h.append(hoge[2])

distance=0
height=0

m=0
while(h[m]==0):
	m+=1
for i in range(0,101):
	for j in range(0,101):
		distance=abs(i-x[m])
		distance+=abs(j-y[m])
		height=distance+h[m]
		for k in range(0,n):
			distance=abs(i-x[k])
			distance+=abs(j-y[k])
			if(max(height-distance,0)!=h[k]):
				break
			if(k==n-1):
				print(i,j,height)
				sys.exit()

Submission status: Accepted

Solution code:
N = int(input())
List = []
for i in range(N):
    List.append([int(a) for a in input().split()])

temp = []

for j in range(N):
    if List[j][2] > 0:
        ind = j
        break

for cx in range(101):
    for cy in range(101):
        H = List[ind][2] + abs(List[ind][0]-cx) + abs(List[ind][1]-cy)
        temp.append([cx,cy,H])
        
for k in range(len(temp)):
    num = 0
    for l in range(N):
        if List[l][2] == max(temp[k][2]-abs(List[l][0]-temp[k][0])-abs(List[l][1]-temp[k][1]),0):
            num += 1
        else:
            break
    if num == N:
        ans = k
        break
    
print("{} {} {}".format(temp[ans][0],temp[ans][1],temp[ans][2]))

Submission status: Accepted

Solution code:

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

for cx in range(101):
    for cy in range(101):
        for i in li:
            if i[2] != 0:
                ans.append([cx, cy, i[2] + abs(i[0]-cx) + abs(i[1] -cy)])
                break

for i in li:
    if len(ans) ==1:
        break
    if i[2] != 0:
        for j in reversed (range(len(ans[:]))):
            if ans[j][2] - abs(i[0]-ans[j][0]) - abs(i[1]-ans[j][1]) != i[2]:
                ans.pop(j)
    if i[2] == 0:
        for j in reversed (range(len(ans[:]))):
            if ans[j][2] - abs(i[0]-ans[j][0]) - abs(i[1]-ans[j][1]) > i[2]:
                ans.pop(j)

print(" ".join(map(str, ans[0])))

Submission status: Accepted

Solution code:
N = int(input())
learn = []
verify = []
for i in range(N):
    a = tuple(map(int, input().split()))
    if a[2] > 0 and learn == []:
        learn.append(a)
    else:
        verify.append(a)

for Cx in range(101):
    for Cy in range(101):
        H = learn[0][2] + abs(learn[0][0] - Cx) + abs(learn[0][1] - Cy)
        right = True
        for v in verify:
            if max(H - abs(v[0] - Cx) - abs(v[1] - Cy), 0) != v[2]:
                right = False
                break
        else:
            break
        continue
    else:
        continue
    break

print(Cx, Cy, H)

Submission status: Accepted

Solution code:
N = int(input())
X = []
Y = []
H = []
for i in range(N):
  x, y, h = map(int, input().split())
  X.append(x)
  Y.append(y)
  H.append(h)
  if h > 0:
    x_, y_, h_ = x, y, h

for px in range(101):
  for py in range(101):
    H_ = h_ + abs(px-x_) + abs(py-y_)
    for i in range(N):
      if H[i] != max(H_ - abs(px-X[i]) - abs(py-Y[i]), 0):
        break
    else:
      print(px, py, H_)
      exit()

Submission status: Accepted

Solution code:
N = int(input())
X = []
Y = []
H = []
xc = None
yc = None
hc = None
for _ in range(N):
    x, y, h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    if h > 0:
        xc = x
        yc = y
        hc = h

for pos_x in range(101):
    for pos_y in range(101):
        center_h = hc + abs(xc - pos_x) + abs(yc - pos_y)

        flag = True
        for n in range(N):
            if H[n] != max(center_h - abs(X[n] - pos_x) - abs(Y[n] - pos_y), 0):
                flag = False
                break
        if flag:
            print(pos_x, pos_y, center_h)
            exit()

Submission status: Accepted

Solution code:
n=int(input())

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

for i in range(101):
	for j in range(101):
		for k in range(n):
			if x[k][2]>0:
				h=x[k][2]+abs(i-x[k][0])+abs(j-x[k][1])
				break
		chk=0
		for k in range(n): 
			if x[k][2]!=max(h-abs(i-x[k][0])-abs(j-x[k][1]),0):
				chk=1
				break
		if chk==0:
			res=[i,j,h]
			break
	if chk==0:
		break

print(*res)

Submission status: Accepted

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

v=[]
count=0

#各頂点に対して、中心座標と仮定して検証
for i in range(101):
    for j in range(101):
        x=abs(j-z[0][0])
        y=abs(i-z[0][1])
        h=z[0][2]+abs(x)+abs(y)
                
            #候補があってるか確認
        for k in range(n):
            if z[k][2]==max(h-abs(z[k][0]-j)-abs(z[k][1]-i),0):
                count+=1
                
        if count==n:
            print(j,i,h)
            exit()
        count=0

Submission status: Accepted

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

xi, yi, hi = None, None, None
for x, y, h in xyh:
    if h > 0:
        xi, yi, hi = x, y, h
        break

for cx in range(101):
    for cy in range(101):
        H = hi + abs(xi - cx) + abs(yi - cy)
        matched = True
        for x, y, h in xyh:
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                matched = False
                break
        if matched:
            print(cx, cy, H)
            exit(0)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [list(map(int, input().split())) for _ in range(n)]
    a0 = list(filter(lambda aa: aa[2] > 0, a))[0]

    for i in range(101):
        for j in range(101):
            is_ok = True
            h_ans = a0[2] + abs(a0[0] - i) + abs(a0[1] - j)
            for x, y, h in a:
                if max(h_ans - abs(x - i) - abs(y - j), 0) != h:
                    is_ok = False
                    break
            if is_ok:
                break
        if is_ok:
            break

    print(i, j, h_ans)


main()

Submission status: Accepted

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

for cx in range(0,101):
    for cy in range(0,101):
        formerH = 0
        H = 0
        flag = 0
        for i in range(n):
            x = l[i][0]
            y = l[i][1]
            h = l[i][2]
            if i == 0:
                formerH = 0
            else:
                formerH = H
            if h == 0:
                if max(H-abs(x-cx)-abs(y-cy),0) != 0:
                    break
            else:         
                H = abs(x-cx)+abs(y-cy)+h
                if i > 0 and H != formerH:
                    break
            if i == n-1:
                a_cx = cx
                a_cy = cy
                a_H = H
                flag = 1
                break
        if flag == 1:
            break
    if flag == 1:
        break

if flag == 1:
    print(a_cx,a_cy,a_H)

Submission status: Accepted

Solution code:
def larger(x, y):
	if x > y:
		return x
	return y

N = int(input())
lst = []
for i in range(0, N):
	x, y, h = map(int, input().split())
	lst.append([x, y, h])
lst.sort(key = lambda v: v[2], reverse = True)
for i in range(0, 101):
	flag1 = False
	for j in range(0, 101):
		H = lst[0][2] + abs(lst[0][0]-i) + abs(lst[0][1]-j)
		flag2 = True
		for k in range(1, N):
			if larger(H-abs(lst[k][0]-i)-abs(lst[k][1]-j), 0) != lst[k][2]:
				flag2 = False
				break
		if flag2:
			print(str(i)+' '+str(j)+' '+str(H))
			flag1 = True
			break
	if flag1:
		break

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])
l.sort(reverse=True, key=lambda x: x[2])
for x in range(101):
    for y in range(101):
        height = l[0][2] + abs(x - l[0][0]) + abs(y - l[0][1])
        for pyx, pyy, pyh in l:
            if pyh != max(height - abs(x - pyx) - abs(y - pyy), 0):
                break
        else:
            print(x, y, height)
            exit()

Submission status: Accepted

Solution code:
n,*xyh=map(int,open(0).read().split())
x=xyh[0::3]
y=xyh[1::3]
h=xyh[2::3]

hmax_i = h.index(max(h))
for cx in range(101):
    for cy in range(101):
        H = abs(cx-x[hmax_i]) + abs(cy-y[hmax_i]) + h[hmax_i]
        for i in range(0,n):
            if max(H-abs(cx-x[i])-abs(cy-y[i]),0) == h[i]:
                if i == n-1:
                    print(cx,cy,H)
                    exit()
                else:
                    continue
            else:
                break

Submission status: Accepted

Solution code:
n,*xyh=map(int,open(0).read().split())
x=xyh[0::3]
y=xyh[1::3]
h=xyh[2::3]

for cx in range(101):
    for cy in range(101):
        hmax_i = h.index(max(h))
        H = abs(cx-x[hmax_i]) + abs(cy-y[hmax_i]) + h[hmax_i]
        for i in range(0,n):
            if max(H-abs(cx-x[i])-abs(cy-y[i]),0) == h[i]:
                if i == n-1:
                    print(cx,cy,H)
                    exit()
                else:
                    continue
            else:
                break

Submission status: Accepted

Solution code:
N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]
H_list= [XYH[i][2] for i in range(N)]
H_max = max(H_list)
H_min = min(H_list)
H_diff = H_max - H_min
ans = []

# 高さH,中心座標を(Cx, Cy)として総当たりで試す
for H in range(H_max - (200 - H_diff), H_max + (201 - H_diff)):
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            count = 0
            for X, Y, h in XYH:
                if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                    count += 1
                else:
                    break

            if count == N:
                ans = [str(Cx), str(Cy), str(H)]

print(' '.join(ans))

Submission status: Accepted

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

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

maxh = 0
for x,y,h in xyh:
    maxh = max(maxh,h)
for H in range(maxh,maxh+201):
    for cx in range(101):
        for cy in range(101):
            for x,y,h in xyh:
                if h != max(H-abs(x-cx)-abs(y-cy),0):
                    break
            else:
                print(cx,cy,H)
                quit()

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

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            flg=True
            for i in H:
                d=i
            for i in range(n):
                x,y,h=a[i]
                if max(0,d-abs(x-cx)-abs(y-cy))!=h:
                    flg=False
            if flg:
                ans=cx,cy,d
print(*ans)

Submission status: Accepted

Solution code:
def solve():
    cands = []
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            is_center = True
            temp_h = -1
            for x, y, h in m:
                if h != 0:
                    calc_h = h + abs(cx - x) + abs(cy - y)
                    if temp_h == -1:
                        temp_h = calc_h
                    else:
                        if temp_h != calc_h:
                            is_center = False
                            break
            if is_center:
                cands.append((cx, cy, temp_h))

    for cx, cy, temp_h in cands:
        is_answer = True
        for x, y, h in m:
            if h == 0:
                if temp_h - abs(cx - x) - abs(cy - y) > 0:
                    # h=0の位置では、計算された高さは0以下の必要がある
                    is_answer = False
                    break
        if is_answer:
            return cx, cy, temp_h

    return -1, -1, -1


n = int(input())
m = tuple(tuple(map(int, input().split())) for _ in range(n))
print(*solve())

Submission status: Accepted

Solution code:
N = int(input())
p = [[] for i in range(N)]

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

p = sorted(p, key=lambda x: x[2], reverse=True)

ok = False
for cx in range(101):
    for cy in range(101):
        x, y, h = p[0]
        H = h + abs(cx - x) + abs(cy - y)
        ok = True
        for i in range(1, N):
            x, y, h = p[i]
            if h != max(H - abs(cx - x) - abs(cy - y), 0):
                ok = False
                break
        if ok:
            print(cx, cy, H)
            break
    if ok:
        break

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
xyhl = [list(map(int, input().split())) for _ in range(n)]
xyhl1 = [xyh for xyh in xyhl if xyh[2] != 0]
xyhl0 = [xyh for xyh in xyhl if xyh[2] == 0]

tmaps = np.zeros((101, 101, len(xyhl1)), dtype="int64")
for d in range(len(xyhl1)) :
    for i in range(101) :
        for j in range(101) :
            x, y, h = xyhl1[d]
            tmaps[i, j, d] = abs(x-i)+abs(y-j)+h

tmap0 = np.zeros((101, 101, len(xyhl0)), dtype="int64")
for d in range(len(xyhl0)) :
    for i in range(101) :
        for j in range(101) :
            x, y, h = xyhl0[d]
            tmap0[i, j, d] = abs(x-i)+abs(y-j)+h

dmaps = np.diff(tmaps, axis=2)
xmap = np.logical_or.reduce(dmaps, axis=2)
place = np.where(np.logical_not(xmap))

for i, j in zip(place[0],place[1]) :
    for t in tmap0[i, j, :].flat :
        if tmaps[i, j, 0] > t :
            break
    else :
        ans = [i, j, tmaps[i, j, 0]]

print("{} {} {}".format(ans[0], ans[1], ans[2]))

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=itemgetter(2))
x, y, h = xyh[-1][0], xyh[-1][1], xyh[-1][2]

for px in range(101):
    for py in range(101):
        ph = h + abs(px - x) + abs(py - y) #適当な情報一つとpx,pyでpyを決め打ち
        ok = True
        for x, y, h in xyh:
            if h > 0 and ph - h != abs(px - x) + abs(py - y): #その情報において式が成り立たない
                ok = False
            if h == 0 and ph > abs(px - x) + abs(py - y):     
                ok = False

        if ok:
            print(str(px) + " " + str(py) + " " + str(ph))

Submission status: Accepted

Solution code:
def height(x, y ,h, Cx, Cy):
    return h + abs(x - Cx) + abs(y - Cy)


N = int(input())
lst_xyh = [tuple(map(int, input().split())) for _ in range(N)]
for Cx in range(101):
    for Cy in range(101):
        for x, y, h in lst_xyh:
            if h != 0:
                H = height(x, y, h, Cx, Cy)
                break
        for x, y, h in lst_xyh:
            if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:
                break
        else:
            print(Cx, Cy, H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
info = [0] * N
ans = [0]*3
for i in range(N):
    info[i] = [0] * 3
    info[i][0], info[i][1], info[i][2] = map(int, input().split())

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

height = [0] * 101
for x_kouho in range(101):
    height[x_kouho] = [0]*101
    for y_kouho in range(101):
        height[x_kouho][y_kouho] = info[0][2] + \
            abs(info[0][0] - x_kouho) + abs(info[0][1] - y_kouho)
        for p in range(N):
            if info[p][2] != max(0, (height[x_kouho][y_kouho] - abs(info[p][0] - x_kouho) - abs(info[p][1] - y_kouho))):
                break
            if p == N - 1:
                if 0 <= height[x_kouho][y_kouho]:
                    print("{} {} {}".format(
                        x_kouho, y_kouho, height[x_kouho][y_kouho]))
                    exit()

Submission status: Accepted

Solution code:
# ABC112C - Pyramid
import sys
input = sys.stdin.readline

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC112C - Pyramid
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    l = sorted(
        [tuple(map(int, input().rstrip().split())) for _ in range(n)],
        key=lambda x: x[2],
        reverse=True,
    )
    for x in range(0, 101):
        for y in range(0, 101):
            i, j, k = l[0]
            h = k + abs(i - x) + abs(j - y)
            for i, j, k in l[1:]:
                if k != max(h - abs(i - x) - abs(j - y), 0):
                    break
            else:
                print(x, y, h)
                break
        else:
            continue
        break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
x=[]
y=[]
h=[]
for i in range(n):
    xx,yy,hh = map(int,input().split())
    x.append(xx)
    y.append(yy)
    h.append(hh)
max_h = h.index(max(h))
for cx in range(0,101):
    for cy in range(0,101):
        flag = True
        high = h[max_h] + abs(x[max_h]-cx) + abs(y[max_h]-cy)
        for i in range(n):
            if h[i]==0:
                if high-abs(x[i]-cx)-abs(y[i]-cy)>0:
                    flag=False
            else:
                if high != abs(x[i]-cx)+abs(y[i]-cy)+h[i]:
                    flag=False
        if flag:
            print(cx,cy,high)
            exit()

Submission status: Accepted

Solution code:
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())

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

Submission status: Accepted

Solution code:
n = int(input())
li = [list(map(int,input().split())) for _ in range(n)]
li = sorted(li,key = lambda x:-x[2])

for i in range(101):
  for j in range(101):
    h = li[0][2] + abs(i-li[0][0]) + abs(j-li[0][1])
    for k in range(1,n):
      if li[k][2] != max(0,h - abs(i-li[k][0]) -abs(j-li[k][1])):
        break
    else:
      print("{} {} {}".format(i,j,h))
      exit()