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=[]
h0=[]
for i in range(n):
    a=[int(j) for j in input().split()]
    xyh.append(a)

from operator import itemgetter
xyh.sort(key=itemgetter(2))
xyh.reverse()

for x in range(101):
    for y in range(101):
        p=0
        l=max(0,xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1]))
        for i in range(n):
            if xyh[i][2]==0:
                if l>abs(x-xyh[i][0])+abs(y-xyh[i][1]):
                    p=1
                    break
                else:
                    continue
            if l==max(0,xyh[i][2]+abs(x-xyh[i][0])+abs(y-xyh[i][1])):
                l=max(0,xyh[i][2]+abs(x-xyh[i][0])+abs(y-xyh[i][1]))
            else:
                p=1
                break
        if p==0:
            print(x,y,l)
            import sys
            sys.exit()

Submission status: Accepted

Solution code:
n = int(input())
e = sorted([[int(i) for i in input().split()] for i in range(n)], key=lambda x:x[2])[::-1]

def f():
    for x in range(101):
        for y in range(101):
            flg = True
            H = e[0][2] + abs(x-e[0][0]) + abs(y-e[0][1])
            for e_ in e:
                if (e_[2] == 0):
                    if H > abs(x-e_[0]) + abs(y-e_[1]):
                        flg = False
                        break
                    else:
                        continue
                
                if H != e_[2] + abs(x-e_[0]) + abs(y-e_[1]):
                    flg = False
                    break
            if flg:
                return (x, y, H)
result = f()
print("{} {} {}".format(result[0], result[1], result[2]) )

Submission status: Accepted

Solution code:
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
x=[]
y=[]
h=[]
for l in L:
    x.append(l[0])
    y.append(l[1])
    h.append(l[2])
Cx=0
Cy=0
H=0

for i in range(101):#Cx
    for j in range(101):#Cy
        flag=True
        for k in range(N):
            if h[k]!=0:
                H=h[k]+abs(i-x[k])+abs(j-y[k])
                break

        for k in range(N):
            if h[k]!=max(H-abs(i-x[k])-abs(j-y[k]),0):
                flag=False
                break
        
        if flag==True:
            Cx,Cy=i,j
            break
    if flag==True:
        break
print("{} {} {}".format(Cx,Cy,H))

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
xyh = sorted(xyh, key = lambda x:-x[2])
mx, my, mh = xyh[0]
for Cx in range(101):
  for Cy in range(101):
    H = mh+abs(mx-Cx)+abs(my-Cy)
    if(all(h == max(0, H-abs(x-Cx)-abs(y-Cy)) for x,y,h in xyh)):
      print(Cx,Cy,H)
      exit()

Submission status: Accepted

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


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    # mountain = np.zeros(101, 101)
    # for i in range(N):
    #     for j in range(101):
    #         for k in range(101):
    #             mountain[j][k] = max(h[i] - abs(x[i]-j) - abs(y[i]-k))
    # highest = np.argmax(mountain)
    candi = 0
    for i in range(N):
        if h[i] == 0:
            continue
        else:
            candi = i
    for i in range(101):
        for j in range(101):
            flag = 1
            candh = h[candi] + abs(x[candi]-i) + abs(y[candi]-j)
            # print(i, j, candh)
            for xx, yy, hh in zip(x, y, h):
                # print(hh, max(candh-abs(xx-i)-abs(yy-j), 0))
                if hh != max(candh-abs(xx-i)-abs(yy-j), 0):
                    flag = 0
                    break
            if flag == 1:
                # print("!!")
                break
        if flag == 1:
            break
    trueh = h[candi] + abs(x[candi]-i) + abs(y[candi]-j)
    print(i, j, trueh)
    return


# Generated by 1.1.3 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())
X = []
Y = []
H = []
ansx = 0
ansy = 0
ansh = 0
for _ in range(N):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

for cx in range(101):
    for cy in range(101):
        center_height = 0
        for i in range(N):
            if H[i] != 0:
                center_height = H[i] + abs(X[i]-cx) + abs(Y[i]-cy)
                break
        
        ok = True
        for i in range(N):
            if H[i] == 0 and center_height - abs(X[i]-cx) - abs(Y[i]-cy)>0:
                ok = False
            if H[i] > 0 and center_height != H[i] + abs(X[i]-cx) + abs(Y[i]-cy):
                ok = False

        if ok is True:
            ansx = str(cx)
            ansy = str(cy)
            ansh = str(center_height)


print(ansx + ' ' + ansy + ' ' + ansh)

Submission status: Accepted

Solution code:
N = int(input())

SIZE = 101

base_data = None
data = []
for i in range(N):
    d = list(map(int, input().split()))
    data.append(d)
    if d[2] > 0:
        base_data = d
for x in range(SIZE):
    for y in range(SIZE):
        H = max(base_data[2] + abs(base_data[0] - x) + abs(base_data[1] - y), 0)
        all = True
        for d in data:
            h = max(H - abs(d[0] - x) - abs(d[1] - y), 0)
            if h != d[2]:
                all = False
                break
        if all:
            print(str(x) + " " + str(y) + " " + str(H))
            exit()

Submission status: Accepted

Solution code:
import sys

N = int(input())

xn = []
yn = []
hn = []

for i in range(N):
    xi, yi, hi = map(int, input().split())

    xn.append(xi)
    yn.append(yi)
    hn.append(hi)

for Cx in range(101):
    for Cy in range(101):

        last = None
        flg = True

        for i in range(N):

            if 0 == hn[i]:
                continue

            H = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

            if H < 0:
                continue

            if last:
                if H != last:
                    flg = False
                    break

            last = H

        if not flg:
            continue

        for i in range(N):

            if 0 == hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                if h < H:
                    flg = False
                    break

        if not flg:
            continue

        print(Cx, Cy, H)
        sys.exit()

Submission status: Accepted

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

flag = 0
a,b,c = 0,0,0
for i in range(101):
    if flag:
        break
    else:
        for j in range(101):
            if flag:
                break
            else:
                for k in range(n):
                    if h[k] != 0:
                        first = abs(x[k]-i)+abs(y[k]-j)+h[k]
                        break
                ct = 0
                for k in range(n): 
                    tmp = abs(x[k]-i)+abs(y[k]-j)+h[k]
                    if first == tmp or (first < tmp and h[k]==0):
                        ct += 1
                    if ct == n:
                        a,b,c = i,j,first
                        flag = 1

print("{} {} {}".format(a,b,c))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
data = np.zeros((N,3))
for i in range(N):
    data[i] = np.array(input().split())

# data = np.array([[2,3,0],[2,1,0],[1,2,0],[3,2,5]])

if len(np.where(data[:,2]!=0)[0]) == 1:
    C_x, C_y, H = map(int,data[np.where(data[:,2]!=0)[0][0]])
    print(C_x, C_y, H)
else:
    for n in range(10201):
        C_x = n // 101
        C_y = n % 101
        correctflg = True
        unsetflg = True
        for x,y,h in data:
            if unsetflg:
                if h >= 1:
                    H = abs(x-C_x)+abs(y-C_y)+h
                    unsetflg = False
            else:
                if h >= 1 and H != abs(x-C_x)+abs(y-C_y)+h:
                    correctflg = False
                    break 
        if correctflg:
            print(C_x,C_y,int(H))
            break

Submission status: Accepted

Solution code:
def ans():
  N = int(input())
  xyh = [list(map(int,input().split())) for _ in range(N)]
  xyh = sorted(xyh, key = lambda x: -x[2])
  mx, my, mh = xyh[0]
  for Cx in range(101):
    for Cy in range(101):
      H = mh+abs(mx-Cx)+abs(my-Cy)
      if(all(h == max(H-abs(x-Cx)-abs(y-Cy), 0) for x,y,h in xyh)):
        print(Cx, Cy, H)
        exit()
ans()

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

N = I()
xyh = []
for i in range(N):
    x, y, h = LI()
    xyh.append([x,y,h])


for i in range(100+1):
    for j in range(100+1):
        cx, cy = i, j
        H = []
        for item in xyh:
            #  print(item)
            if item[2] == 0:
                continue

            new_H = max(item[2] + abs(item[0] - cx) + abs(item[1] - cy), 0)
            H.append(new_H)
        else:
            if len(set(H)) == 1:
                center_H = H[0]
                H = []
                for item in xyh:
                    if item[2] == 0:
                        # 0の場合にも正しいか判定する
                        # 中央の高さ
                        if center_H - abs(item[0] - cx) - abs(item[1] - cy) > 0:
                        #  if ch < center_H:
                            break
                else:
                    print(i, j, center_H)
                    exit()

Submission status: Accepted

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

    xn = []
    yn = []
    hn = []

    for i in range(N):
        xi, yi, hi = map(int, input().split())

        xn.append(xi)
        yn.append(yi)
        hn.append(hi)

    for Cx in range(101):
        for Cy in range(101):

            last = None
            flg = True

            for i in range(N):

                if 0 == hn[i]:
                    continue

                H = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

                if H < 0:
                    continue

                if last:
                    if H != last:
                        flg = False
                        break

                last = H

            if not flg:
                continue

            for i in range(N):

                if 0 == hn[i]:
                    h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                    if h < H:
                        flg = False
                        break

            if not flg:
                continue

            print(Cx, Cy, H)
            return


main()

Submission status: Accepted

Solution code:
N = int(input())

xn = []
yn = []
hn = []

for i in range(N):
    xi, yi, hi = map(int, input().split())
    if hi:
        xn.append(xi)
        yn.append(yi)
        hn.append(hi)

if len(xn) == 1:
    print(xn[0], yn[0], hn[0])
else:
    for Cx in range(101):
        for Cy in range(101):

            last = None
            flg = False

            for i in range(len(xn)):
                H = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

                if H < 0:
                    continue
                if last:
                    if (H != last):
                        break

                last = H
            else:
                flg = True
                print(Cx, Cy, H)
                break

        if flg:
            break

Submission status: Accepted

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

    xn = []
    yn = []
    hn = []

    for i in range(N):
        xi, yi, hi = map(int, input().split())
        if hi:
            xn.append(xi)
            yn.append(yi)
            hn.append(hi)

    if len(xn) == 1:
        print(xn[0], yn[0], hn[0])
        return

    for Cx in range(101):
        for Cy in range(101):

            last = None

            for i in range(len(xn)):
                H = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

                if H < 0:
                    continue
                if last:
                    if (last != H):
                        break

                last = H
            else:
                print(Cx, Cy, H)
                return


main()

Submission status: Accepted

Solution code:
N = int(input())

xn = []
yn = []
hn = []

for i in range(N):
    xi, yi, hi = map(int, input().split())
    xn.append(xi)
    yn.append(yi)
    hn.append(hi)

for Cx in range(101):
    for Cy in range(101):

        flg = True

        for i in range(N):
            if 0 == hn[i]:
                continue

            h = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

            if flg:
                H = h
                flg = False
            else:
                if (H != h):
                    flg = True
                    break

        if flg:
            continue

        for i in range(N):
            if 0 == hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                if h < H:
                    flg = True
                    break

        if flg:
            continue

        print(Cx, Cy, H)
        break

    if not flg:
        break

Submission status: Accepted

Solution code:
N = int(input())

xn = [0] * N
yn = [0] * N
hn = [0] * N

for i in range(N):
    xi, yi, hi = map(int, input().split())
    xn[i] = xi
    yn[i] = yi
    hn[i] = hi

for Cx in range(101):
    for Cy in range(101):

        flg = True

        for i in range(N):
            if 0 == hn[i]:
                continue

            h = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

            if flg:
                H = h
                flg = False
            else:
                if (H != h):
                    flg = True
                    break

        if flg:
            continue

        for i in range(N):
            if 0 == hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                if h < H:
                    flg = True
                    break

        if flg:
            continue

        print(Cx, Cy, H)
        break

    if not flg:
        break

Submission status: Accepted

Solution code:
N = int(input())

xn = [0] * N
yn = [0] * N
hn = [0] * N

for i in range(N):
    xi, yi, hi = map(int, input().split())
    xn[i] = xi
    yn[i] = yi
    hn[i] = hi

for Cx in range(101):
    flg = True

    for Cy in range(101):

        for i in range(N):
            if 0 < hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

                if flg:
                    H = h
                    flg = False
                else:
                    if (H != h):
                        flg = True
                        break

        if flg:
            continue

        for i in range(N):
            if 0 == hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                if h < H:
                    flg = True
                    break

        if flg:
            continue

        print(Cx, Cy, H)
        break

    if not flg:
        break

Submission status: Accepted

Solution code:
N, = (int(x) for x in input().split())

info_arr = []
for _ in range(N):
    info_arr.append(tuple(int(x) for x in input().split()))

H_mat = [[-1]*101 for _ in range(101)]

for x, y, h in [a for a in info_arr if a[2] != 0]:
    for i in range(101):
        for j in range(101):
            height = h+abs(x-i)+abs(y-j)
            if H_mat[i][j] == -1:
                H_mat[i][j] = height
                continue
            if H_mat[i][j] != height:
                H_mat[i][j] = 0

for x, y, h in [a for a in info_arr if a[2] == 0]:
    for i in range(101):
        for j in range(101):
            if H_mat[i][j] > h+abs(x-i)+abs(y-j):
                H_mat[i][j] = 0

max_h = 0
max_ij = (-1, -1)
for i in range(101):
    for j in range(101):
        if H_mat[i][j] > max_h:
            max_h = H_mat[i][j]
            max_ij = (i, j)

print(max_ij[0], max_ij[1], max_h)

Submission status: Accepted

Solution code:
def solve():
    for Cx in range(101):
        for Cy in range(101):
            div = 0
            for i in range(N):

                xi, yi, hi = xyh[i]

                if 0 < hi:
                    h = abs(xi - Cx) + abs(yi - Cy) + hi
                    if div in [0, 2]:
                        H = h
                        div = 1
                    else:
                        if (H != h):
                            div = 2
                            break

            if div == 2:
                continue

            for i in range(N):
                xi, yi, hi = xyh[i]

                if 0 == hi:
                    h = abs(xi - Cx) + abs(yi - Cy)
                    if h < H:
                        div = 2
                        break

            if div == 2:
                continue

            return Cx, Cy, H


N = int(input())

xn = [0] * N
yn = [0] * N
hn = [0] * N

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

Cx, Cy, H = solve()

print(Cx, Cy, H)

Submission status: Accepted

Solution code:
N = int(input())

xn = [0] * N
yn = [0] * N
hn = [0] * N

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

div = 0

for Cx in range(101):
    for Cy in range(101):
        for i in range(N):

            xi, yi, hi = xyh[i]

            if 0 < hi:
                h = abs(xi - Cx) + abs(yi - Cy) + hi
                if div in [0, 2]:
                    H = h
                    div = 1
                else:
                    if (H != h):
                        div = 2
                        break

        if div == 2:
            continue

        for i in range(N):
            xi, yi, hi = xyh[i]

            if 0 == hi:
                h = abs(xi - Cx) + abs(yi - Cy)
                if h < H:
                    div = 2
                    break

        if div == 2:
            continue

        print(Cx, Cy, H)
        break

    if div == 1:
        break

Submission status: Accepted

Solution code:
N = int(input())

xn = [0] * N
yn = [0] * N
hn = [0] * N

for i in range(N):
    xi, yi, hi = map(int, input().split())
    xn[i] = xi
    yn[i] = yi
    hn[i] = hi

div = 0

for Cx in range(101):
    for Cy in range(101):
        for i in range(N):

            if 0 < hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]
                if div in [0, 2]:
                    H = h
                    div = 1
                else:
                    if (H != h):
                        div = 2
                        break

        if div == 2:
            continue

        for i in range(N):
            if 0 == hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                if h < H:
                    div = 2
                    break

        if div == 2:
            continue

        print(Cx, Cy, H)
        break

    if div == 1:
        break

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

N = int(input())

xn = [0] * N
yn = [0] * N
hn = [0] * N

for i in range(N):
    xi, yi, hi = map(int, input().split())
    xn[i] = xi
    yn[i] = yi
    hn[i] = hi

div = 0

for Cx in range(101):
    for Cy in range(101):
        for i in range(N):

            if 0 < hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]
                if div in [0, 2]:
                    H = h
                    div = 1
                else:
                    if (H != h):
                        div = 2
                        break

        if div == 2:
            continue

        for i in range(N):
            if 0 == hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                if h < H:
                    div = 2
                    break

        if div == 2:
            continue

        print(Cx, Cy, H)
        break

    if div == 1:
        break

Submission status: Accepted

Solution code:
def pyramid(N: int, info: list) -> tuple:
    """
    """
    _info = sorted(info, key=lambda x: x[2], reverse=True)
    x, y, h = _info[0]
    candidtes = [
        (cx, cy, h + abs(cx - x) + abs(cy - y))
        for cx in range(100+1)
        for cy in range(100+1)]

    for x, y, h in _info[1:]:
        temp = []
        for cx, cy, H in candidtes:
            th = max(H - abs(cx - x)-abs(cy - y), 0)
            if th == h:
                temp.append((cx, cy, H))

        candidtes = temp

    return candidtes[0]

if __name__ == "__main__":
    N = int(input())
    info = [
        tuple(int(s) for s in input().split())
        for _ in range(N)]
    cx, cy, h = pyramid(N, info)
    print(cx, cy, h)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

N = I()
xyh = []
for i in range(N):
    x, y, h = LI()
    xyh.append([x,y,h])


for i in range(100+1):
    for j in range(100+1):
        cx, cy = i, j
        H = []
        for item in xyh:
            #  print(item)
            if item[2] == 0:
                continue

            new_H = max(item[2] + abs(item[0] - cx) + abs(item[1] - cy), 0)
            H.append(new_H)
        else:
            if len(set(H)) == 1:
                center_H = H[0]
                H = []
                for item in xyh:
                    if item[2] == 0:
                        # 0の場合にも正しいか判定する
                        ch = abs(item[0] - cx) + abs(item[1] - cy)
                        if ch < center_H:
                            break
                else:
                    print(i, j, center_H)
                    exit()

Submission status: Accepted

Solution code:
N = int(input())
xyh = []

for i in range(N):
    xyh.append([int(i) for i in input().split()])

for x in range(101):
    for y in range(101):

        ##Reference Height##

        for i in range(len(xyh)):
            if(xyh[i][2] != 0):
                reference_index = i
        height = abs(x - xyh[reference_index][0]) + \
            abs(y - xyh[reference_index][1]) + xyh[reference_index][2]
        ####################

        counter = 0

        for n in range(N):
            if(xyh[n][2]==0):
                if not (height <= abs(x - xyh[n][0]) +
                        abs(y - xyh[n][1]) + xyh[n][2]):
                    counter += 1

            else:
                if not (height == abs(x - xyh[n][0]) +
                        abs(y - xyh[n][1]) + xyh[n][2]):
                    counter += 1

        if(counter == 0):
            print("{} {} {}".format(x, y, height))

Submission status: Accepted

Solution code:
#Nへの代入
N=int(input())

#データのリストdata [x座標,y座標,高さ]
k=0
data=list()
for i in range(N):
    l=list(map(int,input().split()))
    data.append(l)
    if(l[2]>0):
        k=i

#中心点の探索
for x in range(101):
    for y in range(101):
        H=data[k][2]+abs(x-data[k][0])+abs(y-data[k][1])
        if all([max(H-abs(x-l[0])-abs(y-l[1]),0)==l[2] for l in data]):
            print(x,y,H)

Submission status: Accepted

Solution code:
#Nへの代入
N=int(input())

#データのリストdata [x座標,y座標,高さ]
k=0
data=list()
for i in range(N):
    l=list(map(int,input().split()))
    data.append(l)
    if(l[2]>0):
        k=i

#中心点の探索
for x in range(101):
    for y in range(101):
        H=data[k][2]+abs(x-data[k][0])+abs(y-data[k][1])
        if all([max(H-abs(x-l[0])-abs(y-l[1]),0)==l[2] for l in data]):
            print(x,y,H)
            exit()

Submission status: Accepted

Solution code:
n=int(input())
pyramid=[list(map(int, input().split())) for i in range(n)]
pyramid=sorted(pyramid, key=lambda p:p[2])
for x in range(101):
    for y in range(101):
        px=pyramid[-1][0]
        py=pyramid[-1][1]
        ph=pyramid[-1][2]
        h=ph+abs(x-px)+abs(y-py)
        for i in range(n):
            px=pyramid[i][0]
            py=pyramid[i][1]
            ph=pyramid[i][2]
            if not (ph==max(h-abs(x-px)-abs(y-py), 0)):
                break
            if i==n-1:
                print(x,y,h)
                exit()

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18

N=ri()
X=[0]*N
Y=[0]*N
H=[0]*N
for i in range(N):
    X[i],Y[i],H[i]=rl()
xyh=list(zip(X,Y,H))
xyh.sort(reverse=True,key=lambda x:x[2])
X,Y,H = zip(*xyh)

ans=[-1]*3
for x in range(101):
    if ans[0] != -1:
        break
    for y in range(101):
        if ans[0] != -1:
            break
        rst = H[0]+abs(x-X[0])+abs(y-Y[0])
        for i in range(1,N):
            if H[i] != 0 and rst != H[i]+abs(x-X[i])+abs(y-Y[i]):
                break
            elif H[i] == 0 and rst > H[i]+abs(x-X[i])+abs(y-Y[i]):
                break
            if i == N-1:
                ans = [x,y,rst]

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

Submission status: Accepted

Solution code:
n = int(input())
info = [tuple(map(int, input().split())) for _ in range(n)]
nonzeroinfo = []
for x, y, h in info:
    if h > 0:
        nonzeroinfo.append((x, y, h))
zeroinfo = []
for x, y, h in info:
    if h == 0:
        zeroinfo.append((x, y, h))
def checknonzero(x, y, h):
    for a, b, c in nonzeroinfo:
        if h != abs(x-a) + abs(y-b) + c:
            return False
    return True
def checkzero(x, y, h):
    for a, b, _ in zeroinfo:
        if abs(x-a) + abs(y-b) < h:
            return False
    return True
for x in range(101):
    for y in range(101):
        x1, y1, h1 = nonzeroinfo[0]
        h = abs(x-x1) + abs(y-y1) + h1
        ret1 = checknonzero(x, y, h)
        ret2 = checkzero(x, y, h)
        if ret1 and ret2:
            print(x, y, h)
            exit()

Submission status: Accepted

Solution code:
N = int(input())

x = []
y = []
h = []
flag = True
index = 0

for i in range(N):
    _x, _y, _h = map(int, input().split())
    x.append(_x)
    y.append(_y)
    h.append(_h)

    if _h != 0 and flag:
        index = i

ans = []

for cx in range(101):
    for cy in range(101):
        H = h[index] + abs(x[index] - cx) + abs(y[index] - cy)
        for i in range(N):
            if h[i] == max(H-abs(x[i] - cx) - abs(y[i] - cy), 0):
                if i == N-1:
                    ans = [cx, cy, H]
            else:
                break

[print(i, end=' ') for i in ans]

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18

N=ri()
xyh=[]
for i in range(N):
    xyh += [rl()]
xyh.sort(reverse=True, key=lambda x:x[2])

ans=[-1]*3
for x in range(101):
    if ans[0] != -1:
        break
    for y in range(101):
        if ans[0] != -1:
            break
        if xyh[0][2] == 0:
            h_m = xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
            for i in range(1,N):
                rst = xyh[i][2]+abs(x-xyh[i][0])+abs(y-xyh[i][1])
                if h_m > rst:
                    h_m = rst
                if h_m == 0:
                    break
                elif i==N-1:
                    ans = [x,y,h_m]
        else:
            h = xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
            for i in range(1,N):
                if xyh[i][2] != 0:
                    if h != xyh[i][2]+abs(x-xyh[i][0])+abs(y-xyh[i][1]):
                        break
                elif xyh[i][2] == 0:
                    if h > xyh[i][2]+abs(x-xyh[i][0])+abs(y-xyh[i][1]):
                        break
                if i == N-1:
                    ans = [x,y,h]

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