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())

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

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

        x, y, h = XYH[1]
        H = abs(x-cx) + abs(y-cy) + h

        if all([h == H - abs(x-cx) - abs(y-cy) for x, y, h in XYH]):
            print(cx, cy, H)
            exit()

Submission status: Runtime Error

Solution code:
n = int(input())
XYH = list(tuple(map(int, input().split())) for _ in range(n))

for i in range(n):
    if XYH[i][2] == 0:
        del XYH[i]

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

        x, y, h = XYH[0]
        H = abs(x-cx) + abs(y-cy) + h

        if all([H == abs(x-cx) + abs(y-cy) + h for x, y, h in XYH]):
            print(cx, cy, H)
            exit()

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(map(int, input().split())) for _ in range(n)]
if not n == 1:
    for i in range(101):
        for j in range(101):
            c = s[0][2] + abs(i - s[0][0]) + abs(j - s[0][1])
            d = 0
            for k in range(1, n):
                if not abs(i - s[k][0]) + abs(j - s[k][1]) == c - s[k][2]:
                    d = 1
                    break
            if d == 0:
                ans = [i, j, c]
                break
else:
    ans = s[0]
print(" ".join(map(str, ans)))

Submission status: Runtime Error

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

def set_height(i,x,y):
	ans = z[i][2] + abs(z[i][0] - x) + abs(z[i][1] - y)
	return ans


answer = 0
for j in range(0,101):
	for k in range(0,101):
		answer=set_height(0,j,k)
		flag = 1
		for l in range(1,n):
			if answer!= set_height(l,j,k):
				flag = 0
				break
		if flag == 1 && answer <= 10**9:
			test = map(str,(j,k,answer))
			print(" ".join(test))

Submission status: Runtime Error

Solution code:
INF=10**20
N=int(input())
x=[];y=[];h=[]
for i in range(N):
    X,Y,H=map(int,input().split())
    x.append(X);y.append(Y);h.append(H)
for i in range(101):#Cx
    for j in range(101):#Cy
        res=-INF
        T=True
        mli=[]
        for k in range(N):
            tmp=h[k]+abs(x[k]-i)+abs(y[k]-j)
            if(h[k]>0):
                if(res==-INF):
                    res=tmp
                elif(res!=tmp):
                    T=not T
                    break
            elif(h[k]==0):
                mli.append(tmp)
        for x in mli:
            if(x<res):
                T=not T
                break
        if T:
            print(i,j,res)
            exit()

Submission status: Runtime Error

Solution code:


def read_input():
    n = int(input())
    conds = []
    for _ in range(n):
        x, y, h = map(int, input().split())
        conds.append(((x, y), h))

    return n, conds


def manhattan(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


def satisfy(cond, center):
    c, ch = center
    p, h = cond
    return ch == h + manhattan(p, c)


def submit():
    n, conds = read_input()    

    if n == 1:
        p, h = conds[0]
        print("{} {} {}".format(p[0], p[1], h))
        return

    center_cands = []
    s, sh = conds[0]
    for i in range(101):
        for j in range(101):
            t = (i, j)
            th = sh + manhattan(s, t) # 仮にtがpより高い位置の頂点だとする
            center_cands.append((t, th))
    
    # 各条件について満たすか否かを判定していく
    for cond in conds:
        center_cands = [c for c in center_cands if satisfy(cond, c)]

    # 全条件を満たすポイントは1つのはず
    center, h = center_cands[0]
    print("{} {} {}".format(center[0], center[1], h))
            

if __name__ == "__main__":
    submit()

Submission status: Runtime Error

Solution code:

import math


def read_input():
    n = int(input())
    conds = [tuple(map(int, input().split())) for _ in range(n)]

    return n, conds


def m_dist(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


def submit():
    n, conds = read_input()
    conds = [((c[0], c[1]), c[2]) for c in conds]
    conds.sort(key=lambda x: x[1], reverse=True)

    # n == 1のとき
    # そこが頂点になる
    if len(conds) == 1:
        print("{} {} {}".format(conds[0][0], conds[0][1], conds[1]))
        return

    # max(hi)が重複ない場合
    # 特定できるはずなので、そこが頂点になる
    if conds[0][1] > conds[1][1]:
        print("{} {} {}".format(conds[0][0][0], conds[0][0][1], conds[0][1]))
        return

    # max(hi)が重複する場合、それらをh0, h1とする
    # (x0, y0), (x1, y1)から等距離にある点を考える
    p1, p2 = conds[0][0], conds[1][0]
    h_12 = conds[0][1]

    cands = []
    for x in range(min((p1[0], p2[0])), max((p1[0], p2[0])) + 1):
        for y in range(min((p1[1], p2[1])), max((p1[1], p2[1])) + 1):
            t = (x, y)
            
            if m_dist(t, p1) != m_dist(t, p2):
                continue

            cands.append((t, h_12 + m_dist(t, p1)))

    for cand, cand_h in cands:
        check = True
        for p, h in conds:
            if h != max(0, cand_h - m_dist(cand, p)):
                check = False
                break

        if check:
            print("{} {} {}".format(cand[0], cand[1], cand_h))
            return

    assert False


if __name__ == "__main__":
    submit()

Submission status: Runtime Error

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh=sorted(xyh,reverse=True,key=lambda x:x[2])
p#rint(xyh)
for cx in range(0,101):
    for cy in range(0,101):
        H = 0
        for x,y,h in xyh:
            if H == 0:
                H = h + abs(x - cx) + abs(y - cy)
            else:
                temp_H = h + abs(x - cx) + abs(y - cy)
                if temp_H != H:break
        else:
            if H>=1:
                print(cx,cy,H)
                exit()

Submission status: Runtime Error

Solution code:
n = int(input())

L = [[0, 0, 0] for _ in range(n)]
for i in range(n):
    x, y, h = map(int, input().split())
    L[i][0] = x
    L[i][1] = y
    L[i][2] = h

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
X = []
Y = []
hh = []
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    hh.append(h)

Hmax = float("inf")
allZero = True
for i in range(0,101):
    for j in range(0,101):
        s = set()
        for k in range(N):
            key = abs(X[k] - i) + abs(Y[k] - j) + hh[k]
            if h == 0:
                # H <= abs(X[k]-i) + abs(Y[k]-j)であることがわかる
                Hmax = min(abs(X[k]-i) + abs(Y[k]-j), Hmax)
            else:
                allZero = False
                s.add(key)
        if len(s) == 1:
            H = key
            Cx = i
            Cy = j

if allZero:
    print(Hmax)
else:
    print(Cx, Cy, H)

Submission status: Runtime Error

Solution code:

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

B = []
for X in range(101):
    cnt = 0
    H = 0
    H1 = 0
    for Y in range(101):
        cnt = 0
        H = 0
        H1 = 0
        for i in range(N):
            H = A[i][2] + abs(X - A[i][0]) + abs(Y - A[i][1])
            if  H == H1:
                cnt += 1
                H1 = H
            if cnt >= N-1:
                B.append((X, Y, H))
            H1 = H
print(B[0][0] ,B[0][1] ,B[0][2] )

Submission status: Runtime Error

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

B = []
for X in range(101):
    cnt = 0
    H = 0
    H1 = 0
    for Y in range(101):
        cnt = 0
        H = 0
        H1 = 0
        for i in range(N):
            H = A[i][2] + abs(X - A[i][0]) + abs(Y - A[i][1])
            if  H == H1:
                cnt += 1
                H1 = H
            if cnt >= N-2:
                B.append((X, Y, H))
            H1 = H
print(B[0][0] ,B[0][1] ,B[0][2] )

Submission status: Runtime Error

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

B = []
for X in range(101):
    cnt = 0
    H = 0
    H1 = 0
    for Y in range(101):
        cnt = 0
        H = 0
        H1 = 0
        for i in range(N):
            H = A[i][2] + abs(X - A[i][0]) + abs(Y - A[i][1])
            if  H == H1:
                cnt += 1
                H1 = H
            if cnt == N-1:
                B.append((X, Y, H))
            H1 = H
print(B[0][0] ,B[0][1] ,B[0][2] )

Submission status: Runtime Error

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

B = []
for X in range(101):
    for Y in range(101):
        cnt = 0
        H = 0
        H1 = 0
        for i in range(N):
            H = A[i][2] + abs(X - A[i][0]) + abs(Y - A[i][1])
            if  H == H1:
                cnt += 1
                H1 = H
            if cnt == N-1:
                B.append((X, Y, H))
            H1 = H
print(B[0][0] ,B[0][1] ,B[0][2] )

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
L=[]
for _ in range(n):
    x,y,h=map(int,input().split())
    L.append((x,y,h))
a,b,c=L[0]
mae=a+b+c
for i in range(101):
    for j in range(101):
        takasa=abs(a-i)+(b-j)+c
        flag=1
        for p,q,r in L:
            if r==100:
                ans=(p,q,r)
            if abs(p-i)+abs(q-j)+r == takasa:
                continue
            else:
                flag=0
        if flag:
            ans=(i,j,takasa)
print(*ans, sep=' ')

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)

hmax=h[0]
xhmax=x[0]
yhmax=y[0]
ihmax=0

for i in range(n):
    if hmax<h[i]:
        hmax=h[i]
        xhmax=x[i]
        yhmax=y[i]
        ihmax=i
    
for cx in range(101):
    for cy in range(101):
        hh=hmax+abs(xhmax,cx)+abs(yhmax,cy)
        yesno="yes"
        for i in range(n):
            if h[i]!=max(hh-abs(x[i],cx)-abs(y[i],cy),0):
                yesno="no"
                break
        if yesno=="yes":
            print(cx,cy,hh)

Submission status: Runtime Error

Solution code:
N = int(input())

xyh = []

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

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

        Cx = i
        Cy = j
        ans = True
        flag_h = True

        for x,y,h in xyh:

            if h>0 and flag_h:
                H = h+abs(Cx-x)+abs(Cy-y)
                flag_h = False

            else:
                tmp_h = h+abs(Cx-x)+abs(Cy-y)
                if h>0:
                    if tmp_h != H:
                        ans = False
                        break
                else:
                    if H - abs(Cx-x) -abs(Cy-y) > 0:
                        ans = False
                        break
            
        if ans:
            print(Cx,Cy,H)
            exit()

Submission status: Runtime Error

Solution code:
N = int(input())

xyh = []

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

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

        Cx = i
        Cy = j
        ans = True
        flag_h = True

        for x,y,h in xyh:

            if h>0 and flag_h:
                H = h+abs(Cx-x)+abs(Cy-y)
                flag_h = False

            elif h>0:
                tmp_h = h+abs(Cx-x)+abs(Cy-y)
                if tmp_h != H:
                    ans = False
                    ##break

        elif ans:
            print(Cx,Cy,H)
            exit()

Submission status: Runtime Error

Solution code:
# ABC100 C - Pyramid
n=int(input())
xyh=[]
idx=-1
for i in range(n):
    x,y,h=map(int,input().split())
    if h>=1:
        xyh.append([x,y,h])
        idx=i
for cx in range(101):
    for cy in range(101):
        H=abs(xyh[idx][0]-cx)+abs(xyh[idx][1]-cy)+xyh[idx][2]
        H=max(H,0)
        ok=True
        for i in range(n):
            t_height=H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)
            if xyh[i][2]==0 and t_height>0:
                ok=False
            if xyh[i][2]>0 and xyh[i][2]!=t_height:
                ok=False
        if ok:
            print(cx,cy,H)

Submission status: Runtime Error

Solution code:
# ABC100 C - Pyramid
n=int(input())
xyh=[]
idx=-1
for i in range(n):
    x,y,h=map(int,input().split())
    if h>=1:
        xyh.append([x,y,h])
        idx=i
for cx in range(101):
    for cy in range(101):
        H=abs(xyh[idx][0]-cx)+abs(xyh[idx][1]-cy)+xyh[idx][2]
        H=max(H,0)
        ok=True
        for i in range(n):
            t_height=H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)
            if xyh[i][2]!=t_height:
                ok=False
        if ok:
            print(cx,cy,H)

Submission status: Runtime Error

Solution code:
n = int(input())

xyh = [list(map(int,input().split()))for i in range(n)]
while xyh[0][2]==0: xyh.pop(0)

for i in range(101):
    for j in range(101):
        base = xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for k in range(1, n):
            if xyh[k][2]==0: continue
            if base!=xyh[k][2]+abs(xyh[k][0]-i)+abs(xyh[k][1]-j): break
        else:
            print(i, j, base)
            exit()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
information = [list(map(int, input().split())) for _ in range(n)]
information.sort(key=lambda x: x[2])


def calc(p, w):
    c_x, c_y = p
    x, y, h = w
    if h > 0:
        return h + abs(x-c_x) + abs(y-c_y)


def check(H, p, w):
    c_x, c_y = p
    x, y, h = w
    if h == max(0, H - abs(x - c_x) - abs(y - c_y)):
        return True
    else:
        return False


for i in range(101):
    for j in range(101):
        p = [i, j]
        H = calc(p, information[-1])
        judge = 1
        for w in information[:-1]:
            if check(H, p, w):
                continue
            else:
                judge -= 1
                break
        if judge:
            print(*p, H)
            sys.exit()
        else:
            continue

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
information = [list(map(int, input().split())) for _ in range(n)]
information.sort(key=lambda x: x[2])


def calc(p, w):
    c_x, c_y = p
    x, y, h = w
    if h > 0:
        return h + abs(x-c_x) + abs(y-c_y)


def check(H, p, w):
    c_x, c_y = p
    x, y, h = w
    if h == max(0, H - abs(x - c_x) - abs(y - c_y)):
        return True
    else:
        return False


for i in range(101):
    for j in range(101):
        p = [i, j]
        H = calc(p, information[-1])
        judge = 1
        for w in information[:-1]:
            if check(H, p, w):
                continue
            else:
                judge -= 1
                break
        if judge:
            print(*p, H)
            sys.exit()
        else:
            continue

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
information = [list(map(int, input().split())) for _ in range(n)]
information.sort(key=lambda x: x[2])


def calc(p, w):
    c_x, c_y = p
    x, y, h = w
    if h > 0:
        return h + abs(x-c_x) + abs(y-c_y)


def check(H, p, w):
    c_x, c_y = p
    x, y, h = w
    if h == max(0, H - abs(x - c_x) - abs(y - c_y)):
        return True
    else:
        return False


for i in range(101):
    for j in range(101):
        p = (i, j)
        H = calc(p, information[-1])
        judge = 1
        for w in information[:-1]:
            if check(H, p, w):
                continue
            else:
                judge -= 1
                break
        if judge:
            print(*p, H)
            sys.exit()

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
information = [list(map(int, input().split())) for _ in range(n)]
information.sort(key=lambda x: x[2])


def calc(p, w):
    c_x, c_y = p
    x, y, h = w
    if h > 0:
        return h + abs(x-c_x) + abs(y-c_y)


def check(H, p, w):
    c_x, c_y = p
    x, y, h = w
    if h == max(0, H - abs(x - c_x) - abs(y - c_y)):
        return True
    else:
        return False


for i in range(101):
    for j in range(101):
        p = (i, j)
        H = calc(p, information[-1])
        judge = 1
        for w in information[:-1]:
            if check(H, p, w):
                pass
            else:
                judge -= 1
                break
        if judge:
            print(*p, H)
            sys.exit()

Submission status: Runtime Error

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

for x in range(101):
  for y in range(101):
    h = li[0][2] + abs(x - li[0][0]) + abs(y - li[0][1])
    ok = True

    for i in li:
      if h != i[2] + abs(x - i[0]) + abs(y - i[1]):
        ok = False

    if ok:
      ans = [x, y, h]

print("{} {} {}".format(ans[0], ans[1], ans[2]))

Submission status: Runtime Error

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

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

for tx in range(101):
    for ty in range(101):
        th=h[0]+abs(tx-x[0])+abs(ty-y[0])
        flag=1
        for i in range(N):
            nh=h[i]+abs(tx-x[i])+abs(ty-y[i])
            if nh!=th:
                flag=0
                break
        if flag==1:
            ans=[tx,ty,th]
            break

print(' '.join(map(str, ans)))

Submission status: Runtime Error

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


N = int(input())
x = [list(map(int, input().split())) for i in range(N)]
for cx in range(0, 101):
    for cy in range(0, 101):
        judge = True
        m = [l for l in range(N) if x[l][2]!=0][0]
        H0 = H(x[m][2], x[m][0], x[m][1], cx, cy)
        for n in range(len(x)):
            Hn = H(x[n][2], x[n][0], x[n][1], cx, cy)
            #print(Hn)
            if(x[n][2] != 0):
                if(Hn == H0):
                    judge = judge and True
                else:
                    judge = judge and False
        if(judge):
            for n in range(len(x)):
                if(x[n][2] == 0):
                    Hr = Hr(H0, x[n][0], x[n][1], cx, cy)
                    if(Hr == 0):
                        judge = judge and True
                    else:
                        judge = judge and False
                
            if(judge):
                print(cx, cy, H0)

Submission status: Runtime Error

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


N = int(input())
x = [list(map(int, input().split())) for i in range(N)]
for cx in range(0, 101):
    for cy in range(0, 101):
        judge = True
        m = [l for l in range(N) if x[l][2]!=0][0]
        H0 = H(x[m][2], x[m][0], x[m][1], cx, cy)
        for n in range(len(x)):
            Hn = H(x[n][2], x[n][0], x[n][1], cx, cy)
            #print(Hn)
            if(x[n][2] != 0):
                if(Hn == H0):
                    judge = judge and True
                else:
                    judge = judge and False
        if(judge):
            for n in range(len(x)):
                if(x[n][2] == 0):
                    Hr = Hr(H0, x[n][0], x[n][1], cx, cy)
                    if(Hr == 0):
                        judge = judge and True
                    else:
                        judge = judge and False
                
        if(judge):
            print(cx, cy, H0)

Submission status: Runtime Error

Solution code:
import itertools
N, M = map(int, input().split())
br = set(tuple(map(int, input().split())) for i in range(M))

member = [i+1 for i in range(N)]
#print(member)
ans = 1
for i in range(1, N+1):
    for j in itertools.combinations(member,i):
        k = set(itertools.combinations(j,2))
        #print(k)
        #print(br)
        #print(k <= br)
        if((k <= br)and(i>ans)):
            ans = i
print(ans)

Submission status: Runtime Error

Solution code:
#112
from itertools import product

N=int(input())
px,py,ph=[],[],[]

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)
        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

for Cxi,Cyj in product(range(101),range(101)):

    if len(ph)!=1:
        for i in range(len(ph)):
            nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
            if nowH!=preH:
                break
            preH=nowH
        else:
            print(Cxi,Cyj,nowH)
            break
    else:
        print(px[0],py[0],ph[0])
        break

Submission status: Runtime Error

Solution code:
#112
from itertools import product

N=int(input())
px,py,ph=[],[],[]

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)
        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

for Cxi,Cyj in product(range(101),range(101)):

    if len(ph)!=1:
        for i in range(len(ph)):
            nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
            if nowH!=preH:
                break
            preH=nowH
        else:
            print(Cxi,Cyj,nowH)
            break
    else:
        print(px[0],py[0],ph[0])

Submission status: Runtime Error

Solution code:
#112
from itertools import product

N=int(input())
px,py,ph=[],[],[]

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)
        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

for Cxi,Cyj in product(range(101),range(101)):
    preH=alc_H(Cxi,Cyj,px[0],py[0],ph[0])
    for i in range(len(ph)):
        nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
        if nowH!=preH:
            break
        preH=nowH
    else:
        print(Cxi,Cyj,nowH)

Submission status: Runtime Error

Solution code:
#112
from itertools import product

N=int(input())
px=[]
py=[]
ph=[]
cnt=0

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)
    else:
        cnt+=1

        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

    
    
for Cxi,Cyj in product(range(101),range(101)):
    preH=Calc_H(Cxi,Cyj,px[0],py[0],ph[0])
    for i in range(1,N-cnt):
        nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
        if preH!=nowH:
            break
        preH=nowH
    else:
        print(Cxi,Cyj,nowH)

Submission status: Runtime Error

Solution code:
#112
from itertools import product

N=int(input())
px=[]
py=[]
ph=[]

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)


        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

    
    
for Cxi,Cyj in product(range(101),range(101)):
    preH=Calc_H(Cxi,Cyj,px[0],py[0],ph[0])
    for i in range(1,N):
        nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
        if preH!=nowH:
            break
        preH=nowH
    else:
        print(Cxi,Cyj,nowH)

Submission status: Runtime Error

Solution code:
#112
from itertools import product

N=int(input())
px=[]
py=[]
ph=[]

for _ in range(N):
    x,y,h=map(int,input().split())
    if h!=0:
        px.append(x)
        py.append(y)
        ph.append(h)


        
def Calc_H(Cxi,Cyj,pxi,pyj,hi):
    return hi+abs(Cxi-pxi)+abs(Cyj-pyj)

    
    
for Cxi,Cyj in product(range(101),range(101)):
    preH=Calc_H(Cxi,Cyj,px[0],py[0],ph[0])
    for i in range(1,N):
        nowH=Calc_H(Cxi,Cyj,px[i],py[i],ph[i])
        if preH!=nowH:
            break
        preH=nowH
    else:
        print(Cxi,Cyj,nowH)

Submission status: Runtime Error

Solution code:

N = int(input())

P = []

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

for x in range(101):
  for y in range(101):
    height = -1
    for p in range(N):
      (cx, cy, ch) = P[p]
      if height == -1:
        height = ch + abs(cx - x) + abs(cy - y)
        if height < 1:
          height = -1
      elif height == -2:
        break
      else:
        tmp = ch + abs(cx - x) + abs(cy - y)
        if tmp != height:
          height = -2
    
    if height != -2:
      valid = True
      for p in range(N):
        (cx, cy, ch) = P[p]
        if ch == 0:
          if height - abs(cx - x) - abs(cy - y) > 0:
            valid = False
        else
          if max(0, height - abs(cx - x) - abs(cy - y)) != ch:
            valid = False
      if valid:
        print(x, y, height)
        exit()

Submission status: Runtime Error

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

for j in range(101):
    for k in range(101):
        H=None
        f=1
        for x,y,h in p:
            if h>0 and H==None:
                H=h+abs(x-j)+abs(y-k)
            else:
                if max(0,H-abs(x-j)-abs(y-k))!=h:
                    f=0
        if f:
            print(j,k,H)
            exit()

Submission status: Runtime Error

Solution code:
import sys
 
N = int(input())
for x in range(N):
  XYH = list(map(int,input().split()))

for i in range(0, 101):
    for j in range(0, 101):
        ansH = XYH[0][2] + abs(XYH[0][0]-i) + abs(XYH[0][1]-j)
        if ansH > 0:
            for k in range(N):
                if XYH[k][2] == ansH - abs(XYH[k][0]-i) - abs(XYH[k][1]-j):
                    pass
                else:
                    break
 
                if k == N-1:
                    print('{} {} {}'.format(i,j,ansH))
                    sys.exit()

Submission status: Runtime Error

Solution code:
import sys
 
N = int(input())
for x in range(N):
  XYH = map(int,input().split())
  
for i in range(0, 101):
    for j in range(0, 101):
        ansH = XYH[0][2] + abs(XYH[0][0]-i) + abs(XYH[0][1]-j)
        if ansH > 0:
            for k in range(N):
                if XYH[k][2] == ansH - abs(XYH[k][0]-i) - abs(XYH[k][1]-j):
                    pass
                else:
                    break
 
                if k == N-1:
                    print('{} {} {}'.format(i,j,ansH))
                    sys.exit()

Submission status: Runtime Error

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

for x in range(101):
    for y in range(101):
        h = [0,10**10]
        h_memo = 0
        for i in range(n):
            if xy[i][2] == 0:
                h[1] = min(h[1],abs(xy[i][0]-x) + abs(xy[i][1]-y))
            else:
                h_memo = xy[i][2] + abs(xy[i][0]-x) + abs(xy[i][1]-y)
            #print(x,y,h[1],h_memo)
            if h[0]!=0:
                if h_memo == h[0]:
                    continue
                elif h_memo != h[0]:
                    break
                elif h[1] < h[0]:
                    break
            elif h[0]==0 and h_memo!=0:
                h[0] = h_memo
            elif h[0]==0 and h_memo==0:
                if h[1] < (abs(xy[0]-x) + abs(xy[1]-y)):
                    break
        else:               
            #print(x+1,y+1,h[0])
            if h[0]==0:
                continue
            else:
                print(x,y,h[0])

Submission status: Runtime Error

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

for x in range(101):
    for y in range(101):
        h = [0,10**10]
        h_memo = 0
        for i in range(n):
            if xy[i][2] == 0:
                h[1] = min(h[1],abs(xy[0]-x) + abs(xy[1]-y))
            else:
                h_memo = xy[i][2] + abs(xy[i][0]-x) + abs(xy[i][1]-y)
            #print(x,y,h[1],h_memo)
            if h[0]!=0:
                if h_memo == h[0]:
                    continue
                elif h_memo != h[0]:
                    break
                elif h[1] < h[0]:
                    break
            elif h[0]==0 and h_memo!=0:
                h[0] = h_memo
            elif h[0]==0 and h_memo==0:
                if h[1] < (abs(xy[0]-x) + abs(xy[1]-y)):
                    break
        else:               
            #print(x+1,y+1,h[0])
            if h[0]==0:
                continue
            else:
                print(x,y,h[0])

Submission status: Runtime Error

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

for x in range(101):
    for y in range(101):
        h = [0,10**10]
        h_memo = 0
        for i in range(n):
            if xy[i][2] == 0:
                h[1] = min(h[1],abs(xy[0]-x) + abs(xy[1]-y))
            else:
                h_memo = xy[i][2] + abs(xy[i][0]-x) + abs(xy[i][1]-y)
            #print(x,y,h[1],h_memo)
            if h[0]!=0:
                if h_memo == h[0]:
                    continue
                elif h_memo != h[0]:
                    break
                elif h[1] < h[0]:
                    break
            elif h[0]==0 and h_memo!=0:
                h[0] = h_memo
            elif h==0 and h_memo==0:
                if h[1] < (abs(xy[0]-x) + abs(xy[1]-y)):
                    break
        else:               
            #print(x+1,y+1,h[0])
            if h[0]==0:
                continue
            else:
                print(x,y,h[0])