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

for i in range(101):
    for j in range(101):
        H = -1
        tmp = []
        for l in xyh:
            if l[2]==0:
                tmp.append([l[0],l[1]])
                continue
            h = l[2] + abs(i-l[0]) + abs(j-l[1])
            if H!=-1:
                if H!=h:
                    break
            else:
                H = h
        else:
            if H>=1:
                flag = True
                for mmm in tmp:
                    hhh = H - abs(mmm[0]-i) - abs(mmm[1]-j)
                    if hhh>0:
                        flag = False
                        break
                if flag:
                    print(i,j,H)
                    exit()

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
hs=[xyh[i][-1] for i in range(n)]
mh=max(hs)
if mh==0:
    mh=1
for cx in range(101):
    for cy in range(101):
        for h in range(mh,mh+101):
            j=True
            for i in range(n):
                if max(h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy),0)!=xyh[i][2]:
                    j=False
            if j:
                print(cx,cy,h)
                break

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    cor = [tuple(map(int, input().split())) for i in range(n)]

    cor.sort(reverse=True, key=lambda tup: tup[2])

    for i in range(101):
        for j in range(101):
            if cor[0][2]:
                h = cor[0][2] + abs(i-cor[0][0]) + abs(j-cor[0][1])
            else:
                h = 1

            for x, y, hi in cor:
                if max(h-abs(i-x)-abs(j-y), 0) != hi:
                    break

            else:
                print(i, j, h)
                exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

flag = 0
for i in range(n):
    if data[i][2] > 0:
        flag = 1
        break

if flag == 0:
    print(data[0][0], data[0][1], 0)
else:
    for cx in range(0, 101):
        for cy in range(0, 101):
            for i in range(n):
                if data[i][2] > 0:
                    H = abs(data[i][0]-cx) + abs(data[i][1]-cy) + data[i][2]
            check = 0
            for i in range(n):
                if data[i][2] != max(0, H - abs(data[i][0]-cx) - abs(data[i][1]-cy)):
                    check = 1
            if check == 0:
                print(cx, cy, H)
                exit()

Submission status: Accepted

Solution code:
n=int(input())
x=[]
y=[]
h=[]
for i in range(n):
    s=input().split()
    x.append(int(s[0]))
    y.append(int(s[1]))
    h.append(int(s[2]))
for cx in range(101):
    for cy in range(101):
        for i in range(n):
            if h[i]>0:
                hh=h[i]+abs(cx-x[i])+abs(cy-y[i])
                break
        flag=True
        for i in range(n):
            if h[i]!=max(0,hh-abs(cx-x[i])-abs(cy-y[i])):
                flag=False
                break
        if flag:
            print(cx,cy,hh)

Submission status: Accepted

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)

isOk = False
i = 0
j = 0
constant = -1

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

        constant = -1
        for k in range(n):
            if h[k] != 0:
                temp = h[k] + abs(i - x[k]) + abs(j - y[k])

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for p in range(n):
                if h[p] == 0 and constant - abs(i - x[p]) - abs(j - y[p]) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())

xs = []
ys = []
hs = []

sampleX = -1
sampleY = -1
sampleH = 0

for n in range(N):
  x,y,h = map(int, input().split())
  xs.append(x)
  ys.append(y)
  hs.append(h)

  if h is not 0:
    sampleX = x
    sampleY = y
    sampleH = h

for cx, cy in product(range(101), range(101)):
  H = sampleH + abs(sampleX - cx) + abs(sampleY - cy)
  for x,y,h in zip(xs,ys,hs):
    if not max(H - abs(x-cx) - abs(y-cy), 0) == h:
      break
  else:
    print(cx, cy, H)
    break
else:
  raise "hoge"

Submission status: Accepted

Solution code:
N=int(input().strip())
xyh=[]
for i in range(N):
    xyh.append(list(map(int, input().strip().split())))
xyh=sorted(xyh, key=lambda x:-x[2])

for cx in range(101):
    for cy in range(101):
        flag=True
        Hcand=-1
        for x,y,h in xyh:
            if h==0 and H>0:
                if H-abs(x-cx)-abs(y-cy)>0:
                    flag=False
                    break
            else:
                H= h+abs(x-cx)+abs(y-cy)
                if Hcand==-1:
                    Hcand=H
                else:
                    if Hcand!=H:
                        flag=False
                        break
        if flag:
            break
    if flag:
        break
print("{} {} {}".format(cx,cy,H))

Submission status: Accepted

Solution code:
import sys
fin = sys.stdin.readline
from collections import deque
N = int(fin())
info_list = [[int(elem) for elem in fin().split(' ')] for _ in range(N)]
assert len(info_list[0]) == 3

for cx in range(101):
    for cy in range(101):
        H = None
        queue = deque(info_list)
        while queue:
            x, y, h = queue.popleft()
            if H is None and h != 0:
                H = abs(x - cx) + abs(y - cy) + h
                queue.append([x, y, h])
                continue
            elif H is None and h == 0:
                queue.append([x, y, h])
                continue
            elif H is not None:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    queue.append([x, y, h])
                    break
        if len(queue) != 0:
            continue
        else:
            print("{} {} {}".format(cx, cy, H))
            exit(0)

Submission status: Accepted

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)

for Cx in range(101):
    for Cy in range(101):
        for i in range(N):
            if h[i] != 0:
                H = h[i] + abs(Cx - x[i]) + abs(Cy - y[i])
                break
        
        for i in range(N):
            if h[i] != max(H - (abs(Cx - x[i]) + abs(Cy - y[i])), 0):
                break
        else:
            print (Cx, Cy, H)
            break

Submission status: Accepted

Solution code:
iipt=lambda:int(input())
miipt=lambda:map(int,input().split(" "))
N=iipt()
l=[];
x0,y0,h0=0,0,0
for i in range(N):
    l.append(list(miipt()))
    if l[i][2]:
        x0,y0,h0=l[i]
for cx in range(0,101):
    for cy in range(0,101):
        H=h0+abs(x0-cx)+abs(y0-cy)
        f=False
        for x,y,h in l:
            if h!=max(H-abs(x-cx)-abs(y-cy),0):
                f=True
                break
        if not f:
            print(cx,cy,H)

Submission status: Accepted

Solution code:
# C

# input

N = int(input())
x_list = [0]*N
y_list = [0]*N
h_list = [0]*N

for i in range(N):
    x, y, h = map(int, input().split())
    x_list[i] = x
    y_list[i] = y
    h_list[i] = h
    
# brute force
done = False
for CX in range(101):
    for CY in range(101):
        for i in range(N):
            if h_list[i] > 0:
                H = h_list[i] + abs(CX - x_list[i]) + abs(CY - y_list[i])
                break
        done = True
        for i in range(N):
            if h_list[i] != max(0, H - abs(CX - x_list[i]) - abs(CY - y_list[i])):
                done = False
                break
        if done:
            break
    if done:
        break
print(" ".join([str(CX), str(CY), str(H)]))

Submission status: Accepted

Solution code:
N= int(input())
X=[]
Y=[]
H=[]
f=0
for i in range(N):
    x, y, h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
for CX in range(0,101):
    for CY in range(0, 101):
        for i in range(N):
            if H[i]>0:
                CH=abs(X[i]-CX)+abs(Y[i]-CY)+H[i]
                break
        for i in range(N):
            if max(0,CH-abs(X[i]-CX)-abs(Y[i]-CY))!=H[i]:
                break
            if i==N-1:
                f=1
                break
        if f==1:
            break
    if f==1:
        break
print(str(CX)+" "+str(CY)+" "+str(CH))

Submission status: Accepted

Solution code:
import sys

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

for i in range(101):
    for j in range(101):
        LIST=[]
        for xyh in XYH:
            if xyh[2]==0:
                continue
            else:
                LIST.append(abs(i-xyh[0])+abs(j-xyh[1])+xyh[2])

        if min(LIST)==max(LIST):
            i0,j0,h0=i,j,LIST[0]
        else:
            continue


        CHECK=1


        for xyh in XYH:
            if xyh[2]==0:
                if abs(i0-xyh[0])+abs(j0-xyh[1])<h0:
                    CHECK=0

        if CHECK==1:
            print(i0,j0,h0)

Submission status: Accepted

Solution code:
N = int( input())
X = [ list( map( int, input().split())) for _ in range(N)]
for j in range(N):
    if X[j][2] != 0:
        k = j
        break
A = X[j]
for cx in range(101):
    for cy in range(101):
        H = A[2] + abs( A[0] - cx) + abs( A[1] - cy)
        Flag = True
        for i in range(N):
            if max( H - abs(X[i][0]-cx) - abs(X[i][1] - cy), 0) != X[i][2]:
                Flag = False
                break
        if Flag:
            print('{} {} {}'.format(cx, cy, H))
            break
    if Flag:
        break

Submission status: Accepted

Solution code:
import sys
N = int(raw_input())
arr = []
must = -1
for i in range(N):
    arr.append(list(map(int,raw_input().split())))
    if arr[i][2]:
        must = i
for i in range(101):
    for j in range(101):
        if must!=-1:
            h = arr[must][2]+abs(arr[must][0]-i)+abs(arr[must][1]-j)
            v = 1
            for k in range(N):
                if arr[k][2]:
                    if arr[k][2]+abs(arr[k][0]-i)+abs(arr[k][1]-j)!=h:
                        v = 0
                else:
                    if abs(arr[k][0]-i)+abs(arr[k][1]-j)<h:
                        v = 0
            if v:
                print i,j,h
                sys.exit()
        else:
            v = 1
            for k in range(N):
                if arr[k][0]==i and arr[k][1]==j:
                    v = 0
            if v:
                print i,j,1
                sys.exit()

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))

import numpy as np

N = int(input())
X = np.zeros(N, dtype=np.int64)
Y = np.zeros(N, dtype=np.int64)
H = np.zeros(N, dtype=np.int64)

Q = sorted([inpl() for _ in range(N)], key=lambda x: x[2], reverse=True)

for i, q in enumerate(Q):
    X[i], Y[i], H[i] = q

assert H[0] > 0

for cx in range(101):
    for cy in range(101):
        cH = H[0] + np.abs(X[0] - cx) + np.abs(Y[0] - cy)
        if np.all(H == np.maximum(cH - np.abs(X - cx) - np.abs(Y - cy), 0)):
            print(cx, cy, cH)

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []
h = []
for i in range(n):
    xx,yy,zz = map(int,input().split())	
    x.append(xx)
    y.append(yy)
    h.append(zz)
kk = h.index(max(h))
k= 0
for i in range(101):
    for j in range(101):
        ass = h[kk]+abs(x[kk]-i)+abs(y[kk]-j)
        for r in range(n):
            if h[r] == 0:
                if ass -abs(x[r]-i)-abs(y[r]-j) > 0:
                    ass = -1
            else:
                if ass != abs(x[r]-i)+abs(y[r]-j)+h[r]:
                    ass = -1
        
        if ass != -1:
            print(str(i)+' '+str(j)+ ' '+ str(ass))
            break

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N = input()
ls = []

for i in range(N):
    x, y, h = map(int, raw_input().split())
    ls.append((x, y, h))
    if h > 0:
        stand = x, y, h

for cx in range(101):
    for cy in range(101):
        x, y, h = stand
        H = h + abs(x - cx) + abs(y - cy)
        flag = True
        for x, y, h in ls:
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                flag = False
                break
        if flag:
            print cx, cy, H
            exit()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
xyh = []

bes = -1
for i in range(n):
    xyh.append(na())
    if xyh[-1][2] > 0:
        bes = len(xyh)-1

bx = -1
by = -1
bh = -1
for x in range(101):
    for y in range(101):
        if bh >= 0: continue
        h = abs(xyh[bes][0] - x) + abs(xyh[bes][1] - y) + xyh[bes][2]
        ok = True
        for u in xyh:
            if max(h-abs(u[0]-x)-abs(u[1]-y), 0) != u[2]:
                ok = False
                break
        if ok:
            bx, by, bh = x, y, h

print(bx, by, bh)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    L = [LI() for i in range(N)]
    
    for x in range(101):
        for y in range(101):
            max_num = float('inf')
            ans = 0
            res = True
            for xn, yn, hn in L:
                if hn == 0:
                    max_num = min(min_num, abs(x-xn)+abs(y-yn))
                    if max_num == 0:
                        res = False
                        break
                else:
                    temp = abs(x-xn)+abs(y-yn)+hn
                    if ans != 0 and ans != temp:
                        res = False
                        break
                    else:
                        ans = temp
            if res:
                if ans != 0:
                    print(x,y,ans)
                else:
                    print(x,y,1)
                exit()
    
    
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, x[102] = {}, y[102] = {}, h[102] = {};
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> h[i];
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            int a = abs(i - x[0]) + abs(j - y[0]) + h[0];
            bool w = 0;
            for (int k = 1; k < n; k++) {
                if (abs(i - x[k]) + abs(j - y[k]) + h[k] != a) w = 1;
            }
            if (w == 0) {
                cout << i << ' ' << j << ' ' << a << '\n';
                return 0;
            }
        }
    }
}

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-24 22:31:24 +0900
# LastModified: 2020-09-25 00:42:05 +0900
#


# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    box = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        box.append([x, y, h])
    H_possible = []
    for C_x in range(0, 101):
        for C_y in range(0, 101):
            if box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1]) > 0:
                H_possible.append([C_x, C_y, box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1])])

    for i, (x, y, h) in enumerate(box):
        if i == 0:
            continue
        H_new = []
        for po in H_possible:
            if h+abs(po[0]-x)+abs(po[1]-y) == po[2] or h+abs(po[0]-x)+abs(po[1]-y) == 0:
                H_new.append([po[0], po[1], po[2]])
        H_possible = H_new
    print("{} {} {}".format(H_possible[0][0], H_possible[0][1], H_possible[0][2]))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-24 22:31:24 +0900
# LastModified: 2020-09-25 00:31:33 +0900
#


# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    box = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        box.append([x, y, h])
    H_possible = []
    for C_x in range(0, 101):
        for C_y in range(0, 101):
            if box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1]) > 0:
                H_possible.append([C_x, C_y, box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1])])

    for i, (x, y, h) in enumerate(box):
        if i == 0:
            continue
        H_new = []
        for po in H_possible:
            if h+abs(po[0]-x)+abs(po[1]-y) == po[2] or h+abs(po[0]-x)+abs(po[1]-y) == 0:
                H_new.append([po[0], po[1], po[2]])
        H_possible = H_new
    print("{} {} {}".format(H_possible[0][0], H_possible[0][1], H_possible[0][2]))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-24 22:31:24 +0900
# LastModified: 2020-09-25 00:12:24 +0900
#


# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    box = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        box.append([x, y, h])
    H_possible = []
    for C_x in range(0, 101):
        for C_y in range(0, 101):
            if box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1]) > 0:
                H_possible.append([C_x, C_y, box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1])])

    for i, (x, y, h) in enumerate(box):
        if i == 0:
            continue
        H_new = []
        for po in H_possible:
            if h+abs(po[0]-x)+abs(po[1]-y) == po[2]:
                H_new.append([po[0], po[1], po[2]])
        H_possible = H_new
    print("{} {} {}".format(H_possible[0][0], H_possible[0][1], H_possible[0][2]))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-24 22:31:24 +0900
# LastModified: 2020-09-25 00:11:12 +0900
#


# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    box = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        box.append([x, y, h])
    H_possible = []
    for C_x in range(0, 101):
        for C_y in range(0, 101):
            if box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1]) >= 0:
                H_possible.append([C_x, C_y, box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1])])

    for i, (x, y, h) in enumerate(box):
        if i == 0:
            continue
        H_new = []
        for po in H_possible:
            if h+abs(po[0]-x)+abs(po[1]-y) == po[2]:
                H_new.append([po[0], po[1], po[2]])
        H_possible = H_new
    print("{} {} {}".format(H_possible[0][0], H_possible[0][1], H_possible[0][2]))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-24 22:31:24 +0900
# LastModified: 2020-09-25 00:03:32 +0900
#


# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    box = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        if h < 0:
            box.append([x, y, h])
    H_possible = []
    for C_x in range(0, 101):
        for C_y in range(0, 101):
            H_possible.append([C_x, C_y, box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1])])
#    if len(H_possible) == 1:
#        print("{} {} {}".format())
    for i, (x, y, h) in enumerate(box):
        if i == 0:
            continue
        H_new = []
        for po in H_possible:
            if h+abs(po[0]-box[i][0])+abs(po[1]-box[i][1]) == po[2]:
                H_new.append([po[0], po[1], po[2]])
        H_possible = H_new
    print("{} {} {}".format(H_possible[0][0], H_possible[0][1], H_possible[0][2]))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-24 22:31:24 +0900
# LastModified: 2020-09-24 23:40:22 +0900
#


# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    box = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        if h != 0:
            box.append([x, y, h])
    H_possible = []
    for C_x in range(0, 101):
        for C_y in range(0, 101):
            H_possible.append([C_x, C_y, box[0][2]+abs(C_x-box[0][0])+abs(C_y-box[0][1])])

    for i, (x, y, h) in enumerate(box):
        if i == 0:
            continue
        H_new = []
        for C_x in range(0, 101):
            for C_y in range(0, 101):
                if [C_x, C_y, h+abs(C_x-x)+abs(C_y-y)] in H_possible:
                    H_new.append([C_x, C_y, h+abs(C_x-x)+abs(C_y-y)])
        H_possible = H_new
    print("{} {} {}".format(H_possible[0], H_possible[1], H_possible[2]))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

def answer(cx, cy, xyh):
    h_list = []
    flag = True
    for x, y, h in xyh:
        if h > 0:
            tmp_h = abs(x - cx) + abs(y - cy) + h
            h_list.append(tmp_h)
        if min(h_list) != max(h_list):
            flag = False
    if flag:
        return print(cx, cy, h_list[0], sep=' ')

for cx in range(0, 101):
    for cy in range(0, 101):
        answer(cx, cy, xyh)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    xyh = [[int(i) for i in input().split()] for _ in range(N)]

    for cx in range(0, 101):
        for cy in range(0, 101):
            x, y, h = xyh[0]
            t = h + abs(cx - x) + abs(cy - y)

            f = True
            for x, y, h in xyh[1:]:
                t1 = h + abs(cx - x) + abs(cy - y)
                if t != t1:
                    f = False
                    break
            if f:
                cx1, cy1 = cx, cy
    h = xyh[0][2] + abs(xyh[0][0] - cx1) + abs(cy1 - xyh[0][1])
    print(cx1, cy1, h)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    xyh = [[int(i) for i in input().split()] for _ in range(N)]

    for cx in range(0, 101):
        for cy in range(0, 101):
            x, y, h = xyh[0]
            t = h + abs(cx - x) + abs(cy - y)

            f = True
            for x, y, h in xyh[1:]:
                t1 = h + abs(cx - x) + abs(cy - y)
                if t == t1:
                    f = True
                else:
                    f = False
                    break
            if f:
                cx1, cy1 = cx, cy
    h = xyh[0][2] + abs(xyh[0][0] - cx1) + abs(cy1 - xyh[0][1])
    print(cx1, cy1, h)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    l = [i_list() for i in range(n)]

    for x in range(101):
        for y in range(101):
            H = l[0][2] + abs(x-l[0][0]) + abs(y-l[0][1])
            flg = True
            for x1, y1, h1 in l[1:]:
                if H != h1 + abs(x-x1) + abs(y-y1):
                    flg = False
                    break
            if flg == True:
                ans = [x,y]
    H = l[0][2] + abs(ans[0]-l[0][0]) + abs(ans[1]-l[0][1])
    print(" ".join(map(str, ans)) +" "+str(H))



if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    int tmp;
    rep(i, n)
    {
        if (h[i])
        {
            tmp = i;
            break;
        }
    }

    rep(cx, 100 + 1)
    {
        rep(cy, 100 + 1)
        {
            int H = h[tmp] + abs(x[tmp] - cx) + abs(y[tmp] - cy);
            bool ck = true;
            rep(i, n)
            {
                int hh = max(H - abs(x[i] - cx) - abs(y[i] - cy), 0);
                if (hh != h[i])
                    ck = false;
            }
            if (ck)
            {
                printf("%d %d %d\n", cx, cy, H);
            }
        }
    }
    return 0;
}

Submission status: Runtime Error

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

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


for cx in range(101):
    for cy in range(101):
        H = -1
        for _,cond in enumerate(conditions):
            if cond[2] > 0:
                H_tmp = cond[2] + abs(cond[0]-cx) + abs(cond[1]-cy)
                if H == -1:
                    H = H_tmp
                else:
                    if H_tmp != H:
                        H = -2
                        break

        if H == -2:
            continue

        for _,cond in enumerate(conditions):
            if cond[2] == 0:
                if H > abs(cond[0]-cx) + abs(cond[1]-cy):
                    H = -2
                    break
        
        if H == -2:
            continue
        
        print(cx,cy,H)
        exit(1)

Submission status: Runtime Error

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

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

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

num_cnd = len(conditions)
if num_cnd==1:
    print(conditions[0],conditions[1],conditions[2])
    exit(0)

for cx in range(101):
    for cy in range(101):
        cnt = 0
        h = 0
        for i,cnd in enumerate(conditions):
            h_tmp = getH(cnd[0], cx, cnd[1], cy, cnd[2])
            if h_tmp >= 1:
                if i==0:
                    h = h_tmp
                    cnt += 1
                elif h == h_tmp:
                    cnt += 1
                    if cnt == num_cnd:
                        print(cx,cy,h)
                        exit(0)
                else:
                    break
            else:
                break
        

print('No')

Submission status: Runtime Error

Solution code:
N = int(input())

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

flg = False
for i in range(101):
    if flg:
        break
    for j in range(101):
        if flg:
            break
        for k in range(N):
            h = abs(xyh[k][0]-i)+abs(xyh[k][1]-j)+xyh[k][2]

            if k>=1 and h != h_before:
                break
            elif k == N-1 and h == h_before:
                flg = True
                ans = [i,j,h]
            h_before = h


print(str(ans[0])+' '+str(ans[1])+' '+str(ans[2]))

Submission status: Runtime Error

Solution code:
n = int(input())
if n == 1:
    x, y, h = map(int, input().split())
    print(x, y, h)
    exit()
for _ in range(n):
    s = [list(map(int, input().split())) for _ in range(n)]
    for i in range(101):
        for j in range(101):
            h = -1
            ok = 1
            for t in s:
                if t[2] == 0:
                    ok += 1
                elif h == -1:
                    h = abs(t[0] - i) + abs(t[1] - j) + t[2]
                else:
                    h0 = abs(t[0] - i) + abs(t[1] - j) + t[2]
                    if h == h0:
                        ok += 1
            if ok == n:
                ok = 0
                for t in s:
                    if h == abs(t[0] - i) + abs(t[1] - j) + t[2] or (t[2] == 0 and abs(t[0] - i) + abs(t[1] - j) <= h):
                        ok += 1
                if ok == n:
                    print(i, j, h)
                    exit()