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 = [list(map(int,input().split())) for _ in range(N)]
xyh.sort(key=lambda x:-x[2])

def ok(cx,cy,H):
    res = True
    for i in range(1,N):
        x,y,h = xyh[i]
        if max(H-abs(x-cx)-abs(y-cy),0) != h:
            res = False
            break
    return res

x,y,h = xyh[0]
for cx in range(101):
    for cy in range(101):
        H = h+abs(x-cx)+abs(y-cy)
        if ok(cx,cy,H):
            ans = '{} {} {}'.format(cx,cy,H)

print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def sol():
    N = int(input())
    points = [tuple(map(int, input().split())) for _ in range(N)]
    points.sort(key=itemgetter(2), reverse=True)

    for cx in range(101):
        for cy in range(101):
            bx, by, bh = points[0]
            H = bh + abs(cx - bx) + abs(cy - by)
            for x, y, h in points:
                nowH = max(H - abs(cx - x) - abs(cy - y), 0)
                if h != nowH:
                    break
            else:
                print(cx, cy, H)
                return

sol()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    #print(N)
    p = []
    isFound = False
    for _ in range(N):
        x, y, h = map(int, input().split())
        p.append([x, y, h])
        if not isFound and h > 0:
            ref = [x, y, h]
            isFound = True
    #print(p)

    for cx in range(0, 100+1):
        for cy in range(0, 100+1):
            isCenter = True
            H = ref[2] + abs(ref[0]-cx) + abs(ref[1]-cy)
            for x, y, h in p:
                if h > 0:
                    Hp = h + abs(x-cx) + abs(y-cy)
                    if Hp != H:
                        isCenter = False
                        break
                else:
                    if (H - abs(x-cx) - abs(y-cy)) > 0:
                        isCenter = False
                        break
            if isCenter:
                return [cx, cy, H]
    return [-1,-1,-1]

if __name__ == '__main__':
    output = main()
    print(' '.join(map(str, output)))

Submission status: Accepted

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


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):

    
    ansx = -1
    ansy = -1
    ansh = -1

    # ix = [i for i,x in enumerate(h) if(x > 0)][0]
    # print(ix)
    ix = h.index(max(h))

    for cx in range(101):
        for cy in range(101):
            H = h[ix] + abs(x[ix]-cx) + abs(y[ix]-cy)
            f = True
            for i in range(N):
                if(h[i] > 0 and H-h[i] != abs(x[i]-cx) + abs(y[i]-cy)):
                    f = False
                if(h[i] == 0 and H > abs(x[i]-cx) + abs(y[i]-cy)):
                    f = False
            if(f):
                ansx = cx
                ansy = cy
                ansh = H
        

    print(ansx, ansy, ansh)
    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:
from collections import Counter
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]

for cx in range(101):
  for cy in range(101):
    l0 = [abs(cx - x) + abs(cy - y) for x, y, h in L if h == 0]
    m = min(l0) if l0 else float('inf')
    c = Counter(h + abs(cx - x) + abs(cy - y) for x, y, h in L if h != 0)
    if len(c) == 1 and c.most_common()[0][0] <= m:
      print(cx, cy, c.most_common()[0][0])
      exit()

Submission status: Accepted

Solution code:
N = int(input())

x = [0] * N
y = [0] * N
h = [0] * N

for i in range(N):
    xyh = list(map(int, input().split()))
    x[i] = xyh[0]
    y[i] = xyh[1]
    h[i] = xyh[2]
    if xyh[2] != 0:
        Cx = xyh[0]
        Cy = xyh[1]
        CH = xyh[2]

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

Submission status: Accepted

Solution code:
N = int(input())

x = [0] * N
y = [0] * N
h = [0] * N

for i in range(N):
    xyh = list(map(int, input().split()))
    x[i] = xyh[0]
    y[i] = xyh[1]
    h[i] = xyh[2]
    if xyh[2] != 0:
        Cx = xyh[0]
        Cy = xyh[1]
        CH = xyh[2]

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

Submission status: Accepted

Solution code:
n = int(input())
x, y, h = [], [], []
for i in range(n):
    xyh = list(map(int, input().split()))
    x.append(xyh[0])
    y.append(xyh[1])
    h.append(xyh[2])
for i in range(101):
    for j in range(101):
        flag = True
        m = float('inf')
        ch = -1
        for k in range(n):
            if h[k] != 0:
                if ch == -1:
                    ch = h[k] + abs(x[k] - i) + abs(y[k] - j)
                else:
                    if ch != h[k] + abs(x[k] - i) + abs(y[k] - j) and flag:
                        flag = False
            else:
                m = min(m, abs(x[k] - i) + abs(y[k] - j))
        if flag and ch <= m:
            ans = list(map(str, [i, j, ch]))
print(ans[0] + " " + ans[1] + " " + ans[2])

Submission status: Accepted

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

#もし全部の条件で h = 0 だったら。。。
#if L[0][2] == 0:
#    H = 1
#    for i in range(101):
#        for j in range(101):
#            for k in range(n):
#                if 



for i in range(101):
    for j in range( 101):
        nescond = float("inf")
        H = abs(L[0][0] - i) + abs(L[0][1] - j) + L[0][2]
        cond = True
        for k in range(n):
            absX = abs(i - L[k][0])
            absY = abs(j - L[k][1])
            
            if L[k][2] == 0:
                nescond = min([nescond, absX + absY])
            else:
                if H != absX + absY + L[k][2]:
                    cond = False
                    break
        if cond and H <= nescond:
            for q in[i,j,H]:
                print(q, end = " ")

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

top = [[] for _ in range(101*101)]

for i in range(101):
    for j in range(101):
        top[i*101+j] = [i, j]

#print(top)

H = 0
ansx = -100

for i in range(len(top)):
    topx = top[i][0]
    topy = top[i][1]
    H = 0
    h_list = []
    for j in range(N):
        tmp = abs(topx - x[j]) + abs(topy - y[j]) + h[j]
        h_list.append(tmp)
    if h_list.count(h_list[0]) == N :
        ansx = topx
        ansy = topy
        ansH = h_list[0]
        break

if ansx == -100:
    for i in range(len(top)):
        topx = top[i][0]
        topy = top[i][1]
        H = 0
        h_list = []
        for j in range(N):
            if h[j] != 0:
                tmp = abs(topx - x[j]) + abs(topy - y[j]) + h[j]
                h_list.append(tmp)
        if h_list.count(h_list[0]) == N - h.count(0) :
            ansx = topx
            ansy = topy
            ansH = h_list[0]
            break

print(ansx, ansy, ansH)

Submission status: Accepted

Solution code:
import math,fractions,sys
from collections import Counter
n = int(input())
x = [0] * n
y = [0] * n
h = [0] * n
tmp = 0
if n == 1:
    print(x[0],y[0],h[0])
    sys.exit()
def cal(i,j):
    for _ in range(n):
        if h[_] != 0:
            H = abs(i-x[_]) + abs(j-y[_]) + h[_]
            break
    for _ in range(n):
        h_tmp = max(H - abs(i-x[_]) - abs(j-y[_]),0)
        if h[_] != h_tmp:
            return -1
    return H                      
for i in range(n):
    x[i],y[i],h[i] = map(int,input().split())

for i in range(101):   #x
    for j in range(101):   #y
        if cal(i,j) != -1:
            print(i,j,cal(i,j))

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        H = -1
        ok = True
        for x, y, h in P:
            if h == 0:
                continue
            Hi = abs(x-cx) + abs(y-cy) + h
            if H == -1:
                H = Hi
                continue
            if Hi != H:
                ok = False
                break
        if not ok:
            continue
        for x, y, h in P:
            if h != max(H-abs(cx-x)-abs(cy-y), 0):
                ok = False
        if ok:
            print(cx, cy, H)
            break
    if ok:
        break

Submission status: Accepted

Solution code:
N = int(input())
XYH = []
for n in range(N):
  x, y, h = [int(xyh) for xyh in input().split()]
  if h > 0:
    XYH.append([x, y, h])

l_XYH = len(XYH)

if l_XYH == 1:
  cx, cy, ans_H = XYH[0]
else:
  HH = []
  ans_H = 0
  for cx in range(0, 101):
    for cy in range(0, 101):
      for k in range(l_XYH):
        xk, yk, hk = XYH[k]
        H = hk + abs(xk - cx) + abs(yk - cy)
        if k < l_XYH - 1:
          HH.append(H)
        elif HH.count(H) == l_XYH - 1:
          ans_H = H
          break
        else:
          HH = []
          break
      else:
        continue
      if ans_H == H:
        break
    else:
      continue
    break

ans = str(cx) + " " + str(cy) + " " + str(ans_H)
print(ans)

Submission status: Accepted

Solution code:
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

# ピラミッドの中心に関するH, Cx, Cyが未知数
# (x, y)の高度h = max(H - |Cx -x| - |Cy - y|, 0)
if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]

    # ht < 0の要素を確保しておく
    h_base = 0
    for l in L:
        if l[2] > 0:
            h_base = l[:]
    if h_base == 0:
        print("error")
        exit()

    for Cx in range(0, 101):
        for Cy in range(0, 101):
            all_collect = True
            x, y, h = h_base
            H = h + abs(Cx - x) + abs(Cy - y)
            for l in L:
                x, y, h = l
                if h != max(H - abs(Cx - x) - abs(Cy - y), 0):
                    all_collect = False
                    break
            if all_collect:
                print(Cx, Cy, H)
                exit()

Submission status: Accepted

Solution code:
N = int(input())
p_x = []
p_y = []
p_h = []
for i in range(N):
    x1,y1,h1 = [int(i) for i in input().split()]
    p_x.append(x1)
    p_y.append(y1)
    p_h.append(h1)


#h = H - |X-CX| - |Y-CY|　⇔　H = h + |X-CX| + |Y-CY|
#方針：上記式から与えられた全座標でHの値が一致する点を見つける。
for x in range(101):
    for y in range(101):
        #点を見つけたときにfor文から離脱
        hantei1 = 0
        #一致したときにカウント
        count = 0
        #判定用の変数
        tmp = -1
        #判定用の変数(0) or 判定する値（1）
        tmp_count = 0
        #h[i]==0の保留リスト
        horyu = []
        for i in range(N):
            if p_h[i] == 0:
                horyu.append(i)
            else:
                tmp1 = p_h[i] + abs(x - p_x[i]) + abs(y - p_y[i])
                if tmp1 < 0 :
                    break
                elif tmp_count == 0:
                    tmp = tmp1
                    tmp_count += 1
                elif tmp_count != 0 and tmp1 > 0:
                    if tmp == tmp1:
                        count += 1
            
        if count == N-1 or N-1 == count + len(horyu):
            if len(horyu) == 0:
                Cx = x
                Cy = y
                H = tmp
                hantei1 = 1
                break
            else:
                count2 = 0
                for j in range(len(horyu)):
                    if 0 == max(0, tmp -abs(p_x[horyu[j]] - x) -abs(p_y[horyu[j]] - y)):
                        count2 += 1
                if count2 == len(horyu):
                    Cx = x
                    Cy = y
                    H = tmp
                    hantei1 = 1
    if hantei1 == 1:
        break

print(Cx,Cy,H)

Submission status: Accepted

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

for i in range(N):
    xt, yt, ht = map(int, input().split())
    x.append(xt)
    y.append(yt)
    h.append(ht)
    if ht != 0:
        cx = xt
        cy = yt
        htt = ht

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

Submission status: Accepted

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

for i in range(N):
    xt, yt, ht = map(int, input().split())
    x.append(xt)
    y.append(yt)
    h.append(ht)
    if ht != 0:
        cx = xt
        cy = yt
        htt = ht

for j in range(101):
    for k in range(101):
        H = htt + abs(cx - j) + abs(cy - k)
        for i in range(N):
            if h[i] != max(H - abs(x[i] - j) - abs(y[i] - k), 0):
                break
        if i == N - 1 and h[i]== max(H - abs(x[i] - j) - abs(y[i] - k), 0):
            print(j, k, H)

Submission status: Accepted

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

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

ans_x = -1
ans_y = -1
ans_h = -1

for i in s:
  if(i[2] > 0):
    check_x,check_y,check_h = i
    break

for x in range(101):
  for y in range(101):
    flg = True
    H = check_h + abs(check_x - x) + abs(check_y - y)
    if(H <= 0):
      flg = False
      break

    else:
      for i in range(n):
        h = max( ( H - abs(s[i][0] - x) - abs(s[i][1] - y) ) ,0)
        if(h != s[i][2]):
          flg = False
          break
    if flg:
      ans_y = y
      ans_h = H
      break

  if flg:
    ans_x = x
    break

print("{} {} {}".format(ans_x,ans_y,ans_h))

Submission status: Accepted

Solution code:


import collections
import itertools
import sys


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

n=getint()

values=[getints() for _ in range(n)]

check = []
for h in values:
    if h[2] > 0:
        check = h
        break

check_x, check_y, check_h = check

for cx in range(101):
    for cy in range(101):
        H = check_h + abs(check_x - cx) + abs(check_y - cy)
        ok = True
        for x,y,h in values:
            h_prime = max(0, H - abs(x-cx) - abs(y-cy))
            if h_prime != h:
                ok = False
                break
        if ok:
            print(cx,cy,H)
            sys.exit(0)

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []
h = []
for i in range(n):
    lis = list(map(int,input().split()))
    x.append(lis[0])
    y.append(lis[1])
    h.append(lis[2])
    if lis[2] != 0:
        index = i
for cx in range(101):
    for cy in range(101):
        height = abs(x[index]-cx) + abs(y[index] - cy) + h[index]
        flag = True
        for j in range(n):
            if h[j] != max(height - abs(x[j]-cx) - abs(y[j] - cy), 0):
                flag = False
                break
        if flag == True:
            ans = [cx,cy,height]
print(*ans)

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        mh = 10000000000
        h = []
        for i in range(n):
            x,y,z = xyz[i][0],xyz[i][1],xyz[i][2]
            if z == 0:
                mh = min(mh,abs(x-cx)+abs(y-cy))
            else:
                if len(h) == 0:
                    h.append(z+abs(x-cx)+abs(y-cy))
                else:
                    if h[0] != z+abs(x-cx)+abs(y-cy):
                        h = []
                        break
                    elif h[0]>mh:
                        h = []
                        break
            if len(h)>0 and h[0]>mh:
                h = []
                break
        if len(h) > 0:
            ans = str(cx)+" "+str(cy)+" "+str(h[0])
print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(input())
point = [tuple(map(int, input().split())) for i in range(n)]

for p in range(101):
    for q in range(101):
        for x, y, h in point:
            if h > 0:
                H = h + abs(x-p) + abs(y-q)
                break
        
        for  x, y, h in point:
            if max(H-abs(x-p)-abs(y-q), 0) != h:
                break
        else:
            print(p, q, H)
            sys.exit(0)

Submission status: Accepted

Solution code:
n = int(input())
xyh = [list(map(int,input().split())) for i 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())
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('{} {} {}'.format(cx, cy, H))
            break
    if Flag:
        break

Submission status: Accepted

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

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

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

for cx in range(101):
    for cy in range(101):
        flag = True
        H = data[0][2] + abs(data[0][0]-cx) + abs(data[0][1]-cy)
        for i in range(1, len(data)):
            if not max(H - abs(data[i][0]-cx) - abs(data[i][1]-cy), 0) == data[i][2]:
                flag = False
                break

        else:  # 全て条件を満たしていたら出力
            print(cx, cy, H)
            exit()

Submission status: Accepted

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

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

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

for cx in range(101):
    for cy in range(101):
        flag = True
        H = data[0][2] + abs(data[0][0]-cx) + abs(data[0][1]-cy)
        for i in range(1, len(data)):
            if not max(H - abs(data[i][0]-cx) - abs(data[i][1]-cy), 0) == data[i][2]:
                flag = False
                break

        if flag:
            print(cx, cy, H)
            exit()

Submission status: Accepted

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

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

def sol() :
    for cx in range(0, 101) :
        for cy in range(0, 101) :
            axis.sort(key = lambda A : abs(A[0] - cx) + abs(A[1] - cy))
            H = axis[0][2] + abs(axis[0][0] - cx) + abs(axis[0][1] - cy)
            for x, y, h in axis :
                if not h == max(H - abs(x - cx) - abs(y - cy), 0) :
                    break
            else :
                return (cx, cy, H)
    return (-1, -1, -1)

cx, cy, H = sol()
if cx == -1 :
    print('-1')
else :
    print('{} {} {}'.format(cx, cy, H))

Submission status: Accepted

Solution code:
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
setrecursionlimit(10**6)

n=int(input())
x=sorted([[int(i) for i in input().split()] for _ in range(n)],key=itemgetter(2),reverse=True)
cmpr=x[1:]
for cx in range(101):
    for cy in range(101):
        h=x[0][2]+abs(cx-x[0][0])+abs(cy-x[0][1])
        for i in cmpr:
            nh=max(0,h-abs(i[0]-cx)-abs(i[1]-cy))
            if nh!=i[2]:
                break
        else:
            print(cx,cy,h)
            sys.exit()

Submission status: Accepted

Solution code:
n = int(input())
can = []
xyh = []
for _ in range(n):
  xyh.append(list(map(int,input().split())))
time = 0
while xyh[time][2] == 0:
  time += 1
x,y,h = xyh[time]
for i in range(101):
  for j in range(101):
    can.append([i, j, h + abs(x-i) + abs(y-j)])
step = 0
while len(can) != 1:
  x,y,h = xyh[(time + step) % n]
  if h != 0:
    cnt = 0
    while cnt < len(can):
      now = can[cnt]
      if now[2] != h + abs(x-now[0]) + abs(y-now[1]):
        del can[cnt]
      else:
        cnt += 1
  else:
    cnt = 0
    while cnt < len(can):
      now = can[cnt]
      if now[2] > abs(x-now[0]) + abs(y-now[1]):
        del can[cnt]
      else:
        cnt += 1
  step += 1
print(' '.join(list(map(str,can[0]))))

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        h = l[0][2] + abs(l[0][0] - cx) + abs(l[0][1] - cy)
        for i in l[1:]:
            if max(h - abs(i[0] - cx) - abs(i[1] - cy), 0) != i[2]:
                break
        else:
            print(cx, cy, h)
            exit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
W = 101
def main():
	n = int(input().strip())
	x = [0] * n
	y = [0] * n
	h = [0] * n
	for i in range(n):
		x[i], y[i], h[i] = map(int, input().strip().split())
	for s in range(W):
		for t in range(W):
			needH = -1
			for i in range(n):
				if h[i] > 0:
					tmp = h[i] + abs(x[i]-s) + abs(y[i]-t)
					if needH == -1:
						needH = tmp
					elif needH != tmp:
						needH = -2
						break
			if needH == -2:
				continue
			for i in range(n):
				if h[i] == 0 and needH > abs(x[i]-s) + abs(y[i]-t):
					needH = -2
					break
			if needH == -2:
				continue
			else:
				print("{} {} {}".format(s, t, needH))

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())

pos = [[int(x) for x in input().split(' ')] for _ in range(n)]

for cx, cy in product(range(101), range(101)):
    H = max(max([abs(p[0]-cx)+abs(p[1]-cy)+p[2] for p in pos if p[2] != 0]), 1)
    if all(max(H-abs(p[0]-cx)-abs(p[1]-cy), 0) == p[2] for p in pos):
        print(cx, cy, H)
        exit()

Submission status: Accepted

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

for cx in range(101):
    for cy in  range(101):
        h = l[0][2] + abs(l[0][0] - cx) + abs(l[0][1] - cy)
        for i in l[1:]:
            if max(h - abs(i[0] - cx) - abs(i[1] - cy), 0) != i[2]:
                break
        else:
            print(cx,cy,h)
            exit()

Submission status: Accepted

Solution code:
from operator import itemgetter

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

l.sort(key=itemgetter(2), reverse=True)

for x in range(101):
    for y in range(101):
        h = l[0][2] + abs(l[0][0]-x) + abs(l[0][1]-y)
        for i in range(1, n):
            d = abs(l[i][0]-x) + abs(l[i][1]-y)
            h_i = l[i][2] + d
            if l[i][2] == 0:
                if max(h-d, 0) == 0:
                    continue
                else:
                    break
            if h != h_i:
                break
        else:
            ans = list(map(str, [x, y, h]))
            print(" ".join(ans))
            exit()

Submission status: Accepted

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

lower_h = max([xyh[2] for xyh in xyhs])

def func():
    for ch in range(lower_h,lower_h+201,1):
#         print(ch)
        for cx in range(101):
            for cy in range(101):
#                 print(ch,cx,cy)
                if all([xyh[2] == max(ch - abs(xyh[0]-cx) - abs(xyh[1]-cy),0) for xyh in xyhs]):
#                     print(cx,cy,ch)
                    return cx,cy,ch

cx,cy,ch = func()

print(" ".join(list(map(str,[cx,cy,ch]))))

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        x0, y0, h0 = p[0]
        h = abs(x0 - cx) + abs(y0 - cy) + h0
        if all(max(h - abs(xi - cx) - abs(yi - cy), 0) == hi for xi, yi, hi in p):
            print(cx, cy, h)
            exit()

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        for xi, yi, hi in p:
            if hi > 0:
                h = abs(xi - cx) + abs(yi - cy) + hi
                break
        if all(max(h - abs(xi - cx) - abs(yi - cy), 0) == hi for xi, yi, hi in p):
            print(cx, cy, h)
            exit()

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    points = list(map(string_to_int, inputs))
    points = [p for p in points if p[2] != 0]
    if len(points) == 1:
        return "{} {} {}".format(points[0][0], points[0][1], points[0][2])
    for top_x in range(101):
        for top_y in range(101):
            is_correct = True
            p = points[0]
            prev_h = max(p[2] + abs(p[0] - top_x) + abs(p[1] - top_y), 0)
            for [px, py, ph] in points:
                top_h = max(ph + abs(px - top_x) + abs(py - top_y), 0)
                if top_h != prev_h:
                    is_correct = False
                    break
            if is_correct:
                return "{} {} {}".format(top_x, top_y, prev_h)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

Submission status: Accepted

Solution code:
N=int(input())
A=[]
H=0
flag=0

for i in range(N):
    a,b,c=map(int,input().split())
    A.append([a,b,c])

A.sort(key=lambda x: -x[2])
for x in range(101):
    for y in range(101):
        H=A[0][2]+abs(A[0][0]-x)+abs(A[0][1]-y)
        flag=0
        for n in range(N):
            if A[n][2] != max(H-abs(A[n][0] - x) - abs(A[n][1] - y,),0):
                flag=1
        if flag==0:
            print(str(x)+" "+str(y)+" "+str(H))
            exit(0)

Submission status: Accepted

Solution code:
l_bound = [[1]*101 for _ in range(101)]
u_bound = [[10**10]*101 for _ in range(101)]

N = int(input())
for n in range(N):
    x, y, h = list(map(int, input().split()))

    if h==0:
        for r in range(101):
            for c in range(101):
                u_bound[r][c] = min(u_bound[r][c], abs(c-x) + abs(r-y))
    else:
        for r in range(101):
            for c in range(101):
                l_bound[r][c] = max(l_bound[r][c], h + abs(c-x) + abs(r-y))
                u_bound[r][c] = min(u_bound[r][c], h + abs(c-x) + abs(r-y))

for r in range(101):
    for c in range(101):
        if l_bound[r][c] == u_bound[r][c]:
            print(c, r, l_bound[r][c])

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])
for cx in range(101):
    for cy in range(101):
        good = True
        h = xyh[0][2]+abs(cx-xyh[0][0])+abs(cy-xyh[0][1])
        for i in range(n):
            if xyh[i][2] != max(h-abs(cx-xyh[i][0])-abs(cy-xyh[i][1]), 0):
                good = False
                break
        if good:
            print(cx, cy, h)
            sys.exit()