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: Wrong Answer

Solution code:
import numpy as np
n  = int(input())

xs = []
ys = []
hs = []
for k in range(n):
    xx, yy, hh = list(map(int,input().split()))
    xs.append(xx)
    ys.append(yy)
    hs.append(hh)    
x = np.array(xs)
y = np.array(ys)
h = np.array(hs)

from itertools import product
cand = []
for cx, cy in product(range(101), range(101)):
    temp1 = abs(cx - x) + abs(cy - y)
    temp2 = temp1 + h
    if len(temp2[h>0]) < 2:
        continue
    else:
        if np.max(temp2[h > 0]) == np.min(temp2[h>0]):
            cand.append((cx,cy,np.max(temp2[h > 0])))
if len(cand) == 1:
    print(cand[0][0],cand[0][1],cand[0][2])
elif len(cand)>50:
    print(x[h == 1], y[h==1], 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
num = [[-1] * 100 for i in range(100)]
for i in range(n):
  a = list(map(int,input().split()))
  lis.append(a)
  num[a[0]-1][a[1]-1] = a[2]
for x in range(100):
  for y in range(100):
    if num[x][y] != -1:
      nu = num[x][y]
    else:
      nu = abs(x-lis[0][0])+abs(y-lis[0][1])+lis[0][2]
    for i in range(n):
      if nu != abs(x-lis[i][0])+abs(y-lis[i][1])+lis[i][2]:
        break
      if i == n-1:
        print(x,y,nu)

Submission status: Wrong Answer

Solution code:
n = int(input())
P = [0] * n
for i in range(n):
    P[i] = list(map(int, input().split()))
P = sorted(P, key=lambda x: x[2], reverse=True)

x, y, h = P[-1]
max_h = h + 100
max_h = min(max_h, 10**9)

P2 = set()
for i in range(101):
    for j in range(101):
        P2.add((i, j))
for hh in range(max_h, P[-1][2]-1, -1):
    P3 = P2.copy()
    for x, y, h in P:
        for xx, yy in P3.copy():
            dx = abs(xx - x)
            dy = abs(yy - y)
            if (h == 0 and hh > dx + dy) or hh - dx - dy != h:
                P3.remove((xx, yy))
    if len(P3) == 1:
        xx, yy = P3.pop()
        print('%d %d %d' % (xx, yy, hh))

Submission status: Wrong Answer

Solution code:
import sys
import itertools

N = int(sys.stdin.readline().strip())

set_list = []
for line in sys.stdin.readlines():
    x, y, h = list(map(int, line.strip().split()))
    ans_set = set()
    for Cx, Cy in itertools.product(range(101), range(101)):
        dx = abs(x - Cx)
        dy = abs(y - Cy)
        d = dx + dy
        H = h + d
        if H >= d:
            ans_set.add((Cx, Cy, H))
            continue
        if h == 0 and H >= 1:
            ans_set.add((Cx, Cy, H))
            continue
    set_list.append(ans_set)

ans_set = set_list[0]
if len(set_list) > 1:
    for s in set_list[1:]:
        ans_set = ans_set & s

if len(ans_set) == 1:
    Cx, Cy, H = list(ans_set)[0]
    print(Cx, Cy, H)
#else:
#    for s in set_list:
#        Cx, Cy, H = list(ans_set)[0]
#        if H >= 1:
#            print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

x0, y0, h0 = map(int, input().split())
for i in range(1,N):
  xi, yi, hi = map(int, input().split())
  if xi-x0 == abs(xi-x0):
    hx = hi + xi
  else:
    hx = hi + (100 -xi)

  if yi-y0 == abs(yi-y0):
    hy = hx + yi
  else:
    hy = hx + (100- yi)

print(hy)

Submission status: Wrong Answer

Solution code:
n = int(input())
X_list = []
Y_list = []
H_list = []
for i in range(n):
    tmp1, tmp2, tmp3 = map(int, input().split())
    X_list.append(tmp1)
    Y_list.append(tmp2)
    H_list.append(tmp3)

X_max = max(X_list)
X_min = min(X_list)
Y_max = max(Y_list)
Y_min = min(Y_list)
flag = False
res  = []
for x in range(0, 101):
    for y in range(0, 101):
        tmp = []
        tmp2 = []
        for i in range(n):
            if H_list[i] != 0:
                tmp.append(abs(X_list[i]-x) + abs(Y_list[i]-y)+H_list[i])
            else:
                tmp2.append(abs(X_list[i]-x) + abs(Y_list[i]-y)+H_list[i])
                
        if max(tmp) == min(tmp):
            res.append([x, y, max(tmp)])
        if max(tmp+tmp2) == min(tmp+tmp2):
            res.append([x, y, max(tmp)])
#         if flag:
#             break
#     if flag:
#         break
a = 0
res = res[0]
print(res[0], res[1], res[2])

Submission status: Wrong Answer

Solution code:
N = int(input())
xyh = sorted([list(map(int,input().split())) for _ in range(N)], key=lambda x:x[2], reverse=True)
N = len(xyh)

XY = [[True] * 101 for _ in range(101)]

for i in range(N-1):
    tmp = xyh[i][2] - xyh[i+1][2]
    for x in range(101):
        for y in range(101):
            if not XY[y][x]: 
                continue
            if xyh[i+1][2] != 0 and abs(x-xyh[i][0]) + abs(y-xyh[i][1]) + tmp != abs(x-xyh[i+1][0]) + abs(y-xyh[i+1][1]):
                XY[y][x] = False
            elif xyh[i+1][2] == 0 and abs(x-xyh[i][0]) + abs(y-xyh[i][1]) + tmp < abs(x-xyh[i+1][0]) + abs(y-xyh[i+1][1]):
                XY[y][x] = False

for x in range(101):
    for y in range(101):
        if XY[y][x]:
            print(x,y,abs(x-xyh[0][0]) + abs(y-xyh[0][1]) + xyh[0][2])
            exit()

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

if n == 1:
    print(xyh[0][0], xyh[0][1], xyh[0][2])
else:
    ans = []
    for cx in range(101): #Cx 0~100
        for cy in range(101): #Cy 0~100
            h_list = []
            for i in range(n):
                #x[i], y[i], h[i]のときの高さHを求める
                #H = |x[i] - Cx| + |y[i] - Cy| + h[i]
                h = abs(xyh[i][0] - cx) + abs(xyh[i][1] - cy) + xyh[i][2]
                if h > 0:
                    h_list.append(h)

            # Hがすべて一致するときのCx, Cyが答えである
            if len(set(h_list)) == 1:
                ans.append(cx)
                ans.append(cy)
                ans.append(h_list[0])
                print(ans[0], ans[1], ans[2])

Submission status: Wrong Answer

Solution code:
import sys
import itertools

N = int(sys.stdin.readline().strip())

set_list = []
for line in sys.stdin.readlines():
    x, y, h = list(map(int, line.strip().split()))
    ans_set = set()
    for Cx, Cy in itertools.product(range(101), range(101)):
        dx = abs(x - Cx)
        dy = abs(y - Cy)
        d = dx + dy
        H = h + d
        # if H >= d:
        if H >= 1:
            ans_set.add((Cx, Cy, H))
    set_list.append(ans_set)

ans_set = set_list[0]
if len(set_list) > 1:
    for s in set_list[1:]:
        ans_set = ans_set & s

if len(ans_set) == 1:
    Cx, Cy, H = list(ans_set)[0]
    print(Cx, Cy, H)
#else:
#    for s in set_list:
#        Cx, Cy, H = list(ans_set)[0]
#        if H >= 1:
#            print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
n = int(input())
ma = []
for j in range(101):
    ma.append([0] * 101)
for i in range(n):
    x, y, h = map(int, input().split())
    if i == 0:
        for j in range(101):
            for k in range(101):
                ma[j][k] = h + abs(j - x) + abs(k - y)
    else:
        for j in range(101):
            for k in range(101):
                if ma[j][k] != h + abs(j - x) + abs(k - y) and h + abs(j - x) + abs(k - y) > 0:
                    ma[j][k] = 0
ans = 0
for i in range(101):
    if sum(ma[i]) != 0:
        print(i, ma[i].index(sum(ma[i])), sum(ma[i]))
        break

Submission status: Wrong Answer

Solution code:
N =  int(input())

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

for x0 in range(0, 101):
    for y0 in range(0, 101):
        x,y,h = kei[0]
        HH = abs(x - x0) + abs(y - y0) + h
        flg = True
        for n in range(1,N):
            x,y,h = kei[n]
            H2 = abs(x - x0) + abs(y - y0) + h
            if H2 != HH:
                flg = False
                break
        if flg:
            print(x0, y0, HH)

Submission status: Wrong Answer

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

xs = tmp[0::3]
ys = tmp[1::3]
hs = tmp[2::3]
stopflag = False

for H in range(max(max(hs),1), 10**9+1):
    for cx in range(101):
        for cy in range(101):
            for x,y,h in zip(xs,ys,hs):
                if h != max(H-abs(x-cx)-abs(y-cy),0):
                    break
            else:
                print('{} {} {}'.format(cx,cy,H))
                stopflag = True
                break
        if stopflag:
            break
    if stopflag:
        break

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

x0, y0, h0 = map(int, input().split())
for i in range(1,N):
  xi, yi, hi = map(int, input().split())
  if xi-x0 == abs(xi-x0):
    hx = hi + (100 -xi)
  else:
    hx = hi +xi

  if yi-y0 == abs(yi-y0):
    hy = hx + (100 -yi)
  else:
    hy = hx +yi

print(hy)

Submission status: Wrong Answer

Solution code:
import sys


n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]


for i in range(0, 101):
    for j in range(0, 101):
        c = 0
        dict = {}
        for k in range(n):
            if l[k][2] != 0:
                h = l[k][2] + abs(i - l[k][0]) + abs(j - l[k][1])
                c += 1
                if h in dict:
                    dict[h] += 1
                else:
                    dict[h] = 1
        if dict[h] == c:
            print(i, j, h)
            sys.exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
xymap=[[-1 for j in range(101)] for i in range(101)]
for i in range(n):
    xi,yi,hi=map(int,input().split())
    
    if hi==0:
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]<=a and xymap[x][y]!=-2:
                    pass
                else:
                    xymap[x][y]=-2
    else:
            
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]==a or xymap[x][y]==-1 :
                    xymap[x][y]=a
                else:
                    xymap[x][y]=-2
for x in range(101):
    for y in range(101):
        if xymap[x][y]!=-2:
            flag=1
            print(x,y,xymap[x][y])

Submission status: Wrong Answer

Solution code:
n = int(input())
ma = []
for j in range(101):
    ma.append([0] * 101)
for i in range(n):
    x, y, h = map(int, input().split())
    if i == 0:
        for j in range(101):
            for k in range(101):
                ma[j][k] = h + abs(j - x) + abs(k - y)
    else:
        for j in range(101):
            for k in range(101):
                if ma[j][k] != h + abs(j - x) + abs(k - y) and ma[j][k] != 0:
                    ma[j][k] = 0
ans = 0
for i in range(101):
    if sum(ma[i]) != 0:
        print(i, ma[i].index(sum(ma[i])), sum(ma[i]))
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
x, y, h = [], [], []
x2, y2, h2 = [], [], []
for i in range(N):
    xi, yi, hi = map(int, input().split())
    if hi != 0:
        x.append(xi)
        y.append(yi)
        h.append(hi)


def fn(H, X, Y, Cx, Cy):
    return H + abs(Cx - X) + abs(Cy - Y)

for Cx in range(101):
    for Cy in range(101):
        H = fn(h[0], x[0], y[0], Cx, Cy)
        flag = True
        for i in range(1, len(h)):
            if H != fn(h[i], x[i], y[i], Cx, Cy):
                flag = False
                break
        if flag:
            print(Cx, Cy, H)
            exit()

print(x[0], y[0], h[0])

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
n = int(input())
P = [0] * n
for i in range(n):
    P[i] = list(map(int, input().split()))
P = sorted(P, key=lambda x: x[2], reverse=True)

x, y, h = P[-1]
max_h = h + 100
max_h = min(max_h, 10**9)

P2 = set()
for i in range(101):
    for j in range(101):
        P2.add((i, j))
for hh in range(max_h, P[-1][2]-1, -1):
    P3 = P2.copy()
    for x, y, h in P:
        for xx, yy in P3.copy():
            dx = abs(xx - x)
            dy = abs(yy - y)
            if max(hh - dx - dy, 0) != h:
                P3.remove((xx, yy))
    if len(P3) == 1:
        xx, yy = P3.pop()
        print('%d %d %d' % (xx, yy, hh))

Submission status: Wrong Answer

Solution code:
n = int(input())
ma = []
for j in range(101):
    ma.append([0] * 101)
for i in range(n):
    x, y, h = map(int, input().split())
    if i == 0:
        for j in range(101):
            for k in range(101):
                ma[j][k] = h + abs(j - x) + abs(k - y)
    else:
        for j in range(101):
            for k in range(101):
                if ma[j][k] != h + abs(j - x) + abs(k - y) and h + abs(j - x) + abs(k - y) != 0:
                    ma[j][k] = 0
ans = 0
for i in range(101):
    if sum(ma[i]) != 0:
        print(i, ma[i].index(sum(ma[i])), sum(ma[i]))
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
xyh = []
xyh0 = []
for i in range(0,n):
    X,Y,h = map(int,input().split())
    if h != 0:
        xyh.append((X,Y,h))
    else:
        xyh0.append((X,Y))
ans = []
for i in range(0,101):
    for j in range(0,101):
        flag = "f"
        if len(xyh)>0:
            x,y,h = xyh[0]
            H = h + abs(x-i)+abs(y-j)
            flag = "t"
        for x,y,h in xyh:
            if H !=  h + abs(x-i)+abs(y-j):
                flag = "f"
                break
        if flag == "t":
            ans.append((i,j,H))
if len(ans) > 0:
    for i,j,H in ans:
        flag = "t"
        for x,y in xyh0:
            if H < h + abs(x-i)+abs(y-j):
                flag = "false"
                break
        if flag == "t":
            ans = [(i,j,H)]
        if len(ans) == 1:
            break
print(x,y,h)













#

Submission status: Wrong Answer

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

def abs(n):
    n = int(n)
    if n >= 0:
        return n
    else:
        return -n
j = 0
C_x = 0
C_y = 0
while(j == 0):
    H = abs(L[0][0] - C_x) + abs(L[0][1] - C_y) + L[0][2]
    for i in L:
        if i[2] == H - abs(i[0] - C_x) - abs(i[1] - C_y) or i[2] == 0:
            j += 1
        else:
            j = 0
            if C_x == 100:
                C_x = 0
                C_y += 1
            else:
                C_x += 1
            break

print(C_x, end=' ')
print(C_y, end=' ')
print(H)

Submission status: Wrong Answer

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

for i in range(0,N):
    if h[i] == 0:
        x[i] = -1
        y[i] = -1
        h[i] = -1

l = x.count(-1)
for i in range(0,l):
    x.remove(-1)
    y.remove(-1)
    h.remove(-1)

M = len(x)
H = [0 for i in range(0,M)]
print(H)

for X in range(0,101):
    for Y in range(0,101):
        for i in range(0,M):
            H[i] = h[i] + abs(x[i]-X) + abs(y[i]-Y)
        if max(H) == min(H):
            print("{} {} {}".format(X,Y,max(H)))

Submission status: Wrong Answer

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

x_s = 0
x_e = 100
y_s = 0
y_e = 100

for x, y, z in X:
    for x2, y2, z2 in X:
        if (x, y) == (x2, y2):
            continue
        d = abs(x-x2) + abs(y-y2)
        if d == z - z2:            
            if x < x2:
                x_e = min(x_e, x) #左側
            elif x > x2:
                x_s = max(x_s, x) #右側
            if y < y2:
                y_e = min(y_e, y) #上川
            elif y > y2:
                y_s = max(y_s, y) #下側

        else:
            if x < x2:
                x_s = max(x_s, x) #左側
            elif x > x2:
                x_e = min(x_e, x) #右側
            if y < y2:
                y_s = max(y_s, y) #上川
            elif y > y2:
                y_e = min(y_e, y) #下側

x, y, z = X[0]
print(x_e, y_e, z + abs(x_e - x) + abs(y_e - y))

Submission status: Wrong Answer

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

halt = False
for i in range(100+1):
    for j in range(100+1):
        H_cand = set([])
        for d in data:
            H = abs(d[0] - i) + abs(d[1] - j) + d[2]
            if H >= 1:
                H_cand.add(H)
        if len(H_cand) == 1:
            print(i, j, list(H_cand)[0])
            halt = True
            break
    if halt:
        break

Submission status: Wrong Answer

Solution code:
a = int(input())

b = []

p = 0
pp = 0
ppp = 0
for i in range(a):
    b.append(list(map(int,input().split())))

for i in range(0,101,-1):
    for j in range(0,101,-1):
        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: Wrong Answer

Solution code:
import numpy as np
n  = int(input())

xs = []
ys = []
hs = []
for k in range(n):
    xx, yy, hh = list(map(int,input().split()))
    xs.append(xx)
    ys.append(yy)
    hs.append(hh)    
x = np.array(xs)
y = np.array(ys)
h = np.array(hs)

from itertools import product
cand = []
for cx, cy in product(range(101), range(101)):
    temp1 = abs(cx - x) + abs(cy - y)
    temp2 = temp1 + h
    if len(temp2[h>0]) < 2:
        continue
    else:
        if np.max(temp2[h > 0]) == np.min(temp2[h>0]):
            cand.append((cx,cy,np.max(temp2[h > 0])))
if len(cand) == 1:
    print(cand[0][0],cand[0][1],cand[0][2])
elif len(cand)>50:
    cx = np.zeros([101])
    for c in cand:
        cc[c[0]] = 1
    x = np.where(cc == 0)[0]
    cx = np.zeros([101])
    for c in cand:
        cc[c[1]] = 1
    y = np.where(cc == 0)[0]
    print(x,y,1)

Submission status: Wrong Answer

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

H = -1
C_x = 0
C_y = 0

def height(C_x,C_y,x,y,h):
  H = h + abs(x-C_x) + abs(y-C_y)
  return H

def koud(C_x,C_y,H,x,y):
  h = H - abs(x-C_x) - abs(y-C_y)
  return h

flag = False
for i in range(0,101):
  C_x = i
  for j in range(0,101):
    C_y = j
    H = -1
    for k in range(N):
      if zahyou[k][2] == 0:#高度が0のとき
        continue
      if H < 0:
        H = height(C_x,C_y,zahyou[k][0],zahyou[k][1],zahyou[k][2])
      else:
        if zahyou[k][2] != koud(C_x,C_y,H,zahyou[k][0],zahyou[k][1]):
          break
        else:
          continue        
    else:
      flag = True
      break
    if flag:
      break
  if flag:
    break

print(C_x,C_y,H)

Submission status: Wrong Answer

Solution code:
def cal(X,Y,H):
    flag=0
    if(H[0]==0):    flag=1
    if(H[0]==0 and H[1]==0):    flag=2
    
    if(flag==0):
        for i in range(0,101):
            for j in range(0,101):
                temp=H[0]+abs(X[0]-i)+abs(Y[0]-j)
                for l in range(1,N):
                    if(H[l]!=0):
                        s=H[l]+abs(X[l]-i)+abs(Y[l]-j)
                        if(temp==s):
                            temp=s
                        else:
                            break
                    else:
                        if(temp-abs(X[l]-i)-abs(Y[l]-j)>0):
                            break
                else:
                    return print("{} {} {}".format(i,j,temp))
            
    elif(flag==1):
        p=[]
        for i in range(2,N):
            p.append(i)
        for i in range(0,101):
            for j in range(0,101):
                temp=H[1]+abs(X[1]-i)+abs(Y[1]-j)
                for l in p:
                    if(H[l]!=0 and l!=0):
                        s=H[l]+abs(X[l]-i)+abs(Y[l]-j)
                        if(temp==s):
                            temp=s
                        else:
                            break
                    else:
                        if(temp-abs(X[l]-i)-abs(Y[l]-j)>0):
                            break
                else:
                    if(temp-abs(X[0]-i)-abs(Y[0]-j)<0):
                        return print("{} {} {}".format(i,j,temp))       
                    
    elif(flag==2):
        p=[]
        for i in range(3,N):
            p.append(i)
        for i in range(0,101):
            for j in range(0,101):
                temp=H[1]+abs(X[1]-i)+abs(Y[1]-j)
                for l in p:
                    if(H[l]!=0 and l!=0):
                        s=H[l]+abs(X[l]-i)+abs(Y[l]-j)
                        if(temp==s):
                            temp=s
                        else:
                            break
                    else:
                        if(temp-abs(X[l]-i)-abs(Y[l]-j)>0):
                            break
                else:
                    if(temp-abs(X[0]-i)-abs(Y[0]-j)<0):
                        return print("{} {} {}".format(i,j,temp))   
    

N=int(input())
X=[]
Y=[]
H=[]
for i in range(N):
    x,y,h=list(map(int,input().split()))
    X.append(x)
    Y.append(y)
    H.append(h)
cal(X,Y,H)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
H = []
L = []
for i in range(N) :
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    L.append([x,y,h])
maxH = max(H)
if H.count(maxH) == 1 :
    for j in range(N) :
        if H[j] == maxH :
            print(X[j],Y[j],maxH)
            break
else :
    P = []
    Q = []
    for k in range(N) :
        if H[k] == maxH :
            P.append(X[k])
            Q.append(Y[k])
    if len(P) == 2 and len(Q) == 2 :
        for l in range(N) :
            if P[0] == L[l][0] and Q[1] == L[l][1] :
                answerX = P[1]
                answerY = Q[0]
                answerH = maxH + abs(P[0]-P[1])
                print(answerX,answerY,answerH)
                break
            elif P[1] == L[l][0] and Q[0] == L[l][1] :
                answerX = P[0]
                answerY = Q[1]
                answerH = maxH + abs(P[0]-P[1])
                print(answerX,answerY,answerH)
                break
    elif len(P) == 2 :
        Q = sorted(Q)
        answerY = Q[N//2]
        answerX = (min(Q)+max(Q))//2
        answerH = maxH + (max(Q)-min(Q))
        print(answerX,answerY,answerH)
        
    elif len(Q) == 2 :
        P = sorted(P)
        answerX = P[N//2]
        answerY = (min(P)+max(P))//2
        answerH = maxH + (max(P)-min(P))
        print(answerX,answerY,answerH)
        
    else :
        answerX = (min(X)+max(X))//2
        answerY = (min(Y)+max(Y))//2
        answerH = maxH + (max(P)-min(P))
        print(answerX,answerY,answerH)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for x in range(101):
  for y in range(101):
    a=abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2]
    c=0
    for z in range(1,n):
      if abs(l[z][0]-x)+abs(l[z][1]-y)+l[z][2]==a:c+=1
      if c==n-1:print(x,y,abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2])

Submission status: Wrong Answer

Solution code:
#coding: utf-8
# 調査データの数
N = int(input())

xi = 0
yi = 0
hi = 0
for _ in range(N):
    x_val, y_val, h_val = map(int, input().split())
    xi += x_val
    yi += y_val
Cx = xi // N
Cy = yi // N
H = h_val + abs(x_val - Cx) + abs(y_val - Cy)

# 答え
print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
N = input().strip()
import copy

import sys
cc = set()
first = True
for line in sys.stdin:
    x, y, h = [int(x) for x in line.strip().split(' ')]

    if first:
        for cx in range(101):
            for cy in range(101):
                H = h + abs(x-cx) + abs(y-cy)
                if h != 0:
                    cc.add((cx,cy,H))
                else:
                    if H <= 100:
                        for i in range(100-H+1):
                            cc.add((cx, cy, H+i))
        first = False
    else:
        ncc = set()
        for cx in range(101):
            for cy in range(101):
                H = h + abs(x-cx) + abs(y-cy)
                if h != 0:
                    if (cx,cy,H) in cc:
                        ncc.add((cx,cy,H))
                else:
                    if H <= 100:
                        for i in range(100-H+1):
                            if (cx, cy, H+i+1) in cc:
                                ncc.add((cx, cy, H+i))
        cc = copy.deepcopy(ncc)

for i in cc:
    print(i[0], i[1], i[2])
    break

Submission status: Wrong Answer

Solution code:
N = int(input())

x=[]
y=[]
h=[]

for i in range(N):
	x_i,y_i,h_i = list(map(int,input().split()))
	x.append(x_i)
	y.append(y_i)
	h.append(h_i)

s = "A"
s_max=20000
flag = 0
x_a=0
y_a=0
h_a=0

for C_X in range(101):
	for C_Y in range(101):
		for i in range(N):
			if h[i]!=0:
				if s=="A":
					s = abs(x[i]-C_X)+abs(y[i]-C_Y)+h[i]
					if s_max<s: break
					#print("%d %d %d set" % (C_X,C_Y,s))
				elif abs(x[i]-C_X)+abs(y[i]-C_Y)+h[i] != s:
					#print("%d %d %d failed" % (C_X,C_Y,s))
					s=0
					break
			else:
				if s=="A":
					if s_max==20000: s_max=abs(x[i]-C_X)+abs(y[i]-C_Y)
					elif abs(x[i]-C_X)+abs(y[i]-C_Y)<s_max: s_max=abs(x[i]-C_X)+abs(y[i]-C_Y)
				else:
					if abs(x[i]-C_X)+abs(y[i]-C_Y) < s:
						s="A"
						break
			if i==N-1:
				h_a=s
				flag=2
				break
		if flag:
			y_a=C_Y
			break
	if flag:
		x_a=C_X
		break

print("%d %d %d" % (x_a,y_a,h_a))

Submission status: Wrong Answer

Solution code:
import sys
import itertools


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


N = int(sys.stdin.readline().strip())

set_list = []
for line in sys.stdin.readlines():
    x, y, h = list(map(int, line.strip().split()))
    if h == 0:
        continue
    ans_set = set()
    for Cx, Cy in itertools.product(range(101), range(101)):
        dx = abs(x - Cx)
        dy = abs(y - Cy)
        d = dx + dy
        H = h + d
        # if H >= d:
        if H >= 1:
            ans_set.add((Cx, Cy, H))
    set_list.append(ans_set)

ans_set = set_list[0]
for s in set_list[1:]:
    ans_set = ans_set & s

if len(ans_set) == 1:
    Cx, Cy, H = list(ans_set)[0]
    print(Cx, Cy, H)
else:
    for s in set_list:
        Cx, Cy, H = list(ans_set)[0]
        if H >= 1:
            print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

ans = []
for cx in range(101): #Cx 0~100
    for cy in range(101): #Cy 0~100
        h_list = []
        for i in range(n):
            #x[i], y[i], h[i]のときの高さHを求める
            #H = |x[i] - Cx| + |y[i] - Cy| + h[i]
            h = abs(xyh[i][0] - cx) + abs(xyh[i][1] - cy) + xyh[i][2]
            if h > 0:
                h_list.append(h)

        # Hがすべて一致するときのCx, Cyが答えである
        if len(set(h_list)) == 1:
            ans.append(cx)
            ans.append(cy)
            ans.append(h_list[0])
            print(ans[0], ans[1], ans[2])

Submission status: Wrong Answer

Solution code:
n = int(input())
ma = []
for j in range(101):
    ma.append([0] * 101)
for i in range(n):
    x, y, h = map(int, input().split())
    if i == 0:
        for j in range(101):
            for k in range(101):
                ma[j][k] = h + abs(j - x) + abs(k - y)
    else:
        for j in range(101):
            for k in range(101):
                if ma[j][k] != h + abs(j - x) + abs(k - y):
                    ma[j][k] = 0
ans = 0
for i in range(101):
    if sum(ma[i]) != 0:
        print(i, ma[i].index(sum(ma[i])), sum(ma[i]))
        break

Submission status: Wrong Answer

Solution code:
def dist(a, b, x, y, h):
    return h + abs(a - x) + abs(b - y)

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

for i in range(N-1):
    a, b, c = map(int, input().split())
    if P[a][b] != c:
        P[a][b] = False
    for j in range(101):
        for k in range(101):
            if P[j][k] != False and P[j][k] != dist(j, k, a, b, c):
                P[j][k] = False
for i in range(101):
    for j in range(101):
        if P[i][j]:
            print(i, j, P[i][j])
            break

Submission status: Wrong Answer

Solution code:
N = int(input())
xyh = sorted([list(map(int,input().split())) for _ in range(N)], key=lambda x:x[2], reverse=True)
xyh = [(x,y,h) for x,y,h in xyh if h != 0]
N = len(xyh)

XY = [[True] * 101 for _ in range(101)]

for i in range(N-1):
    tmp = xyh[i][2] - xyh[i+1][2]
    for x in range(101):
        for y in range(101):
            if not XY[y][x]: 
                continue
            if abs(x-xyh[i][0]) + abs(y-xyh[i][1]) != abs(x-xyh[i+1][0]) + abs(y-xyh[i+1][1]) - tmp:
                XY[y][x] = False

for x in range(101):
    for y in range(101):
        if XY[y][x]:
            print(x,y,abs(x-xyh[0][0]) + abs(y-xyh[0][1]) + xyh[0][2])
            exit()

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