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: Runtime Error

Solution code:
#encoding utf-8

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

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

def conh(temH,cx,cy,data):
    return temH-abs(data[0]-cx)-abs(data[1]-cy)


for i in range(101):
    for j in range(101):
        temH = calH(i,j,data[0])
        count = 0
        for k in range(n):
            ignore_flag = 0
            if data[k][2] == 0:
                if conh(temH,i,j,data[k]) < 0:
                    ignore_flag = 1
                    count += 1

            if ignore_flag == 0:
                if calH(i,j,data[k]) != temH:
                    break
                else:
                    count += 1
            if count == n:
                answer=[i,j,calH(i,j,data[0])]

print(answer[0],answer[1],answer[2])

Submission status: Runtime Error

Solution code:
n = int(input())
x=[]
y=[]
h=[]
for i in range(0,n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    h.append(c)
 
 
 
for i in range(0,101):
    for j in range(0,101):
        tmph=0
        flag = True
        for k in range(0,n):
            if tmph == 0 and h[k] != 0:
                tmph=abs(x[k]-i)+abs(y[k]-j)+h[k]
                break
            for k in range(0,n):
            calch = tmph - abs(x[k]-i)-abs(y[k]-j)
            if h[k] != max(calch,0):
                flag = False
                break
        if flag == False:
            continue
        elif tmph == 0:
            flag2 = True
            for c in range(0,101):
                if i == x[c] and j == y[c]:
                    flag2 = False
                    break
            if flag2:
                ansx = i
                ansy = j
                ansh = 1
        else:
            ansx=i
            ansy=j
            ansh=tmph
 
print(ansx,ansy,ansh)

Submission status: Runtime Error

Solution code:
n = int(input())
x=[]
y=[]
h=[]
for i in range(0,n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    h.append(c)
 
 
 
for i in range(0,101):
    for j in range(0,101):
        tmph=0
        flag = True
        for k in range(0,n):
            if tmph == 0 and h[k] != 0:
                tmph=abs(x[k]-i)+abs(y[k]-j)+h[k]
                break
            for k in range(0,n):
            calch = tmph - abs(x[k]-i)-abs(y[k]-j)
            if h[k] != max(calch,0)
                flag = False
                break
        if flag == False:
            continue
        elif tmph == 0:
            flag2 = True
            for c in range(0,101):
                if i == x[c] and j == y[c]:
                    flag2 = False
                    break
            if flag2:
                ansx = i
                ansy = j
                ansh = 1
        else:
            ansx=i
            ansy=j
            ansh=tmph
 
print(ansx,ansy,ansh)

Submission status: Runtime Error

Solution code:
N=int(raw_input())
pts1=[]
Xco=[]
Yco=[]
height=[]
for n in N:
  tmp=raw_input().split(" ")
  Xco.append(int(tmp[0]))
  Yco.append(int(tmp[1]))
  height.append(int(tmp[2]))
 #pts.append([int(tmp[0]),int(tmp[1]),int(tmp[2])])
ph=max(height)
phi=[]
for i,j in enumerate(height):
  if j==ph:
    phi.append(i)
if len(phi)==1 and phi[0]!=0:
  ci=phi[0]
  if max(height[ci]-|Xco[ci]-Xco[0]|-|Yco[ci]-Xco[0]|,0)==height[0]:
    print(str(Xco[ci])+" "+str(Yco[ci])+" "+str(height[ci]))
if len(phi)==1 and phi[0]==0:
  ci=phi[0]
  if max(height[ci]-|Xco[ci]-Xco[1]|-|Yco[ci]-Xco[1]|,0)==height[1]:
    print(str(Xco[ci])+" "+str(Yco[ci])+" "+str(height[ci]))

Submission status: Runtime Error

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


for i in range(0,size):
    for j in range(0,size):
        tmph=0
        flag = True
        for k in range(0,n):
            if tmph == 0 and h[k] != 0:
                tmph=abs(x[k]-i)+abs(y[k]-j)+h[k]
            break
        for k in range(0,n):
            calch = abs(x[k]-i)+abs(y[k]-j)+h[k]
            if tmph != calch and h[k] != 0:
                flag = False
                break
            calcrh = tmph- abs(x[k]-i)-abs(y[k]-j)
            if calcrh != h[k]:
                flag = False
                break
        if flag == False:
            continue
        elif tmph == 0:
            flag2 = True
            for c in range(0,n):
                if i == x[c] and j == y[c]:
                    flag2 = False
                    break
            if flag2:
                ansx = i
                ansy = j
                ansh = 1
        else:
            ansx=i
            ansy=j
            ansh=tmph

print(ansx,ansy,ansh)

Submission status: Runtime Error

Solution code:
#C
import itertools
N=int(input())
X=[]
Y=[]
H=[]
finish=False
for n in range(N):
    x,y,h=map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

for cx, cy in itertools.product(range(101), range(101)):
    if finish==True:
        break
    for n,(x,y,h) in enumerate(zip(X,Y,H)):
        if n==0:
            height_zero=abs(x-cx)+abs(y-cy)+h
        else:
            height=abs(x-cx)+abs(y-cy)+h
            if height_zero!=height:
                break
        if n==N-1:
            finish=True
            x_ans=cx
            y_ans=cy
print(x_ans,y_ans,height_zero)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
xyh = []
for _ in range(n):
    xyh.append(tuple(list(li())))
    

# 中心になりうる点を全探索
def search_cent(xyh: list):
    n = len(xyh)
    for x_cent in range(101):
        for y_cent in range(101):
            
            # 各点と中心との距離
            dist = []
            is_cent = True
            for x,y,_ in xyh:
                dist.append((abs(x-x_cent), abs(y-y_cent)))
                
            # 中心との距離と高さの差に矛盾が無いかチェック
            for i in range(n):
                for j in range(n):
                    if (xyh[i][2]-xyh[j][2]) != -(sum(dist[i]) - sum(dist[j])):
                        is_cent = False
                        break
                if not is_cent:
                    break

            if is_cent:
                return x_cent, y_cent

                
x_cent, y_cent = search_cent(xyh)
h_cent = xyh[0][2] + abs(xyh[0][0] - x_cent) + abs(xyh[0][1] - y_cent)

print(x_cent, y_cent, h_cent)

Submission status: Runtime Error

Solution code:
import numpy as np

if __name__ == '__main__':
    N = int(input())
    info = []
    for i in range(N):
        info.append(list(map(int, input().split())))

    info.sort(key=lambda x:x[2])
    info = info[::-1]
    info = np.array(info)

    suceed = False
    for i in range(101):
        for j in range(101):
            if info[0][2] == 0:
                continue
            H = abs(info[0][0] - i) + abs(info[0][1] - j) + info[0][2]
            for k in range(N):
                if info[k][2] == 0:
                    continue
                if H != abs(info[k][0] - i) + abs(info[k][1] - j) + info[k][2]:
                    break
                if k == N - 1:
                    cx = i
                    cy = j
                    suceed = True
                    break
            if suceed:
                break
        if suceed:
            break

    print('{} {} {}'.format(cx, cy, H))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N = int(input())
XYH = [list(map(int,input().split())) for _ in range(N)]

Cxy = defaultdict(int)

#-1 NG
# 0 default
#1+ ok
verify =[]
XYH.sort(key=lambda x:-x[2])
for x,y,h in XYH:
    for cx in range(101):
        for cy in range(101):
            val = Cxy[(cx,cy)]
            if val<0:
                continue
            tmp_H = abs(x-cx)+abs(y-cy)+h
            if h==0:
                if tmp_H <= Cxy[(cx,cy)]:
                    Cxy[((cx, cy))]=-1
                continue

            if val==0:
                Cxy[(cx,cy)] = tmp_H
            elif val != tmp_H:
                Cxy[(cx, cy)] =-1

def find(d):
    for key in d.keys():
        if d[key] >0:

            return key,d[key]

(X,Y),H = find(Cxy)
print(X,Y,H)

Submission status: Runtime Error

Solution code:
def cal(X,Y,H):

    zerolist=[]
    for i in range(0,101): #C_x
        for j in range(0,101): #C_y
            temp=H[0]+abs(X[0]-i)+abs(Y[0]-j)
            for l in range(1,N):
                if(H[l]<0):
                    zerolist.append(l)
                else:
                    s=H[l]+abs(X[l]-i)+abs(Y[l]-j)
                    if(temp==s):
                        temp=s
                    else:
                        break
            else:
                for k in zerolist:
                    if(temp-abs(X[k]-i)-abs(Y[k]-j)>0):
                        break
                else:
                    return print("{} {} {}".format(i,j,temp))

cal(X,Y,H)

Submission status: Runtime Error

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

H = 1
C_x = 0
C_y = 0

def height(C_x,C_y,x,y,h):
  H = h + abs(x-C_x) + abs(y-C_y)
  return H

def koud(C_x,C_y,H,x,y):
  h = H - abs(x-C_x) - abs(y-C_y)
  return max(h,0)

flag = False
for i in range(0,101):
  C_x = i
  for j in range(0,101):
    C_y = j
    memo = []
    for k in range(N):
      if zahyou[k][2] == 0:#高度が0のとき
        memo.append[k]
        continue
      if len(memo) >= 1 :      
        if k == memo[len(memo)-1] + 1 :
          H = height(C_x,C_y,zahyou[k][0],zahyou[k][1],zahyou[k][2])
        else:
          if zahyou[k][2] != koud(C_x,C_y,H,zahyou[k][0],zahyou[k][1]):
            break
          else:
            continue
      else:
        if k == 0:
          H = height(C_x,C_y,zahyou[k][0],zahyou[k][1],zahyou[k][2])
        else:
          if zahyou[k][2] != koud(C_x,C_y,H,zahyou[k][0],zahyou[k][1]):
            break
          else:
            continue        
    else:
      for l in range(len(memo)):
        if H > abs(zahyou[l][0] - C_x) + abs(zahyou[l][1] - C_y):
          break
        else:
          continue
      else:
        flag = True
        break
    if flag:
      break
  if flag:
    break

print(C_x,C_y,H)

Submission status: Runtime Error

Solution code:
N = int(input())

X = [None] * N
Y = [None] * N
H = [None] * N

R = []

for n in range(N):
    X[n], Y[n], H[n] = map(int, input().split())

for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True
        for n in range(N):
            if n == 0:
                ch = H[n] + abs(X[n] - cx) + abs(Y[n] - cy)
            if max(ch - abs(X[n] - cx) - abs(Y[n] - cy), 0) != H[n]:
                flag = False
                break
        if flag == True:
            R.append([cx, cy, ch])

print(R[0][0], R[0][1], R[0][2])

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
xyh = [na() for _ in range(n)]

for cx in range(101):
    for cy in range(101):
        count = 0
        bef = float('inf')
        for i in xyh:
            he = i[2]+(max(i[0],cx)-min(i[0],cx))+(max(i[1],cy)-min(i[1],cy))
            if bef == he:
                count += 1
                if count == n-1:
                    CX = cx
                    CY = cy
                    height = he
                    break
            bef = he
print(CX, CY, height)

Submission status: Runtime Error

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


for i in range(0,size):
    for j in range(0,size):
        tmph=0
        flag = True
        for k in range(0,n):
            if tmph == 0 and h[k] != 0:
                tmph=abs(x[k]-i)+abs(y[k]-j)+h[k]
            break
        for k in range(0,n):
            calch = abs(x[k]-i)+abs(y[k]-j)+h[k]
            if tmph != calch and h[k] != 0:
                flag = False
                break
        if flag == False:
            continue
        elif tmph == 0:
            flag2 = True
            for c in range(0,n):
                if i == x[c] and j == y[c]:
                    flag2 = False
                    break
            if flag2:
                ansx = i
                ansy = j
                ansh = 1
        else:
            ansx=i
            ansy=j
            ansh=tmph

print(ansx,ansy,ansh)

Submission status: Runtime Error

Solution code:
3
99 1 191
100 1 192
99 0 192

Submission status: Runtime Error

Solution code:
n=int(input())
xymap=[[-1 for j in range(101)] for i in range(101)]
inp=[]
for i in range(n):
    xi,yi,hi=map(int,input().split())
    if hi==0:
        inp.append(xi,yi,hi)
        pass
    else:
            
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]==a or xymap[x][y]==-1 :
                    xymap[x][y]=a
                else:
                    xymap[x][y]=-2
flag=0
for x in range(101):
    for y in range(101):
        if xymap[x][y]!=-2:
            flag=1
            print(x,y,xymap[x][y])
if flag==0:
    xymap=[[-1 for j in range(101)] for i in range(101)]
    for i in range(len(inp)):
        xi=inp[i][0]
        yi=inp[i][1]
        hi=inp[i][2]
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]==a or xymap[x][y]==-1 :
                    xymap[x][y]=a
                else:
                    xymap[x][y]=-2
    for x in range(101):
        for y in range(101):
            if xymap[x][y]!=-2:
                print(x,y,xymap[x][y])

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
x = np.array([xyh[i][0] for i in range(N)])
y = np.array([xyh[i][1] for i in range(N)])
h = np.array([xyh[i][2] for i in range(N)])
x_ = x[h != 0]
y_ = y[h != 0]
h_ = h[h != 0]
for Cx in range(101):
    for Cy in range(101):
        H = h_ + list(map(abs, [xi - Cx for xi in x_])) + list(map(abs, [yi - Cy for yi in y_]))
        if len(set(H)) == 1 and h[[x==Cx] and [y==Cy]] == list(set(H)):
            break
    else:
        continue
    break
H = list(set(H))
print("{} {} {}".format(Cx, Cy, H[0]))

Submission status: Runtime Error

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

from operator import itemgetter

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

    xsorted = sorted(xyh_list, key=itemgetter(0))
    cy_flag = False
    for i in range(n - 1):
        x, y, h = xsorted[i]
        nx, ny, nh = xsorted[i+1]
        if x == nx:
            cy_flag = True
            cy, hy = search_peak(y, h, ny, nh)
            shx = x
            break

    ysorted = sorted(xyh_list, key=itemgetter(1))
    cx_flag = False
    for i in range(n - 1):
        x, y, h = ysorted[i]
        nx, ny, nh = ysorted[i+1]
        if y == ny:
            cx_flag = True
            cx, hx = search_peak(x, h, nx, nh)
            shy = y
            break

    if not cx_flag:
        cx, shy, hx = [xyh for xyh in xyh_list if xyh[0] == 0 or xyh[0] == 100][0]

    if not cy_flag:
        shx, cy, hy = [xyh for xyh in xyh_list if xyh[1] == 0 or xyh[1] == 100][0]

    h = hx + abs(shy - cy)
    print("{} {} {}".format(cx, cy, h))


def search_peak(p1, h1, p2, h2):
    if p1 > p2:
        p1, p2 = p2, p1
        h1, h2 = h2, h1

    cp = (p2 + h2 - h1 - p1) / 2 + p1
    ch = h1 + cp - p1
    return int(cp), int(ch)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = input()
l = []
isz = 0
for i in xrange(n):
    x, y, h = map(int, raw_input().strip().split())
    if h == 0: isz += 1
    l.append([x, y, h])

assert isz != n

ans = [0,0,0]

for cx in xrange(101):
    for cy in xrange(101):
        H = 0
        zH = int(1e18)
        poss = True
        for xyh in l:
            x, y, h = xyh
            tx = abs(cx - x) + abs(cy - y)
            if h != 0:
                nH = tx + h
                if H != 0 and nH != H:
                    poss = False
                    break
                elif H == 0: H = nH
            elif h == 0:
                zH = min(zH, tx + h)
                
        if poss:
            ans = [cx, cy, H]
            break
        
    if poss: break
    
if ans != [0, 0, 0]:
    check = True
    for xyh in l:
        x, y, h = xyh
        tx = abs(cx - x) + abs(cy - y)
        assert h == max(ans[2] - tx, 0)
 
print ans[0], ans[1], ans[2]

Submission status: Runtime Error

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

H = 1
C_x = 0
C_y = 0

def height(C_x,C_y,x,y,h):
  H = h + abs(x-C_x) + abs(y-C_y)
  return H

def koud(C_x,C_y,H,x,y):
  h = H - abs(x-C_x) - abs(y-C_y)
  return max(h,0)

flag = False
for i in range(0,101):
  C_x = i
  for j in range(0,101):
    C_y = j
    memo = []
    for k in range(N):
      if zahyou[k][2] == 0:#高度が0のとき
        memo.append[k]
        continue
      if k == 0 :
        H = height(C_x,C_y,zahyou[k][0],zahyou[k][1],zahyou[k][2])
      else:
        if zahyou[k][2] != koud(C_x,C_y,H,zahyou[k][0],zahyou[k][1]):
          break
        else:
          continue
    else:
      for l in range(len(memo)):
        if H > abs(zahyou[l][0] - C_x) + abs(zahyou[l][1] - C_y):
          break
        else:
          continue
      else:
        flag = True
        break
    if flag:
      break
  if flag:
    break

print(C_x,C_y,H)

Submission status: Runtime Error

Solution code:
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 cx in range(101):
  for cy in range(101):
    hx = -1
    for i in range(n):
      if h[i] != 0:
        hx = h[i] + abs(cx - x[i]) + abs(cy - y[i])
        break
    flag = true
    for i in range(n):
      if h[i] != max(hx - abs(cx - x[i]) - abs(cx - x[i]), 0):
        flag = false
        break
    if flag:
      print('{} {} {}'.format(cx, cy, hx))

Submission status: Runtime Error

Solution code:
import numpy as np
def kouho(x, y, h):
    if h:
        return np.abs(np.arange(101) - x)[:, np.newaxis]  + np.abs(np.arange(101) - y) [np.newaxis] + h

n = int(input())
arrs = []
arrs0 = [np.ones((101, 101), dtype=np.int)*1000000000]
for _ in range(n):
  x, y, h = map(int, input().split())
  if h:
    arrs.append(kouho(x, y, h))
  else:
    arr0.append(kouho(x, y, h))
    
arrs = np.array(arrs)
arrs0 = np.array(arrs0)
for i in range(101):
  for j in range(101):
    if np.all(arrs[:,i,j]==arrs[0,i,j]) and (arrs[0,i,j] <= arrs0[:,i,j].min()):
      print(i, j, arrs[0, i, j])
      break

Submission status: Runtime Error

Solution code:
#encoding utf-8

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



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

for i in range(101):
    for j in range(101):
        temH = calH(i,j,data[0])
        for k in range(n):
            if calH(i,j,data[k]) != temH:
                break
            else:
                if k == n-1:
                    answer=[i,j,calH(i,j,data[0])]

print(answer[0],answer[1],answer[2])

Submission status: Runtime Error

Solution code:
#C
N=int(input())
X=[]
Y=[]
H=[]
finish=False
for n in range(N):
    x,y,h=map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    
for cx in range(101):
    if finish==True:
        break
    for cy in range(101):
        if finish==True:
            break
        for n,(x,y,h) in enumerate(zip(X,Y,H)):
            if n==0:
                height_zero=abs(x-cx)+abs(y-cy)+h
            else:
                height=abs(x-cx)+abs(y-cy)+h
                if height_zero!=height:
                    break
            if n==N-1:
                finish=True
                x_ans=cx
                y_ans=cy
print(x_ans,y_ans,height_zero)

Submission status: Runtime Error

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

H = 1
C_x = 0
C_y = 0

def height(C_x,C_y,x,y,h):
  H = h + abs(x-C_x) + abs(y-C_y)
  return H

def koud(C_x,C_y,H,x,y):
  h = H - abs(x-C_x) - abs(y-C_y)
  return max(h,0)
  
flag = False
for i in range(0,101):
  C_x = i
  for j in range(0,101):
    C_y = j
    memo = []
    for k in range(N):
      if zahyou[k][2] == 0:#高度が0のとき
        memo.append[k]
        continue
      if k == 0 :
        H = height(C_x,C_y,zahyou[k][0],zahyou[k][1],zahyou[k][2])
      else:
        if zahyou[k][2] != koud(C_x,C_y,H,zahyou[k][0],zahyou[k][1]):
          break
        else:
          continue
    else:
      for l in range(len(memo)):
        if zahyou[k][2] != koud(C_x,C_y,H,zahyou[k][0],zahyou[k][1]):
          break
        else:
          continue
      else:
        flag = True
        break
    if flag:
      break
  if flag:
    break

print(C_x,C_y,H)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import itertools

N = int(input())
ta = [list(map(int,input().split())) for _ in range(N)]
for Cx, Cy in itertools.product(range(101),range(101)):
    # もしcx,cyが決まっていた場合矛盾が起こらないか
    # H = abs(x-cx)+abs(y-cy) + h
    H = None
    for [x,y,h] in ta:
        if h == 0:
            pass
        else:
            if H is None:
                H = h + abs(x-Cx)+abs(y-Cy)
            else:
                if H != h + abs(x-Cx)+abs(y-Cy):
                    break
        if h != max(H - abs(x-Cx) - abs(y-Cy),0):
            break
    else:
        break
print(Cx,Cy,H)

Submission status: Runtime Error

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 Cx in range(101):
    p = False
    for Cy in range(101):
        w = True
        previous = None
        for i in range(0,N):
            H = h[i] + abs(X[i] - Cx) + abs(Y[i] - Cy)
            if H - abs(X[i] - Cx) - abs(Y[i] - Cy) >= 0:
                if not previous:
                    previous = H
                elif H != previous or H < 1:
                    w = False
                    break
        
        if w:
            answer = [Cx,Cy,H]
            p = True
            break

    if p:
        break

print(answer[0],answer[1],answer[2])

Submission status: Runtime Error

Solution code:
n = int(input())
#x = []
#y = []
#h = []
l = []
for i in range(n):
    ex,ey,eh = map(int,input().split())
    #x.append(ex)
    #y.append(ey)
    #h.append(eh)
    if eh != 0:
        l.append([ex,ey,eh])

def func(cx,cy,l1,l2):
    ans1 = -abs(l1[0]-cx)+abs(l2[0]-cx)-abs(l1[1]-cy)+abs(l2[1]-cy)
    ans2 = l1[2]-l2[2]
    if ans1 == ans2:
        return True
    else:
        return False

def func2(cx,cy,l):
    ans = l[2] + abs(l[0]-cx) +  abs(l[1]-cy)
    return ans

cx = -1
cy = -1
flag = False
for i in range(101):
    for j in range(101):
        for k in range(n-1):
            if func(i,j,l[k],l[k+1]):
                if k == n-2:
                    cx = i
                    cy = j
                    flag = True
                    break
            else:
                break
        if flag:
            break
    if flag:
        break
h = func2(cx,cy,l[0])

print(cx, cy, h)

Submission status: Runtime Error

Solution code:
N=int(input())
list1=[]
for i in range(N):
  x1=list(map(int,input().split()))
  list1.append(x1)
flag=0
for i in range(101):
  for j in range(101):
    list2=[]
    for k in range(N):
      Hx=list1[k][2]+abs(list1[k][0]-i)+abs(list1[k][1]-j)
      list2.append(Hx)
    if len(set(list2))==1:
      list3=[0]
      for l in range(N):
         d=Hx-abs(list1[l][0]-i)-abs(list1[l][1]-j)
         list3.append(d)
      if min(list3[0])>=0:
         print(i,j,Hx)
         flag=1
      else:
        pass
    elif flag==1:
      break
    else:
      continue
  if flag==1:
    break

Submission status: Runtime Error

Solution code:
N=int(input())
if N==2:
    X1, Y1,h1 =map(int,input().split())
    X2, Y2,h2 =map(int,input().split())   
    for Cx in range (0,101):
        for Cy in range (0,101):
            for H in range (h1, h1+100):
                if  h1==max(H-abs(X1-Cx)-abs(Y1-Cy),0) and h2==max(H-abs(X2-Cx)-abs(Y2-Cy),0) :
                    print ('%d %d %d'%(Cx,Cy,H))
if N==3:
    X1, Y1,h1 =map(int,input().split())
    X2, Y2,h2 =map(int,input().split()) 
    X3, Y3,h3 =map(int,input().split())   
    for Cx in range (0,101):
        for Cy in range (0,101):
            for H in range (h1, h1+100):
                if  h1==max(H-abs(X1-Cx)-abs(Y1-Cy),0) and h2==max(H-abs(X2-Cx)-abs(Y2-Cy),0) and h3==max(H-abs(X3-Cx)-abs(Y3-Cy),0):
                    print ('%d %d %d'%(Cx,Cy,H))
else:
    X1, Y1,h1 =map(int,input().split())
    X2, Y2,h2 =map(int,input().split()) 
    X3, Y3,h3 =map(int,input().split())   
    X4, Y4,h4 =map(int,input().split())   
    for Cx in range (0,101):
        for Cy in range (0,101):
            for H in range (h1, h1+100):
                if  h1==max(H-abs(X1-Cx)-abs(Y1-Cy),0) and h2==max(H-abs(X2-Cx)-abs(Y2-Cy),0) and h3==max(H-abs(X3-Cx)-abs(Y3-Cy),0)  and h4==max(H-abs(X4-Cx)-abs(Y4-Cy),0):
                    print ('%d %d %d'%(Cx,Cy,H))

Submission status: Runtime Error

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



for i in range(0,101):
    for j in range(0,101):
        tmph=0
        flag = True
        for k in range(0,n):
            if tmph == 0 and h[k] != 0:
                tmph=abs(x[0]-i)+abs(y[0]-j)+h[0]
            calch = abs(x[k]-i)+abs(y[k]-j)+h[k]
            if tmph != calch and h[k] != 0:
                flag = False
                break
        if flag == False:
            continue
        else:
            ansx=i
            ansy=j
            ansh=tmph

print(ansx,ansy,ansh)

Submission status: Runtime Error

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

for i in range(0,N):
    if h[i] == 0:
        del x[i]
        del y[i]
        del h[i]

M = len(x)
H = [0 for i in range(0,M)]

for X in range(0,101):
    for Y in range(0,101):
        for i in range(0,M):
            H[i] = h[i] + abs(x[i]-X) + abs(y[i]-Y)
        if max(H) == min(H):
            print("{} {} {}".format(X,Y,max(H)))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())

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

ans = []
ans_c = 0
for i in range(101):
    for j in range(101):
        H = -1
        judge = True
        for k in range(N):
            if info[k][2] == 0:
                continue
            dis = abs(i - info[k][0]) + abs(j - info[k][1])
            if H == -1:
                H = info[k][2] + dis
            else:
                if H != (info[k][2] + dis):
                    judge = False
        if judge == True:
            ans_c += 1
            add_data = [i,j,H]
            ans.append(add_data)


for i in range(ans_c):
    judge = True
    for k in range(N):
        judge = True
        if info[k][2] == 0:
            h = max(abs(ans[i][0] - info[k][0]) + abs(ans[j][1] - info[k][1]),0)
            if h != 0:
                judge = False
    if judge == True:
        ans[0][0] = ans[i][0]
        ans[0][1] = ans[i][1]
        ans[0][2] = ans[i][2]
print("{} {} {}".format(ans[0][0],ans[0][1],ans[0][2]))

Submission status: Runtime Error

Solution code:
n = int(input())

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

ans = []
for cx in range(101): #Cx 0~100
    for cy in range(101): #Cy 0~100
        h = []
        for i in range(n):
            #x[i], y[i], h[i]のときの高さHを求める
            #H = |x[i] - Cx| + |y[i] - Cy| + h[i]
            h.append(abs(xyh[i][0] - cx) + abs(xyh[i][1] - cy) + xyh[i][2])

        # Hがすべて一致するときのCx, Cyが答えである
        if len(set(h)) == 1:
            ans.append(cx)
            ans.append(cy)
            ans.append(h[0])

print(ans[0], ans[1], ans[2])