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())
x = []
y = []
h = []

for _ in range(N):
    tmp, tmp2, tmp3 = map(int, input().split())
    x.append(tmp)
    y.append(tmp2)
    h.append(tmp3)
    
# Cx, Cyについて全探索し、Hが一意に定まるかどうかを確かめる
# h_i == 0のとき、Hの最大値についての情報を記録する

for Cx in range(101):
    for Cy in range(101):
        H_tmp = []
        max_h_tmp = float("inf")
        
        for i in range(N):
            if h[i] == 0:
                max_h_tmp = min(max_h_tmp, abs(x[i]-Cx) + abs(y[i]-Cy))
            else:
                H_tmp.append(h[i] + abs(x[i]-Cx) + abs(y[i]-Cy))
        
        H_tmp = set(H_tmp)
        if max(H_tmp) <= max_h_tmp and len(H_tmp) == 1:
            print(Cx, Cy, list(H_tmp)[0])
            exit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  query = []
  candi = []
  for i in range(n):
    x,y,h = (int(i) for i in input().split())
    query.append((x,y,h))
  if n == 1:
    print(*[x,y,h])
    exit()
  query = sorted(query,reverse = True,key=lambda x: x[2])
  for cx in range(0,101):
    for cy in range(0,101):
      judge = True
      x,y,h = query[0]
      karih = h +abs(cx-x)+abs(cy-y)
      karih2 = 0
      for i in range(n-1):
        nx,ny,nh = query[i+1]
        if nh == max(karih-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:
        candi.append((cx,cy,karih))
        
  print(*candi[0])
        
          
      
      
solve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  query = []
  candi = []
  for i in range(n):
    x,y,h = (int(i) for i in input().split())
    query.append((x,y,h))
  if n == 1:
    print(*[x,y,h])
    exit()
  for cx in range(0,101):
    for cy in range(0,101):
      judge = True
      for j in range(n):
        x,y,h = query[j]
        if not h == 0:
          karih = h +abs(cx-x)+abs(cy-y)
          karih2 = 0
      for i in range(n):
        nx,ny,nh = query[i]
        if nh == max(karih-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:
        candi.append((cx,cy,karih))
        
      judge = True 
      for i in range(n-1):
        nx,ny,nh = query[i+1]
        if nh == max(karih2-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:
        candi.append((cx,cy,karih2))
  print(*candi[0])
        
          
      
      
solve()

Submission status: Accepted

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

for cx in range(101):
  for cy in range(101):
    x,y,h=xyh[0]
    H=abs(x-cx)+abs(y-cy)+h
    d=0
    for x,y,h in xyh:
      if h>0:
        if H!=abs(x-cx)+abs(y-cy)+h:
          break
      else:
        if H>abs(x-cx)+abs(y-cy):
          break
      d+=1
    if d==N:
      print(cx,cy,H)
      exit()

Submission status: Accepted

Solution code:
n = int(input())

data = []
p, q, r = (0, 0, 0)
for _ in range(n):
    (l, m, n) = map(int, input().split())
    data.append([l, m, n])
    if n:
        p = l
        q = m
        r = n


for x in range(101):
    for y in range(101):
        h = r + abs(p - x) + abs(q - y)
        if all(c == max(h - abs(a - x) - abs(b - y), 0) for a, b, c in data):
            print("{} {} {}".format(x, y, h))
            exit(0)

Submission status: Accepted

Solution code:
n = int(input())
loc = [list(map(int,input().split())) for _ in range(n)]
loc.sort(key = lambda x:x[2] ,reverse = True)
for i in range(101):
  for j in range(101):
    h = abs(loc[0][0]-i)+abs(loc[0][1]-j)+loc[0][2]
    for l in loc[1:]:
      if l[2] != max(h-abs(l[0]-i)-abs(l[1]-j),0):
        break
    else:
      print(i,j,h)
      break

Submission status: Accepted

Solution code:
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
from itertools import product
H={(i,j):-10**10 for i,j in product(range(101),repeat=2)}
for n in range(N):
    x,y,h=xyh[n]
    K=[e for e in H.keys()]
    for i,j in K:
        k0=H[i,j]
        k=abs(i-x)+abs(j-y)+h if h else -(abs(i-x)+abs(j-y))
        if k<0:
            if k0<k:
                H[i,j]=k
            elif -k<k0:
                del H[i,j]
        elif k0<0:
            if k<=-k0:
                H[i,j]=k
            else:
                del H[i,j]
        elif k!=k0:
            del H[i,j]
i,j=list(H.keys())[0]
print(i,j,H[i,j])

Submission status: Accepted

Solution code:
def get_H(cx,cy):
  for info in info_list:
    if info[2] != 0:
      H0 = info[2] + abs(info[0]-cx) + abs(info[1]-cy)
      break

  for info in info_list:
    if info[2] != max(H0 - abs(info[0]-cx) - abs(info[1]-cy),0): return -1  
  return H0

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

for cx in range(101):
  for cy in range(101):
    res = get_H(cx,cy)
    if res != -1:
      print(cx,cy,res)

Submission status: Accepted

Solution code:
n = int(input())
xyh_list = [list(map(int, input().split())) for _ in range(n)]
list_0_100 = [i for i in range(0, 101)]
possible_list = []
for a in range(len(xyh_list)):
    if xyh_list[a][2] != 0:
        x1 = xyh_list[a][0]
        y1 = xyh_list[a][1]
        h1 = xyh_list[a][2]
        break

for cx in list_0_100:
    for cy in list_0_100:
        H = h1 + abs(x1 - cx) + abs(y1 - cy)
        count = 0
        for i in range(n):
            x = xyh_list[i][0]
            y = xyh_list[i][1]
            h = xyh_list[i][2]
            if h == max(H - abs(x - cx) - abs(y - cy), 0):
                count += 1
        if count == n:
            ansx = cx
            ansy = cy
            ansH = H
print(ansx, ansy, ansH)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
XYH = [list(map(int,input().split())) for _ in range(N)]
XYH.sort(key=lambda x: x[2],reverse=True)

for cx in range(0,101):
    for cy in range(0,101):
        flag = True
        H = XYH[0][2] + abs(XYH[0][0]-cx) + abs(XYH[0][1]-cy)
        for x,y,h in XYH:
            if h != max(H-abs(x-cx)-abs(y-cy),0):
                flag = False
                break

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

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], reverse=True)
# 中心座標を全探索（たかだか101*101*N通り）
for i in range(101):
    for j in range(101):
        # １つ目の要素を用いてHを設定
        H=xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for x,y,h in xyh:
            if h==max(H-abs(x-i)-abs(y-j),0):
                continue
            else:
                break
        else:
            print(i,j,H)

Submission status: Accepted

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


for cx in range(101):
    for cy in range(101):
        h = 0
        hmax =float('inf')
        false = 0
        for  hi,x,y in records:
            if hi==0:
                hmax=min(hmax,abs(cx-x)+abs(cy-y))
            else:
                if h ==0:
                    h = hi +abs(cx-x)+abs(cy-y)
                else:
                    if h != abs(cx-x)+abs(cy-y) +hi:
                        false = 1
                        break
        if false:
            continue
        else:
            if (1 <=h <= hmax):
                print(cx,cy,h)
                exit()
            else:
                if h==0 and hmax ==1:
                    print(cx,cy,h)
                    exit()
                else:
                    continue

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    points = [tuple(map(int, input().split())) for _ in range(N)]
    base_point = [(x,y,h) for x,y,h in points if h > 0][0]
    for cx in range(101):
        for cy in range(101):
            H = abs(cx-base_point[0])+abs(cy-base_point[1])+base_point[2]
            for x,y,h in points:
                if h != max(H-abs(cx-x)-abs(cy-y),0): break
            else:
                print(cx,cy,H)
                return 0

if __name__ == '__main__':
    main()

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], reverse=True)

for i in range(101):
    for j in range(101):
        h = xyh[0][2] + abs(xyh[0][0] - i) + abs(xyh[0][1] - j)
        for k in xyh:
            if k[2] == max(h - abs(k[0] - i) - abs(k[1] - j), 0):
                continue
            else:
                break
        else:
            print(i, j, h)

Submission status: Accepted

Solution code:
if __name__=='__main__':
    n = int(input())
    c = [[int(i) for i in input().split()] for i in range(n)]
    # print(c)
    a = [[0 for i in range(101)] for i in range(101)]
    # print(a)
    for i in range(101):
        for j in range(101):
            for p in range(n):
                if c[p][2] != 0:
                    a[i][j] = abs(i - c[p][0]) + abs(j - c[p][1]) + c[p][2]
                    break


            for p in range(n):
                if c[p][2] != 0:
                    h = abs(i - c[p][0]) + abs(j - c[p][1]) + c[p][2]
                    if a[i][j] != h:
                        a[i][j] = -1
                        break
                if c[p][2] == 0:
                    h = abs(i - c[p][0]) + abs(j - c[p][1])
                    if a[i][j] > h:
                        a[i][j] = -1
                        break


    for i in range(101):
        for j in range(101):
            flag = True
            if a[i][j] == -1:continue
            # for p in range(n):
            #     h = abs(i-c[p][0])+ abs(j-c[p][1]) + c[p][2]
            #     if h != a[i][j]:
            #         flag = False
            #         break
            # if flag:
            for p in range(n):
                h = max(a[i][j] - abs(i-c[p][0])- abs(j-c[p][1]),0)
                if h!= c[p][2]:
                    flag = False
                    break
            if flag:
                print(i,j,a[i][j])
                quit()

Submission status: Accepted

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

use=()
for some in lists:
    if some[2]==0:
        continue
    else:
        use=some
        break

for i in range(0,101):
    for j in range(0,101):
        height=use[2]+abs(i-use[0])+abs(j-use[1])   
        ok=True
        for inn in lists:
            if inn[2]==0:
                if height>abs(i-inn[0])+abs(j-inn[1]):
                    ok=False
            if inn[2]>0:
                if inn[2]+abs(i-inn[0])+abs(j-inn[1])!=height:
                    ok=False
        if ok:
            ans=[i,j,height]
            print(*ans)
            break
        else:
            continue

Submission status: Accepted

Solution code:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
H =[]
for i in range(0,101):
    for j in range(0, 101):
        H.append([i,j,0])

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

for X,Y,H0 in H:
    this_sum = []
    H1 = a[0][2] + abs(X-a[0][0]) + abs(Y-a[0][1])
    for x,y,h in a:
        if h == max(H1 - abs(x-X) - abs(y-Y), 0):
            continue
        else:
            break
    else:
        print(" ".join(list(map(str, [X, Y, H1]))))

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], reverse=True)

for i in range(101):
    for j in range(101):
        h = xyh[0][2] + abs(xyh[0][0] - i) + abs(xyh[0][1] - j)
        for k in xyh:
            if k[2] == max(h - abs(k[0] - i) - abs(k[1] - j), 0):
                continue
            else:
                break
        else:
            print(i, j, h)

Submission status: Accepted

Solution code:
def test():
    n = int(input())
    a = [(list(map(int,input().split()))) for i in range(n)]
    for cx in range(101):
        for cy in range(101):
            for x,y,h in a:
                if h > 0:
                    H = h + abs(x-cx) + abs(y-cy)
                    break
            for x,y,h in a:
                if max(H-abs(x-cx)-abs(y-cy),0) != h:
                    break
            else:
                print(cx,cy,H)
                return


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

#初期化
N = int(input())
L = []
for i in range(N):
	x, y, h = getlist()
	L.append([x, y, h])

#探索
for i in range(101):
	for j in range(101):
		D = defaultdict(int)
		for k in range(N):
			if L[k][2] != 0:
				val = abs(L[k][0] - i) + abs(L[k][1] - j) + L[k][2]
				D[val] += 1
		if len(D) == 1:
			judge = "Yes"
			for k in range(N):
				if val - abs(L[k][0] - i) - abs(L[k][1] - j) > L[k][2]:
					judge = "No"
					break
			if judge == "Yes":
				print(i, j, val)

Submission status: Accepted

Solution code:
import math
N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N
#Cx Cy H を求める
for i in range(N):
    x[i], y[i], h[i] = map(int,input().split())
#h>0となるものは必ず存在するので
#そのときに答えの(cx,cy,H)の候補としてprobに(10000個)格納する
#最大でN*100*100=10^6
prob = []
for i in range(N):
    if h[i] > 0:
        for cx in range(101):
            for cy in range(101):
                H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                prob.append([cx,cy,H])
        break
#答えの候補probの中からすべての条件を満たすものを探す
#最大でN*10000 = 10^6
for i in range(N):
    minus = []
    for j in range(len(prob)):
        cx = prob[j][0]
        cy = prob[j][1]
        H = prob[j][2]
        if h[i] == max(H-abs(x[i] - cx) -abs(y[i] - cy),0):
            continue
        else:
            minus.append([cx,cy,H])
    if len(minus) == 0:
        continue
    else:
        for k in range(len(minus)):
            prob.remove(minus[k])
print(str(prob[0][0])+' '+str(prob[0][1])+' '+str(prob[0][2]))

Submission status: Accepted

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

flag = True
id = 0
for i in range(n):
    P = list(map(int, input().split( )))
    p.append(P)
    if P[2]>0:
        id = i
cand = [[-1 for y in range(101)] for x in range(101)]
 
for x in range(101):
    for y in range(101):
        cand[x][y] = p[id][2]+abs(x-p[id][0])+abs(y-p[id][1])
ans =  [[1 for y in range(101)] for x in range(101)]

for i in range(n):
    for x in range(101):
        for y in range(101):
            h = max(cand[x][y]- abs(x-p[i][0])-abs(y-p[i][1]), 0)
            if p[i][2] != h:
                ans[x][y] = 0

ans_x = -1
ans_y = -1
for x in range(101):
    for y in range(101):
        if ans[x][y] == 1:
            ans_x, ans_y = x,y

print(ans_x,ans_y,cand[ans_x][ans_y])

Submission status: Accepted

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

# 与えられた情報のhiがすべて0ということはありえない。
# cx,cyを全探索し、与えられた情報がすべて矛盾がない場合を答えとして出力する。
x0,y0,h0 = XYH[0]
for cx in range(101):
  for cy in range(101):
    ch = h0 + abs(x0-cx) + abs(y0-cy)
    flag = True
    for i in range(1,N):
      x,y,h = XYH[i]
      if (h > 0 and ch != h + abs(x-cx) + abs(y-cy)) or (h == 0 and ch > h + abs(x-cx) + abs(y-cy)):
        flag = False
        break
    if flag:
      print(cx,cy,ch)
      exit()

Submission status: Accepted

Solution code:
N=int(input())
xyh=[list(map(int, input().split())) for i in range(N)]
 
for i in range(101):
  for j in range(101):
    check=True
    k=0
    while xyh[k][2]==0:
      k+=1
      
    h=abs(xyh[k][0]-i)+abs(xyh[k][1]-j)+xyh[k][2]
    
    for k in range(N):
      temph=abs(xyh[k][0]-i)+abs(xyh[k][1]-j)+xyh[k][2]
      if xyh[k][2]==0:
        if temph<h:
          check=False
      else:
        if h!=temph:
          check=False
        
    if check==True and 0<h:
        print(' '.join([str(i), str(j), str(h)]))
        exit()
        
sonnnakannsuuhateigisiteinai()

Submission status: Accepted

Solution code:
N = int(input())
x, y, h = [], [], []
for i in range(N):
    s, t, u = map(int, input().split())
    x.append(s)
    y.append(t)
    h.append(u)

# h>0となるものは必ず存在するので
# そのときの答えの(cx, cy, H)の候補としてprobに(10000個)格納する
# 最大でN*100*100=10^6
prob = []
for i in range(N):
    if h[i] > 0:
        for cx in range(101):
            for cy in range(101):
                H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                prob.append([cx, cy, H])
        break

# 答えの候補probの中から全ての条件を満たすものを探す
# 最大でN*10000=10^6
for i in range(N):
    minus = []
    for j in range(len(prob)):
        cx = prob[j][0]
        cy = prob[j][1]
        H = prob[j][2]
        if h[i] == max(H - abs(x[i] - cx) - abs(y[i] - cy), 0):
            continue
        else:
            minus.append([cx, cy, H])
    if len(minus) == 0:
        continue
    else:
        for k in range(len(minus)):
            prob.remove(minus[k])

ans = ' '.join(list(map(str, list(list(prob)[0]))))
print(ans)

Submission status: Accepted

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

cands = []
for cy in range(101):
    for cx in range(101):
        h_tmp = None
        for x,y,h in XYH:
            if h==0: continue
            d = abs(cy-y) + abs(cx-x)
            if h_tmp is None:
                h_tmp = h+d
            else:
                if h+d != h_tmp:
                    break
        else:
            cands.append((cx,cy,h_tmp))

for cx,cy,ch in cands:
    for x,y,h in XYH:
        if max(ch - abs(x-cx) - abs(y-cy), 0) != h:
            break
    else:
        print(cx,cy,ch)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
N = int(readline())
XYH = [list(map(int, readline().split())) for _ in range(N)]
X, Y, H = map(list, zip(*XYH))
i = 0
for i in range(N):
    if H[i] != 0:
        x, y, h = X[i], Y[i], H[i]
        break
mh = min(H)
Mh = max(H)
for i in range(101):
    for j in range(101):
        ch = abs(x-i) + abs(y-j) + h
        for xi, yi, hi in XYH:
            if hi != max(0, -abs(xi- i) - abs(yi-j) + ch):
                break
        else:
            ans = (i, j, ch)
print(*ans)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    
    P = set()
    for i in range(n):
        x,y,h = map(int,input().split())
        if h != 0:
            P.add((x,y,h))
    x,y,h = P.pop()
    if not P:
        return x,y,h
    for cx in range(101):
        for cy in range(101):
            H = h + abs(x-cx) + abs(y-cy)
            for p in P:
                if H != p[2] + abs(p[0]-cx) + abs(p[1]-cy):
                    break
            else:
                return cx,cy,H
        
if __name__ == '__main__':
    print(*(solve()))

Submission status: Accepted

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

N = int(input().split()[0])
xyh_list = []
not_zero_h_list = []

for _ in range(N):
    x, y, h = list(map(int, input().split()))
    xyh_list.append((x, y, h))
    if h != 0:
        not_zero_h_list.append((x, y, h))

# 高さ0の情報は除く
target_x, target_y, target_h = not_zero_h_list[0]

for cx in range(0, 101):
    for cy in range(0, 101):
        # cx, cy = 2, 2
        H_list = []
        # 基準
        H = target_h + abs(target_x - cx) + abs(target_y - cy)
        H = max(0, H)
        is_ok = True

        # 他の座標の結果と一致するかどうか確認する
        for x, y, h in xyh_list:  # ここが問題
            if h == 0:
                if (H - abs(x - cx) - abs(y - cy)) <= 0:
                    continue
                else:
                    # 一致しない
                    is_ok = False
                    break
            else:
                HH = h + abs(x - cx) + abs(y - cy)
                HH = max(0, HH)
                if HH != H:
                    # 一致しない
                    is_ok = False
                    break
        if is_ok:
            break

    if is_ok:
        break
ans = "{} {} {}".format(cx, cy, H)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True

        for i, (x,y,h) in enumerate(xyh):
            if h != 0:
                H = h + abs(x - cx) + abs(y - cy)

        for i, (x,y,h) in enumerate(xyh):
            if h == max(H - abs(x - cx) - abs(y - cy), 0):
                continue
            else:
                flag = False
                break
        if flag:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
from collections import defaultdict
if __name__ == '__main__':
    N = int(input())
    xyh = [None]*N
    for i in range(N):
        xyh[i] = list(map(int, input().split()))
    
    H = 0
    for i in range(N):
        if xyh[i][2] >= H:
            X = xyh[i][0]
            Y = xyh[i][1]
            H = xyh[i][2]
            I = i
    
    flag = True
    for i in range(0, N):
        if xyh[i][2] != max(H - abs(xyh[i][0] - X) - abs(xyh[i][1] - Y), 0):
            flag = False
            break
    
        
    if not flag:
        for x in range(0, 101):
            for y in range(0, 101):
                flag = True
                height = 0
                for i in range(0, N):
                    if xyh[i][2] != 0:
                        if height == 0:
                            height = xyh[i][2] + abs(xyh[i][0] - x) + abs(xyh[i][1] - y)
                        if height != xyh[i][2] + abs(xyh[i][0] - x) + abs(xyh[i][1] - y):
                            flag = False
                            break
                    else:
                        if abs(xyh[i][0] - x) + abs(xyh[i][1] - y) < height:
                            flag = False
                            break
                if flag and height:
                    X = x
                    Y = y
    
    H = xyh[I][2] + abs(xyh[I][0] - X) + abs(xyh[I][1] - Y)
     
    print(X, Y, H)

Submission status: Accepted

Solution code:
N = int(input())
D = [tuple(map(int,input().split())) for _ in range(N)]
D = sorted(D,key=lambda x:x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        ind = 1
        x,y,h = D[0]
        H = abs(x-cx)+abs(y-cy)+h
        for i in range(1,N):
            x,y,h = D[i]
            if h>0 and abs(x-cx)+abs(y-cy)+h!=H:
                ind = 0
                break
            elif h==0 and abs(x-cx)+abs(y-cy)<H:
                ind = 0
                break
        if ind==1:
            CX = cx
            CY = cy
            break
    if ind==1: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], reverse=True)
for cx in range(101):
    for cy in range(101):
        x = xyh[0][0]
        y = xyh[0][1]
        h = xyh[0][2]
        ans = [cx, cy, h + abs(x - cx) + abs(y - cy)]
        for i in range(1, n):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            if h != max(ans[2] - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            print(*ans)

Submission status: Accepted

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

for cx in range(0,101):
    for cy in range(0, 101):
        ch = 0
        for i in range(0,N):
            if xyh[i][2] > 0:
                ch = xyh[i][2] + abs(xyh[i][0] - cx) + abs(xyh[i][1] - cy)
                break
        for i in range(0, N):

            if xyh[i][2] != max(ch - abs(xyh[i][0] - cx) - abs(xyh[i][1] -  cy), 0):
                break
        else:
            print('{} {} {}'.format(cx, cy, ch))
            break
    else:
        continue
    break

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    p = []
    for i in range(N):
        x,y,h = map(int,input().split())
        p.append([x,y,h])
 
    p.sort(key=lambda x: x[2])
    a,b,c = p[-1]
    for i in range(101):
        for j in range(101):
            H = c + abs(a - i) + abs(b - j)
            for x,y,h in p:
                if h != max(H - abs(x - i) - abs(y - j), 0):
                    break
            else:
                print(i,j,H)
                exit()


main()

Submission status: Accepted

Solution code:
N = int(input())
surveys = [list(map(int, input().split())) for _ in range(N)]
surveys.sort(key = lambda x:-x[2])
for x in range(101):
  for y in range(101):
    before = -1
    identified = True
    for survey in surveys:
      height = survey[2] + abs(x-survey[0]) + abs(y-survey[1])
      if before != -1 and before != height:
        if survey[2] == 0 and before < height:
          continue
        identified = False
        break
      if before == -1:
        before = height
    if identified:
      print(x, y, before)
      break

Submission status: Accepted

Solution code:
n=int(input())
p = []
for i in range(n):
    ta,tb,tc = map(int,input().split())
    p.append([ta,tb,tc])

p.sort(key=lambda x: x[2])
a,b,c=p[-1]
for y in range(101):
    for x in range(101):
        h=c+abs(a-x)+abs(b-y)
        if all(k==max(h-abs(i-x)-abs(y-j),0) for i,j,k in p):
            print(x,y,h)
            exit()

Submission status: Accepted

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

a = sorted(a, key=lambda x: -x[2])

m = 0
mx = 0
my = 0

for cx in range(101):
    for cy in range(101):
        flag = True
        x, y, h = a[0]
        H = max(abs(x-cx) + abs(y-cy) + h, 0)
        for i in range(n):
            xx, yy, hh = a[i]
            if hh != max(H - abs(xx - cx) - abs(yy - cy), 0):
                flag = False

        if flag == True:
            mx = cx
            my = cy
            m = H

print(str(mx) + ' ' + str(my) + ' ' + str(m))

Submission status: Accepted

Solution code:
N = int(input())

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

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

for i in range(101):
    for j in range(101):
        det = 0
        H = 0
        for k in range(N):
            if H == 0 and h[k] > 0:
                H = h[k] + abs(x[k]-i) + abs(y[k]-j)
            elif h[k] != max(0,H - abs(x[k]-i) - abs(y[k]-j)):
                det = -1
                break
        if det == 0:
            ans = [i,j,H]

print(" ".join(map(str,ans)))

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    xyh = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    xyh.sort(key=lambda x: x[2], reverse=True)
    for x in range(101):
        for y in range(101):
            h = xyh[0][2] + abs(xyh[0][0] - x) + abs(xyh[0][1] - y)
            b = True
            for xl, yl, hl in xyh:
                if max(0, h - abs(xl - x) - abs(yl - y)) != hl:
                    b = False
                    break
            if b:
                print(x, y, h)
                exit()


if __name__ == '__main__':
    slove()

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],reverse=True)


for i in range(101):
    for j in range(101):
        h=xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for k in xyh:
            if k[2]==max(h-abs(k[0]-i)-abs(k[1]-j),0):
                continue
            else:
                break
        else:
            print(i,j,h)

Submission status: Accepted

Solution code:
N = int(input())
p = [tuple(map(int,input().split())) for _ in range(N)]
p.sort(key=lambda x:x[2])
mx,my,mh = p[-1]

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 p):
      print(cx, cy, H)
      exit()

Submission status: Accepted

Solution code:
n=int(input())
#(x,y,h)
r=sorted([list(map(int,input().split()))[::-1] for _ in range(n)])[::-1]

for i in range(101):
  for j in range(101):
    h1=r[0][0]+abs(r[0][1]-i)+abs(r[0][2]-j)
    flag=0
    for item in r[1:]:
      if item[0]>0:
        if item[0]+abs(item[1]-i)+abs(item[2]-j)!=h1:
          flag=1
          break
      else:
        if h1-abs(item[1]-i)-abs(item[2]-j)>0:
          flag=1
          break
    if flag==0:
      print(j,i,h1)
      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]= [int(x) for x in input().split()]
H = 0
j = 0
while h[j]==0:
  j +=1
for cx in range(101):
  for cy in range(101):
    H = h[j]+abs(cx-x[j])+abs(cy-y[j])
    for n in range(N):
      res = max(H-abs(cx-x[n])-abs(cy-y[n]),0)
      if res==h[n]:
        if n==N-1:
          print(cx,cy,H)
          exit()
        continue
      else :
        break