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())
l=[list(map(int,input().split())) for i in range(n)]

for x in range(101):
    for y in range(101):
        k=set(e+abs(x-q)+abs(w-y)  for q,w,e in l if e)
        for pre in k:
            for a,s ,d in l:

                if d!=max(0,pre-abs(x-a)-abs(s-y)):break
            else:print(x,y,pre);exit()

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


def main():
    N = int(input())
    X = []
    Y = []
    H = []
    si = -1
    for i in range(N):
        x, y, h = map(int, input().split())
        X.append(x)
        Y.append(y)
        H.append(h)
        if h > 0:
            si = i

    for cx in range(0, 101):
        for cy in range(0, 101):
            h = H[si] + abs(X[si] - cx) + abs(Y[si] - cy)
            ok = True
            for i in range(N):
                if H[i] != max(h - abs(X[i] - cx) - abs(Y[i] - cy), 0):
                    ok = False
                    break
            if ok:
                return print(cx, cy, h)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
XYH = [lr() for _ in range(N)]
height = [x for x in XYH if x[2] > 0]
zero = [x for x in XYH if x[2] == 0]
answer = None
for x in range(101):
    for y in range(101):
        bl = True
        top = height[0]
        cand = abs(x-top[0]) + abs(y-top[1]) + top[2]
        for x2, y2, h in height[1:]:
            temp = abs(x-x2) + abs(y-y2) + h
            if cand != temp:
                bl = False
                break
        if not bl:
            continue
        for x2, y2, h in zero:
            temp = abs(x-x2) + abs(y-y2) + h
            if temp < cand:
                bl = False
                break
        if bl:
            answer = (x, y, cand)

print(*answer)

Submission status: Accepted

Solution code:
def dis(xi, xj, yi, yj):
    return abs(xi - xj) + abs(yi - yj)
n = int(input())
coords = [tuple(map(int, input().split())) for _ in range(n)]
grids = [(i, j) for i in range(101) for j in range(101)]
for x, y, h in coords:
    if h > 0:
        break    
for xj, yj in grids:
    flag = True
    base = dis(x, xj, y, yj) + h
    for xi, yi, hi in coords:
        if hi != max(base-abs(xi-xj)-abs(yi-yj), 0):
            flag = False
    if flag:
        break
print(xj, yj, dis(x, xj, y, yj) + h)

Submission status: Accepted

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

height = None
found = False
for cx in range(0, 101):
    for cy in range(0, 101):
        candidate = 0
        for x, y, h in xyh:
            if h == 0: continue
            dx = abs(x - cx)
            dy = abs(y - cy)
            candidate = dx + dy + h 
            break

        found = True
        for x, y, h in xyh:
            _h = max(candidate - abs(x - cx) - abs(y - cy), 0)
            if h != _h:
                found = False
                break
        
        if found is True: break
    if found is True: break
height = candidate if candidate is not None else 0

print(cx, cy, height)

Submission status: Accepted

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

height = None
found = False
for cx in range(0, 101):
    for cy in range(0, 101):
        candidate = 0
        for x, y, h in xyh:
            if h == 0: continue
            dx = abs(x - cx)
            dy = abs(y - cy)
            candidate = dx + dy + h 
            break

        found = True
        for x, y, h in xyh:
            _h = candidate - abs(x - cx) - abs(y - cy)
            if h == 0 and _h <= 0: continue
            if not h == _h:
                found = False
                break
        
        if found is True: break
    if found is True: break
height = candidate if candidate is not None else 0

print(cx, cy, height)

Submission status: Accepted

Solution code:
# 1つ見れば、マス目に対する高さが確定する
# 100件についてテスト
import numpy as np
N = int(input())
U = 100
XYH = np.array([[int(x) for x in input().split()] for _ in range(N)])
XYH = XYH[np.argsort(-XYH[:,2])] # 高い順なので0番目は正

x0,y0,h0 = XYH[0]
dx = np.abs(np.arange(U+1) - x0)
dy = np.abs(np.arange(U+1) - y0)
# そこに頂上があるとするとその高さ
H = dx[:,None] + dy[None,:] + h0
possible = np.full_like(H, True)

for x,y,h in XYH[1:]:
  dx = np.abs(np.arange(U+1) - x)
  dy = np.abs(np.arange(U+1) - y)
  possible &= (np.maximum(H-dx[:,None]-dy[None,:],0) == h)

nz = possible.nonzero()
x,y = nz[0][0], nz[1][0]
h = H[x,y]
print(x,y,h)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
xyh = [list(map(int, readline().split())) for _ in range(n)]
xyh.sort(key=lambda x: -x[2])
for dx in range(101):
    for dy in range(101):
        check = abs(xyh[0][0] - dx) + abs(xyh[0][1] - dy) + xyh[0][2]
        for x, y, h in xyh[1:]:
            if max(check - abs(x - dx) - abs(y - dy), 0) != h:
                break
        else:
            print(dx, dy, check)
            exit()

Submission status: Accepted

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

def main():
    N  = int(input())
    P = []
    for i in range(N):
        x, y, h = map(int, input().split())
        P.append([h, x, y])
    P.sort(reverse = True)

    for x in range(101):
        for y in range(101):
            distance =abs(x-P[0][1]) + abs(y-P[0][2]) + P[0][0]
            for p in P[1:]:
                if max(distance - abs(x-p[1]) - abs(y-p[2]), 0) !=  p[0]:
                    break
            else:
                print(x, y , distance)
                return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
x,y,h=[0]*n,[0]*n,[0]*n
for i in range(n):
  x[i],y[i],h[i]=map(int,input().split())
mn_h=min(h)
mx_h=max(h)
for C_x in range(101):
  for C_y in range(101):
    for i in range(n):
      H=h[i]+abs(x[i]-C_x)+abs(y[i]-C_y)
      if H>0:
        if all(max(H-abs(x[j]-C_x)-abs(y[j]-C_y),0)==h[j] for j in range(n)):
          print(C_x,C_y,H)
          exit()

Submission status: Accepted

Solution code:
# solution

import math
import io

data = int(input())

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

n, m, k = list(filter(lambda n: n[2], array))[0]

for i in range(101):
  for j in range(101):
    kite = k + abs(n-i) + abs(m-j)
    if all(max(kite-abs(t[0]-i)-abs(t[1]-j), 0) == t[2] for t in array):
      print(i,j,kite)

Submission status: Accepted

Solution code:
import sys

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


def find_height(cx, cy):
    upperbound = 10 ** 12
    summit = None
    for x, y, h in obs:
        s = h + abs(cx - x) + abs(cy - y)
        if s < lowerbound:
            return None
        if h == 0:
            upperbound = min(upperbound, s)
        elif summit is None:
            summit = s
        elif summit != s:
            return None
        if summit is not None and (summit > upperbound or summit < lowerbound):
            return None
    return summit


for cx in range(0, 101):
    for cy in range(0, 101):
        ch = find_height(cx, cy)
        if ch is not None:
            print(cx, cy, ch)
            sys.exit()

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  xyh = [[int(_) for _ in input().split()] for __ in range(N)]
  for cx in range(0, 101):
    for cy in range(0, 101):
      H = set()
      for x, y, h in xyh:
        if h == 0:
          continue
        H.add(abs(cx - x) + abs(cy - y) + h)
      if len(H) == 1:
        ok = True
        hh = list(H)[0]
        for x, y, h in xyh:
          if h == 0:
            if max(hh - abs(cx - x) - abs(cy - y), 0) == 0:
              continue
            else:
              ok = False
        if ok:
          print(cx, cy, *H)
          break
    else:
      continue
    break
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
def solve():
  size = 101
  n = int(input())
  points = []
  for _ in range(n):
    x, y, h = map(int, input().split())
    # h=0の点はスキップ ←勾配がないので高さ計算に使えない
    if h == 0: continue
    else: points.append((x, y, h))

  if len(points) == 1:
    # 必ず頂上が1つに定まる制約なので、測定点が1つしかなければそれが答え
    ans = points[0]
    return ans

  ans = (-1, -1, -1)
  for i in range(size):
    for j in range(size):
      # 高いほうに持ち上げるよう試みて、整合性とれなければ却下
      max_h = None
      succ = True
      for x, y, h in points:
        tmp = abs(i-x) + abs(j-y) + h
        if max_h == None:
          max_h = tmp
          continue
        else:
          if max_h != tmp:
            succ = False
            break
      # 成り立っているなかでの最高点を更新していく
      if succ:
        if ans[2] < max_h:
          ans = (i, j, max_h)
  # すべて終了
  return ans

ans = solve()
print('{} {} {}'.format(ans[0], ans[1], ans[2]))

Submission status: Accepted

Solution code:
n = int(input())
info = []
for i in range(n):
    x,y,h = map(int,input().split())
    info.append((x,y,h))
info.sort(key=lambda x:x[2], reverse=True)

for i in range(0,101):
    for j in range(0,101):
        crt_h = info[0][2] + abs(info[0][0]-i) + abs(info[0][1]-j)
        flag = True
        for k in range(1, n):
            tar_x = info[k][0]
            tar_y = info[k][1]
            tar_h = info[k][2]
            H = tar_h + abs(tar_x - i) + abs(tar_y - j)
            if tar_h != 0:
                if H != crt_h:
                    flag = False
            else:
                if crt_h > H:
                    flag = False
        if flag:
            print(i,j,crt_h)

Submission status: Accepted

Solution code:
import sys

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

for x in range(101):
    for y in range(101):
        flag=0
        H=P[0][0]+abs(P[0][1]-x)+abs(P[0][2]-y)
        for p in P:
            ph=p[0]
            px=p[1]
            py=p[2]
            if ph==0:
                if H-abs(px-x)-abs(py-y)>0:
                    flag=1
                    break
            else:
                if H-abs(px-x)-abs(py-y)!=ph:
                    flag=1
                    break
        if flag==1:
            continue
        else:
            print(x,y,H)
            sys.exit()

Submission status: Accepted

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

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

for x in range(101):
  for y in range(101):
    tmp_H = XYH[0][2]+abs(XYH[0][0]-x)+abs(XYH[0][1]-y)
    A = 0
    for i in range(1,N):
      if tmp_H - abs(XYH[i][0]-x) - abs(XYH[i][1]-y) == XYH[i][2]:
        A += 1
      elif tmp_H - abs(XYH[i][0]-x) - abs(XYH[i][1]-y) < 0 and XYH[i][2] == 0 :
        A += 1
    
    if A == N-1:
      print(x,y,tmp_H)

Submission status: Accepted

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

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

for i in range(101):
    for j in range(101):
        x, y, h = xyh[0]
        H = h + abs(i - x) + abs(j - y)
        for x, y, h in xyh[1:]:
            if h != max(H - abs(i - x) - abs(j - y), 0):
                break
        else:
            ans = i, j, H
print(*ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    H = []
    ans = 0
    X = []
    Y = []
    a = 0
    tmpx = 0
    tmpy = 0
    for _ in range(n):
        x,y,h = map(int,input().split())
        X.append(x)
        Y.append(y)
        H.append(h)
        if h != 0:
            tmpx = x
            tmpy = y
            tmph = h

    for x in range(101):
        for y in range(101):
            flg = True
            h = tmph + abs(x-tmpx) + abs(tmpy-y)
            for i in range(n):
                hh = max(h - abs(x-X[i]) - abs(y - Y[i]), 0)
                if hh != H[i]:
                    flg = False
                    break
            if flg:
                print(x,y,h)
                return
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
xyh = sorted([list(map(int, input().split())) for i in range(n)], key = itemgetter(2),reverse=True)
X,Y,H = xyh[0][0],xyh[0][1],xyh[0][2]
if n == 1:
  print(X,Y,H)
  exit()
for cx in range(101):
  for cy in range(101):
    height = abs(cx-X) + abs(cy-Y) + H
    for x,y,h in xyh[1:]:
      if h != max(0, height - abs(cx-x) - abs(cy-y)):
        break
    else:
      print(cx,cy,height)
      exit()

Submission status: Accepted

Solution code:
n = int(input())
xyh = []
inf = 10 ** 10
for _ in range(n):
    x, y, h = map(int, input().split())
    xyh.append((x, y, h))
xyh.sort(key=lambda x:x[2], reverse=True)

# 全ての中央座標の組み合わせを試す
for i in range(101):
    for j in range(101):
        x, y, h = xyh[0]
        H = h + abs(i-x) + abs(j-y)
        for x, y, h in xyh:
            if h != max(H - abs(i-x) - abs(j-y), 0):
                break
        else:
            ans = i, j, H
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
X, Y, H = [0]*N, [0]*N, [0]*N
for i in range(N):
  X[i], Y[i], H[i] = map(int, input().split())
  
for Cx in range(0, 100+1):
  for Cy in range(0, 100+1):
    H_TOP = 1
    for i in range(N):
      if H[i]:
        H_TOP = H[i] + abs(X[i] - Cx) + abs(Y[i] - Cy)
    ok = True
    for i in range(N):
      if (max(H_TOP - abs(X[i] - Cx) - abs(Y[i] - Cy), 0) != H[i]):
        ok = False
    if ok:
      print(Cx, Cy, H_TOP)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)


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

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

for cx in range(0, 101):
    for cy in range(0, 101):
        H = [1, float('inf')]
        ok = True
        for x, y, h in points:
            # max(H - abs(cx - x) - abs(cy - y), 0) = h
            if h == 0:
                v = abs(cx - x) + abs(cy - y)
                if v < H[0]:
                    ok = False
                H[1] = v
            else:
                v = h + abs(cx - x) + abs(cy - y)
                if not H[0] <= v <= H[1]:
                    ok = False
                H[0] = H[1] = v
        if ok:
            print(cx, cy, H[0])
            exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)
for X in range(0,101):
    for Y in range(0,101):
        f=True
        H=xyh[0][2]+abs(xyh[0][0]-X)+abs(xyh[0][1]-Y)
        for i in range(1,n):
            x,y,h=xyh[i]
            if h!=max(H-abs(x-X)-abs(y-Y),0):
                f=False
                break
        if f:
            print(X,Y,H)
            break

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)
for X in range(0,101):
    for Y in range(0,101):
        f=True
        H=xyh[0][2]+abs(xyh[0][0]-X)+abs(xyh[0][1]-Y)
        for i in range(1,n):
            x,y,h=xyh[i]
            if h==0:
                if H-abs(x-X)-abs(y-Y)>0:
                    f=False
                    break
            else:
                if H-abs(x-X)-abs(y-Y)!=h:
                    f=False
                    break
        if f:
            print(X,Y,H)
            break

Submission status: Accepted

Solution code:
def solve():

    N = int(input())

    prots = []

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

    # 高さ０をモデルケースにしない
    prots.sort(reverse=True)

    for centerx in range(101):
        for centery in range(101):
            h, x, y = prots[0]
            # 仮置
            H = h+abs(centerx - x) + abs(centery - y)
            flag = True
            for i in range(N):
                h, x, y = prots[i]
                if h != max(0, H-abs(centerx - x) - abs(centery - y)):
                    flag = False
                    break
            if flag:
                print(centerx, centery, H)
                exit()


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# Cx, Cyは0〜100の整数なので、101 * 101パターンを全探索

N=int(input())
data=[None] * N
for i in range(N):
  data[i] = list(map(int,input().split()))

for Cx in range(101):
  for Cy in range(101):
    H = -1
    for i in range(len(data)):
      if data[i][2]<1:
        continue
      H = data[i][2] + abs(data[i][0] - Cx) + abs(data[i][1] - Cy)
      break
    
    for i in range(len(data)):
      if data[i][2] != max(H - abs(data[i][0] - Cx) - abs(data[i][1] - Cy),0):
        break
    else:
      print(Cx,Cy,H)
      exit(0)

Submission status: Accepted

Solution code:
n = int(input())
xyh = []
inf = 10 ** 10
for _ in range(n):
    x, y, h = map(int, input().split())
    xyh.append((x, y, h))
xyh.sort(key=lambda x:x[2], reverse=True)
for i in range(101):
    for j in range(101):
        x, y, h = xyh[0]
        H = h + abs(i-x) + abs(j-y)
        for x, y, h in xyh:
            if h != max(H - abs(i-x) - abs(j-y), 0):
                break
        else:
            ans = i, j, H
print(*ans)

Submission status: Accepted

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

    for cx in range(0, 101):
        for cy in range(0, 101):
            hmax = 10 ** 10
            ha = 0
            for x, y, h in inp:
                m = abs(x-cx) + abs(y-cy)
                if h == 0:
                    hmax = min(hmax, m)
                else:
                    ht = m + h
                    if ht < 1:
                        ha = 0
                        break
                    if ha:
                        if ht != ha:
                            ha = 0
                            break
                    else:
                        ha = ht
            
            if 0 < ha <= hmax:
                print(cx, cy, ha)
                exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    for cx in range(0, 101):
        for cy in range(0, 101):
            hmax = 10 ** 10
            ha = 0
            for x, y, h in inp:
                m = abs(x-cx) + abs(y-cy)
                if h == 0:
                    hmax = min(hmax, m)
                else:
                    ht = m + h
                    if ht < 1:
                        ha = 0
                        break
                    if ha:
                        if ht != ha:
                            ha = 0
                            break
                    else:
                        ha = ht
            
            if ha:
                if ha <= hmax:
                    print(cx, cy, ha)
                    exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    for cx in range(0, 101):
        for cy in range(0, 101):
            hmax = 10 ** 10
            flg = False
            ha = 0
            for x, y, h in inp:
                m = abs(x-cx) + abs(y-cy)
                if h == 0:
                    hmax = min(hmax, m)
                else:
                    ht = m + h
                    if ht < 1:
                        break
                    if flg:
                        if ht != ha:
                            flg = False
                            break
                    else:
                        flg = True
                        ha = ht
            
            if flg:
                if ha:
                    if ha <= hmax:
                        print(cx, cy, ha)
                        exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
x = [0] * n
y = [0] * n
h = [0] * n
for i in range(n):
    x2, y2, h2 = map(int, input().split())
    x[i] = x2
    y[i] = y2
    h[i] = h2
ans = [0,0,0]
for i in range(101):
    for j in range(101):
        l = 0
        while h[l] == 0:
            l += 1
        #print(l)
        val = h[l] + abs(i-x[l]) + abs(j-y[l])
        flg = True
        for k in range(n):
            if val != h[k] + abs(i-x[k]) + abs(j-y[k]) and h[k] != 0:
                flg = False
            if h[k] == 0 and abs(i-x[k]) + abs(j-y[k]) < val:
                flg = False
        if flg == True:
            ans = [i,j,val]
print(' '.join(map(str,ans)))

Submission status: Accepted

Solution code:
import sys

n, *xyh = map(int, sys.stdin.read().split())
xyh = list(zip(*[iter(xyh)] * 3))

def contradict(cx, cy, ch, x, y, h):
    return max(ch - abs(x - cx) - abs(y - cy), 0) != h

def main():
    for x, y, h in xyh:
        if h: x0, y0, h0 = x, y, h; break

    for cx in range(101):
        for cy in range(101):
            ch = h0 + abs(cx - x0) + abs(cy - y0)
            for x, y, h in xyh:
                if contradict(cx, cy, ch, x, y, h): break
            else:
                print(cx, cy, ch)
                return

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n, *xyh = map(int, sys.stdin.read().split())
xyh = list(zip(*[iter(xyh)] * 3))

def contradict(cx, cy, ch, x, y, h):
    return max(ch - abs(x - cx) - abs(y - cy), 0) != h

def main():
    for x, y, h in xyh:
        if h: x0, y0, h0 = x, y, h; break
    cand = []
    for cx in range(101):
        for cy in range(101):
            ch = h0 + abs(cx - x0) + abs(cy - y0)
            for x, y, h in xyh:
                if contradict(cx, cy, ch, x, y, h): break
            else:
                cand.append((ch, cx, cy))
    cand.sort(reverse=True)
    res = cand[0]
    print(res[1], res[2], res[0])

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    vx = []
    vy = []
    vh = []
    si = -1
    for i in range(n):
        a,b,c = readInts()
        vx.append(a)
        vy.append(b)
        vh.append(c)
        if vh[i] > 0:
            si = i


    resx,resy,resh = -1,-1,-1
    for cx in range(101):
        for cy in range(101):
            h = vh[si] + abs(cx - vx[si]) + abs(cy - vy[si])
            ok = True
            for i in range(n):
                if vh[i] > 0:
                    if h - vh[i] != abs(cx - vx[i]) + abs(cy - vy[i]):
                        ok = False
                if vh[i] == 0:
                    if h > abs(cx - vx[i]) + abs(cy - vy[i]):
                        ok = False
            if ok:
                resx = cx
                resy = cy
                resh = h
    print(resx,resy,resh)



if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n):
  l.append(list(map(int, input().split())))
l = sorted(l, key=lambda x: x[2], reverse=True)
for cx in range(101):
  for cy in range(101):
    flag = True
    cnt = 0
    for x, y, h in l:
      if not cnt:
        H =  h+abs(x-cx)+abs(y-cy)
        cnt = 1
      else:
        if h != max(H-abs(x-cx)-abs(y-cy), 0):
          flag = False
          break
    if flag:
      ans = [cx, cy, H]
      break
  if flag:
    break
    
print(*ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())
Info = []
for _ in range(N):
    Info.append(list(map(int,input().split())))
for X in range(101):
    for Y in range(101):
        H = None
        for x, y, h in Info:
            if h != 0:
                if H is None:
                    H = h + abs(X-x) + abs(Y-y)
                if H != h + abs(X-x) + abs(Y-y):
                    H = None
                    break
        if H is not None:
            flag = 1
            for x, y, h in Info:
                if h != max(H - abs(X-x) - abs(Y-y), 0):
                    flag = 0
            if flag:
                print(*[X,Y,H])
                sys.exit()

Submission status: Accepted

Solution code:
N = int(input())

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

A.sort(key=lambda x:-x[2])

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

Submission status: Accepted

Solution code:
N = int(input())

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

A.sort(key=lambda x:-x[2])

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

Submission status: Accepted

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

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

def height(i, j, xn, yn, hn):
    return abs(j - xn) + abs(i - yn) + hn

def check(i, j, x, y, h, H):
    N = len(x)
    for n in range(N):
        if h[n] > 0:
            if height(i, j, x[n], y[n], h[n]) != H:
                return False
        else:
            if H - abs(j - x[n]) - abs(i - y[n]) > 0:
                return False
    return True


ok = False
for i in range(101):
    for j in range(101):
        for n in range(N):
            if h[n] > 0:
                H = height(i, j, x[n], y[n], h[n])
                ok = check(i, j, x, y, h, H)
                break
            if ok:
                break
        if ok:
            break
    if ok:
        break

print(j, i, H)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
xyh = []
for _ in range(n):
    xyh.append(LIST())
for x in range(0, 101):
    for y in range(0, 101):
        h = -1
        flag = True
        tmp = []
        for i in range(n):
            clc = abs(x - xyh[i][0]) + abs(y - xyh[i][1])
            if xyh[i][2] == 0:
                tmp.append(xyh[i][:2])
                continue
            if xyh[i][2] + clc == h or h == -1:
                h = xyh[i][2] + clc
            else:
                flag = False
                break
        if flag and h > 0:
            for i in tmp:
                clc = abs(x - i[0]) + abs(y - i[1])
                if h - clc > 0:
                    flag = False
            if flag:
                print(x, y, h)
                exit()

Submission status: Accepted

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

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

def height(X,Y,xn,yn,hn):
    return hn+abs(X-xn)+abs(Y-yn)

def check(x,y,h,X,Y,H):
    for n in range(N):
        if h[n]>0:
            if height(X,Y,x[n],y[n],h[n])!=H:
                return False
        elif H-abs(X-x[n])-abs(Y-y[n])>0:
            return False
    return True

for X in range(101):
    for Y in range(101):
        for n in range(N):
            if h[n]>0:
                H = height(X,Y,x[n],y[n],h[n])
                if check(x,y,h,X,Y,H) is True:
                    print(X,Y,H)
                    exit()