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())
xyh = []
fxyh = []
for _ in range(n):
    xyh.append(list(map(int, input().split())))
    if xyh[-1][2]:
        fxyh = xyh[-1]


for i in range(100 + 1):
    for j in range(100 + 1):
        h = fxyh[2] + abs(fxyh[0] - i) + abs(fxyh[1] - j)
        if 1 > h:
            continue
        ok = True
        for k in range(n):
            if xyh[k][2] != max(0, h - abs(xyh[k][0] - i) - abs(xyh[k][1] - j)):
                ok = False
                break
        if ok:
            print(str(i) + ' ' + str(j) + ' ' + str(h))
            sys.exit(0)

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]

N = int(input())
xyh = []
for _ in range(N):
    xyh.append(inpl())
for x, y, h in xyh:
    if h:
        tx, ty, th = x, y, h
        break
    
for i in range(101):
    for j in range(101):
        cx, cy, ch  = i, j, (th + abs(i-tx) + abs(j-ty))
        for kx, ky, kh in xyh:
            if max(0, ch - abs(cx-kx) - abs(cy-ky)) != kh:
                break
        else:
            print(cx, cy, ch)
            break
    else:
        continue
    break

Submission status: Accepted

Solution code:
n = int(input())

l = []
a = {}
b = {}

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

for cx in range(100+1):
    for cy in range(100+1):
              
        count = 0
        preheight = abs(l[0][0]-cx) + abs(l[0][1]-cy) + l[0][2]

        for ll in l :
            height = abs(ll[0]-cx) + abs(ll[1]-cy) + ll[2] 
            if preheight != height:
                break
            count = count + 1

        if count >= len(l) :
            if preheight in a:
                a[preheight] += 1
                b[preheight] = [cx,cy]
            else:
                a[preheight] = 1
                b[preheight] = [cx,cy]

for ans in a.keys() :
    if a[ans] == 1 :
        print(b[ans][0],b[ans][1],ans)
        exit(0)

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

			if h == 0:
				if H > abs(x - cx) + abs(y - cy):
					break
			else:
				if H != h + abs(x - cx) + abs(y - cy):
					break
		else:
			if H < 1:
				H = 1
			print(cx, cy, H)
			exit()

Submission status: Accepted

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

C_x = C_y = H = 0


for i in range(N):
    for c_x in range(101):
        for c_y in range(101):
            H = h[i] + abs(x[i] - c_x) + abs(y[i] - c_y)

            for j in range(N):
                if h[j] == max(H - abs(x[j] - c_x) - abs(y[j] - c_y), 0):
                    continue
                break

            else:
                C_x = c_x
                C_y = c_y
                break
            continue
        else:
            continue
        break
    else:
        continue
    break

else:
    print('No!')

print(C_x, C_y, H)

Submission status: Accepted

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

INF = float('inf')
for cx in range(101):
    for cy in range(101):
        H = INF
        Hmax = INF
        for i in range(n):
            if h[i] > 0 and H == INF:
                H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
            elif h[i] > 0 and H != h[i] + abs(x[i] - cx) + abs(y[i] - cy):
                break
            elif h[i] == 0:
                Hmax = min(Hmax, abs(x[i] - cx) + abs(y[i] - cy))
        else:
            if H <= Hmax:
                print(cx, cy, H)
                exit()
            elif H == INF and Hmax == 1:
                print(cx, cy, 1)
                exit()

Submission status: Accepted

Solution code:
N = int(input())
L = [list(map(int, input().split())) for k in range(N)]
m = 0
for l in L:
    m = max(m,l[2])

for x in range(101):
    for y in range(101):
        for h in range(m,m+101):
            f = 1
            for l in L:
                if l[2]!=max(h-abs(l[0]-x)-abs(l[1]-y),0):
                    f = 0
                    break
            if f:
                print(x,y,h)
                exit(0)

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 = []
hmax = 0
xmax = -1
ymax = -1
for _ in range(n):
    x,y,h = li()
    if h > hmax:
        hmax = h
        xmax = x
        ymax = y
        
    xyh.append((x,y,h))
    
xans = -1
yans = -1
hans = -1
flag = False
    
for x in range(101):
    for y in range(101):
        hcent = hmax + abs(xmax-x) + abs(ymax-y)
        consis = True
        
        for xi,yi,hi in xyh:
            if hi != max(0, hcent - abs(x-xi) - abs(y-yi)):
                consis = False
                
        if not consis:
            continue
                
        if consis:
            xans = x
            yans = y
            hans = hcent
            
            flag = True
            break
            
    if flag:
        break
            
            
print(xans, yans, hans)

Submission status: Accepted

Solution code:
N = int(input())
xyh = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h != 0:
        xyh.append([x, y, h])

if len(xyh) == 1:
    Cx, Cy, H = xyh[0][0], xyh[0][1], xyh[0][2]

elif len(xyh) == 2:
    if xyh[0][2] > xyh[1][2]:
        Cx, Cy, H = xyh[0][0], xyh[0][1], xyh[0][2]
    else:
        Cx, Cy, H = xyh[1][0], xyh[1][1], xyh[1][2]

else:
    flag = False
    for i in range(101):
        for j in range(101):
            sampleH = xyh[0][2] + abs(i-xyh[0][0]) + abs(j-xyh[0][1])
            for k in range(1, len(xyh)):
                flag = True
                if xyh[k][2] + abs(i-xyh[k][0]) + abs(j-xyh[k][1]) != sampleH:
                    flag = False
                    break
            if flag:
                Cx, Cy, H = i, j, sampleH
                break
        if flag:
            break

print(Cx, Cy, H)

Submission status: Accepted

Solution code:
n=int(input())
x,y,h=map(int,input().split())
d=set([(x,y,h)])
t=[x,y,h]
for i in range(n-1):
    x,y,h=map(int,input().split())
    d.add((x,y,h))
    if t[2]==0: t=[x,y,h]

for i in range(101):
    for j in range(101):
        f=0
        p=abs(t[0]-i)+abs(t[1]-j)+t[2]
        for k in d:
            if k[2]!=0 and abs(k[0]-i)+abs(k[1]-j)+k[2]!=p: f=1
            if k[2]==0 and abs(k[0]-i)+abs(k[1]-j)+k[2]<p: f=1
        if f==0:
            print(i,j,p)
            exit()

Submission status: Accepted

Solution code:
def main():
    n = int(input())

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

    l.sort(key = lambda x:-x[2])

    for cx in range(0, 101):
        for cy in range(0, 101):
            for i, xyh in enumerate(l):
                x,y,h = xyh
                if i == 0:
                    H = h + abs(x-cx) + abs(y-cy)
                    if H < 1 or H != int(H):
                        break
                    continue
                if h != max((H - abs(x-cx) - abs(y-cy)), 0):
                    break
                if i == n-1:
                    print(cx,cy,H)
                    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
D = []
for i in range(N):
  D.append(list(map(int, input().split())))
D.sort(key = lambda x:x[2], reverse = True)
for i in range(101):
  for j in range(101):
    F = True
    H = abs(i - D[0][0]) + abs(j-D[0][1]) + D[0][2]
    for k in range(1,N):
      if D[k][2] != 0:
        if H != abs(i - D[k][0]) + abs(j-D[k][1]) + D[k][2]:
          F = False
          break
      else:
        if H > abs(i - D[k][0]) + abs(j-D[k][1]) + D[k][2]:
          F = False
          break
    if F == True:
      print(str(i) + " " + str(j) + " " + str(H))
      exit()

Submission status: Accepted

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

for cx in range(100 + 1):
    for cy in range(100 + 1):
        flg = True
        for i in range(N):
            if hs[i] == 0:
                continue
            H = hs[i] + abs(xs[i] - cx)  + abs(ys[i] - cy)
            if H != 0:
                break
        if H == 0:
            break
        for i in range(N):
            h_ = max(H - abs(xs[i] - cx) - abs(ys[i] - cy), 0)
            if hs[i] != h_:
                flg = False
                break
        if flg:
            print("{0} {1} {2}".format(cx, cy, H))
            exit()

Submission status: Accepted

Solution code:
n = int(input())
data = [list(map(int, input().split())) for _ in range(n)]
for c_x in range(101):
    for c_y in range(101):
        valid = True
        H = None
        # h==0でも情報はあって、これを逃さない
        for i in range(n):
            x, y, h = data[i]
            if h >= 1:
                H = h + abs(x-c_x) + abs(y-c_y)
                break
        for i in range(n):
            x, y, h = data[i]
            if h != max(H - abs(x-c_x) - abs(y-c_y), 0):
                valid = False
                break
        if valid:
            print(c_x, c_y, H)

Submission status: Accepted

Solution code:

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

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

ans_xy = [(0,0)]
ans_H  = 0
for X in range(101):
    for Y in range(101):
        for i in range(N):
            x,y,h = XYH[i]

            if i == 0:
                H_q = h + abs(X-x) + abs(Y-y)
            else:
                h_now = max(0, H_q - abs(X-x) - abs(Y-y))
                if h_now != h:
                    break
        else:
            ans_H = H_q
            print(X,Y,ans_H)
            exit()

Submission status: Accepted

Solution code:
n = int(input())
points = []
for i in range(n):
    x, y, h = map(int, input().split())
    points.append((h, x, y))
points.sort(reverse=True)

for i in range(101):
    for j in range(101):
        ph, px, py = points[0]
        hp = ph + abs(i - px) + abs(j - py)
        if all([ph == max(hp - abs(i - px) - abs(j - py), 0) for ph, px, py in points]):
            print(i, j, hp)
            exit()

Submission status: Accepted

Solution code:
import sys
N = int(input())
point = [[int(i) for i in input().split()] for _ in range(N)]
point.sort(key=lambda x:x[2],reverse=True)
for cx in range(101):
    for cy in range(101):
        H = point[0][2]+abs(cx-point[0][0])+abs(cy-point[0][1])
        OK = True
        for i in range(N):
            if not point[i][2]==max(H-abs(cx-point[i][0])-abs(cy-point[i][1]),0):
                OK = False
                break
        if OK:
            print(cx,cy,H)
            sys.exit(0)

Submission status: Accepted

Solution code:
from math import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = sorted(all_input_list, key=lambda x: x[2])[-1]
for cx in range(101):
    for cy in range(101):
        H = h + abs(cx - x) + abs(cy - y)
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                break
        else:
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

Submission status: Accepted

Solution code:
from math import *

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        H = h + abs(cx - x) + abs(cy - y)
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                break
        else:
            print("%s %s %s" % (cx, cy, H))
            exit()

Submission status: Accepted

Solution code:
from math import *

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        H = h + abs(cx - x) + abs(cy - y)
        #変数を個別に格納しない方が、メモリ節約になる
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                break
        else:
            print("%s %s %s" % (cx, cy, H))
            exit()

Submission status: Accepted

Solution code:
from math import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        H = h + abs(cx - x) + abs(cy - y)
        for xi, yi, hi in all_input_list:
            if (hi != max(H - abs(cx - xi) - abs(cy - yi), 0)):
                break
        else:
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

Submission status: Accepted

Solution code:
from math import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        H = h + abs(cx - x) + abs(cy - y)
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                break
        else:
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

Submission status: Accepted

Solution code:
from math import *
import sys

N = int(input())
all_input_list = [[int(j) for j in input().split()] for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = h + abs(cx - x) + abs(cy - y)
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                flag = 0
                break
        if (flag == 1):
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

Submission status: Accepted

Solution code:
from math import *
from itertools import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx, cy in product(range(101), range(101)):
    flag = 1
    H = h + abs(cx - x) + abs(cy - y)
    for input_list in all_input_list:
        if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
            flag = 0
            break
    if (flag == 1):
        print("%s %s %s" % (cx, cy, H))
        sys.exit(0)

Submission status: Accepted

Solution code:
from math import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = h + abs(cx - x) + abs(cy - y)
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                flag = 0
                break
        if (flag == 1):
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

Submission status: Accepted

Solution code:
from math import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x_y_h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = x_y_h[2] + abs(cx - x_y_h[0]) + abs(cy - x_y_h[1])
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                flag = 0
                break
        if (flag == 1):
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

Submission status: Accepted

Solution code:
from math import *

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x_y_h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = x_y_h[2] + abs(cx - x_y_h[0]) + abs(cy - x_y_h[1])
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                flag = 0
                break
        if (flag == 1):
            print("%s %s %s" % (cx, cy, H))
            break
    if (flag == 1):
        break

Submission status: Accepted

Solution code:
n = int(input())

w = [(list(map(int, input().split()))) for i in range(n)]#x,y,h
w.sort(key=lambda x:(x[2]),reverse=True)
hcon1 = 0
hcon2 = 0
for cx in range(101):
    for cy in range(101):
        for i in range(n):
            if w[i][2] > 0:
                if i == 0:
                    hcon1 = abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]
                elif i != 0 and i != n - 1:
                    hcon2 = abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]
                    if hcon1 != hcon2:
                        break
                    else:
                        hcon1 = hcon2
                else:
                    hcon2 = abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]
                    if hcon1 != hcon2:
                        break
                    else:
                        print(cx,cy,hcon1)
                        exit()
            else:
                if i == 0:
                    hcon1 = 1
                elif i != 0 and i != n - 1:
                    if hcon1 > abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]:
                        break
                else:
                    if hcon1 > abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]:
                        break
                    else:
                        print(cx, cy, hcon1)
                        exit()

Submission status: Accepted

Solution code:
n = int(input())
x,y,h = [0]*n,[0]*n,[0]*n
for i in range(n):
  x[i],y[i],h[i] = map(int,input().split())
for a in range(101):
  for b in range(101):
    p = -1
    q = 2000000000
    f = 0
    for i in range(n):
      t = h[i] + abs(x[i]-a) + abs(y[i]-b)
      if h[i]>0:
        if p == -1:
          p = t
        elif not p == t:
          f = 1
          break         
      else:
        q = min(q,t)
    if f == 0 and p<=q:
      print(a,b,p)
      exit()

Submission status: Accepted

Solution code:

n=int(input())
data=[] # data[[x1,y1,h1],...,[xn,yn,hn]]
for i in range(n):
    (xi,yi,hi)=map(int, input().split())
    data.append([xi,yi,hi])

data.sort(key=lambda x:x[2])
data.reverse()

breakflg=False
for cx in range(101):
    if(breakflg):
        break
    for cy in range(101):
        h=abs(data[0][0]-cx)+abs(data[0][1]-cy)+data[0][2]
        flag=True
        for i in range(n):
            h_est=h-abs(data[i][0]-cx)-abs(data[i][1]-cy)
            if(h_est<0):
                h_est=0
            if(data[i][2]!=h_est):
                flag=False
                break
        if(flag):
            print(cx,cy,h)
            breakflg=True;

Submission status: Accepted

Solution code:
N = int(input())
X, Y, H = [], [], []
X0, Y0, H0 = 0, 0, 0
for i in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    if h >= 1:
        X0, Y0, H0 = x, y, h

M = 101
for i in range(M):
    for j in range(M):
        H1 = H0 + abs(X0 - i) + abs(Y0 - j)

        flag = True
        for k in range(N):
            if max(H1 - abs(i - X[k]) - abs(j - Y[k]), 0) != H[k]:
                flag = False

        if flag:
            print(i, j, H1)
            exit()

Submission status: Accepted

Solution code:
import sys

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

xyh.sort(key=lambda x:x[2])

        
if N==1:
    print(xyh[0][0], xyh[0][1] , xyh[0][2])
else:
    for xc in range(101):
        for yc in range(101):
            H = xyh[-1][2] + abs(xyh[-1][0] - xc) + abs(xyh[-1][1] - yc)
            for xi, yi, hi in xyh:
                if hi !=  max(H - abs(xi - xc) - abs(yi - yc), 0):
                    break
            else:
                print(xc, yc, H)
                sys.exit()

Submission status: Accepted

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 cx in range(0, 101):
    for cy in range(0, 101):
        f_i = 0
        for i in range(N):
            if h[i] != 0:
                f_i = i
        H = h[f_i] + abs(x[f_i]-cx) + abs(y[f_i]-cy)
        for i in range(N):
            if H - abs(x[i]-cx) - abs(y[i]-cy) < 0 and h[i] == 0:
                continue
            if H != h[i] + abs(x[i]-cx) + abs(y[i]-cy):
                break
        else:
            print(cx, cy, H)
            exit()
        continue

Submission status: Accepted

Solution code:
N = int(input())
p_infos = []

for i in range(N):
    p_info = [int(s) for s in input().split()]
    if p_info[2] == 0:
        p_infos.append(p_info)
    else:
        p_infos.insert(0, p_info)

is_finished = False
for c_x in range(101):
    if is_finished: break
    for c_y in range(101):
        if is_finished: break
        c_h = -1 # impossible value
        for p in p_infos:
            x, y, h = p[0], p[1], p[2] 
            x_d, y_d = abs(x - c_x), abs(y - c_y)
            if h > 0:
                if c_h == -1:
                    c_h = h + x_d + y_d
                elif c_h != h + x_d + y_d:  
                    break
            elif c_h - x_d - y_d > 0:
                break

            if p == p_infos[-1]:
                print(c_x, c_y, c_h)
                is_finished = True

Submission status: Accepted

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

def reheight(center, point):
    if point[2] == 0:
        return 0
    else:
        return (point[2] + abs(center[0] - point[0]) + abs(center[1] - point[1]))

def height(center, high, point):
    return max(high - abs(center[0] - point[0]) - abs(center[1] - point[1]), 0)

for i in range(101):
    for j in range(101):
        k_ = 0
        center = [i, j]
        while (reheight(center, hints[k_]) == 0):
            k_ += 1
        hmax = reheight(center, hints[k_])
        k = 0
        while (k < n and (hints[k])[2] == height(center, hmax, (hints[k])[:2])):
            k += 1
        if k == n:
            break
    if k == n:
        break
        
print("{} {} {}".format(center[0], center[1], hmax))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
x = np.empty(N,dtype=np.int)
y = np.empty(N,dtype=np.int)
h = np.empty(N,dtype=np.int)
for n in range(N):
    (x[n],y[n],h[n]) = map(int,input().split())

M = 100

grads = np.array([[1,1],[-1,1],[-1,-1],[1,-1]],dtype=np.int)
def height(x,y,h,i,j,d):
    # d=0-3
    return (h + grads[d,0]*(i-x) + grads[d,1]*(j-y))

def quadrant(x,y):
    if x > 0 and y >= 0:
        return 0
    elif y > 0:
        return 1
    elif x < 0:
        return 2
    else:
        return 3

Clist = [(Cx,Cy) for Cy in range(M+1) for Cx in range(M+1)]
k = h.argmax()
for (Cx,Cy) in Clist:
    H = height(x[k],y[k],h[k],Cx,Cy,quadrant(Cx-x[k],Cy-y[k]))
    for n in range(N):
        Hn = height(x[n],y[n],h[n],Cx,Cy,quadrant(Cx-x[n],Cy-y[n]))
        if h[n] == 0:
            if Hn < H:
                break
        else:
            if Hn != H:
                break
    else:
        break

print(Cx,Cy,H)

Submission status: Accepted

Solution code:
N = int(input())

x = []
y = []
h = []
x_t, y_t, h_t = 0, 0, 0
for i in range(N):
    x_i, y_i, h_i = map(int, input().split())
    x.append(x_i)
    y.append(y_i)
    h.append(h_i)
    if h_i > 0 and h_t == 0:
        x_t = x_i
        y_t = y_i
        h_t = h_i

for i in range(101):
    for j in range(101):
        px = i
        py = j
        ph = h_t + abs(px - x_t) + abs(py - y_t)
        flag = True
        for k in range(N):
            if max(ph - abs(x[k] - px) - abs(y[k] - py), 0) != h[k]:
                flag = False
                break
        if flag:
            print(px, py, ph)
            break
    if flag:
        break

Submission status: Accepted

Solution code:
N = int(input())
x = {}
y = {}
h = {}
for i in range(N):
  x[i], y[i], h[i] = map(int, input().split())
  if h[i] != 0:
    x0, y0, h0 = x[i], y[i], h[i]
for cx in range(101):
  for cy in range(101):
    H = h0 + abs(cx - x0) + abs(cy - y0)
    for i in range(N):
      if max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]:
        break
    else:
      print(cx, cy, H)
      break
    continue
  else:
    continue
  break

Submission status: Accepted

Solution code:
import sys

x=[]
y=[]
h=[]
n=int(input())
for i in range(n):
    a,b,c=list(map(int,input().split()))
    x.append(a)
    y.append(b)
    h.append(c)

for cx in range(101):
    for cy in range(101):
        for i in range(n):
            if(h[i]==0):
                continue
            else:
                H=h[i]+abs(cx-x[i])+abs(cy-y[i])
                break
        for i in range(n):
            if(h[i]!=max(H-abs(cx-x[i])-abs(cy-y[i]),0)):
                    break
        else:
            print("{} {} {}".format(cx,cy,H))
            sys.exit(0)

Submission status: Accepted

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


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


def g(l, cx, cy):
    H_max_l = set(H(cx, cy, x, y, h) for x, y, h in l if h == 0)
    h_max = min(H_max_l) if any(H_max_l) else -1
    
    TH = set(H(cx, cy, x, y, h) for x, y, h in l if h > 0)
    if len(TH) == 1:
        high = TH.pop()
        if h_max == -1 or high <= h_max:
            return high
    return -1


def f(l):
    for cx in range(0, 101):
        for cy in range(0, 101):
            h = g(l, cx, cy)
            if h > 0:
                return cx, cy, h

cx, cy, h = f(xyh)
print(cx, cy, h)

Submission status: Accepted

Solution code:
N = int(input())
x = {}
y = {}
h = {}
for i in range(N):
  x[i], y[i], h[i] = map(int, input().split())
  if h[i] != 0:
    x0, y0, h0 = x[i], y[i], h[i]
for cx in range(101):
  for cy in range(101):
    H = h0 + abs(cx - x0) + abs(cy - y0)
    for i in range(N):
      if max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]:
        break
    else:
      print(cx, cy, H)
      break
    continue
  else:
    continue
  break

Submission status: Accepted

Solution code:
N = int(input())

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

ok = False
for x in range(101):
    for y in range(101):
        if ok:
            break
        cand = []
        for i in range(N):
            h = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
            if hs[i] == 0:
                cand.append((h, False))
            else:
                cand.append((h, True))

    
        cand2 = set([c[0] for c in cand if c[1]])
        if len(cand2) != 1:
            continue

        assert len(cand2) == 1
        ans = cand2.pop()

        if all([c[0] >= ans for c in cand if not c[1]]):
            print(x, y, ans)
            ok = True





assert ok

Submission status: Accepted

Solution code:

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

for i in range(101):
    for j in range(101):
        tmp_h=h[hizero]+abs(x[hizero]-i)+abs(y[hizero]-j)
        for k in range(0,n):
            if(max([0,tmp_h-abs(x[k]-i)-abs(y[k]-j)])!=h[k]):
                break
        if(max([0,tmp_h-abs(x[k]-i)-abs(y[k]-j)])==h[k]):
            break
    if(max([0,tmp_h-abs(x[k]-i)-abs(y[k]-j)])==h[k]):
        break
print("{} {} {}".format(i,j,tmp_h))

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
#print(l) 
for j in range(0,101):
    for k in range(0,101):
        for i in range(n):
            if l[i][2]>0:
                h=(l[i][2]+abs(j-l[i][0])+abs(k-l[i][1]))
                #print(j,k,h)
                break
        for i in range(n):
            h_r=max((h-abs(j-l[i][0])-abs(k-l[i][1])),0)
            if l[i][2] !=h_r:
                #print(True)
                break
        else:
            print(j,k,h)