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:
#!/usr/bin/env python3
import sys
INF = float("inf")


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

    # hが正である組を選ぶ
    for i in range(N):
        if h[i] > 0:
            break

    # 領域を全探索する。各位置が頂点になる場合の高さをh[i]から求める
    cand = [[0]*101 for _ in range(101)]
    for j in range(101):
        for k in range(101):
            cand[j][k] = h[i]+abs(x[i]-k)+abs(y[i]-j)

    # 各頂点の高さが適切か。適切なら出力。
    for i in range(101):
        for j in range(101):
            flags = [max(cand[i][j]-abs(x[k]-j)-abs(y[k]-i), 0) == h[k]
                     for k in range(N)]
            if all(flags):
                print(j, i, cand[i][j])
                return

    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:
# -*- coding: utf-8 -*-

class Info():
    def __init__(self, x, y, h):
        self.X = x
        self.Y = y
        self.H = h

def main():
    N = int(input())
    infos = []
    for i in range(N):
        x, y, h = list(map(int, input().split(" ")))
        infos.append(Info(x, y, h))
    
    # [0, 100]に座標があるのでMAXを定義する
    MAX = 100
    for posY in range(0, MAX+1):
        for posX in range(0, MAX+1):
            # 頂上がどれくらいの高さであってほしいか。
            # -1はまだよくわからないとき。0以上は確定してるとき
            # -2はだめだとわかったとき
            ans_h = -1

            for i in range(N):
                # 各座標について考える
                if infos[i].H > 0:
                    H = infos[i].H + abs(posY - infos[i].Y) + abs(posX - infos[i].X)
                    if ans_h == -1:
                        ans_h = H
                    else:
                        if ans_h != H:
                            ans_h = -2
                            break
            
            # ダメだったら別の場所を探す
            if ans_h == -2:
                continue
            
            is_ok = True
            for i in range(N):
                # 各座標について、高さが0の場合に矛盾していないか調べる
                if infos[i].H == 0:
                    if ans_h - abs(posY - infos[i].Y) - abs(posX - infos[i].X) <= 0:
                        continue
                    else:
                        is_ok = False
                        break
            
            if is_ok:
                print(posX, posY, ans_h)
                return
            

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

class Info():
    def __init__(self, x, y, h):
        self.X = x
        self.Y = y
        self.H = h

def main():
    N = int(input())
    infos = []
    for i in range(N):
        x, y, h = list(map(int, input().split(" ")))
        infos.append(Info(x, y, h))
    
    # [0, 100]に座標があるのでMAXを定義する
    MAX = 100
    for posY in range(0, MAX+1):
        for posX in range(0, MAX+1):
            # 頂上がどれくらいの高さであってほしいか。
            # -1はまだよくわからないとき。0以上は確定してるとき
            # -2はだめだとわかったとき
            ans_h = -1

            for i in range(N):
                # 各座標について考える
                if infos[i].H > 0:
                    H = infos[i].H + abs(posY - infos[i].Y) + abs(posX - infos[i].X)
                    if ans_h == -1:
                        ans_h = H
                    else:
                        if ans_h != H:
                            ans_h = -2
                            break
            
            # ダメだったら別の場所を探す
            if ans_h == -2:
                continue
            
            is_ok = True
            for i in range(N):
                # 各座標について、高さが0の場合に矛盾していないか調べる
                if infos[i].H == 0:
                    if ans_h - abs(posY - infos[i].Y) - abs(posX - infos[i].X) <= 0:
                        continue
                    else:
                        is_ok = False
                        break
            
            if is_ok:
                print(posX, posY, ans_h)
                return
            """
                if infos[i].H == 0:
                    dist = abs(posY - infos[i].Y) + abs(posX - infos[i].X)
                    if ans_h > dist:
                        ans_h = -2
                        break
            
            if ans_h == -2:
                continue

            print(posX, posY, ans_h)
            return

            """
            

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
xyh = []
xx, yy, hh = -1, -1, -1
for _ in range(N):
    x, y, h = map(int, input().split())
    xyh.append([x, y, h])
    if h > 0:
        xx, yy, hh = x, y, h

ansX = -1
ansY = -1
ansH = -1
for cx in range(0, 101):
    for cy in range(0, 101):
        H = hh + abs(xx - cx) + abs(yy - cy)
        for x, y, h in xyh:
            if h == 0 and H > abs(x - cx) + abs(y - cy):
                H = -1
                break
            if h > 0 and H != h + abs(x - cx) + abs(y - cy):
                H = -1
                break
        if H > 0:
            ansH = H
            ansX = cx
            ansY = cy

print(ansX, ansY, ansH)

Submission status: Accepted

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


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    idx = 0
    for i in range(N):
        if h[i] > 0:
            idx = i
            break
    for cx in range(101):
        for cy in range(101):
            H = h[idx] + abs(cx - x[idx]) + abs(cy - y[idx])
            found = True
            for i in range(N):
                tmp_h = max(H - abs(cx - x[i]) - abs(cy - y[i]), 0)
                if tmp_h != h[i]:
                    found = False
                    break
            if H > 0 and found:
                print(cx, cy, H)
                return
    print('error')
    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:
N=int(input())
xyh=sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[2], reverse=True)

def find(cx, cy, H):
	for x,y,h in xyh:
		if h != max(H-abs(x-cx)-abs(y-cy), 0):
			return False
	return True

def solve():
	for cx in range(101):
		for cy in range(101):
			x,y,h = xyh[0]
			H = h + abs(x-cx) + abs(y-cy)
			if find(cx, cy, H):
				return "%d %d %d" % (cx, cy, H)
	raise Exception

print(solve())

Submission status: Accepted

Solution code:
import sys

N = int(input())

x = []
y = []
h = []

for _ in range(N):
    t_x, t_y, t_h = map(int, input().split())
    x.append(t_x)
    y.append(t_y)
    h.append(t_h)

for i in range(101):
    for j in range(101):

        H = -1
        # 初期化
        for index, t_h in enumerate(h):
            if t_h != 0:
                H = abs(i - x[index]) + abs(j - y[index]) + t_h
                break

        for t_x, t_y, t_h in zip(x, y, h):
            if t_h == 0:
                if H > abs(i - t_x) + abs(j - t_y):
                    break
            elif H != abs(i - t_x) + abs(j - t_y) + t_h:
                break
        else:
            print(i, j, H)
            sys.exit(0)

Submission status: Accepted

Solution code:
N = int(input())

x = []
y = []
h = []

for _ in range(N):
    t_x, t_y, t_h = map(int, input().split())
    x.append(t_x)
    y.append(t_y)
    h.append(t_h)

for i in range(101):
    for j in range(101):

        H = -1
        # 初期化
        for index, t_h in enumerate(h):
            if t_h != 0:
                H = abs(i - x[index]) + abs(j - y[index]) + t_h
                break

        for t_x, t_y, t_h in zip(x, y, h):
            if t_h == 0:
                if H > abs(i - t_x) + abs(j - t_y):
                    break
            elif H != abs(i - t_x) + abs(j - t_y) + t_h:
                break
        else:
            print(i, j, H)
            break

        continue
    else:
        continue

    break

Submission status: Accepted

Solution code:
import sys

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

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

for i in H:
    x, y, h = i
    for c_x in range(101):
        for c_y in range(101):
            Height = h + abs(x-c_x) + abs(y-c_y)
            for j in range(N):
                if H[j][2] != max(Height-abs(H[j][0]-c_x)-abs(H[j][1]-c_y), 0):
                    break
                if j == N-1:
                    print(c_x, c_y, Height)
                    sys.exit()

Submission status: Accepted

Solution code:
N = int(input())

x = []
y = []
h = []

for _ in range(N):
    t_x, t_y, t_h = map(int, input().split())
    x.append(t_x)
    y.append(t_y)
    h.append(t_h)

for i in range(101):
    for j in range(101):

        H = 1
        # 初期化
        for index, t_h in enumerate(h):
            if t_h != 0:
                H = abs(i - x[index]) + abs(j - y[index]) + t_h
                break

        for t_x, t_y, t_h in zip(x, y, h):
            if t_h == 0:
                if H > abs(i - t_x) + abs(j - t_y):
                    break
            elif H != abs(i - t_x) + abs(j - t_y) + t_h:
                break
        else:
            print(i, j, H)
            break

        continue
    else:
        continue

    break

Submission status: Accepted

Solution code:
N = int(input())


info = [[0,0,0] for i in range(N)]

for n in range(N):
    info[n][0],info[n][1],info[n][2] = map(int,input().split())

info.sort(key=lambda x:x[2],reverse=True)
for cx in range(101):
    for cy in range(101):
        cnt = 1
        H = info[0][2] + abs(info[0][0]-cx) + abs(info[0][1]-cy)
        for n in range(1,N):
            cnt += 1 
            if info[n][2] != max(H-abs(info[n][0]-cx)-abs(info[n][1]-cy),0):
                break
            if cnt == N:
                print(cx,cy,H)
                exit()

Submission status: Accepted

Solution code:
N = int(input())
A = [tuple(map(int,input().split())) for i in range(N)]
D = 0
for Cx in range(101):
    for Cy in range(101):
        H = 0
        F = 1
        for i in A:
            if H < 1:
                if i[2] == 0:
                    continue
                H = i[2] + abs(i[0]-Cx) + abs(i[1]-Cy)
            elif i[2] == max(H-abs(i[0]-Cx)-abs(i[1]-Cy),0):
                continue
            else:
                F = 0
                break
        for i in A:
            if not (i[2] == max(H-abs(i[0]-Cx)-abs(i[1]-Cy),0)):
                F = 0
                break
        if F == 1 and H >= 1 and D == 0:
            D = 1
            print(Cx,Cy,H)

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	xi, yi, hi = [0]*n, [0]*n, [0]*n
	stack = []
	result = []
	for i in range(n):
		xi[i], yi[i], hi[i] = map(int, input().split())
		if hi[i] > 0:
			stack = [xi[i], yi[i], hi[i]]
	for i in range(101):
		for j in range(101):
			guess = stack[2] + abs(stack[0]-i) + abs(stack[1]-j)
			is_result = True
			for k in range(n):
				result = guess - abs(xi[k]-i) - abs(yi[k]-j)
				result = max(result, 0)
				if hi[k] != result:
					is_result = False
					break
			if is_result:
				print(str(i)+" "+str(j)+" "+str(guess))
				return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import *

n = int(input())
xyh = []
for i in range(n):
    xyh += [list(map(int, input().split()))]
xyh.sort(reverse=True, key=lambda x: x[2])
[x0, y0, h0] = xyh[0]
for x, y in product(range(0, 101), range(0, 101)):
    h = h0 + abs(x - x0) + abs(y - y0)
    for k in xyh[1:]:
        if k[2] != max(h - abs(x - k[0]) - abs(y - k[1]), 0):
            break
    else:
        break
print(x, y, h)

Submission status: Accepted

Solution code:
A=abs;p=eval('list(map(int,input().split())),'*int(input()));x,y,h=[x for x in p if x[2]][0]
for I in range(10201):j,i=I//101,I%101;H=h+A(x-j)+A(y-i);print(*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for s,t,u in p))

Submission status: Accepted

Solution code:
import sys
write = sys.stdout.write

def valid(x, y):
    H = info[nzpoint][2] + abs(info[nzpoint][0]-x) + abs(info[nzpoint][1]-y)
    for i in range(N):
        if i == nzpoint:
            continue
        if max(0, H - abs(x-info[i][0]) - abs(y-info[i][1])) != info[i][2]:
            return False
    return True
        

def printheight(i, j):
    write(str(info[nzpoint][2] + abs(i-info[nzpoint][0]) + abs(j-info[nzpoint][1])) + "\n")

N = int(input())
info = []
nzpoint = 0
for i in range(N):
    info.append(list(map(int,input().split())))
    if info[i][2] > 0:
        nzpoint = i
#0-100で全探索してみよか
for i in range(101):
    for j in range(101):
        if valid(i, j):
            write(str(i) + " " + str(j) + " ")
            printheight(i, j)
            sys.exit()

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
maxh = 0
minh = 10 ** 9
for i in range(N):
  if xyh[i][2] > maxh:
    maxh = xyh[i][2]
  if xyh[i][2] < minh:
    minh = xyh[i][2]
def hantei(x, y, h):
  for i in range(N):
    if max(h - abs(xyh[i][0] - x) - abs(xyh[i][1] - y), 0) != xyh[i][2]:
      return(False)
  return(True)

def solve():
  for p in range(maxh, minh + 205):
    for q in range(101):
      for r in range(101):
        if hantei(q,r,p) == True:
          return([q,r,p])
print(solve()[0],solve()[1],solve()[2])

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    xyh = LIR(n)
    xyh.sort(key = lambda x:x[2], reverse = True)
    x1, y1, h1 = xyh[0]
    del xyh[0]
    for x in range(101):
        for y in range(101):
            h = abs(x - x1) + abs(y - y1) + h1
            flg = True
            for xn, yn, hn in xyh:
                if max(h - abs(x - xn) - abs(y - yn), 0) == hn:
                    continue
                flg = False
                break
            if flg:
                print(x, y, h)
                return 
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    ans = float("inf")
    for i in range(n+1):
        m = 0
        k = i
        while k > 0:
            m += k%6
            k //= 6
        k = n-i
        while k > 0:
            m += k%9
            k //= 9
        if m < ans:
            ans = m
    print(ans)
    return

#B
def B():
    n = I()
    x = [None for i in range(n)]
    y = [None for i in range(n)]
    h = [None for i in range(n)]
    for i in range(n):
        x[i],y[i],h[i] = LI()
    if n == 1:
        print(x[0],y[0],h[0])
        quit()
    for cy in range(101):
        for cx in range(101):
            for i in range(n):
                if h[i] > 0:break
            ch = h[i]+abs(x[i]-cx)+abs(y[i]-cy)
            f = 1
            for i in range(n):
                if max(ch-abs(x[i]-cx)-abs(y[i]-cy),0) != h[i]:f = 0
            if f:
                print(cx,cy,ch)
                quit()
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    B()

Submission status: Accepted

Solution code:
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(n):
  if h[i]!=0:s=i;break

for cx in range(101):
  for cy in range(101):
    H=h[s]+abs(x[s]-cx)+abs(y[s]-cy)
    for i in range(n):
      if h[i]!=max(0,H-abs(x[i]-cx)-abs(y[i]-cy)):break
      if i==n-1:print(cx,cy,H);exit()

Submission status: Accepted

Solution code:
def high(i):
    return max(H - abs(x[i] - Cx) - abs(y[i] - Cy), 0)

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

for i in range(N):
    if h[i] != 0:
        non_zero = i
        break

found = False
for Cx in range(0, 101):
    for Cy in range(0, 101):
        H = h[non_zero] + abs(x[non_zero] - Cx) + abs(y[non_zero] - Cy)
        if all([h[i] == high(i) for i in range(N)]):
            print('{} {} {}'.format(Cx, Cy, H))
            found = True
            break
    if found:
        break

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
	a.append([int(n) for n in input().split()])
	a[i][0], a[i][2] = a[i][2], a[i][0]
a = sorted(a)
for x in range(101):
	for y in range(101):
		h = a[n - 1][0] + abs(x - a[n - 1][2]) + abs(y - a[n - 1][1])
		for k in range(n):
			d = h - abs(x - a[k][2]) - abs(y - a[k][1])
			if a[k][0] != max(d, 0):
				break
			if k == n - 1:
				print(x, y, h)
				exit()

Submission status: Accepted

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



for Cx in range(101):
    for Cy in range(101):
        for x, y, h in data:
            if h != 0:
                H = abs(x - Cx) + abs(y - Cy) + h
                break
        count = 0
        for x, y, h in data:
            if h != max(H-abs(x-Cx)-abs(y-Cy), 0):
                break
            count += 1
        if count == N:
            print(Cx, Cy, H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
p = [list(map(int, input().split())) for i in range(N)]
h = [h for x, y, h in p]
maxh = max(h)
def height(H, cx, cy, l):
    for x, y, h in l:
        if h != max(H-abs(x-cx)-abs(y-cy) , 0):
            return False
    return True
flag = False
for i in range(maxh,10**9 +201):
    for cx in range(101):
        for cy in range(101):
            if height(i, cx, cy, p):
                print(cx, cy, i)
                flag = True
                break
        if flag:
            break
    if flag:
        break

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from itertools import product

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

if N == 1:
    print(xyh[0][0], xyh[0][1], xyh[0][2])
else:
    for x, y in product(range(101), range(101)):
        for i in xyh:
            if i[2] > 0:
                H = i[2] + abs(x-i[0]) + abs(y-i[1])
                break
        for i in xyh:
            if i[2] != max(0, H-abs(x-i[0])-abs(y-i[1])):
                break
        else:
            print(x, y, H)
            break

Submission status: Accepted

Solution code:
from collections import namedtuple

Point = namedtuple('Point', ('x', 'y', 'h'))

def main():
    n = int(input())
    points = [read_point() for _ in range(n)]
    print(*solve(points))

def solve(points):
    for p in points:
        if p.h != 0:
            base = p
            break

    for x in range(0, 101 + 1):
        for y in range(0, 100 + 1):
            h = base.h + abs(base.x - x) + abs(base.y - y)
            for p in points:
                ph = max(h - abs(x - p.x) - abs(y - p.y), 0)
                if ph != p.h:
                    break
            else:
                return Point(x, y, h)

def read_point():
    x, y, h = map(int, input().split())
    return Point(x, y, h)

main()

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
x, y, h = [], [], []
for _ in range(N):
    xi, yi, hi = s_inpl()
    x.append(xi)
    y.append(yi)
    h.append(hi)

# [0, 100]に座標があるので
MAX = 100;

ans_x, ans_y, ans_h = -1, -1, -1
for pos_y in range(MAX+1):
    for pos_x in range(MAX+1):
        # 頂上がどのくらいの高さであってほしいか
        need_h = -1
        # hが0より大きいときについて考察
        for i in range(N):
            if h[i] > 0:
                # xi, yi, hiからみて，　頂点がpos_x, pos_yのときに
                # どのくらいの高さがあってほしいか求める
                tmp_h = h[i] + abs(pos_y-y[i]) + abs(pos_x-x[i])
                if need_h == -1:
                    need_h = tmp_h
                else:
                    if need_h != tmp_h:
                        need_h = -2
                        break
        # だめだったら別のpos_x, pos_yを探す
        if need_h == -2:
            continue

        # hが1のときについて考察
        # need_hにおいて矛盾が起こらないかを調べる
        for i in range(N):
            if h[i] == 0:
                dist = abs(pos_y - y[i]) + abs(pos_x - x[i])
                if need_h > dist:
                    need_h = -2

        if need_h == -2:
            continue
        ans_x, ans_y, ans_h = pos_x, pos_y, need_h

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

Submission status: Accepted

Solution code:
N=int(input())

xyh=[]
for i in range(N):
    xi,yi,hi=map(int,input().split())
    xyh.append([xi,yi,hi])
xyh.sort(reverse=True,key=lambda x:x[2])
for Cx in range(0,101):
    for Cy in range(0,101):
        for i in range(N):
            X=xyh[i][0]
            Y=xyh[i][1]
            h=xyh[i][2]
            if i==0:
                H=h+abs(X-Cx)+abs(Y-Cy)
                continue
            H_=h+abs(X-Cx)+abs(Y-Cy)
            if h==0:
                if H_<H:
                    break
            elif H!=H_:
                break
            if i==N-1:
                print(Cx,Cy,H)
                quit()

Submission status: Accepted

Solution code:
import sys
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x: x[2],reverse=True)
ans=[]

if a[0][2]==100:
    print(a[0][0],a[0][1],a[0][2])
    sys.exit()



for i in range(0,101):
    for j in range(0,101):
        p=a[0][2]+abs(i-a[0][0])+abs(j-a[0][1])
#       q=a[1][2]+abs(i-a[1][0])+abs(j-a[1][1])
        for k in range(1,N):
            if a[k][2]>0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])!=p : break
            elif a[k][2]==0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])<p : break
            if k==N-1:
                print(i,j,p)
                sys.exit()

Submission status: Accepted

Solution code:
def checkheight(H, data, coordinate):
    cx, cy = coordinate

    for px, py, ph in data:
        if not ph == max(H - abs(px - cx) -  abs(py - cy), 0):
            return None

    return (cx, cy, H)

def makeheight(data, cx, cy):
    px, py, ph = list(filter(lambda dataset: dataset[2] > 0, data))[0]
    return ph + abs(px - cx) + abs(py - cy)


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

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


    for cx in range(101):
        for cy in range(101):
            tmpch = makeheight(data.copy(), cx, cy)

            res = checkheight(tmpch, data, (cx, cy))

            if res:
                print(*res)
                return



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
X,Y,H = [],[],[]
for i in range(N):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
hAns = [0]*N

# x=i, y=jでは条件を満たすか?
for i in range(101):
    for j in range(101):
        # k番目のデータで"頂点の高さ"を計算
        for k in range(N):
            hAns[k] = H[k]+abs(X[k]-i)+abs(Y[k]-j)
        # 入力データが同じ答えを出したら,その座標と高さが答えになる
        # H[l]==0のときのみ、違う値になっているかもしれない
        for l in range(N):
            if H[l] == 0:
                hAns[l] = min(hAns)
        if all(hAns[c]==hAns[c+1] for c in range(len(hAns)-1)):
            print(i,j,hAns[0])
            break

Submission status: Accepted

Solution code:
N = int(input())
points = []
f = None
for i in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        f = [x, y, h]
    points.append([x, y, h])

def height(cx, cy):
    H = f[2] + abs(f[0] - cx) + abs(f[1] - cy)
    for p in points:
        if p[2] != max(H - abs(p[0] - cx) - abs(p[1] - cy), 0):
            return 0
    return H

for x in range(101):
    for y in range(101):
        h = height(x, y)
        if h > 0:
            print(' '.join([str(x), str(y), str(h)]))

Submission status: Accepted

Solution code:
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
H = 0
for X in range(101):
  for Y in range(101):
    for i in range(N):
      h = 0
      if L[i][2] != 0:
        h = L[i][2]
        break
    flag = True
    H = h+abs(L[i][0]-X)+abs(L[i][1]-Y)
    for j in range(N):
      if L[j][2] != max(H-abs(L[j][0]-X)-abs(L[j][1]-Y),0):
        flag = False
        break
    if flag:
      print(X,Y,H)
      exit()

Submission status: Accepted

Solution code:
from sys import exit
n=int(input())
pyramid=[]
for i in range(n):
  x,y,h=map(int,input().split())
  pyramid.append([x,y,h])
flag=0
for i in range(n):
  if flag==0 and pyramid[i][2]!=0:
    flag=-1
  elif flag==-1 and pyramid[i][2]!=0:
    flag=1
if flag==-1:
  for i in range(n):
    if pyramid[i][2]!=0:
      print(pyramid[i][0],pyramid[i][1],pyramid[i][2])
      exit()
ans=[[0 for i in range(101)] for i in range(101)]
for i in range(n):
  if pyramid[i][2]!=0:
    for cx in range(101):
      for cy in range(101):
        H=pyramid[i][2]+abs(pyramid[i][0]-cx)+abs(pyramid[i][1]-cy)
        if flag==1:
          ans[cx][cy]=H
        else:
          if ans[cx][cy]!=H:
            ans[cx][cy]=0
    flag=0
for i in range(101):
  for j in range(101):
    if ans[i][j]!=0:
      print(i,j,ans[i][j])

Submission status: Accepted

Solution code:
class Plot:

    def __init__(self, inp):
        self.x, self.y, self.h = inp


def plot_check(xyh, cx, cy, H):
    for i in xyh:
        if max(H - abs(i.x - cx) - abs(i.y - cy),0) != i.h:
            return False
    return True


def main():
    xyh = []
    kensa = 0
    N = int(input())
    for i in range(N):
        xyh.append(Plot(map(int, input().split())))
    for i in range(len(xyh)):
        if xyh[i].h > 0:
            kensa = i
            break
    for cxi in range(101):
        for cyi in range(101):
            H = abs(xyh[kensa].x - cxi) + abs(xyh[kensa].y - cyi) + xyh[kensa].h
            if plot_check(xyh, cxi, cyi, H):
                print(cxi, cyi, H)
                return


main()