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:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    for cx in range(101):
        for cy in range(101):
            i = 0
            while True:
                x, y, h = xyh[i]
                if h == 0:
                    i += 1
                    continue
                else:
                    H = h + abs(x - cx) + abs(y - cy)
                    break

            for x, y, h in xyh:
                tmp = max(H - abs(x - cx) - abs(y - cy), 0)
                if tmp == h:
                    continue
                else:
                    break
            else:
                print(cx, cy, H)
                return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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


for cx in range(101):
    for cy in range(101):
        for xyh in XYH:
            if xyh[2] > 0:
                H = abs(cx - xyh[0]) + abs(cy - xyh[1]) + xyh[2]
                break
        for xyh in XYH:
            _x, _y, _h = xyh
            if _h == max(0, H - abs(cx-_x) - abs(cy-_y)):
                continue
            break
        else:
            print(cx, cy, H)
            sys.exit(0)

Submission status: Accepted

Solution code:
def search_center(xyh_list):
    xyh_list.sort(key=lambda r: r[2], reverse=True)
    highest = xyh_list[0]
    for cx in range(101):
        for cy in range(101):
            h = highest[2] + abs(highest[0] - cx) + abs(highest[1] - cy)
            matched = True
            for xyh in xyh_list[1:]:
                if xyh[2] == 0:
                    if h - abs(xyh[0] - cx) - abs(xyh[1] - cy) > 0:
                        matched = False
                        break
                else:
                    hh = xyh[2] + abs(xyh[0] - cx) + abs(xyh[1] - cy)
                    if h != hh:
                        matched = False
                        break
            if matched:
                return cx, cy, h
    return None


def main():
    N = int(input())
    xyh_list = [list(map(int, input().split(' '))) for _ in range(N)]
    xyh_list.sort(key=lambda r: r[2], reverse=True)
    cx, cy, ph = search_center(xyh_list)
    print('{} {} {}'.format(cx, cy, ph))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
h = [0 for _ in range(n)]
for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())

for cx in range(0, 101):
    for cy in range(0, 101):
        ok = True
        H = None
        under = INF
        for i in range(n):
            if h[i] == 0:
                under = min(under, abs(x[i] - cx) + abs(y[i] - cy))
            else:
                H2 = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                # if cx == 2 and cy == 2:
                    # print("H2 = %d, i = %d" % (H2, i))
                if H2 < 1:
                    ok = False
                    break
                if H == None:
                    H = H2
                    continue
                elif H != H2:
                    # if cx == 2 and cy == 2:
                        # print("i = %d" % i)
                    ok = False
                    break
        if H > under:
            ok = False
        if ok:
            print(cx, cy, H)
            sys.exit()

Submission status: Accepted

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

f = lambda i, j, k, l: abs(i - k) + abs(j - l)

for c_x in range(0, 101):
    for c_y in range(0, 101):
        d = []
        h_max = float("inf")
        for m in info:
            x, y, h = m[0], m[1], m[2]
            if h > 0:
                H = f(x, y, c_x, c_y) + h
                d.append(H)
            else:
                h_max = min(h_max, f(x, y, c_x, c_y))
        else:
            d = list(set(d))
            if len(d) == 1 and 1 <= d[-1] and d[-1] <= h_max:
                print(c_x, c_y, d[-1])
                exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
xyh = li2(N)

for c_x in range(101):
    for c_y in range(101):
        flag = 0
        left = 1
        right = float('inf')
        for i in range(N):
            #print(i, left, right)
            tmp = xyh[i][2] + abs(c_x-xyh[i][0]) + abs(c_y-xyh[i][1])
            #print(tmp, xyh[i][2])
            if xyh[i][2] > 0:
                if not(left <= tmp <= right):
                    flag = 1
                    break
                left = right = tmp
            else:
                if tmp < 1 or left > tmp:
                    flag = 1
                    break
                right = min(right, tmp)
        if not flag:
            print(c_x, c_y, right)
            exit()

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        candidate_h = info[0][2] + abs(info[0][0] - cx) + abs(info[0][1] - cy)
        for i in range(1, N):
            x, y, h = info[i]
            if max(candidate_h - abs(x - cx) - abs(y - cy), 0) != h:
                break
        else:
            print("{} {} {}".format(cx, cy, candidate_h))
            exit()

Submission status: Accepted

Solution code:
from sys import exit

def ht(cx,cy,x,y,h):
	return h+abs(x-cx)+abs(y-cy)

n=int(input())			#高々100なのでほとんどが高さ0っていう状況はない
xyh=[0]*n

for i in range(n):
	x,y,h=map(int,input().split())
	xyh[i]=[x,y,h]
xyh.sort(key=lambda x:x[2],reverse=True)			#h=0を選択してしまうことを避ける

for cx in range(101):
	for cy in range(101):
		H=ht(cx,cy,xyh[0][0],xyh[0][1],xyh[0][2])
		for i in range(1,n):
			if max(H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy),0)!=xyh[i][2]:			#H=ht(このfor文で選択した座標)にすると、高さ0の場合に合わなくなる
				break
			
		else:			#直前のifが行われなければ、という意味。forの外における
			print(cx,cy,H)
			exit()

Submission status: Accepted

Solution code:
# https://betrue12.hateblo.jp/entry/2018/10/06/224032

n = int(input())
x, y, h = [], [], []
for i in range(n):
	a, b, c = map(int, input().split())
	x.append(a)
	y.append(b)
	h.append(c)


for i in range(101):
	for j in range(101):
		H = -1
		Hmax = 2 * 10 ** 9
		success = True
		for k in range(n):
			d = abs(i - x[k]) + abs(j - y[k])
			if h[k] > 0:
				H2 = h[k] + d
				if H > 0 and H != H2:
					success = False
					break
				else:
					H = H2
			else: # h[k] == 0
				Hmax = min(Hmax, d)
		
		if success and H <= Hmax:
			print(i, j, H)
			exit()

Submission status: Accepted

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

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

# sort by h
P.sort(key=lambda x: x[2], reverse=True)

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

Submission status: Accepted

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

for i in range(0,101):
  for j in range(0,101):
    temp=0
    onezero=1
    for k in range(0,n):
      k=n-k-1
      xhoukou=abs(i-lis[k][1])
      yhoukou=abs(j-lis[k][2])
      hhoukou=lis[k][0]
      if hhoukou>0:
        keep=xhoukou+yhoukou+hhoukou
        if temp==0:
          temp=keep
        else:
          if keep!=temp:
            onezero=0
      else:
        if xhoukou+yhoukou<temp:
          onezero=0
    if onezero==1:
      print(i,j,temp)

Submission status: Accepted

Solution code:
from itertools import product
n, *XYH = map(int, open(0).read().split())
for cx, cy in product(range(101), repeat=2):
    B, C = set(), set()
    for x, y, h in zip(XYH[::3], XYH[1::3], XYH[2::3]):
        s = h + abs(x-cx) + abs(y-cy)
        if h:
            C.add(s)
        else:
            B.add(s)
    if len(C) == 1:
        h = C.pop()
        if all(h <= b for b in B):
            print(cx, cy, h)
            exit()

Submission status: Accepted

Solution code:
from itertools import product
n, *XYH = map(int, open(0).read().split())
X, Y, H = XYH[::3], XYH[1::3], XYH[2::3]
A = []
for cx, cy in product(range(101), repeat=2):
    B = set()
    C = set()
    for x, y, h in zip(X, Y, H):
        s = h + abs(x-cx) + abs(y-cy)
        if h == 0:
            B.add(s)
        else:
            C.add(s)
    if len(C) == 1:
        h = C.pop()
        if all(h <= b for b in B):
            A.append((cx, cy, h))
print(*A.pop())

Submission status: Accepted

Solution code:
N = int(input())

XYH = []
for _ in range(N):
    x, y, h = map(int, input().split())
    XYH.append((x, y, h))
XYH.sort(key=lambda x: -x[2])

for Cx in range(0, 101):
    for Cy in range(0, 101):
        flg = True

        Ch = XYH[0][2]+abs(XYH[0][0]-Cx)+abs(XYH[0][1]-Cy)

        for x, y, h in XYH:
            if h != max(Ch - abs(x-Cx) - abs(y-Cy), 0):
                flg = False

        if flg:
            print(Cx, Cy, Ch)
            exit()

Submission status: Accepted

Solution code:
N = int(input())

XYH = []
for _ in range(N):
    x, y, h = map(int, input().split())
    XYH.append((x, y, h))
XYH.sort(key=lambda x: -x[2])

for Cx in range(0, 101):
    for Cy in range(0, 101):
        flg = True

        if XYH[0][2] == 0:
            Ch = 1
        else:
            Ch = XYH[0][2]+abs(XYH[0][0]-Cx)+abs(XYH[0][1]-Cy)

        for x, y, h in XYH:
            if h != max(Ch - abs(x-Cx) - abs(y-Cy), 0):
                flg = False

        if flg:
            print(Cx, Cy, Ch)
            exit()

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
x0,y0,h0=0,0,0
for x,y,h in xyh:
  if h>0:
    x0,y0,h0=x,y,h
    break
# 頂点を固定して全探索
for cx in range(101):
  for cy in range(101):
    h=h0+abs(cx-x0)+abs(cy-y0)
    flg=True
    for xi,yi,hi in xyh:
      if hi!=max(h-abs(cx-xi)-abs(cy-yi),0):
        flg=False
    if flg:
      print(cx,cy,h)

Submission status: Accepted

Solution code:
import sys
import bisect

inf = 10**15
mod = 10**9+7

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

inf = 10**15
mod = 10**9+7
n = int(input())
Hinfo = [list(map(int, input().split())) for i in range(n)]
H = -1
Hmax = inf
for Cx in range(101):
    for Cy in range(101):
        H = -1
        flag = True
        for tmp in Hinfo:
            x,y,h = tmp
            if h == 0:
                Hmax = getH(Cx, Cy, x, y, h)
            else:
                canH = getH(Cx, Cy, x, y, h)
                if H > 0:
                    if H != canH:
                        flag = False
                        break
                else:
                    H = canH
            if Hmax < H:
                flag = False
                break
        if Hmax >= H and flag:
            print('{} {} {}'.format(Cx, Cy, H))
            sys.exit()

Submission status: Accepted

Solution code:
n=int(input())

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

hxy.sort()

for cx in range(101):
    for cy in range(101):
        flag=0
        temp=hxy[-1]
        H=temp[0]+abs(temp[1]-cx)+abs(temp[2]-cy)

        for item in hxy:
            h=item[0]
            x=item[1]
            y=item[2]
            if h!=max(H-abs(x-cx)-abs(y-cy),0):
                flag=1
                break
        
        if flag==0:
            print(cx,cy,H)
            exit()

Submission status: Accepted

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

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

		for x,y,h in xyh:
			if h == 0:
				continue

			H = h + abs(x - Cx) + abs(y - Cy)
			break
		ok = True
		for x,y,h in xyh:
			if max(H - abs(x - Cx) -abs(y - Cy), 0) != h:
				ok = False
				break
		if ok:
			print("{} {} {}".format(Cx, Cy, H))
			sys.exit(0)

Submission status: Accepted

Solution code:
N = int(input())
data = [tuple(map(int, input().split())) for _ in range(N)]
data.sort(key=lambda x: -x[2])
for cx in range(101):
    for cy in range(101):
        h0 = None
        for x, y, h in data:
            if h:
                h_tmp = h + abs(cx - x) + abs(cy - y)
                if h_tmp != h0 and h0 is not None:
                    break
                h0 = h_tmp
            else:
                if abs(cx - x) + abs(cy - y) < h0:
                    break
        else:
            print(cx, cy, h0)
            exit()

Submission status: Accepted

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

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


for cx in range(101):
    for cy in range(101):
        flag = True
        # x0, y0, h0 = XYH[0][0],XYH[0][1],XYH[0][2]
        # prob_H = h0 + abs(x0-cx) + abs(y0-cy)
        for x0, y0, h0 in XYH[0:]:
            prob_H = h0 + abs(x0-cx) + abs(y0-cy)
            if h0 == 0:
                continue
            break
        for xi, yi, hi in XYH[0:]:
            if max(prob_H - abs(xi-cx) - abs(yi-cy),0) == hi:
                continue
            else:
                flag = False
                break
        if flag == False:
            continue

        print(cx,cy,prob_H)
        quit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
c = []
for i in range(n):
  a = [int(i) for i in input().split()]
  c.append(a)

from operator import itemgetter
c = sorted(c,key=itemgetter(2),reverse=True)
p,q,r = c[0]
end = c[-1]
c = c[1:]
for i in range(101):
  for j in range(101):
    if r > 0:
      chk = abs(p-i)+abs(q-j)+r
    else:
      chk = 1
    for num,k in enumerate(c):
      x,y,h = k
      if h == 0:
        if abs(x-i)+abs(y-j) < chk:
          break
      else:
        if abs(x-i)+abs(y-j)+h != chk:
          break
      if k == end:
        ans = (i,j,chk)

print(*ans)

Submission status: Accepted

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

cands = []
x0,y0,h0 = hist[0]

for i in range(0,101):
  for j in range(0,101):
    if h0 == 0:
      cands.append((i,j,1))
    else:
      cands.append((i,j, h0+abs(i-x0)+abs(j-y0)))
    
for X,Y,H in cands:
  for x,y,h in hist:
    if max(H-abs(X-x)-abs(Y-y),0) == h:
      continue
    else:
      break
  else:
    print(X,Y,H)
    break

Submission status: Accepted

Solution code:
n = int(input())
t = [list(map(int,input().split())) for i in range(n)]
for x,y,h in t:
    if h > 0:
        a = [x,y,h]            # hが0でない1つの組(地面以外の部分)

for cx in range(101):
    for cy in range(101):
        flag = True
        ch = abs(a[0]-cx) + abs(a[1] - cy) + a[2]     # 高さ
        for x,y,h in t:
            if h != max(ch - abs(x - cx) - abs(y - cy),0):    # 高さが条件に合うか 
                flag = False
                break
        if flag:
            print(cx,cy,ch)
            exit()

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    vx = []
    vy = []
    vh = []
    for i in range(n):
        x,y,h = readInts()
        vx.append(x)
        vy.append(y)
        vh.append(h)
        if h > 0:
            si = i
    # 基準となる座標はどこでもいい
    # けど、h = 0 のところはだめやねん
    #
    resx,resy,resh = -1,-1,-1
    for x in range(101):
        for y in range(101):
            h = vh[si] + abs(x - vx[si]) + abs(y - vy[si])
            ok = True
            for i in range(n):
                if vh[i] > 0 and h - vh[i] != abs(x - vx[i]) + abs(y - vy[i]):
                    ok = False
                if vh[i] == 0 and h > abs(x - vx[i]) + abs(y - vy[i]):
                    ok = False
            if ok:
                resx = x
                resy = y
                resh = h
    print(resx,resy,resh)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]


#全探索すれば良い

#1つめの高さが0ではない情報を記録
for xi,yi,hi in xyh:
    if hi>0:
        memo = [xi,yi,hi]
        break

for cx in range(0,101):
    for cy in range(0,101):
        flg = True
        #cx,cyが中心座標の場合、memoの情報から高さを得られる
        ch = abs(memo[0]-cx)+abs(memo[1]-cy)+memo[2]
        for xi,yi,hi in xyh:
            #各情報の検証
            if hi!=max(ch-abs(xi-cx)-abs(yi-cy),0):
                flg = False
                break
        if flg:
            print("{} {} {}".format(cx,cy,ch))
            import sys
            sys.exit()

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
X, Y, H = [0] * N, [0] * N, [0] * N

notzero = -1
for i in range(N):
    X[i], Y[i], H[i] = map(int, input().split())
    if H[i] != 0:
        notzero = i

def solve():
    for x in range(101):
        for y in range(101):
            cx, cy = x, y
            h = H[notzero] + abs(X[notzero] - cx) + abs(Y[notzero] - cy)
            ok = True
            for i in range(N):
                ok &= max(0, h - abs(X[i] - cx) - abs(Y[i] - cy)) == H[i]
            if ok:
                return cx, cy, h

print(*solve())

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

lsts = []

xyh = xyhs[0]
for cy in range(101):
    for cx in range(101):
        lsts.append([cx, cy, xyh[2] + abs(xyh[0] - cx) + abs(xyh[1] - cy)]) 

for xyh in xyhs[1:]:
    lst = []
    while len(lsts):      
        p = lsts.pop()
        h = xyh[2] + abs(xyh[0] - p[0]) + abs(xyh[1] - p[1])
        if p[2] == h:
            lst.append(p)
    lsts = lst[:]
    if len(lsts) == 1: break
print(*lsts[0])

Submission status: Accepted

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

pos = sorted(pos, key=lambda x: x[2])
tx,ty,th = pos[-1]
def solve():
  for cx in range(101):
    for cy in range(101):
      H = th+abs(tx-cx)+abs(ty-cy)
      for x,y,h in pos:
        if h != max(H-abs(x-cx)-abs(y-cy), 0):
          break
      else:
        return(cx,cy,H)

cx,cy,H=solve()
print(cx,cy,H)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    for cx in range(101):
        for cy in range(101):
            chs = {
                hi + abs(xi - cx) + abs(yi - cy)
                for xi, yi, hi in zip(x, y, h)
                if hi != 0
            }
            if len(chs) != 1:
                continue
            ch, = chs
            if any(max(ch - abs(xi - cx) - abs(yi - cy), 0) != hi
                   for xi, yi, hi in zip(x, y, h)):
                print(cx, cy, ch, file=sys.stderr)
                continue
            print(cx, cy, ch)
            return


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 functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    x = [0]*N
    y = [0]*N
    h = [0]*N
    for i in range(N):
        x[i], y[i], h[i] = map(int, input().split())
    
    for Cx in range(101):
        for Cy in range(101):
            H = INF
            for i in range(N):
                if h[i] > 0:
                    H = h[i] + abs(x[i]-Cx) + abs(y[i]-Cy)

            flg = True
            for i in range(N):
                if max(H - abs(x[i]-Cx) - abs(y[i]-Cy), 0) != h[i]:
                    flg = False
                    break
            if flg:
                print(" ".join([str(Cx), str(Cy), str(H)]))
                return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split()))[::-1]for _ in range(n)]
xyh.sort(reverse=1)
for xx in range(101):
  for yy in range(101):
    f=True
    hh=xyh[0][0]+abs(xx-xyh[0][2])+abs(yy-xyh[0][1])
    for h,y,x in xyh[1:]:
      if max(hh-abs(x-xx)-abs(y-yy),0)!=h:f=False
    if f:print(xx,yy,hh);exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
a = abs
z = [list(map(int, input().split())) for _ in range(int(input()))]
z.sort(key = lambda x: x[2])
x, y, h = z[-1]
r = range(101)
for c in r:
    for d in r:
        H = h + a(c-x) + a(d-y)
        if all(u == max(H - a(s-c) - a(t-d), 0) for s, t, u in z):
            print(c, d, H)
            exit()

Submission status: Accepted

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

def calc_h(cx, cy, xyh):
    return xyh[2] + abs(cx - xyh[0]) + abs(cy - xyh[1])

base = -1
for i in range(n):
    if xyhn[i][2] != 0:
        base = i
        break

ans = None
for cx in range(0, 101):
    for cy in range(0, 101):
        result = True
        tmp_h = calc_h(cx, cy, xyhn[base])
        for k in range(n):
            if xyhn[k][2] > 0 and tmp_h != calc_h(cx, cy, xyhn[k]):
                result = False
                break
            if xyhn[k][2] == 0 and abs(cx - xyhn[k][0]) + abs(cy - xyhn[k][1]) < tmp_h:
                result = False
                break
        if result:
            ans = [cx, cy, calc_h(cx, cy, xyhn[base])]
            break

print(' '.join(map(str, list(ans))))

Submission status: Accepted

Solution code:

cc=0
if cc==0:
    n=int(input())
    xyh=[[0]*3 for i in range(n)]
    for i in range(n):
        xyh[i]=list(map(int,input().split()))
        if xyh[i][2]>=1:
            px=xyh[i][0]
            py=xyh[i][1]
            ph=xyh[i][2]
else:
    n=4
    px=3
    py=2
    ph=5
    xyh=[[0]*3 for i in range(n)]
    xyh[0]=[2,3,5]
    xyh[1]=[2,1,5]
    xyh[2]=[1,2,5]
    xyh[3]=[3,2,5]
        
yn=""
for cx in range(102):
    for cy in range(102):
        h=ph+abs(px-cx)+abs(py-cy)
        yn=""
        for i in range(n):
            if xyh[i][2]!=max(0,h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)):
                yn="No"
                break
        if yn=="No":
#            print(cx,cy,h,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy))
            continue
        else:
#            print("1:",cx,cy,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy))
            yn="Yes"
            break
#    print("2:",yn,cx,cy,h,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy))
    if yn=="Yes":
        break
    
print(cx,cy,h)

Submission status: Accepted

Solution code:
import sys
N = int(input())
l = []
for i in range(N):
  l.append(list(map(int,input().split())))

#Cx,Cyの探索
ansC = [0,0]
for i in range(0,100+1):
  for j in range(0,100+1):
    Cx = i
    Cy = j
    #Nこのデータから高さを決める
    for k in range(N):
      X,Y,h = l[k]
      c = 0
      if h >= 1:
        H = h + abs(X-Cx) + abs(Y-Cy)
        for k in range(N):
          X,Y,h = l[k]
          if h != max(H-abs(X-Cx)-abs(Y-Cy),0):
            break
          if k == N-1:  
            print(Cx,Cy,H)
            sys.exit()

Submission status: Accepted

Solution code:
import sys
import collections
from math import ceil

ma = lambda : map(int,input().split())
ni = lambda : int(input())
def height(H,cy,cx,y,x):
    return max(H- abs(cy-y) - abs(cx-x),0)

n = ni()
hs = [[-1]*101 for i in range(101)]
nx,ny = -1,-1
ls = []
#E h >0?
for i in range(n):
    x,y,h = ma()
    hs[y][x] = h
    if h>0:
        nx,ny = x,y
    ls.append((y,x))

for cy in range(101):
    for cx in range(101):
        H = hs[ny][nx] + abs(cy-ny) + abs(cx-nx)
        for y,x in ls:
            if hs[y][x]!= height(H,cy,cx,y,x):
                break
        else:print(cx,cy,H)