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:
import sys
N=int(input())
table=[]
def f(cx,cy,h,x,y):
    return max(h-abs(x-cx)-abs(y-cy),0)
for i in range(N):
    x,y,h=map(int,input().split())
    table.append((x,y,h))
for cx in range(101):
    for cy in range(101):
        n=0
        h=0
        while n<N:
            x,y,z=table[n]
            if z>0:
                h=z+abs(cx-x)+abs(cy-y)
                break
            n+=1
        flag=True
        for x,y,z in table:
            if f(cx,cy,h,x,y)!=z:
                flag=False
                break
        if flag:
            print(cx,cy,h)
            sys.exit()

Submission status: Accepted

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):
		n = -1	
		for h in h_list:
			n += 1
			if h >= 1:
				H = abs(cx - x_list[n])+abs(cy - y_list[n])+h
				h_now_list=[]
				break
		for i in range(N):
			h_now = max((H-abs(cx - x_list[i])-abs(cy - y_list[i])), 0)
			h_now_list.append(h_now)
			if h_now != h_list[i]:
				break	
			else:
				if len(h_now_list)==N:
					print(str(cx)+' '+str(cy)+' '+str(H))
					break
	else:
		continue
	break

Submission status: Accepted

Solution code:
import sys
iN = int(input())
aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
aData.sort(key=lambda x:x[2],reverse=True)

if iN == 1:
    print(aData[0][0],aData[0][1],aData[0][2])
else:
    z0 = aData[0][2]
    bF = False
    for i in range(iN):
        if z0 > aData[i][2]:
            break
        else:
            bF = True
    x0 = aData[0][0]
    y0 = aData[0][1]
    xi = aData[i][0]
    yi = aData[i][1]
    if bF or x0 == xi:
        RangeX = range(0,101)
    elif xi < x0:
        RangeX = range(x0,101)
    else:
        RangeX = range(x1,-1,-1)
    if bF or y0 == yi:
        RangeY = range(0,101)
    elif yi < y0:
        RangeY = range(y0,101)
    else:
        RangeY = range(y0,-1,-1)

    for cx in RangeX :
        for cy in RangeY :
            h = 0
            bF = True
            for x,y,z in aData :
                d = abs(x-cx)+abs(y-cy)
                if z > 0 :
                    if h == 0 :
                        h = z + d
                    else :
                        if h != z + d:
                            bF = False
                            break
                else :
                    if h > d:
                        bF = False
                        break
            if bF :
                print(cx,cy,h)
                exit()

Submission status: Accepted

Solution code:
import sys
iN = int(input())
aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
aData.sort(key=lambda x:x[2],reverse=True)

for cx in range(0,101) :
    for cy in range(0,101) :
        h = 0
        bF = True
        for x,y,z in aData :
            d = abs(x-cx)+abs(y-cy)
            if z > 0 :
                if h == 0 :
                    h = z + d
                else :
                    if h != z + d:
                        bF = False
                        break
            else :
                if h > d:
                    bF = False
                    break
        if bF :
            print(cx,cy,h)
            exit()

Submission status: Accepted

Solution code:
N = int(input())

in_list = []
x0, y0, h0 = 0, 0, 0
for i in range(N):
    xyh = list(map(int, input().split()))
    in_list.append(xyh)

for i in range(N):
    if in_list[i][2]:
        x0, y0, h0 = in_list[i]

for Cx in range(0, 101):
    for Cy in range(0, 101):
        for xyh in in_list:
            x, y, h = xyh[0], xyh[1], xyh[2]
            H = h0 + abs(x0-Cx) + abs(y0-Cy)
            if h != max(H-abs(x-Cx)-abs(y-Cy), 0):
                break
        else:
            print(Cx, Cy, H)

Submission status: Accepted

Solution code:
N = int(input())
X, Y, H = [], [], []

def main():
    for i in range(N):
        x, y, h = map(int, input().split())
        X.append(x)
        Y.append(y)
        H.append(h)

    for posY in range(101):
        for posX in range(101):

            # 頂点の高さを求める
            # -1はよく分かってないない時、だけど0より上は決まってる
            # -2はだめだとわかった時
            needH = -1
            
            for i in range(N):

                # H[i]==0 は、平地の可能性もあるので、高さの確認から省く
                if H[i] > 0:
                    
                    # 各座標の情報から、現在のposX、posYが頂点だとした時、
                    # 頂点の高さはどのくらい必要かを求める
                    tmp = H[i] + abs(posY - Y[i]) + abs(posX - X[i])

                    #最初、-1だったらtmpを保存する
                    if needH == -1:
                        needH = tmp
                    #2回め以降、与えられた座標から得たtmpがneedHと違っていたら間違ってる
                    elif needH != tmp:
                        needH = -2
                        break

            # 省いた H[i]==0　に矛盾がないか調べる
            for i in range(N):
                if H[i] == 0:

                    # 頂上との距離が高さより大きければH[i]==0の情報は正しい
                    dist = abs(posY - Y[i]) + abs(posX - X[i])
                    if needH > dist:
                        needH = -2
                        break
            #だめだったら別の場所を探す
            if needH == -2:
                continue
            
            #見つけたらそのまま出力する
            print(posX, posY, needH)
            return 0

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

XYH = set()
flag = True
for i in range(N):
    x, y, h = map(int, input().split())
    if (flag is True) and h > 0:
        flag = False
        ex_x = x
        ex_y = y
        ex_h = h
        continue
    XYH.add((x, y, h))

flag = False
for x in range(0, 101):
    for y in range(0, 101):
        # print(x, y)
        hight = ex_h + abs(x - ex_x) + abs(y - ex_y)
        for tx, ty, th in XYH:
            div = abs(x - tx) + abs(y - ty)
            if div > hight:
                if th == 0:
                    continue
                else:
                    break

            if hight != th + abs(x - tx) + abs(y - ty):
                break
        else:
            print(x, y, hight)
            exit()

Submission status: Accepted

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

x0, y0, h0 = 0, 0, 0

#hが0でない組をサンプルとして代入
for i in range(N):
    if list[i][2]:
        x0, y0, h0 = list[i]

for Cx in range(101):
    for Cy in range(101):
        H = h0 + abs(x0 - Cx) + abs(y0 - Cy)
        for i in range(len(list)):
            if list[i][2] != max(H-abs(list[i][0]-Cx)-abs(list[i][1]-Cy),0):
                break
        else:
            print(Cx,Cy,H)

Submission status: Accepted

Solution code:
import sys
iN = int(input())
aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
aData.sort(key=lambda x:x[2],reverse=True)

for cx in range(0,101) :
    for cy in range(0,101) :
        aH = []
        uH = False
        bF = True
        for x,y,z in aData :
            d = abs(x-cx)+abs(y-cy)
            if z > 0 :
                aH.append( z + d )
            else :
                if aH[0] > d:
                    bF = False
                if uH :
                    uH = min(uH,d)
                else :
                    uH = d
        for i in range(1,len(aH)) :
            if aH[0] != aH[i] :
                bF = False
        if uH :
            if uH < aH[0] :
                bF = False
        if bF :
            print(cx,cy,aH[0])
            exit()

Submission status: Accepted

Solution code:
N = int(input())
xyhlist = []
idx = -1
for i in range(N):
    xyhlist.append(tuple(map(int, input().split())))
    if xyhlist[-1][2] > 0:
        idx = i

px, py, ph = xyhlist[idx]
for cx in range(101):
    for cy in range(101):
        ch = abs(px - cx) + abs(py - cy) + ph

        ok = True
        for (x, y, h) in xyhlist:
            if max(ch - abs(x - cx) - abs(y - cy), 0) != h:
                ok = False
                break
        if ok:
            print(cx, cy, ch)
            break

Submission status: Accepted

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

x, y, h = search()
print("{} {} {}".format(x, y, h))

Submission status: Accepted

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

flag = False

for i in range(N):
    if l[i][2] != 0:
        l[0],l[i]=l[i],l[0]
        break

for cx in range(102):
    if flag:
        break
    for cy in range(102):
        if flag:
            break
        ll = []
        flag = True
        for i in range(N):
            x,y,h = l[i]
            if i == 0:
                H = h+abs(x-cx)+abs(y-cy)
            if h != 0:
                if H != h+abs(x-cx)+abs(y-cy):
                    flag = False
                    break
            else:
                if H > abs(x-cx)+abs(y-cy):
                    flag = False
                    break
                    
print('{} {} {}'.format(cx-1,cy-1,H))

Submission status: Accepted

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

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

for h in range(101):
    for w in range(101):
        x, y, z = X[0]
        d = z + abs(x-w) + abs(y-h)
        for x, y, z in X:
            d2 = z + abs(x-w) + abs(y-h)
            if z == 0:
                if d2 < d:
                    break 
            elif d2 != d:
                break
        else:
            print(w, h, d)
            exit()

Submission status: Accepted

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

if n == 1:
	#x, y, h = map(int, input().split())
	print(ps[0][0], ps[0][1], ps[0][2])
else:
	for X in range(101):
		for Y in range(101):
			valid = True
			const = -1
			for p in ps:
				x, y, h = p[0], p[1], p[2]
				if h != 0:
					if const < 0:
						const = abs(X - x) + abs(Y - y) + h
					else:
						if abs(X - x) + abs(Y - y) + h != const:
							valid = False
							break
				else:
					if const >= 0:
						if const - abs(X - x) - abs(Y - y) > 0:
							valid = False
							break
			for p in ps:
				x, y, h = p[0], p[1], p[2]
				if h == 0:
					if const >= 0:
						if const - abs(X - x) - abs(Y - y) > 0:
							valid = False
							break

			if valid == True:
				print(X, Y, const)
				sys.exit()

Submission status: Accepted

Solution code:
def calcCh(cx, cy, x, y, h):
    return abs(x-cx)+abs(y-cy)+h
def calcH(cx, cy, ch, x, y, h):
    return max(ch - calcCh(cx, cy, x, y, 0), 0)
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
xyh = sorted(xyh, key = lambda x: x[2])[::-1]
lst = [[x, y] for x in range(101) for y in range(101)]
for Cx, Cy in lst:
    Ch = calcCh(Cx, Cy, *xyh[0])
    if all(xyh[i][2] == calcH(Cx, Cy, Ch, *xyh[i]) for i in range(n)):
        break
print(Cx, Cy, Ch)

Submission status: Accepted

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

D.sort(key=lambda d: d[2], reverse=True)
for cx in range(100+1):
    for cy in range(100+1):
        f = True
        for i, (x, y, h) in enumerate(D):
            if i == 0:
                ch0 = h + abs(x - cx) + abs(y - cy)
            else:
                ch = h + abs(x - cx) + abs(y - cy)
                if h != 0 and ch0 != ch:
                    f = False
                if h == 0 and ch0 > ch:
                    f = False
        if f:
            print(cx, cy, ch0)
            exit(0)

Submission status: Accepted

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]))
for i in range(101):
    for j in range(101):
        ansh=[0]*n
        for k,(x,y,h) in enumerate(a):
            ansh[k]=h+abs(i-x)+abs(j-y)
            if h==0:ansh[k]=min([ansh[k],max(ansh[:k])])
        if len(set(ansh))==1:
             print(i,j,ansh[1])

Submission status: Accepted

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], reverse=True)

for Cx in range(101):
    for Cy in range(101):
        H = None
        for xi, yi, hi in points:
            dx = abs(xi - Cx)
            dy = abs(yi - Cy)
            if hi > 0:
                """観測点の高さが1以上なら頂点高を予測"""
                H_calc = hi + dx + dy
                if H is None:
                    H = H_calc
                elif H != H_calc:
                    H = None
                    break  # 頂点高が一意ではない場合はNG
            else:
                """観測点の高さが0なら式を満たしているかチェック"""
                if H > dx + dy:
                    H = None
                    break  # 満たしていない場合はNG

        if H:
            print('{} {} {}'.format(Cx, Cy, H))
            exit()

Submission status: Accepted

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], reverse=True)

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

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

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

Submission status: Accepted

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


def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


def main():
    n, = get_ints()

    inp = [get_ints() for _ in range(n)]
    x, y, h = zip(*inp)

    def calc(cx, cy):
        low = 1
        high = max(h) + 2000

        for x_, y_, h_ in zip(x, y, h):
            if h_ > 0:
                H = abs(cx - x_) + abs(cy - y_) + h_
                if low <= H <= high:
                    low = high = H
                else:
                    return None
            else:
                H = abs(cx - x_) + abs(cy - y_) + h_
                high = min(high, H)
                if low > high:
                    return None
                    
        if low == high:
            return low
        else:
            return None

    for cx in range(101):
        for cy in range(101):
            ans = calc(cx, cy)
            if ans is not None:
                print(cx, cy, ans)
                return
    assert False


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = int(input())

b = []

p = 0
pp = 0
ppp = 0

for i in range(a):
    b.append(list(map(int,input().split())))
b.sort(key=lambda x:-x[2])
for i in range(0,101):
    for j in range(0,101):
        for k in range(a):
            if k == 0:
                p = abs(b[k][0] - i) + abs(b[k][1]-j)+b[k][2]
            else:
                if max(0,p - abs(b[k][0]-i)- abs(b[k][1]-j)) != b[k][2]:
                    pp = 1
        if pp == 0:
            ppp = 1
            break
        else:
            pp = 0
    if ppp == 1:
        print(i,j,p)
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Oct  6 17:56:47 2018
ABC112C
@author: maezawa
"""
import itertools as itr
n = int(input())
xyh = []
for i in range(n):
    xyhi = list(map(int, input().split()))
    xyh.append(xyhi)
xyh.sort(key=lambda x:x[2], reverse=True)
#print(xyh)

for cx, cy in itr.product(range(101),range(101)):
    hres = abs(xyh[0][0]-cx)+abs(xyh[0][1]-cy)+xyh[0][2]
    ok = 0
    for i in range(1,n):
        if xyh[i][2] > 0:
            htemp = abs(xyh[i][0]-cx)+abs(xyh[i][1]-cy)+xyh[i][2]
            #print(cx, cy, i, hh)
            if  htemp != hres:
                ok = -1
                break    
        else:
            if abs(xyh[i][0]-cx)+abs(xyh[i][1]-cy) < hres:
                ok = -1
                break
    if ok == 0:
        print(cx, cy, hres)
        break

Submission status: Accepted

Solution code:
N = int(input())
posX, posY, h = [], [], []

for i in range(N):
    tmp = list(map(int, input().split()))
    posX.append(tmp[0])
    posY.append(tmp[1])
    h.append(tmp[2])

h_start = max(h)

for x in range(101):
    for y in range(101):
        for k in range(h_start, h_start + 201):
            flag = True
            for i in range(N):
                tmp_h = max(k - abs(posX[i] - x) - abs(posY[i] - y), 0)
                #print(x, y, k, tmp_h, h[i])
                if tmp_h != h[i]:
                    flag = False
                    break
            if flag == True:
                print(x, y, k)
                exit

Submission status: Accepted

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

W = 101

cs = [[0] * W for i in range(W)]

XYH.sort(key=lambda e:e[2], reverse=True)

h = XYH[0][2]
sx, sy = XYH[0][0:2]
for x in range(W):
    for y in range(W):
        cs[y][x] = h + abs(x - sx) + abs(y - sy)

#print(cs)

for i in range(1, N):
    h = XYH[i][2]
    sx, sy = XYH[i][0:2]
    for x in range(W):
        for y in range(W):
            h1 = h + abs(x - sx) + abs(y - sy)
            if h > 0:
                if cs[y][x] != h1:
                    cs[y][x] = 0
            else:
                if cs[y][x] > h1:
                    cs[y][x] = 0
    #print(cs)

cx, cy, ch = 0, 0, 0

for x in range(W):
    for y in range(W):
        h = cs[y][x]
        if h > 0:
            cx, cy, ch = x, y, h

print(cx, cy, ch)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
n = ni()
xyh = []
for _ in range(n):
    xyh.append(tuple(list(li())))

def search_cent(xyh:list):    
    xmax ,ymax, hmax = -1, -1, -1
    for x,y,h in xyh:
        if h > hmax:
            xmax = x
            ymax = y
            hmax = h
            
    for x_cent in range(101):
        for y_cent in range(101):
            h_cent = hmax + abs(xmax-x_cent) + abs(ymax-y_cent)
            
            # 矛盾チェック
            is_cent = True
            for x,y,h in xyh:
                hi = max(0, h_cent - abs(x-x_cent) - abs(y-y_cent))
                
                if hi != h:
                    is_cent = False
                    break

            if is_cent:
                return x_cent, y_cent, h_cent
        
xc, yc, hc = search_cent(xyh)
print(xc,yc,hc)

Submission status: Accepted

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


for cx in range(101): 
    for cy in range(101):
        H = -1
        for i in range(N):
            if h[i] > 0:
                tmp = h[i]+abs(x[i]-cx)+abs(y[i]-cy)
                if H == -1:
                    H = tmp
                elif H != tmp:
                    H = -2
                    break
        if H == -2:
            continue
        for i in range(N):
            if h[i] == 0:
                dist = abs(x[i]-cx)+abs(y[i]-cy)
                if H > dist:
                    H = -2
                    break
        if H == -2:
            continue
        print(cx,cy,H)

Submission status: Accepted

Solution code:
border = 101


def manhattan_distance(Cx, Cy, H, X, Y):
    return max(H - abs(X - Cx) - abs(Y - Cy), 0)


def judge_center(Cx, Cy, cords):
    for x, y, h in cords:
        if h > 0:
            H = abs(x - Cx) + abs(y - Cy) + h
            break
    for x, y, h in cords:
        tmp = manhattan_distance(Cx, Cy, H, x, y)
        if h != tmp:
            return -1
    return H


def main():
    N = int(input())
    cords = [list(map(int, input().split(' '))) for _ in range(N)]

    for tmp_Cx in range(border):
        for tmp_Cy in range(border):
            h = judge_center(tmp_Cx, tmp_Cy, cords)
            if h != -1:
                print('{} {} {}'.format(tmp_Cx, tmp_Cy, h))
                return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
border = 101


def manhattan_distance(Cx, Cy, H, X, Y):
    return max(H - abs(X - Cx) - abs(Y - Cy), 0)


def judge_center(Cx, Cy, cords):
    for x, y, h in cords:
        if h > 0:
            H = abs(x - Cx) + abs(y - Cy) + h
            break
    for x, y, h in cords:
        tmp = manhattan_distance(Cx, Cy, H, x, y)
        if (h > 0 and h != tmp) or (h == 0 and h < tmp):
            return -1
    return H


def main():
    N = int(input())
    cords = [list(map(int, input().split(' '))) for _ in range(N)]

    for tmp_Cx in range(border):
        for tmp_Cy in range(border):
            h = judge_center(tmp_Cx, tmp_Cy, cords)
            if h != -1:
                print('{} {} {}'.format(tmp_Cx, tmp_Cy, h))
                return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

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 cx, cy in itertools.product(range(101), range(101)):
    H = []
    for i in range(n):
        if h[i] == 0:
            continue
        H.append(h[i] + abs(x[i] - cx) + abs(y[i] - cy))
    if len(set(H)) == 1 and H[0] >= 1:
        for j in range(n + 1):
            if j == n:
                break
            if max(H[0] - abs(x[j] - cx) - abs(y[j] - cy), 0) != h[j]:
                break
        if j == n:
            break
print("{} {} {}".format(cx, cy, H[0]))

Submission status: Accepted

Solution code:
MAX = 101

def judge_center(Cx, Cy, cords):
    H = -1
    for x, y, h in cords:
        if h > 0:
            tmpH = abs(x - Cx) + abs(y - Cy) + h
            if H == -1:
                H = tmpH
            else:
                if tmpH != H:
                    return -1
    for x, y, h in cords:
        if h == 0:
            tmpH = abs(x - Cx) + abs(y - Cy) + h
            if H > tmpH:
                return -1
    return H

def main():
    N = int(input())
    cords = [list(map(int, input().split(' '))) for _ in range(N)]

    for tmp_Cx in range(MAX):
        for tmp_Cy in range(MAX):
            H = judge_center(tmp_Cx, tmp_Cy, cords)
            if H != -1:
                print('{} {} {}'.format(tmp_Cx, tmp_Cy, H))
                return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(input())
xN, yN, hN = [0] * N, [0] * N, [0] * N
for i in range(N):
    xN[i], yN[i], hN[i] = map(int, input().split())

# 頂上としてありうる座標101*101を全検索
for y in range(101):
    for x in range(101):
        # 仮の頂上の高さを保持する
        tmpH = 0
        # 実施回数と一致回数の比較用
        cnt1, cnt2 = 0, 0
        # 任意の座標について、N個の情報との矛盾がないかを確認していく
        for i in range(N):
            # 高さ0の座標は高さの比較対象として相応しくないのでいったん無視
            if hN[i] == 0:
                continue
            cnt1 += 1
            # 頂上座標を仮固定しているので、仮の頂上の高さが定まる
            h = hN[i] + abs(x - xN[i]) + abs(y - yN[i])
            # 初回は値を保持
            if tmpH == 0:
                tmpH = h
                cnt2 += 1
            # 2回目以降は保持した初回の値と今回を比較
            else:
                # 一致しなければ矛盾しているので、その座標は終了
                if tmpH != h:
                    break
                else:
                    cnt2 += 1
        # 高さ0の場所について、矛盾がないか確認
        # (tmpHの確定後に全ての場所を試したいので別ループにする)
        for i in range(N):
            if hN[i] == 0:
                cnt1 += 1
                # 仮の高さがマンハッタン距離より大きいのはおかしい
                # (距離のが大きいのは問題ない。本来マイナスなくらい遠くても高さは0スタートだから)
                if tmpH > abs(x - xN[i]) + abs(y - yN[i]):
                    break
                else:
                    cnt2 += 1
        # 実施回数と一致回数が一致していれば正しい情報として出力
        if cnt1 == cnt2:
            print(str(x) + ' ' + str(y) + ' ' + str(tmpH))
            exit()

Submission status: Accepted

Solution code:
import itertools

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 t in range(n):
    if h[t] >= 1:
        break
for cx, cy in itertools.product(range(101), range(101)):
    H = h[t] + abs(x[t] - cx) + abs(y[t] - cy)
    if H < 1:
        continue
    for i in range(n + 1):
        if i == n:
            break
        if max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]:
            break
    if i == n:
        break
print("{} {} {}".format(cx, cy, H))

Submission status: Accepted

Solution code:
N = int(input())
Xs = [list(map(int, input().split(" "))) for _ in range(N)]
"""
input = ["2 3 5","2 1 5","1 2 5","3 2 5"]
input = ["0 0 100", "1 1 98"]
input = ["99 1 191", "100 1 192", "99 0 192"]
Xs = [list(map(int, x.split(" "))) for x in input]
"""

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


def solv(Xs):
    for x in range(101):
        for y in range(101):
            Cx, Cy, h = tuple(Xs[0])
            H = h + abs(x - Cx) + abs(y - Cy)
            for Cx, Cy, h in Xs:
                if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:
                    break
            else:
                return (x, y, H)


print("%d %d %d" % solv(Xs))

Submission status: Accepted

Solution code:
N = int(input())
Xs = [list(map(int, input().split(" "))) for _ in range(N)]
"""
input = ["2 3 5","2 1 5","1 2 5","3 2 5"]
input = ["0 0 100", "1 1 98"]
input = ["99 1 191", "100 1 192", "99 0 192"]
Xs = [list(map(int, x.split(" "))) for x in input]
"""

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


def solv(Xs):
    for x in range(101):
        for y in range(101):
            h= Xs[0][2]
            Cx = Xs[0][0]
            Cy = Xs[0][1]
            H = h + abs(x - Cx) + abs(y - Cy)
            for i in range(len(Xs)):
                h = max(H - abs(x - Xs[i][0]) - abs(y - Xs[i][1]), 0)
                if h != Xs[i][2]:
                    break
                if i == len(Xs)-1:
                    print("%d %d %d" % (x, y, H))
                    exit(0)


solv(Xs)

Submission status: Accepted

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

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

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

for i in range(101):
    for j in range(101):
        for k in range(len(l)-1):
            if func2(i,j,l[k]) == func2(i,j,l[k+1]):
                if k == len(l)-2:
                    print(i, j, func2(i,j,l[k]))
                    exit()
            else:
                break

Submission status: Accepted

Solution code:
N=int(input())
lis=[]
for i in range(101):
    for j in range(101):
        lis.append([i,j])
l2=[]
for i in range(N):
    l2.append(list(map(int, input().split())))
l2.sort(key=lambda x:x[2],reverse=True)
for i in lis:
    n=N
    l=0
    for j in l2:
        k=abs(i[0]-j[0])+abs(i[1]-j[1])+j[2]
        if j[2]==0:
            if k>l:
                n-=1
            else:
                if l==k or l==0:
                    l=k
                    n-=1
                else: break
        else:
            if l==k or l==0:
                l=k
                n-=1
            else: break
        if n==0:
            m=(i[0],i[1],l)
print('{} {} {}'.format(m[0],m[1],m[2]))

Submission status: Accepted

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

ss = sorted(ss, key=lambda x: x[2], reverse=True)


cx, cy, ch = ss[0]
if len(ss) == 1:
    print(cx, cy, ch)
else:
    for a in range(101):
        for b in range(101):
            H = ch + abs(cx-a) + abs(cy - b)
            for x, y, h in ss[1:]:
                if h != max(H - abs(x-a) - abs(y - b), 0):
                    break
            else:
                print(a, b, H)
                flg = True

Submission status: Accepted

Solution code:
n = int(input())
card = []

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


 
def check(cx,cy):
    needH = -1
    for i in range(n):
        x,y,h = card[i]

        if h>0:
            global H
            H = abs(x-cx)+abs(y-cy)+h
            if needH == -1:
                needH = H
            else:
                if needH != H:
                    return False
    
    for i in range(n):
        x,y,h = card[i]

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

    
for i in range(101):
    for j in range(101):
        if check(i,j):

            print("{} {} {}".format(i,j,H))