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())
d=[]
if n>=4:
  for i in range(4):
    d.append(list(map(int,input().split())))
else:
  d=[list(map(int,input().split())) for i in range(n)]
  
for Cx in range(1,101):
  for Cy in range(1,101):
    k=0
    if n>=2:
      for i in range(3):
        if d[i][2]+abs(d[i][0]-Cx)+abs(d[i][1]-Cy) != d[i+1][2]+abs(d[i+1][0]-Cx)+abs(d[i+1][1]-Cy):
          k=1
      if k==0:
        print(Cx,Cy,d[i][2]+abs(d[i][0]-Cx)+abs(d[i][1]-Cy))

Submission status: Runtime Error

Solution code:
n=int(input())
d=[]
if n>=4:
  for i in range(4):
    d.append(list(map(int,input().split())))
else:
  d=[list(map(int,input().split())) for i in range(n)]
  
for Cx in range(1,101):
  for Cy in range(1,101):
    k=0
    if n>=2:
      for i in range(4):
        if d[i][2]+abs(d[i][0]-Cx)+abs(d[i][1]-Cy) != d[i+1][2]+abs(d[i+1][0]-Cx)+abs(d[i+1][1]-Cy):
          k=1
      if k==0:
        print(Cx,Cy,d[i][2]+abs(d[i][0]-Cx)+abs(d[i][1]-Cy))

Submission status: Runtime Error

Solution code:
n=int(input())
d=[]
if n>=4:
  for i in range(4):
    d.append(list(map(int,input().split())))
else:
  d=[list(map(int,input().split())) for i in range(n)]
  
for Cx in range(101):
  for Cy in range(101):
    k=0
    if n>=2:
      for i in range(n-1):
        if d[i][2]+abs(d[i][0]-Cx)+abs(d[i][1]-Cy) != d[i+1][2]+abs(d[i+1][0]-Cx)+abs(d[i+1][1]-Cy):
          k=1
      if k==0:
        print(Cx,Cy,d[i][2]+abs(d[i][0]-Cx)+abs(d[i][1]-Cy))

Submission status: Runtime Error

Solution code:
n=int(input())
d=[]
if n>=4:
  for i in range(4):
    d.append(list(map(int,input().split())))
else:
  d=[list(map(int,input().split())) for i in range(n)]
  
for Cx in range(101):
  for Cy in range(101):
    k=0
    for i in range(n-1):
      if d[i][2]+abs(d[i][0]-Cx)+abs(d[i][1]-Cy) != d[i+1][2]+abs(d[i+1][0]-Cx)+abs(d[i+1][1]-Cy):
        k=1
    if k==0:
      print(Cx,Cy,d[i][2]+abs(d[i][0]-Cx)+abs(d[i][1]-Cy))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
lis = np.zeros((101,101))
s = list()
for k in range(N):
    tmp = list()
    x,y,h = map(int,input().split())
    if h == 0:
        continue
    if s:
        if len(s) == 1:
            break
        for i in s:
            if i[2] == h+abs(i[0]-x)+abs(i[1]-y):
                tmp.append(i)
        s = tmp
    else:
        for i in range(101):
            for j in range(101):
                if lis[i][j] == 0:
                    lis[i][j] = h+abs(i-x)+abs(j-y)
                elif lis[i][j] == h+abs(i-x)+abs(j-y):
                    s.append([i,j,lis[i][j]])
print(s[0][0], s[0][1], int(s[0][2]))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
lis = np.zeros((101,101))
s = list()
for k in range(N):
    tmp = list()
    x,y,h = map(int,input().split())
    if s:
        if len(s) == 1:
            break
        for i in s:
            if i[2] == h+abs(i[0]-x)+abs(i[1]-y):
                tmp.append(i)
        s = tmp
    else:
        for i in range(101):
            for j in range(101):
                if lis[i][j] == 0:
                    lis[i][j] = h+abs(i-x)+abs(j-y)
                elif lis[i][j] == h+abs(i-x)+abs(j-y):
                    s.append([i,j,lis[i][j]])
print(s[0][0], s[0][1], int(s[0][2]))

Submission status: Runtime Error

Solution code:
def f(n, x):
    if n >= 0: return n//x+1
    else: return 0

a,b,x = map(int, input().split())
print(f(b,x)-f(a-1,x))

Submission status: Runtime Error

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

for _ in range(N):
    temp = list(map(int, input().split()))
    xyz.append(temp)

if N == 1:
    ans = [str(xyz[0][0]), str(xyz[0][1]), str(xyz[0][2])]
else:
    for i in range(101):
        for j in range(101):
            h = max(xyz[0][2] + abs(xyz[0][0] - i) + abs(xyz[0][1] - j),0)

            count = N
            for n in range(0,N):
                g = max(h - abs(i - xyz[n][0]) - abs(j - xyz[n][1]),0)
                if g == xyz[n][2]:
                    count -= 1
            
            if count == 0:
                ans = [str(i), str(j), str(h)]
                break

ans_s = ' '.join(ans)
print(ans_s)

Submission status: Runtime Error

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

for _ in range(N):
    temp = list(map(int, input().split()))
    xyz.append(temp)

if N == 1:
    ans = [str(xyz[0][0]), str(xyz[0][1]), str(xyz[0][2])]
else:
    for i in range(101):
        for j in range(101):
            h = xyz[0][2] + abs(xyz[0][0] - i) + abs(xyz[0][1] - j)

            count = N
            for n in range(0,N):
                g = max(h - abs(i - xyz[n][0]) - abs(j - xyz[n][1]),0)
                if g == xyz[n][2]:
                    count -= 1
            
            if count == 0:
                ans = [str(i), str(j), str(h)]
                break

ans_s = ' '.join(ans)
print(ans_s)

Submission status: Runtime Error

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

for _ in range(N):
    temp = list(map(int, input().split()))
    xyz.append(temp)

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

        count = N
        for n in range(0,N):
            g = max(h - abs(i - xyz[n][0]) - abs(j - xyz[n][1]),0)
            if g == xyz[n][2]:
                count -= 1
        
        if count == 0:
            ans = [str(i), str(j), str(h)]
            break

ans_s = ' '.join(ans)
print(ans_s)

Submission status: Runtime Error

Solution code:
N = int(input())
xyz = []
r = 0

for _ in range(N):
    temp = list(map(int, input().split()))
    xyz.append(temp)

for n in range(N):
    if xyz[n][2] == 10**9:
        ans = [str(xyz[n][0]), str(xyz[n][1]), str(xyz[n][2])]
        r = 1

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

            count = N
            for n in range(0,N):
                g = h - abs(i - xyz[n][0]) - abs(j - xyz[n][1])
                if g == xyz[n][2]:
                    count -= 1
            
            if count == 0:
                ans = [str(i), str(j), str(h)]
                break

ans_s = ' '.join(ans)
print(ans_s)

Submission status: Runtime Error

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

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

        count = N-1
        for n in range(1,N):
            g = h - abs(i - xyz[n][0]) - abs(j - xyz[n][1])
            if g == xyz[n][2]:
                count -= 1
        
        if count == 0:
            ans = [str(i), str(j), str(h)]
            break

ans_s = ' '.join(ans)
print(ans_s)

Submission status: Runtime Error

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

for Cx in range(101):
    for Cy in range(101):
        for i in range(N):
            if xyh[i][2] >= 1:
                H = xyh[0][2] + abs(Cx-xyh[0][0]) + abs(Cy-xyh[0][1])
                break
        for i in range(N):
            if xyh[i][2] != max(H-abs(xyh[i][0]-Cx)-abs(xyh[i][1]-Cy), 0):
                break
        else:
            res = [str(Cx), str(Cy), str(H)]

print(" ".join(res))

Submission status: Runtime Error

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

for Cx in range(101):
    for Cy in range(101):
        H = xyh[0][2] + abs(Cx-xyh[0][0]) + abs(Cy-xyh[0][1])
        for i in range(1, N):
            if xyh[i][2] != max(H-abs(xyh[i][0]-Cx)-abs(xyh[i][1]-Cy), 0):
                break
        else:
            res = [str(Cx), str(Cy), str(H)]

print(" ".join(res))

Submission status: Runtime Error

Solution code:
n=int(input())

L=[list(map(int,input().split())) for i in range(n)]
LSort=sorted(L,key=lambda x:x[2])
x,y,z=LS[-1]

for cx in range(1,101):
	for cy in range(1,101):
		H=h+abs(x-cx)+abs(y-cy)
		if all([h=max(H-abs(x-cx)-abs(y-cy),0) for x,y,h in LSort])
		print(cx,cy,H)
		exit()

Submission status: Runtime Error

Solution code:
n=int(input())

L=[list(map(int,input().split())) for i in range(n)]
LSort=sorted(L,key=lambda x:x[2])
x,y,z=LS[-1]

for cx in range(1,101):
	for cy in range(1,101):
		H=h+abs(x-cx)+abs(y-cy)
		if all([h=max(H-abs(x-cx)-abs(y-cy),0) for x,y,z in LSort])
		print(cx,cy,H)
		exit()

Submission status: Runtime Error

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

judge = 0
for i in range(101):
	cx = i
	for j in range(101):
		cy = j
		h = []
		for k in range(n):
			h.append(xyh[k][2] + abs(xyh[k][0]-cx) + abs(xyh[k][1]-cy))
		if len(h) == 1:
			lst = [cx, cy, h[k]]
			lst = [str(i) for i in lst]
			print(" ".join(lst))
			exit(0)
		for k in range(len(h)-1):
			if h[k] != h[k+1]:
				break
			if k == len(h)-2:
				lst = [cx, cy, h[k]]
				lst = [str(i) for i in lst]
				print(" ".join(lst))
				exit(0)

Submission status: Runtime Error

Solution code:
N = int(input())
XYH = [[int(x) for x in input().split()] for _ in range(N)]
ans = -1
for i in range(101):
    if (ans != -1): break
    for j in range(101):
        if (ans != -1): break
        x0, y0, h0 = XYH[0]
        H = h0 + abs(i - x0) + abs(j - y0)
        isTop = all([H == h + abs(i - x) + abs(j - y) for x,y,h in XYH])
        if (isTop and H > 0): ans = [i, j, H]
print(ans[0], ans[1], ans[2])

Submission status: Runtime Error

Solution code:
N = int(input())
XYH = [[int(x) for x in input().split()] for _ in range(N)]
ans = -1
if (N == 1):
    x0, y0, h0 = XYH[0]
    print(x0, y0, h0)
    exit()
for i in range(101):
    if (ans != -1): break
    for j in range(101):
        if (ans != -1): break
        x0, y0, h0 = XYH[0]
        H = h0 + abs(i - x0) + abs(j - y0)
        isTop = all([H == h + abs(i - x) + abs(j - y) for x,y,h in XYH])
        if (isTop): ans = [i, j, H]
print(ans[0], ans[1], ans[2])

Submission status: Runtime Error

Solution code:
from sys import setrecursionlimit
setrecursionlimit(10**7)

N = int(input())
XYH = [[int(x) for x in input().split()] for _ in range(N)]
ans = -1
for i in range(101):
    if (ans != -1): break
    for j in range(101):
        if (ans != -1): break
        x0, y0, h0 = XYH[0]
        H = h0 + abs(i - x0) + abs(j - y0)
        isTop = all([H == h + abs(i - x) + abs(j - y) for x,y,h in XYH])
        if (isTop): ans = [i, j, H]
print(ans[0], ans[1], ans[2])

Submission status: Runtime Error

Solution code:
N = int(input())
XYH = [[int(x) for x in input().split()] for _ in range(N)]
ans = -1
for i in range(101):
    if (ans != -1): break
    for j in range(101):
        if (ans != -1): break
        x0, y0, h0 = XYH[0]
        H = h0 + abs(i - x0) + abs(j - y0)
        isTop = all([H == h + abs(i - x) + abs(j - y) for x,y,h in XYH])
        if (isTop): ans = [i, j, H]
print(ans[0], ans[1], ans[2])

Submission status: Runtime Error

Solution code:
N = int(input())

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

p = points[0][0]
q = points[0][1]
r = points[0][2]

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

for i in range(0,101):
  for j in range(0,101):
    H= points[0][2] + point(points[0][0] - i) + abs(points[0][1] - j)
    for x,y,z in points:
      if z != max(H - abs(x - i) - abs(y - j),0):
        break
    else:
      print(i,j,H)

Submission status: Runtime Error

Solution code:
N = int(input()) 
  
grid = []
p, q, r = (0, 0, 0)
for _ in range(n):
    (l, m, n) = map(int, input().split())
    grid.append([l, m, n])
    if N:
        p = l
        q = m
        r = n
 
 
for cx in range(101):
    for cy in range(101):
        h = r + abs(p - cx) + abs(q - cy)
        if all(c == max(h - abs(a - cx) - abs(b - cy), 0) for a, b, c in grid):
            print("{} {} {}".format(cx, cy, h))
            exit(0)

Submission status: Runtime Error

Solution code:
N = int(input())
 
grid = []
p,q,r = (0,0,0)

for _ in range(N):
    (l,m,n) = map(int, input().split())
    grid.append([l, m, n])
    if N:
        p = l
        q = m
        r = n


#101*101通りのため、中心座標cx,cyについて全探索を行う 
for cx in range(101):
    for cy in range(101):
        #各cs,cyについての座標の高さを求める
        h = r + abs(p - cx) + abs(q - cy)
        #与えられた座標の値を順に代入していき、条件を満たすcx,cyの組み合わせに当たれば
        #出力する
        if all(c == max(h - abs(a - cx) - abs(b - cy), 0) for a, b, c in grid):
            print("{} {} {}".format(cx, cy, h))
            exit(0)
            
n = int(input())

Submission status: Runtime Error

Solution code:
N = int(input())

xyh1 = [] # h > 0
xyh2 = [] # h = 0
for _ in range(N) :
    x, y, h = map(int, input().split())
    if h > 0 :
        xyh1.append((x, y, h))
    else :
        xyh2.append((x, y, h))

def solve() :
    for Cx in range(0, 101) :
        for Cy in range(0, 101) :
            # 特定できるからxyh1は必ず1つは要素を持つ?
            x, y, h = xyh1[0]
            H = h + abs(x-Cx) + abs(y-Cy)
            
            flag = False
            for x, y, h in xyh1[1:] :
                if H != h + abs(x-Cx) + abs(y-Cy) :
                    flag = True
                    break
                    
            if flag :
                continue
                
            for x, y, h in xyh2 :
                if h + abs(x-Cx) + abs(y-Cy) > 0 :
                    flag = True
                    break
                    
            if flag :
                continue
                
            return (Cx, Cy, H)
            
print(*solve())

Submission status: Runtime Error

Solution code:
N = int(input())
arr = [list(map(int,input().split())) for _ in range(N)]
global flag
flag = 0
for cx in range(101):
  for cy in range(101):
    ch_arr = []
    cnt = 0
    for x,y,h in arr:
      if h != 0:
      	ch = h + abs(x-cx) + abs(y-cy)
      	ch_arr.append(ch)
      	if cnt > 0:
          if ch_arr[-2] != ch_arr[-1]:
          	break
        cnt += 1
    if len(set(ch_arr))==1:
      flag = 1
      break
  if flag:
    break

print(cx,cy,ch)

Submission status: Runtime Error

Solution code:
N = int(input())
arr = [list(map(int,input().split())) for _ in range(N)]
global flag
flag = 0
for cx in range(101):
  for cy in range(101):
    ch_arr = []
    cnt = 0
    for x,y,h in arr:
      ch = h + abs(x-cx) + abs(y-cy)
      ch_arr.append(ch)
      if cnt > 0:
        if ch_arr[-2] != ch_arr[-1]:
          break
    if (len(set(ch_arr))==1)&&(list(set(ch_arr))[0] != 0)
      flag = 1
      break
  if flag:
    break

print(cx,cy,ch)

Submission status: Runtime Error

Solution code:
N = int(input())

xyh = []
max_h = 0
for i in range(N):
    x = list(map(int, input().split()))
    xyh.append(x)
    if max_h < x[2]:
        max_h = x[2]

flag = False    
while True:
    for i in range(101):
        for j in range(101):
            count = 0
            for k in range(3):
                if xyh[k][2] == max(max_h - abs(xyh[k][0] - i) - abs(xyh[k][1] - j), 0):
                    count += 1
            if count == 3:
                cx = i
                cy = j
                H = max_h
                flag = True
                break
        if flag == True:
            break
            
    max_h += 1
    if flag == True:
        break

print(cx, cy, H)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

N = int(input())
X = np.zeros(N, dtype = np.int64)
Y = np.zeros(N, dtype = np.int64)
H = np.zeros(N, dtype = np.int64)
for i in range(N):
    x, y, h = map(int, input().split())
    X[i] = x
    Y[i] = y
    H[i] = h
node = 10 ** 9
for x in range(101):
    for y in range(101):
        result = (abs(X - x) + abs(Y - y) + H) * (H != 0)
        s = set(result)
        if 0 in s:
            s -= {0}
        if len(s) <= 1:
            height = (abs(X - x) + abs(Y - y) + H).min()
            print(x, y, height)
            sys.exit(0)

Submission status: Runtime Error

Solution code:
N=int(input())
info=[list(map(int,input().split())) for i in range(N)]
info.sort(key=lambda x:x[2],reverse=True)
for i in range(101):
  for j in range(101):
    height=info[0][2]+abs(info[0][0]-i)+abs(info[0][1]-j)
    for h in range(1,N):
      if info[h][2]+abs(info[h][0]-i)+abs(info[h][1]-j)!=height;break
    print(i,j,height);exit()

Submission status: Runtime Error

Solution code:
N = int(input())
maxH = 0
tmpMaxX = -1
tmpMaxY = -1
xs = []
ys = []
hs = []
for i in range(N):
    x, y, h = [int(a) for a in input().split()]
    xs.append(x)
    ys.append(y)
    hs.append(h)
    if (h > maxH):
        tmpMaxX = x
        tmpMaxY = y
        maxH = h
    elif (h == maxH):
        if (tmpMaxX == x):
            tmpMaxX = x
            tmpMaxY = int((tmpMaxY + y) / 2)
            maxH = h + 1
        elif (tmpMaxY == y):
            tmpMaxX = int((tmpMaxX + x) / 2)
            tmpMaxY = y
            maxH = h + 1
        else:
            for j in range(N):
                if (h == (hs[j] + 1)):
                    maxH = h + 1
                    if (tmpMaxX == xs[j]):
                        tmpMaxX = x
                    else:
                        tmpMaxY = y
print (str(tmpMaxX) + ' ' + str(tmpMaxY) + ' ' + str(maxH))

Submission status: Runtime Error

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


def f(points):
    for x in range(0, 101):
        for y in range(0, 101):
            h = 0
            same = True
            for p in points:
                h_p = abs(x - p[0]) + abs(y - p[1]) + p[2]
                if h != 0 and h != h_p:
                    same = False
                    break
                elif h == 0:
                    h = h_p
            if same:
                return x, y, h

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

Submission status: Runtime Error

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


def f(points):
    for x in range(0, 101):
        for y in range(0, 101):
            h = 0
            same = True
            for p in points:
                h_p = abs(x - p[0]) + abs(y - p[1]) + p[2]
                if h != 0 and h != h_p:
                    same = False
                    break
                elif h == 0:
                    h = h_p
            if same:
                return x, y, h


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

Submission status: Runtime Error

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

def f(points):
  for x in range(0,101):
    for y in range(0,101):
      h = 0
      same = True
      for p in points:
        h_p = abs(x-p[0]) + ans(y-p[1]) + p[2]
        if h != 0 and h != h_p:
          same = False
          break
        elif h == 0:
          h = h_p
      if same:
        return x,y,h
      
ans = f(points)
print("{} {} {}", format(ans[0], ans[1], ans([2])))

Submission status: Runtime Error

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

for i in range(101):  # x座標
    for j in range(101):  # y座標
        tmp_h = abs(xyh[0][0]-i)+abs(xyh[0][1]-j)+xyh[0][2]
        cnt = 0
        for k in range(N):
            if xyh[k][2] == max(0,tmp_h-abs(xyh[k][0]-i)-abs(xyh[k][1]-j)):
                cnt += 1
        if cnt == N:
            ans_x = i
            ans_y = j
            ans_h = tmp_h
            break
print(ans_x, ans_y, ans_h)

Submission status: Runtime Error

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

for i in range(101):  # x座標
    for j in range(101):  # y座標
        tmp_h = abs(xyh[0][0]-i)+abs(xyh[0][1]-j)+xyh[0][2]
        cnt = 0
        for k in range(N):
            if tmp_h == abs(xyh[k][0]-i)+abs(xyh[k][1]-j)+xyh[k][2]:
                cnt += 1
        if cnt == N:
            ans_x = i
            ans_y = j
            ans_h = tmp_h
            break
print(ans_x, ans_y, ans_h)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  query = []
  candi = []
  for i in range(n):
    x,y,h = (int(i) for i in input().split())
    query.append((x,y,h))
  if n == 1:
    print(*[x,y,h])
    exit()
  for cx in range(0,101):
    for cy in range(0,101):
      judge = True
      x,y,h = query[0]
      karih = h +abs(cx-x)+abs(cy-y)
      karih2 = 0
      for i in range(n-1):
        nx,ny,nh = query[i+1]
        if nh == max(karih-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:
        candi.append((cx,cy,karih))
        
      judge = True 
      for i in range(n-1):
        nx,ny,nh = query[i+1]
        if nh == max(karih2-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:
        candi.append((cx,cy,karih2))
  print(*candi[0])
        
          
      
      
solve()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  query = []
  candi = []
  for i in range(n):
    x,y,h = (int(i) for i in input().split())
    query.append((x,y,h))
  if n == 1:
    print(*[x,y,h])
    exit()
  for cx in range(0,101):
    for cy in range(0,101):
      judge = True
      x,y,h = query[0]
      karih = h +abs(cx-x)+abs(cy-y)
      for i in range(n-1):
        nx,ny,nh = query[i+1]
        if nh == max(karih-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:

        candi.append((cx,cy,karih))
  print(*candi[0])
        
          
      
      
solve()

Submission status: Runtime Error

Solution code:
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
from itertools import product
H={(i,j):-10**9 for i,j in product(range(101),repeat=2)}
for n in range(N):
    x,y,h=xyh[n]
    K=[e for e in H.keys()]
    for i,j in K:
        k0=H[i,j]
        k=abs(i-x)+abs(j-y)+h if h else -(abs(i-x)+abs(j-y))
        if k<0:
            if k0<k:
                H[i,j]=k
            elif -k<k0:
                del H[i,j]
        elif k0<0:
            if k<=-k0:
                H[i,j]=k
            else:
                del H[i,j]
        elif k!=k0:
            del H[i,j]
i,j=list(H.keys())[0]
print(i,j,H[i,j])

Submission status: Runtime Error

Solution code:
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
from itertools import product
H={(i,j):-10**9 for i,j in product(range(101),repeat=2)}
for n in range(N):
    x,y,h=xyh[n]
    K=[e for e in H.keys()]
    for i,j in K:
        k0=H[i,j]
        k=abs(i-x)+abs(j-y)+h if h else -(abs(i-x)+abs(j-y))
        if k<0:
            if k0<k:
                H[i,j]=k
        elif k0<0:
            if k<=-k0:
                H[i,j]=k
            else:
                del H[i,j]
        elif k!=k0:
            del H[i,j]
i,j=list(H.keys())[0]
print(i,j,H[(i,j)])

Submission status: Runtime Error

Solution code:
n = int(input())
xyh_list = [list(map(int, input().split())) for _ in range(n)]
list_0_100 = [i for i in range(0, 101)]
possible_list = []
for b in range(len(xyh_list)):
    if xyh_list[b][2] != 0:
        x1 = xyh_list[b][0]
        y1 = xyh_list[b][1]
        h1 = xyh_list[b][2]
        break
for a in range(b+1, len(xyh_list)):
    x2 = xyh_list[a][0]
    y2 = xyh_list[a][1]
    h2 = xyh_list[a][2]
    break

for i in list_0_100:
    for j in list_0_100:
        if (h2 + abs(x2 - i) + abs(y2 - j)) == (h1 + abs(x1 - i) + abs(y1 - j)):
            possible_list.append([i, j])   # cx, cy 候補
pos_list = []
h0_list = []
for i in range(n):
    if len(possible_list) == 1:
        break
    x = xyh_list[i][0]
    y = xyh_list[i][1]
    h = xyh_list[i][2]
    if h == 0:
        h0_list.append([x, y])
        pos_list.append([x, y])
        continue
    for j in range(len(possible_list)):
        x_ = possible_list[j][0]
        y_ = possible_list[j][1]
        if (h + abs(x - x_) + abs(y - y_)) == (h2 + abs(x2 - x_) + abs(y2 - y_)):
            pos_list.append([x_, y_])
    possible_list = pos_list
    pos_list = []

for i in range(len(h0_list)):
    h0 = h0_list[i][0]
    h1 = h0_list[i][1]
    for x_, y_ in possible_list:
        if (h2 + abs(x2 - x_) + abs(y2 - y_)) <= (abs(h0 - x_) + abs(h1 - y_)):
            possible_list = [x_, y_]
print(possible_list[0][0], possible_list[0][1], \
      h2 + abs(x2 - possible_list[0][0]) + abs(y2 - possible_list[0][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
xyh_list = [list(map(int, input().split())) for _ in range(n)]
list_0_100 = [i for i in range(0, 101)]
possible_list = []
for b in range(len(xyh_list)):
    if xyh_list[b][2] != 0:
        x1 = xyh_list[b][0]
        y1 = xyh_list[b][1]
        h1 = xyh_list[b][2]
        break
for a in range(b+1, len(xyh_list)):
    x2 = xyh_list[a][0]
    y2 = xyh_list[a][1]
    h2 = xyh_list[a][2]
    break

for i in list_0_100:
    for j in list_0_100:
        if (h2 + abs(x2 - i) + abs(y2 - j)) == (h1 + abs(x1 - i) + abs(y1 - j)):
            possible_list.append([i, j])   # cx, cy 候補
pos_list = []
h0_list = []
for i in range(n):
    if len(possible_list) == 1:
        break
    x = xyh_list[i][0]
    y = xyh_list[i][1]
    h = xyh_list[i][2]
    if h == 0:
        h0_list.append([x, y])
        continue
    for j in range(len(possible_list)):
        x_ = possible_list[j][0]
        y_ = possible_list[j][1]
        if (h + abs(x - x_) + abs(y - y_)) == (h2 + abs(x2 - x_) + abs(y2 - y_)):
            pos_list.append([x_, y_])
    possible_list = pos_list
    pos_list = []

for i in range(len(h0_list)):
    h0 = h0_list[i][0]
    h1 = h0_list[i][1]
    for x_, y_ in possible_list:
        if (h2 + abs(x2 - x_) + abs(y2 - y_)) <= (abs(h0 - x_) + abs(h1 - y_)):
            possible_list = [x_, y_]
print(possible_list[0][0], possible_list[0][1], \
      h2 + abs(x2 - possible_list[0][0]) + abs(y2 - possible_list[0][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
xyh_list = [list(map(int, input().split())) for _ in range(n)]
list_0_100 = [i for i in range(0, 101)]
possible_list = []
for i in range(len(xyh_list)):
    if xyh_list[i][2] != 0:
        x1 = xyh_list[i][0]
        y1 = xyh_list[i][1]
        h1 = xyh_list[i][2]
        break
for a in range(i+1, len(xyh_list)):
    x2 = xyh_list[a][0]
    y2 = xyh_list[a][1]
    h2 = xyh_list[a][2]
    break
    
for i in list_0_100:
    for j in list_0_100:
        if (h2 + abs(x2 - i) + abs(y2 - j)) == (h1 + abs(x1 - i) + abs(y1 - j)):
            possible_list.append([i, j])   # cx, cy 候補
pos_list = []
for i in range(a+1, n):
    if len(possible_list) == 1:
        break
    x = xyh_list[i][0]
    y = xyh_list[i][1]
    h = xyh_list[i][2]
    for j in range(len(possible_list)):  
        x_ = possible_list[j][0]
        y_ = possible_list[j][1]
        if (h + abs(x - x_) + abs(y - y_)) == (h2 + abs(x2 - x_) + abs(y2 - y_)):
            pos_list.append([x_, y_])
    possible_list = pos_list
    pos_list = []

print(possible_list[0][0], possible_list[0][1], \
      h2 + abs(x2 - possible_list[0][0]) + abs(y2 - possible_list[0][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
xyh_list = [list(map(int, input().split())) for _ in range(n)]
list_1_100 = [i for i in range(0, 101)]
possible_list = []

x1 = xyh_list[0][0]
y1 = xyh_list[0][1]
h1 = xyh_list[0][2]
x2 = xyh_list[1][0]
y2 = xyh_list[1][1]
h2 = xyh_list[1][2]
for i in list_1_100:
    for j in list_1_100:
        if (h2 + abs(x2 - i) + abs(y2 - j)) == (h1 + abs(x1 - i) + abs(y1 - j)):
            possible_list.append([i, j])   # cx, cy 候補
pos_list = []
for i in range(2, n):
    if len(possible_list) == 1:
        break
    x = xyh_list[i][0]
    y = xyh_list[i][1]
    h = xyh_list[i][2]
    for j in range(len(possible_list)):  
        x_ = possible_list[j][0]
        y_ = possible_list[j][1]
        if (h + abs(x - x_) + abs(y - y_)) == (h2 + abs(x2 - x_) + abs(y2 - y_)):
            pos_list.append([x_, y_])
    possible_list = pos_list
    pos_list = []

print(possible_list[0][0], possible_list[0][1], h2 + abs(x2 - possible_list[0][0]) + abs(y2 - possible_list[0][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
H =[]
for i in range(0,101):
    for j in range(0, 101):
        H.append([i,j,0])

for X,Y,H0 in H:
    this_sum = []
    for x,y,h in a:
        if h >0:
            this_sum.append(max(h + abs(x-X) + abs(y-Y)), 0)
    if all([i == this_sum[0] for i in this_sum]):
        H0 = this_sum[0]
        print(" ".join(list(map(str, [X, Y, H0]))))
        break

Submission status: Runtime Error

Solution code:
N = int(input())
XYH = []
for i in range(N):
  XYH.append(list(map(int,input().split())))
XYH.sort(key=lambda x: x[2], reverse=True)
#print(XYH)

# 与えられた情報のhiがすべて0ということはありえない。
# cx,cyを全探索し、与えられた情報がすべて矛盾がない場合を答えとして出力する。
x0,y0,h0 = XYH[0]
for cx in range(101):
  for cy in range(101):
    ch = h0 + abs(x0-cx) + abs(y0-cy)
    flag = True
    for i in range(1,N):
      x,y,h = XYH[i]
      if (h > 0 and ch != h + abs(x-cx) + abs(y-cy)) or (h == 0 and ch > h + abs(x-cx) + abs(y-cy))
        flag = False
        break
    if flag:
      print(cx,cy,ch)
      exit()