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:
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:
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]<=a and xymap[x][y]!=-2:
                    pass
                else:
                    xymap=-2
    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:
    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:
# -*- coding: utf-8 -*-
"""
Created on Sat Oct  6 17:56:47 2018
ABC112C
@author: maezawa
"""
import itertools as itr
n = int(input())
x = []
y = []
h = []
for i in range(n):
    xi, yi, hi = list(map(int, input().split()))
    x.append(xi)
    y.append(yi)
    h.append(hi)
    
ans = 1    
for i in range(n):
    if h[i] > 0:
        break
    cx = sum(x)//len(x)
    cy = sum(y)//len(y)
    h = 1
    print(cx, cy, h)
    ans = 0


for cx, cy in itr.product(range(101),range(101)):
    hh = set([])  
    for i in range(n):
        if h[i] > 0:
            hh.add(abs(x[i]-cx)+abs(y[i]-cy)+h[i])
            #print(cx, cy, i, hh)
            if  len(hh) > 1:
                break
        elif abs(x[i]-cx)+abs(y[i]-cy) < 1:
            break
    else:
        if len(hh) == 1:
            if ans ==1:
                print(cx, cy, hh.pop())
                break

Submission status: Runtime Error

Solution code:
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

flg = True


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


# print(f'ss: {ss}')
for s in ss:
    x = s[0]
    y = s[1]
    h = s[2]
    if x == y == 0:
        print(x, y, h)
        flg = False

ans = []
if flg:
    for i in range(len(ss)-1):

        temp = [] if i == 0 else get_unique_list(ans)
        ans = []

        x1 = ss[i][0]
        y1 = ss[i][1]
        h1 = ss[i][2]
        x2 = ss[i+1][0]
        y2 = ss[i+1][1]
        h2 = ss[i+1][2]

        for a in range(100):
            for b in range(100):
                left = h1 + abs(x1-a) + abs(y1 - b)
                right = h2 + abs(x2-a) + abs(y2 - b)
                if left == right and left > 0 and right > 0:
                    if i == 0:  # 1回目のループ
                        ans.append([a, b])
                    elif [a, b] in temp:  # 2回目移行
                        ans.append([a, b])

    h = ss[0][2] + abs(ss[0][0] - ans[0][0]) + abs(ss[0][1] - ans[0][1])
    print(ans[0][0], ans[0][1], h)

Submission status: Runtime Error

Solution code:
def H(h,cx,cy,x,y):
    return h+abs(cx-x)+abs(cy-y)

def checkH(H,cx,cy,x,y):
    return (H-abs(cx-x)-abs(cy-y))>0

n = int(input())
arr=[]
for i in range(n):
    arr.append(list(map(int, input().split())))
isSame = True
for cx in range(0,101):
    for cy in range(0,101):
        isSame = True
        h_prev=-1
        for a in arr:
            h= H(a[2],cx,cy,a[0],a[1])
            if checkH(h,cx,cy,x,y):
                if h_prev==-1:
                    h_prev=h
                if h!=h_prev:
                    isSame=False
                    break
                else:
                    h_prev=h
        if isSame==True:
            print("{} {} {}".format(cx,cy,h))
            exit

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())
x = np.zeros(N)
y = np.zeros(N)
h = np.zeros(N)
value = np.zeros(N)
for i in range(N):
    xx, yy, hh = input().split()
    x[i] = int(xx)
    y[i] = int(yy)
    h[i] = int(hh)

max_h = np.max(h)

for h in np.arange(max_h, math.pow(10, 9)):
    for cx in range(100):
        for cy in range(100):
            value = h - np.abs(x-cx) - np.abs(y-cy)
            for i in range(N):
                if value[i] < 0:
                    value[i] = 0
            boolean = (value == h).sum()
            if boolean == N:
                print(cx, cy, h)
                flag == True
                break
        if flag:
            break
    if flag:
        break

Submission status: Runtime Error

Solution code:
# C
def H(h,cx,cy,x,y):
    return h+abs(cx-x)+abs(cy-y)

def checkH(H,cx,cy,x,y):
    return H>(abs(cx-x)+abs(cy-y))


n = int(input())
arr=[]
for i in range(n):
    arr.append(list(map(int, input().split())))
isSame = True
for cx in range(0,101):
    for cy in range(0,101):
        isSame = True
        h_prev=-1
        for a in arr:
            h= H(a[2],cx,cy,a[0],a[1])
            if a[2]>0 or checkH(h,cx,cy,x,y):
                if h_prev==-1:
                    h_prev=h
                if h!=h_prev:
                    isSame=False
                    break
                else:
                    h_prev=h
        if isSame==True:
            print("{} {} {}".format(cx,cy,h))
            exit

Submission status: Runtime Error

Solution code:
N = int(input())
xyh = sorted([list(map(int,input().split())) for _ in range(N)], key=lambda x:x[2], reverse=True)
xyh = [(x,y,h) for x,y,h in xyh if h != 0]

XY = [[True] * 101 for _ in range(101)]

for i in range(N-1):
    tmp = xyh[i][2] - xyh[i+1][2]
    for x in range(101):
        for y in range(101):
            if not XY[y][x]: 
                continue
            if abs(x-xyh[i][0]) + abs(y-xyh[i][1]) != abs(x-xyh[i+1][0]) + abs(y-xyh[i+1][1]) - tmp:
                XY[y][x] = False

for x in range(101):
    for y in range(101):
        if XY[y][x]:
            print(x,y,abs(x-xyh[0][0]) + abs(y-xyh[0][1]) + xyh[0][2])
            break

Submission status: Runtime Error

Solution code:
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
l = []
for i in range(n):
    a, b, c = il()
    l.append([a, b, c])
cx, cy = 0, 0
x, y = 0, 0
hoge = []
for i in range(n):
    for j in range(n):
        if i == j: continue
        if l[i][2] == l[j][2]:
            if l[i][0] == l[j][0] or l[i][1] == l[j][1]:
                hoge.append([i, j])
                print((l[i][0] + l[j][0]) // 2, (l[i][1] + l[j][1]) // 2, l[1][2]+1)
                exit()
a, b = hoge[0]
if l[a][0] == l[b][0]:
    if l[a][1] + l[b][1] > 100:
        print(l[a][0], 100, l[a][2]+1)
    else:
        print(l[a][0], 0, l[a][2]+1)
else:
    if l[a][0] + l[b][0] > 100:
        print(100, l[a][1], l[a][2]+1)
    else:
        print(0, l[a][1], l[a][2]+1)

Submission status: Runtime Error

Solution code:
import sys
import itertools


def height(x, y, Cx, Cy, H):
    return max([H - abs(x - Cx) - abs(y - Cy), 0])


N = int(sys.stdin.readline().strip())

set_list = []
for line in sys.stdin.readlines():
    x, y, h = list(map(int, line.strip().split()))
    ans_set = set()
    for Cx, Cy in itertools.product(range(101), range(101)):
        dx = abs(x - Cx)
        dy = abs(y - Cy)
        d = dx + dy
        H = h + d
        if H >= d:
            ans_set.add((Cx, Cy, H))
            continue
        if h == 0:
            ans_set.add((Cx, Cy, H))
            continue
    set_list.append(ans_set)

ans_set = set_list[0]
for s in set_list[1:]:
    ans_set = ans_set & s

if len(ans_set) == 1:
    Cx, Cy, H = list(ans_set)[0]
    print(Cx, Cy, H)
else:
    for s in set_list:
        Cx, Cy, H = list(ans_set)[0]
        if H >= 1:
            print(Cx, Cy, H)
            break

Submission status: Runtime Error

Solution code:
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
l = []
grid = [[-1] * 100 for _ in range(100)]
for i in range(n):
    a, b, c = il()
    grid[a][b] = c
    l.append(list(a, b, c))
cx, cy = 0, 0
x, y = 0, 0
hoge = []
for i in range(n):
    for j in range(n):
        if i == j: continue
        if l[i][2] == l[j][2]:
            if l[i][0] == l[j][0] or l[i][1] == l[j][1]:
                hoge.append(list(i, j))
                print((l[i][0] + l[j][0]) // 2, (l[i][1] + l[j][1]) // 2, l[1][2]+1)
                exit()
a, b = hoge[0]
if l[a][0] == l[b][0]:
    if l[a][1] + l[b][1] > 100:
        print(l[a][0], 100, l[a][2]+1)
    else:
        print(l[a][0], 0, l[a][2]+1)
else:
    if l[a][0] + l[b][0] > 100:
        print(100, l[a][1], l[a][2]+1)
    else:
        print(0, l[a][1], l[a][2]+1)

Submission status: Runtime Error

Solution code:
n = int(input())
numss = [[int(i) for i in input().split()] for i in range(n)]
 
def h(x,y,h,cx,cy):
    return h+abs(x-cx)+abs(y-cy)
def hc(x,y,cx,cy,H):
    return max(H-abs(x-cx)-abs(y-cy),0)
def check(cx,cy,H):
    flag = True
    for nums in numss:
        if hc(nums[0],nums[1],cx,cy,H) == nums[2]:
            pass
        else:
            flag=False
            break
    return flag
ans=[]
for cx in range(0,101):
    for cy in range(0,101):
        for nums in numss:
            H=h(nums[0],nums[1],nums[2],cx,cy)
            if check(cx,cy,H):
                ans.append(cx)
                ans.append(cy)
                ans.append(H)
                break
if len(ans)==0:
    print("0 0 0")
else:
    print(ans[0],ans[1],ans[2])
n = int(input())
numss = [[int(i) for i in input().split()] for i in range(n)]

def h(x,y,h,cx,cy):
    return h+abs(x-cx)+abs(y-cy)
def hc(x,y,cx,cy,H):
    return max(H-abs(x-cx)-abs(y-cy),0)
def check(cx,cy,H):
    flag = True
    for nums in numss:
        if hc(nums[0],nums[1],cx,cy,H) == nums[2]:
            pass
        else:
            flag=False
            break
    return flag
ans=[]
for cx in range(0,101):
    for cy in range(0,101):
        for nums in numss:
            H=h(nums[0],nums[1],nums[2],cx,cy)
            if check(cx,cy,H):
                ans.append(cx)
                ans.append(cy)
                ans.append(H)
                break
if len(ans)==0:
    print("0 0 0")
else:
    print(ans[0],ans[1],ans[2])

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
X = []
Y = []
H = []
for i in range(N):
    x, y, h = map(int, input().split())
    if h != 0:
        X.append(x)
        Y.append(y)
        H.append(h)
x1 = X[0]
y1 = Y[0]
h1 = H[0]
for Cx in range(101):
    for Cy in range(101):
        h = h1 + abs(x1-Cx) + abs(y1-Cy)
        i = 1
        while i < N and h == H[i] + abs(X[i]-Cx) + abs(Y[i]-Cy):
            i += 1
        if i == N:
            print(Cx, Cy, h)
            sys.exit()

Submission status: Runtime Error

Solution code:
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]

    suceed = False
    for i in range(101):
        for j in range(101):
            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:
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

flg = True


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


# print(f'ss: {ss}')
for s in ss:
    x = s[0]
    y = s[1]
    h = s[2]
    if x == y == 0:
        print(x, y, h)
        flg = False

ans = []
for i in range(len(ss)-1):

    temp = [] if i == 0 else get_unique_list(ans)
    ans = []

    x1 = ss[i][0]
    y1 = ss[i][1]
    h1 = ss[i][2]
    x2 = ss[i+1][0]
    y2 = ss[i+1][1]
    h2 = ss[i+1][2]

    for a in range(100):
        for b in range(100):
            left = h1 - abs(x1-a) - abs(y1 - b)
            right = h2 - abs(x2-a) - abs(y2 - b)
            if left == right and left > 0 and right > 0:
                if i == 0:  # 1回目のループ
                    ans.append([a, b])
                elif [a, b] in temp:  # 2回目移行
                    ans.append([a, b])

    # print(f'i: {i}, temp: {temp}, ans: {get_unique_list(ans)}')

h = ss[0][2] + abs(ss[0][0] - ans[0][0]) + abs(ss[0][1] - ans[0][1])

print(ans[0][0], ans[0][1], h)
# print(get_unique_list(list_c))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
lx=[];ly=[];la=[];lb=[]
for p in range(n):
  lx.append(l[p][0]+l[p][1])
for q in range(n):
  ly.append(l[q][0]-l[q][1])
for r in range(n):
  la.append(l[r][0])
for s in range(n):
  lb.append(l[s][1])
if n>=4:
  L=[l[lx.index(min(lx))],l[lx.index(max(lx))]]
  if l[ly.index(min(ly))] not in L:L.append(l[ly.index(min(ly))])
  if l[ly.index(max(ly))] not in L:L.append(l[ly.index(max(ly))])
  if l[la.index(min(la))] not in L:L.append(l[la.index(min(la))])
  if l[la.index(max(la))] not in L:L.append(l[la.index(max(la))])
  if l[la.index(min(lb))] not in L:L.append(l[la.index(min(lb))])
  if l[la.index(max(lb))] not in L:L.append(l[la.index(max(lb))])
  for x in range(101):
    for y in range(101):
      if abs(L[0][0]-x)+abs(L[0][1]-y)+L[0][2]==abs(L[1][0]-x)+abs(L[1][1]-y)+L[1][2]==abs(L[2][0]-x)+abs(L[2][1]-y)+L[2][2]==abs(L[3][0]-x)+abs(L[3][1]-y)+L[3][2]:
        print(x,y,abs(L[0][0]-x)+abs(L[0][1]-y)+L[0][2])
elif n>=3:
  for x in range(101):
   for y in range(101):
     if abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2]==abs(l[1][0]-x)+abs(l[1][1]-y)+l[1][2]==abs(l[2][0]-x)+abs(l[2][1]-y)+l[2][2]:
       print(x,y,abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2])
else:
  for x in range(101):
   for y in range(101):
     if abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2]==abs(l[1][0]-x)+abs(l[1][1]-y)+l[1][2]:
       print(x,y,abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2])

Submission status: Runtime Error

Solution code:
n = int(input())

x = [int(i) for i in range(n)]
y = [int(i) for i in range(n)]
h = [int(i) for i in range(n)]

for i in range(n):
  x[i], y[i], h[i] = [int(i) for i in input().split()]
  
for i in range(101):
  for j in range(101):
    H = abs(i - x[0]) + abs(j - y[0]) + h[0] 
    for k in range(n):
      if  H != abs(i - x[k]) + abs(j - y[k]) + h[k]:
        break
    else:
      ansx = i
      ansy = j
      ansH = H
      
print(ansx, ansy, ansH)

Submission status: Runtime Error

Solution code:
import numpy as np
n  = int(input())

xs = []
ys = []
hs = []
for k in range(n):
    xx, yy, hh = list(map(int,input().split()))
    xs.append(xx)
    ys.append(yy)
    hs.append(hh)    
x = np.array(xs)
y = np.array(ys)
h = np.array(hs)

from itertools import product
cand = []
for cx, cy in product(range(101), range(101)):
    temp1 = abs(cx - x) + abs(cy - y)
    temp2 = temp1 + h
    if len(temp2[h>0]) < 2:
        continue
    else:
        if np.max(temp2[h > 0]) == np.min(temp2[h>0]):
            cand.append((cx,cy,np.max(temp2[h > 0])))
if len(cand) == 1:
    print(cand[0][0],cand[0][1],cand[0][2])
elif len(cand)>5:
    aaaaaaaaa
else:
    print(cand[-1][0],cand[-1][1],cand[-1][2])

Submission status: Runtime Error

Solution code:
n = int(input())
numss = [[int(i) for i in input().split()] for i in range(n)]

def h(x,y,h,cx,cy):
    return h+abs(x-cx)+abs(y-cy)
def hc(x,y,cx,cy,H):
    return H-abs(x-cx)-abs(y-cy)
def check(cx,cy,H):
    flag = True
    for nums in numss:
        if hc(nums[0],nums[1],cx,cy,H) == nums[2]:
            pass
        else:
            flag=False
            break
    return flag
ans=[]
for cx in range(0,101):
    for cy in range(0,101):
        for nums in numss:
            H=h(nums[0],nums[1],nums[2],cx,cy)
            if check(cx,cy,H):
                ans.append(cx)
                ans.append(cy)
                ans.append(H)
                break
print(ans[0],ans[1],ans[2])

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] - sum(dist[i]) < 0 or xyh[j][2] - sum(dist[j]) < 0:
                        pass
                    
                    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:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b


heights = []
N = getN()
xmax, ymax, xmin, ymin = (-1,0,0), (0,-1,0), (200,0,0), (0,200,0)

for i in range(N):
    data = getlist()
    x,y,h = data[0],data[1],data[2]
    heights.append(data)
    if x > xmax[0]:
        xmax = (x,y,h)
    if x < xmin[0]:
        xmin = (x,y,h)
    if y > ymax[1]:
        ymax = (x,y,h)
    if y < ymin[1]:
        ymin = (x,y,h)
ansx, ansy, ansh = 0,0,0
first = heights[0]
fx,fy,fh = first[0], first[1], first[2]
for x in range(0,101):
    for y in range(0,101):
        flag = 1
        cand_h = fh + abs(fx-x) + abs(fy-y)
        #print(cand_h, x,y)
        for i in range(0,N):
            comp = heights[i]
            if (cand_h - abs(comp[0]-x) - abs(comp[1]-y)) >= 0:
                if (comp[2] + abs(comp[0]-x) + abs(comp[1]-y)) != cand_h:
                    #print("break",x,y)
                    flag = 0

        if flag == 1:
            if cand_h <= 1000000000
            #print("success", x,y)
                ansx, ansy, ansh = x, y, cand_h
if N == 1:
    print(fx, fy, fh)
else:
    print(ansx,ansy,ansh)

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] - sum(dist[i]) < 0 or xyh[j][2] - sum(dist[j]) < 0:
                        pass
                    
                    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:
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:
        x[i] = -1
        y[i] = -1
        h[i] = -1

x.remove(-1)
y.remove(-1)
h.remove(-1)

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:
import collections
import math
n = int(input())
numss = [[int(i) for i in input().split()] for i in range(n)]

def h(x,y,h,cx,cy):
    return h+abs(x-cx)+abs(y-cy)
def hc(x,y,cx,cy,H):
    return H-abs(x-cx)-abs(y-cy)
def check(cx,cy,H):
    flag = True
    for nums in numss:
        # print("-------------")
        # print(hc(nums[0],nums[1],cx,cy,H) )
        # print(nums[2])
        # print("--------------")
        if hc(nums[0],nums[1],cx,cy,H) == nums[2]:
            # print("!!!!!")
            pass
        else:
            flag=False
            break
    return flag
ans=[]
for cx in range(101):
    for cy in range(101):
        for nums in numss:
            H=h(nums[0],nums[1],nums[2],cx,cy)
            # print(cx,cy,H)
            if check(cx,cy,H):
                ans.append(cx)
                ans.append(cy)
                ans.append(H)
                break
print(ans[0],ans[1],ans[2])

Submission status: Runtime Error

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


for i in range(101):
    for j in range(101):
        decide = False
        for k in range(n - 1):
            gaph = abs((abs(i - x[k]) + abs(j - y[k])) - (abs(i - x[k + 1]) + abs(j - y[k + 1])))
            if gaph != abs(h[k + 1] - h[k]):
                break
        else:
            decide = True
        if decide:
            answerx = i
            answery = j
            answerh = h[0] + abs(i - x[0]) + abs(j - y[0])
            break
    if decide:
        break

print(answerx, answery, answerh)

Submission status: Runtime Error

Solution code:
n = int(input())

info = []
for i in range(n):
    pre = list(map(int,input().split(" ")))
    info.append(pre)
    
end = 0
if n >=3:
    for x in range(101):
        for y in range(101):
            H = info[0][2] + abs(x-info[0][0]) + abs(y-info[0][1])
            if H <= 10**9
                for i in range(1,n):
                    if info[i][2] != H - abs(x-info[i][0]) - abs(y- info[i][1]):
                        break
                else:
                    print(x,y,H)
                    end = 1
                
                if end == 1:
                    break
            if end == 1:
                break
elif n ==2:
    info = sorted(info, key = lambda x:x[2])
    if info[0][0] > info[1][0]:
        h = info[1][2] + info[1][0]
        x = 0
    else:
        h = info[1][2] + 100- info[1][0]
        x = 100
    if info[0][1] > info[1][1]:
        h += info[1][1]
        y = 0
    else:
        h += 100 - info[1][1]
        y =100
    ans = list(map(str,(x,y,h)))
    print(" ".join(ans))

Submission status: Runtime Error

Solution code:

def check(cx, cy, H, x, y, h):
    if (h == 0) and (abs(cx-x)+abs(cy-y) > H):
        return True
    if H-h == abs(cx-x)+abs(cy-y):
        return True
    else:
        return False

def a():
    N = int(input())
    xs = []
    ys = []
    hs = []
    for _ in range(N):
        i = input().split(' ')
        xs.append(int(i[0]))
        ys.append(int(i[1]))
        hs.append(int(i[2]))
    
    for i, h in enumerate(hs):
        if h==0:
            continue
        else:
            init_x = xs[i]
            init_y = ys[i]
            init_h = h
            break
    for cx in range(101):
        for cy in range(101):
                H = abs(cx-init_x)+abs(cy-init_y)+init_h
            flag_stop = False
            for x, y, h in zip(xs, ys, hs):
                if not check(cx, cy, H, x, y, h):
                    flag_stop = True
                    break
            if flag_stop:
                continue
            else:
                print('{} {} {}'.format(cx, cy, H))
                return
a()

Submission status: Runtime Error

Solution code:
N = int(input())
x =[]
y =[]
h =[]
for i in range(N):
    x1, y1, h1 = [int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    h.append(h1)

for i in range(101):
    for j in range(101):
        flag = True
        for k in range(N):

            if k == 0 and h[k] != 0:
                temp = max(abs(x[k]-i) + abs(y[k]-j) + h[k], 0)

            if temp != max(abs(x[k]-i) + abs(y[k]-j) + h[k], 0) and h[k] != 0:
                flag = False

        if flag == True:
            print(i, j, temp)

Submission status: Runtime Error

Solution code:
import numpy as np
n  = int(input())

xs = []
ys = []
hs = []
for k in range(n):
    xx, yy, hh = list(map(int,input().split()))
    xs.append(xx)
    ys.append(yy)
    hs.append(hh)    
x = np.array(xs)
y = np.array(ys)
h = np.array(hs)

from itertools import product
cand = []
for cx, cy in product(range(101), range(101)):
    temp1 = abs(cx - x) + abs(cy - y)
    temp2 = temp1 + h
    if len(temp2[h>0]) < 2:
        continue
    else:
        if np.max(temp2[h > 0]) == np.min(temp2[h>0]):
            cand.append((cx,cy,np.max(temp2[h > 0])))
if len(cand) == 1:
    print(cand[0][0],cand[0][1],cand[0][2])
else:
    aaaaaaaaa

Submission status: Runtime Error

Solution code:
import math
a = list(map(int,input().split()))

b = a[1]//a[0]

c = []

for i in range(1,int(math.sqrt(a[1]))):
    if a[1] % i == 0 and i <= b:
        c.append(i)
c.reverse()
for i in c:
    if a[1] % i == 0:
        print(i)
        break

Submission status: Runtime Error

Solution code:
def run():
	N = int(input())
	lst = list()

	for _ in range(N):
		lst.append(input().split().reverse())

	lst.sort()
	ls = list()
	frag = True
	h = -1

	for i in lst:
		if frag or h != i[0]:
			h = i[0]
			frag = False
			frag_x = False
			frag_y = False
			y, x = i[0:]

			H = 0
			d_x = 0
			d_y = 0

		else:
			if x != i[2] and not frag_x:
				d_x = (x + i[2]) / 2
				H = h + obs(x - d_x)
				frag_x = True

			if y != i[1] and not frag_y:
				d_y = (x + i[2]) / 2
				H = h + obs(y - d_y)
				frag_y = True

	print(d_x, d_y, H)

if __name__ == '__main__':
	run()

Submission status: Runtime Error

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


cxyl = []
for i in range(101):
    for j in range(101):
        cxyl.append((i,j))
cxy = set(cxyl)
hd = {}
for i in range(n):
    for c in list(cxy):
        if h[i] == 0:
            if 1 > abs(x[i]-c[0]) + abs(y[i]-c[1]):
                cxy.remove(c)
                continue
        else:
            H = abs(x[i]-c[0]) + abs(y[i]-c[1]) + h[i]
            if H < 1:
                cxy.remove(c)
                continue
            if c in hd:
                if hd[c] != H:
                    cxy.remove(c)
                    continue
            else:
                hd[c] = H
if len(cxy) != 1:
    raise ValueError
ret = cxy.pop()
print(str(ret[0]) + ' ' + str(ret[1]) + ' ' + str(hd[ret]))

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:
    print(inp[0][0]+1,inp[0][1],1)

Submission status: Runtime Error

Solution code:
N = int(input())
x =[]
y =[]
h =[]
for i in range(N):
    x1, y1, h1 = [int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    h.append(h1)

for i in range(101):
    for j in range(101):
        flag = True
        for k in range(N):
            
            if k == 0 and h[i] != 0:
                temp = max(abs(x[k]-i) + abs(y[k]-j) + h[k], 0)

            if temp != max(abs(x[k]-i) + abs(y[k]-j) + h[k], 0) and h[i] != 0 :
                flag = False

        if flag == True:
            print(i, j, temp)