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:
def main():
    """
    1 <= N      <= 100
    0 <= xi, yi <= 100
    0 <= hi     <= 10^9
    """
    N = int(input())
    x, y, h = zip(*(
        map(int, input().split())
        for _ in range(N)
    ))

    import sys
    if "PyPy" in sys.version:
        ans4 = loop_xyh_N(x, y, h)
        print(*ans4)
    else:
        # ans = no_sub(x, y, h)
        ans1 = editorial_movie(x, y, h)
        ans2 = editorial_pdf(x, y, h)
        ans3 = ref_sub_xyn(x, y, h)
        print(*ans2)
        assert ans1 == ans2 == ans3


def h_H(cx, cy, x, y):
    return - abs(x - cx) - abs(y - cy)


def no_sub(x, y, h):
    max_h = -1
    ans = None
    dict_h = {(_x, _y): _h for _x, _y, _h in zip(x, y, h)}
    for _x, _y, _h in zip(x, y, h):
        for cx in range(1, 100+1):
            for cy in range(1, 100+1):
                tmp = h_H(cx, cy, _x, _y)
                pos = (cx, cy)
                H = _h - tmp
                if pos in dict_h and H != dict_h[pos]:
                    continue

                if H > max_h:
                    max_h = H
                    ans = _x, _y, H

                # print((_x, _y), (cx, cy), _h, tmp, sep="\t")

    return ans


def editorial_movie(x, y, h):
    """
    H >= 1, これ重要
        コンテスト中にこれを意識していなかった
        入力の制約しか意識していなかった

    h(x, y) = max(H - |x - Cx| - |y - Cy|, 0)
    より
        h(x,y) > 0:
            H            - |x - Cx| - |y - Cy| > 0
            H  = h(x, y) + |x - Cx| - |y - Cy|
        h(x,y) = 0:
            H            - |x - Cx| - |y - Cy| <= 0
            H <= h(x, y) + |x - Cx| + |y - Cy|
            頂点なら制約を満たしていない
    """
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            # 頂上がどれくらいの高さであってほしいか。
            # -1はまだ良く分からない時。0以上は確定してるとき
            # -2はダメだって分かった時
            need_h = -1

            # h=0 より大きい場合の検証
            for _x, _y, _h in zip(x, y, h):
                if not _h > 0:
                    continue

                # 頂点候補座標および調査座標の組合せにおいてHになるべき値
                tmp = _h + abs(_x - cx) + abs(_y - cy)
                if need_h == -1:
                    need_h = tmp
                elif need_h != tmp:
                    need_h = -2
                    break

            if need_h == -2:
                continue

            # h=0 の検証
            for _x, _y, _h in zip(x, y, h):
                if not _h == 0:
                    continue

                # _h == 0 より、計算式上では省略してマンハッタン距離のみ求めている
                dist = abs(_x - cx) + abs(_y - cy)
                if need_h > dist:
                    need_h = -2
                    break

            if need_h == -2:
                continue

            return cx, cy, need_h


def ref_sub_xyn(x, y, h):
    """
    https://beta.atcoder.jp/contests/abc112/submissions/3348987
    """
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            # 頂点候補をだしておき、0なら1に補正して確実に頂点候補とする
            # h_min, h_max は矛盾の確認用に２つ用意
            h_min = h[0] + abs(x[0] - cx) + abs(y[0] - cy)
            h_max = h_min
            if h[0] == 0:
                h_min = 1

            for _x, _y, _h in zip(x[1:], y[1:], h[1:]):
                # min: TODO
                h_max = min(h_max, _h + abs(_x - cx) + abs(_y - cy))
                if _h != 0:
                    h_min = max(h_min, _h + abs(_x - cx) + abs(_y - cy))

            if h_min == h_max:
                return cx, cy, h_min


def editorial_pdf(x, y, h):
    """
    条件を満たすピラミッドがただ 1 つなのであれば、必ず以下のものが 1 個以上存在します。
        • 調査で得られた情報のうち、hi ≥ 1 を満たす情報 (xi, yi, hi)。

    なぜなら、全部 hi = 0 であるとき、
    調査を行っていない整数座標を中心とする高さ 1 のピラミッドが条件を満たしてしまうので、
        最低でも 101×101− N 個、N = 100 の場合 10, 101 個以上の条件を満たすピラミッドが存在することになるからです。
        そこで、前述の条件を満たす情報のうち 1 個を (xt, yt, ht) とおきます。
    """
    # 候補, 調査点の高さ0のときはない（解説より）
    gx, gy, gh = (-1, -1, -1)
    for xyh in zip(x, y, h):
        if xyh[-1] >= 1:
            gx, gy, gh = xyh

    for cx in range(100 + 1):
        for cy in range(100 + 1):
            v = gh + abs(gx - cx) + abs(gy - cy)
            v = max(v, 0)
            flag = True

            for _x, _y, _h in zip(x, y, h):
                # _h との検証
                vv = v - abs(_x - cx) - abs(_y - cy)
                if _h != vv:
                    flag = False

            if flag:
                return cx, cy, v


def loop_xyh_N(x, y, h):
    h_base = max(h)

    for cx in range(100 + 1):
        for cy in range(100 + 1):
            # 探索範囲100x100より、調査点の候補より200以内
            for ch in range(h_base, h_base + 200 + 1):
                ok = True
                for _x, _y, _h in zip(x, y, h):
                    tmp = _h + abs(_x - cx) + abs(_y - cy)
                    if _h > 0 and ch != tmp:
                        ok = False
                        break
                    elif _h == 0 and ch > tmp:
                        ok = False
                        break

                if ok:
                    return cx, cy, ch


def f2(x, y, h):
    chs = []
    for _x, _y, _h in zip(x, y, h):
        for cx in range(0, 100 + 1):
            for cy in range(0, 100 + 1):
                tmp = h_H(cx, cy, _x, _y)
                print((_x, _y), (cx, cy), _h, tmp, sep="\t")

    return 1


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def check():
    for k in range(0,n):
        if h[k]!=0:
            break
    for i in range(0,101):
        for j in range(0,101):
            flag=True
            h1=abs(i-x[k])+abs(j-y[k])+h[k]
            for l in range(k+1,n):
                if h[l]!=max(h1-abs(i-x[l])-abs(j-y[l]),0)
                    flag=False
                    break
            if flag==True:
                print(i,j,h1)
                return
            
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())
check()

Submission status: Runtime Error

Solution code:
// finish date: 2018/09/30

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

struct hxy {
    int h, x, y;

    bool operator<(const hxy &another) const {
        //メンバ変数であるnum1で比較した結果を
        //この構造体の比較とする
        return h < another.h;
    }
};

int main() {
    int N;
    cin >> N;
    vector<hxy> p(N);
    rep(i, N) {
        int in1, in2, in3;
        cin >> in1 >> in2 >> in3;
        p[i].h = in3;
        p[i].x = in1;
        p[i].y = in2;
    }
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    rep(x, 101) {
        rep(y, 101) {
            int H = p[0].h + abs(x - p[0].x) + abs(y - p[0].y);
            FOR(i, 1, N) {
                int check = p[i].h + abs(x - p[i].x) + abs(y - p[i].y);
                if (!((p[i].h == 0 && check <= H) || (p[i].h != 0 && check == H))) break;
                if (i == N - 1) {
                    cout << x << " " << y << " " << H << endl;
                    return 0;
                }
            }
        }
    }


    return 0;
}

Submission status: Runtime Error

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

def abs(n):
    if n < 0:
        return -1*n
    else:
        return n

def max(a,b):
    if a > b:
        return a
    else:
        return b

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

def get_center_height(Cx,Cy,x0,y0,h0):
    H = h0 + abs(Cx - x0) + abs(Cy - y0)
    return H

for Cy in range(101):
    for Cx in range(101):
        Ch = get_center_height(Cx,Cy,xlist[0],ylist[0],hlist[0])
        judge=[]
        for i in range(1,N):
            if height(Cx,Cy,Ch,xlist[i],ylist[i]) == hlist[i]:
                judge.append(True)
            else:
                judge.append(False)
        if False not in judge:
            answer=[Cx,Cy,Ch]
            break

print('{} {} {}'.format(answer[0],answer[1],answer[2]))

Submission status: Runtime Error

Solution code:
	h.append(xyh[2])

for i in range(101):
	for j in range(101):
		for k in range(n):
			if h[k] != 0:
				height = abs(i-x[k]) + abs(j-y[k]) + h[k]
				break
			
		flag = 0
		for k in range(n):
			if h[k] != max(height- abs(i-x[k]) - abs(j-y[k]) , 0):
				flag = 1
				break
			
		if flag == 0:
			ans = [i,j,height]
			break
		
	
print('{0} {1} {2}'.format(ans[0], ans[1], ans[2]))

Submission status: Runtime Error

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

max = 100

for posX in range(0,101) :
    for posY in range(0,101) :
        needH = -1
        
        for i in range(0,n) :
            if p[i][2] > 0 :
                tmp = p[i][2] + abs(posY-p[i][1]) + abs(posX - p[i][0])
                if needH == -1 :
                    needH = tmp
            else :
                if needH != tmp :
                    needH = -2
                    break
        if needH == -2 : continue
            
        for i in range(0,n) :
            if p[i][2] == 0 :
                dist =  abs(posY-p[i][1]) + abs(posX - p[i][0])
                if needH > dist :
                    needH = -2
                    break
        if needH == -2 : continue
        
        print(posX, posY, needH)
        break
    break

Submission status: Runtime Error

Solution code:
import numpy as np

input_N = input().split()
N = int(input_N[0])

input_xyh = [input().split() for i in range(N)]

xyh = np.array(input_xyh)
xyh = xyh.astype(np.int64)
xyh = xyh.T
h = xyh[0]
x = xyh[1]
y = xyh[2]

# [0, 100]に座標があるのでMAXを定義する
coord_max = 100

for pos_y in range(coord_max):
    for pos_x in range(coord_max):
        # 頂上がどれくらいの高さであってほしいか
        # -1はまだよくわからないとき、0以上は確定
        # -2はダメ
        needH = -1

        for i in range(N):
            if h[i] > 0:
                tmp = h[i] + abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break
        if needH == -2:
            continue

        for i in range(N):
            # 高さが0の場合に矛盾してないか調べる
            if h[i] == 0:
                dist = abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH > dist:
                    needH = -2
                    break

        if needH == -2: continue

        # 見つけられたら答えをそのまま返す
        print(pos_x + " " + pos_y + " " + needH)

Submission status: Runtime Error

Solution code:
import numpy as np

input_N = input().split()
N = int(input_N[0])

input_xyh = [input().split() for i in range(N)]

xyh = np.array(input_xyh)
xyh = xyh.astype(np.int64)
xyh = xyh.T
h = xyh[0]
x = xyh[1]
y = xyh[2]

# [0, 100]に座標があるのでMAXを定義する
coord_max = 100

for pos_y in range(coord_max):
    for pos_x in range(coord_max):
        # 頂上がどれくらいの高さであってほしいか
        # -1はまだよくわからないとき、0以上は確定
        # -2はダメ
        needH = -1

        for i in range(N):
            if h[i] > 0:
                tmp = h[i] + abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break
        if needH == -2:
            continue

        for i in range(N):
            # 高さが0の場合に矛盾してないか調べる
            if h[i] == 0:
                dist = abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH > dist:
                    needH = -2
                    break

        if needH == -2: continue

        # 見つけられたら答えをそのまま返す
        print(pos_x + " " + pos_y + " " + needH)

return 0

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
X=[]
Y=[]
H=[]
MAX=100
for i in range(n):
    x,y,h=map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
for posX in range(MAX+1):
    for posY in range(MAX+1):
        needH=-1
        for i in range(n):
            if H[i]>0:
                tmp=H[i]+abs(X[i]-posX)+abs(Y[i]-posY)
                if needH==-1:
                    needH=tmp
                else:
                    if needH!=tmp:
                        needH=-2
                        break
                 
        if needH==-2:
            continue
        for i in range(n):
            if H[i]==0: 
                dis=abs(X[i]-posX)+abs(Y[i]-posY)
                if needH>dist:
                    needH=-2
                    break 
        if needH==-2:
            continue
        print(posX,posY,needH)

Submission status: Runtime Error

Solution code:
MAX=100
for PosY in range(MAX+1):
    for PosX in range(MAX+1):
        needH=-1
        for i in range(N):
            tmp=xyh[i][2]+abs(PosX-xyh[i][0])+abs(PosY-xyh[i][1])
            if needH==-1:
                needH=tmp
            else:
                if needH!=tmp:
                    needH=-2
                    break
        if needH==-2:
            continue
        for i in range(N):
            if xyh[i][2]==0:
                dist=abs(PosX-xyh[i][0])+abs(PosY-xyh[i][1])
                if needH>dist:
                    needH=-2
                    break
        if needH==-2:
            continue
        print(PosX,PosY,needH)

Submission status: Runtime Error

Solution code:
def main():
    """
    1 <= N      <= 100
    0 <= xi, yi <= 100
    0 <= hi     <= 10^9
    """
    N = int(input())
    x, y, h = zip(*(
        map(int, input().split())
        for _ in range(N)
    ))

    # ans = no_sub(x, y, h)
    ans1 = editorial_movie(x, y, h)
    ans2 = ref_sub_xyn(x, y, h)
    assert ans1 == ans2
    print(*ans1)


def h_H(cx, cy, x, y):
    return - abs(x - cx) - abs(y - cy)


def no_sub(x, y, h):
    max_h = -1
    ans = None
    dict_h = {(_x, _y): _h for _x, _y, _h in zip(x, y, h)}
    for _x, _y, _h in zip(x, y, h):
        for cx in range(1, 100+1):
            for cy in range(1, 100+1):
                tmp = h_H(cx, cy, _x, _y)
                pos = (cx, cy)
                H = _h - tmp
                if pos in dict_h and H != dict_h[pos]:
                    continue

                if H > max_h:
                    max_h = H
                    ans = _x, _y, H

                # print((_x, _y), (cx, cy), _h, tmp, sep="\t")

    return ans


def editorial_movie(x, y, h):
    """
    H >= 1, これ重要
        コンテスト中にこれを意識していなかった
        入力の制約しか意識していなかった

    h(x, y) = max(H - |x - Cx| - |y - Cy|, 0)
    より
        h(x,y) > 0: H  = h(x, y) + |x - Cx| - |y - Cy|
        h(x,y) = 0:
            頂点なら制約を満たしていない
                    H <= h(x, y) + |x - Cx| - |y - Cy|
    """
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            # 頂上がどれくらいの高さであってほしいか。
            # -1はまだ良く分からない時。0以上は確定してるとき
            # -2はダメだって分かった時
            need_h = -1

            # h=0 より大きい場合の検証
            for _x, _y, _h in zip(x, y, h):
                if not _h > 0:
                    continue

                # 頂点候補座標および調査座標の組合せにおいてHになるべき値
                tmp = _h + abs(_x - cx) + abs(_y - cy)
                if need_h == -1:
                    need_h = tmp
                elif need_h != tmp:
                    need_h = -2
                    break

            if need_h == -2:
                continue

            # h=0 の検証
            for _x, _y, _h in zip(x, y, h):
                if not _h == 0:
                    continue

                # _h == 0 より、計算式上では省略してマンハッタン距離のみ求めている
                dist = abs(_x - cx) + abs(_y - cy)
                if need_h > dist:
                    need_h = -2
                    break

            if need_h == -2:
                continue

            return cx, cy, need_h


def ref_sub_xyn(x, y, h):
    """
    https://beta.atcoder.jp/contests/abc112/submissions/3348987
    """
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            # 頂点候補をだしておき、0なら1に補正して確実に頂点候補とする
            h_min = h[0] + abs(x[0] - cx) + abs(y[0] - cy)
            h_max = h_min
            if h[0] != 0:
                h_min = 1

            # h_min, h_max は矛盾の確認用に２つ用意
            for _x, _y, _h in zip(x[1:], y[1:], h[1:]):
                h_max = max(h_max, _h + abs(_x - cx) + abs(_y - cy))
                if _h != 0:
                    h_min = max(h_min, _h + abs(_x - cx) + abs(_y - cy))

                if h_min == h_max:
                    return cx, cy, h_min


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

ans = None
for cx in range(101):
    for cy in range(101):
        H_tmp = 0
        for xi, yi, hi in xyh:
            dx = xi - cx if xi >= cx else cx - xi
            dy = yi - cy if yi >= cy else cy - yi
            if H_tmp == 0 or H_tmp == hi + dx + dy: H_tmp = hi + dx + dy
            else: break
        else:
            ans = (cx, cy, H_tmp)
        if ans != None: break
    if ans != None: break

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

Submission status: Runtime Error

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

for CX in range(101):
    for CY in range(101):
        ans = True
        i = 0
        for x, y, h in xyh:
            if h != 0:
                if i == 0:
                    H = h + abs(x - CX) + abs(y - CY)
                if H != h + abs(x - CX) + abs(y - CY):
                    ans = False
                    break
            i += 1
            if not ans:
                break
        for x, y, h in xyh:
            if not ans:
                break
            if h == 0:
                if h != max(H - abs(x - CX) + abs(y - CY), 0):
                    ans = False
        if ans:
            print(CX, CY, H)
    if ans:
        break

Submission status: Runtime Error

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

flag = False
for i in range(101):
    for j in range(101):
        H = abs(jouhou[0][0] - i) + abs(jouhou[0][1] - j) + jouhou[0][2]
        for k in range(1, N):
            if abs(jouhou[k][0] - i) + abs(jouhou[k][1] - j) + jouhou[k][2] != H:
                break
        else:
            cx = i
            cy = j
            flag = True
            break
    if flag:
        break
print(cx, cy, H)

Submission status: Runtime Error

Solution code:
N = int(input())

x_list=[]
y_list=[]
h_list=[]

def all_same(items):
	return all(map(lambda x: x == items[0], items))

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)
		
for cy in range(101):
	for cx in range(101):
		i = -1	
		for h in h_list:
			i += 1
			if h >= 1:
				H = abs(cx - x_list[i])+abs(cy - y_list[i])+h
				break
		for i in range(N):
			h = max(H-abs(cx - x_list[i])-abs(cy - y_list[i]), 0)
			H_list.append(h) 
		if all_same(H_list):
			print(str(cx)+' '+str(cy)+' '+str(H))
			break		
	else:
		continue
	break

Submission status: Runtime Error

Solution code:
N = int(input())

x_list=[]
y_list=[]
h_list=[]

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)

i = -1	
for h in h_list:
	i += 1
	if h >= 1:
		H = abs(cx - x_list[i])+abs(cy - y_list[i])+h
		break
		
for cy in range(101):
	for cx in range(101):
		for i in range(N):
			h = max(H-abs(cx - x_list[i])-abs(cy - y_list[i]), 0)
			H_list.append(h) 
			if h != H:
				break 
		if len(H_list) == N:
			print(str(cx)+' '+str(cy)+' '+str(H_list[0]))
			break		
	else:
		continue
	break

Submission status: Runtime Error

Solution code:
#N=2のときは高さHが大きい方が無条件で中心座標(一意性より)
#N=1のときはそこが中心座標
#N=3の時は
#最低点+距離=最高点の場合、その最高点が中心座標
#最低点+距離<最高点ということは起きない
#最低点+距離>最高点の場合、どこかに中心座標がある

#素直に全探索で良かった。

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

#print(l)
for i in range(101):
    for j in range(101):
        a = l[0]
        h = a[2]+abs(a[0]-i)+abs(a[1]-j)
        if h<0:
            h=0
        for k in l:
            if h != k[2]+abs(k[0]-i)+abs(k[1]-j)
                break
        else:
            print(str(i)+' '+str(j)+' '+str(h))

Submission status: Runtime Error

Solution code:
N = int(input())

x_list=[]
y_list=[]
h_list=[]

def all_same(items):
	return all(map(lambda x: x == items[0], items))

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)
	
if h_list[0] == 0:
	h_list[0], h_list[1]=h_list[1], h_list[0]	
	x_list[0], x_list[1]=x_list[1], x_list[0]
	y_list[0], y_list[1]=y_list[1], y_list[0]		
		
for cy in range(101):
	for cx in range(101):
		H_list = []
		for i in range(N):
			if h_list[i] != 0:
				H = abs(cx - x_list[i])+abs(cy - y_list[i])+h_list[i]
				H_list.append(H) 
			if h_list[i] == 0:
				h_mathematical=H_list[0]-abs(cx-x_list[i])-abs(cy-y_list[i])
				if h_mathematical > 0:
					break 
		if len(H_list) == N:
			if all_same(H_list):
				print(str(cx)+' '+str(cy)+' '+str(H_list[0]))
				break		
	else:
		continue
	break

Submission status: Runtime Error

Solution code:
N = int(input())

x_list=[]
y_list=[]
h_list=[]

def all_same(items):
	return all(map(lambda x: x == items[0], items))

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)	
		
for cy in range(101):
	for cx in range(101):
		H_list = []
		for i in range(N):
			if h_list[i] != 0:
				H = abs(cx - x_list[i])+abs(cy - y_list[i])+h_list[i]
				H_list.append(H) 
			if h_list[i] == 0:
				h_mathematical=H_list[0]-abs(cx-x_list[i])-abs(cy-y_list[i])
				if h_mathematical > 0:
					break
		if len(H_list) == N:
			if all_same(H_list):
				print(str(cx)+' '+str(cy)+' '+str(H_list[0]))
				break		
	else:
		continue
	break

Submission status: Runtime Error

Solution code:
N = int(input())

x_list=[]
y_list=[]
h_list=[]

def all_same(items):
	return all(map(lambda x: x == items[0], items))

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)	
		
for cy in range(101):
	for cx in range(101):
		H_list = []
		for i in range(N):
			if h_list[i] != 0:
				H = abs(cx - x_list[i])+abs(cy - y_list[i])+h_list[i]
				H_list.append(H) 
			if h_list[i] == 0:
				h_mathematical=H_list[0]-abs(cx-x)-abs(cy-y)
				if h_mathematical > 0:
					break
		if len(H_list) == N:
			if all_same(H_list):
				print(str(cx)+' '+str(cy)+' '+str(H_list[0]))
				break		
	else:
		continue
	break

Submission status: Runtime Error

Solution code:
N = int(input())

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

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

# 全探索
def search():
    for Cx in range(101):
        for Cy in range(101):
            x, y, h = tuple(coords[0])
            H = h + abs(Cx - x) + abs(Cy - y)
            for x, y, h in coords:
                if max(H - abs(Cx - x) - abs(Cy - y), 0) != h:
                    break
            else:
                return (Cx, Cy, H)

print("{} {} {}".format(search()))

Submission status: Runtime Error

Solution code:
N = int(input())

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

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

# 全探索
def search():
    for Cx in range(101):
        for Cy in range(101):
            x, y, h = coords[0]
            H = h + abs(Cx - x) + abs(Cy - y)
            for x, y, h in coords:
                if max(H - abs(Cx - x) - abs(Cy - y), 0) != h:
                    break
            else:
                return (Cx, Cy, H)

print("{} {} {}".format(search()))

Submission status: Runtime Error

Solution code:
N = int(input())

x_list=[]
y_list=[]
h_list=[]

def all_same(items):
	return all(map(lambda x: x == items[0], items))

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)	
		
for cy in range(N+1):
	for cx in range(N+1):
		H_list = []
		for i in range(N):
			if h_list[i] != 0:
				H = abs(cx - x_list[i])+abs(cy - y_list[i])+h_list[i]
				H_list.append(H) 
			if h_list[i] == 0:
				H = abs(cx - x_list[i])+abs(cy - y_list[i])+h
				if H > 0:
					break
		if all_same(H_list):
			print(str(cx)+' '+str(cy)+' '+str(H_list[0]))
			break		
	else:
		continue
	break

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(list(map(int, input().split())))
a.sort(key=lambda x:(-x[2],x[0]+x[1]))
if n==1:
    print(a[0][0],a[0][1],a[0][2])
else:
    for i in range(101):
        for j in range(101):
            ansh=[0]*(n+2)
            for k,(x,y,h) in enumerate(a):
                ansh[k]=h+abs(i-x)+abs(j-y)
                if h==0:ansh[k]=min[ans[k],max(ansh[:k])]
            if len(set(ansh))==2:
                print(i,j,ansh[1])

Submission status: Runtime Error

Solution code:
N = int(input())
points = [[int(s) for s in input().split()] for i in range(N)]
points.sort(key=lambda x: x[2])
h_max = points[0][2]

for Cx in range(101):
    for Cy in range(101):
        kouho = set()
        for x, y, h in points:
            if len(kouho) > 1:
                break  # 頂点が一意でない

            if h > 0:
                """観測点の高さが1以上なら頂点高を予測"""
                kouho.add(h + abs(x - Cx) + abs(y - Cy))
            else:
                """観測点の高さが0なら式を満たしているかチェック"""
                if list(kouho)[0] - abs(x - Cx) - abs(y - Cy) != 0:
                    kouho = set()
                    break

        if len(kouho) == 1:
            print('{} {} {}'.format(Cx, Cy, list(kouho)[0]))
            exit()

Submission status: Runtime Error

Solution code:
N = int(input())
points = [[int(s) for s in input().split()] for i in range(N)]
h_max = max(h for x, y, h in points)

for Cx in range(101):
    for Cy in range(101):
        kouho = set()
        for x, y, h in points:
            if len(kouho) > 1:
                break  # 頂点が一意でない

            if h > 0:
                kouho.add(h + abs(x - Cx) + abs(y - Cy))
            else:
                if list(kouho)[0] - abs(x - Cx) - abs(y - Cy) != 0:
                    kouho = set()
                    break

        if len(kouho) == 1:
            print('{} {} {}'.format(Cx, Cy, list(kouho)[0]))
            exit()

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
X=[]
Y=[]
H=[]
MAX=100
for i in range(n):
    x,y,h=map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
for posX in range(MAX+1):
    for posY in range(MAX+1):
        needH=-1
        for i in range(n):
            if H[i]>0:
                tmp=H[i]+abs(X[i]-posX)+abs(Y[i]-posY)
                if needH==-1:
                    needH=tmp
                else:
                    if needH!=tmp:
                        needH=-2
                        break
  
        if needH==-2:
            continue
        for i in range(n):
            if H[i]==0:    
                dis=abs(X[i]-posX)+abs(Y[i]-posY)
                if needH>dist:
                    needH=-2
                    break         
        if needH==-2:
            continue
        print(posX,posY,needH)
        sys.exit()

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
X=[]
Y=[]
H=[]
MAX=100
for i in range(n):
    x,y,h=map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
for posX in range(MAX+1):
    for posY in range(MAX+1):
        needH=-1
        for i in range(n):
            if H[i]>0:
                tmp=H[i]+abs(X[i]-posX)+abs(Y[i]-posY)
                if needH==-1:
                    needH=tmp
                else:
                    if needH!=tmp:
                        needH=-2
                        break
  
        if needH==-2:
            continue
        for i in range(n):
            if H[i]==0:    
                dis=abs(X[i]-posX)+abs(Y[i]-posY)
                if needH>dist:
                    needH=-2
                    break         
        if needH==-2:
            continue
        print(posX,posY,needH)
        sys.exit()

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
X=[]
Y=[]
H=[]
MAX=100
for i in range(n):
    x,y,h=map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
for posX in range(MAX+1):
    for posY in range(MAX+1):
        needH=-1
        for i in range(n):
            if H[i]>0:
                tmp=H[i]+abs(X[i]-posX)+abs(Y[i]-posY)
                if needH==-1:
                    needH=tmp
                else:
                    if needH!=tmp:
                        needH=-2
                        break
  
        if needH==-2:
            continue
        for i in range(n):
            if H[i]==0:    
                dis=abs(X[i]-posX)+abs(Y[i]-posY)
                if needH>dist:
                    needH=-2
                    break         
        if needH==-2:
            continue
        print(posX,posY,needH)
        sys.exit()