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 itertools

N = int(input())
params = []
for i in range(N):
    xyh = [int(n) for n in input().split()]
    params.append(xyh)

#if len(params) == 1:
#    print(*params[0])

#else:

Cx, Cy, H = 0, 0, 0
for cxi, cyi in itertools.product(range(101), range(101)):
    hight_ = params[0][2] + abs(params[0][0] - cxi) + abs(params[0][1] - cyi)

    for k in range(N):
        if params[k][2] > 0:
            hight = params[k][2] + abs(params[k][0] - cxi) + abs(params[k][1] - cyi)

            if hight < 1:
                break
            else:
                if hight != hight_:
                    break
                else:
                    hight_ = hight
                    continue

        elif params[k][2] == 0:
            if 1 > (abs(params[k][0] - cxi) + abs(params[k][1] - cyi)):
                break
    
    else:
        Cx = cxi
        Cy = cyi
        H = hight
        print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
params = []
for i in range(N):
    xyh = [int(n) for n in input().split()]
    params.append(xyh)

#if len(params) == 1:
#    print(*params[0])

#else:

#Cx, Cy, H = 0, 0, 0
for cxi, cyi in itertools.product(range(101), range(101)):
    hight_ = params[0][2] + abs(params[0][0] - cxi) + abs(params[0][1] - cyi)

    for k in range(N):
        if params[k][2] > 0:
            hight = params[k][2] + abs(params[k][0] - cxi) + abs(params[k][1] - cyi)

            if hight < 1:
                break
            else:
                if hight != hight_:
                    break
                else:
                    hight_ = hight
                    continue

        elif params[k][2] == 0:
            if 1 > (abs(params[k][0] - cxi) + abs(params[k][1] - cyi)):
                break
    
    else:
        Cx = cxi
        Cy = cyi
        H = hight
        print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
params = []
for i in range(N):
    xyh = [int(n) for n in input().split()]
    params.append(xyh)

#if len(params) == 1:
#    print(*params[0])

#else:

#Cx, Cy, H = 0, 0, 0
for cxi, cyi in itertools.product(range(101), range(101)):
    hight_ = params[0][2] + abs(params[0][0] - cxi) + abs(params[0][1] - cyi)

    for k in range(N):
        if params[k][2] > 0:
            hight = params[k][2] + abs(params[k][0] - cxi) + abs(params[k][1] - cyi)

            if hight < 1:
                break
            else:
                if hight != hight_:
                    break
                else:
                    hight_ = hight
                    continue

        #elif params[k][2] == 0:
        #    if 1 > (abs(params[k][0] - cxi) + abs(params[k][1] - cyi)):
        #        break
    
    else:
        Cx = cxi
        Cy = cyi
        H = hight
    
    #continue

        print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
params = []
for i in range(N):
    xyh = [int(n) for n in input().split()]
    params.append(xyh)

if len(params) == 1:
    print(*params[0])

else:

    Cx, Cy, H = 0, 0, 0
    for cxi, cyi in itertools.product(range(101), range(101)):
        counter = 0
        for x, y, h in params:
            if h > 0:
                hight = h + abs(x - cxi) + abs(y - cyi)
                if counter == 0:
                    hight_ = hight
                counter += 1

                if hight < 1:
                    break
                else:
                    if hight != hight_:
                        break
                    else:
                        hight_ = hight
            elif h == 0:
                if 1 > (abs(x - cxi) + abs(y - cyi)):
                    break

        else:
            Cx = cxi
            Cy = cyi
            H = hight
        continue

    print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
params = []
for i in range(N):
    xyh = [int(n) for n in input().split()]
    params.append(xyh)

Cx, Cy, H = 0, 0, 0

for cxi, cyi in itertools.product(range(101), range(101)):
    counter = 0
    for x, y, h in params:
        if h > 0:
            hight = h + abs(x - cxi) + abs(y - cyi)
            if counter == 0:
                hight_ = hight
            counter += 1

            if hight < 1:
                break
            else:
                if hight != hight_:
                    break
                else:
                    hight_ = hight
        elif h == 0:
            if 1 > (abs(x - cxi) + abs(y - cyi)):
                break

    else:
        Cx = cxi
        Cy = cyi
        H = hight
    continue

print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
params = []
for i in range(N):
    xyh = [int(n) for n in input().split()]
    params.append(xyh)

Cx, Cy, H = 0, 0, 0

for cxi, cyi in itertools.product(range(101), range(101)):
    counter = 0
    for x, y, h in params:
        hight = h + abs(x - cxi) + abs(y - cyi)
        if counter == 0:
            hight_ = hight
        counter += 1

        if hight < 1:
            break
        else:
            if hight != hight_:
                break
            else:
                hight_ = hight

    else:
        Cx = cxi
        Cy = cyi
        H = hight
    continue

print(Cx, Cy, H)

Submission status: Wrong Answer

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

import itertools

for cxi, cyi in itertools.product(range(101), range(101)):
    counter = 0
    for x, y, h in params:
        hight = h + abs(x - cxi) + abs(y - cyi)
        if counter == 0:
            hight_ = hight
        counter += 1

        if hight < 1:
            break
        else:
            if hight != hight_:
                break
            else:
                hight_ = hight

    else:
        Cx = cxi
        Cy = cyi
        H = hight
        print(Cx, Cy, H)

    continue

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[1]:


import numpy as np


# In[45]:


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


# In[47]:


for i in range(101):
    for j in range(101):
        tmp = data - np.array([i,j,0])
        #print(abs(tmp))
        #print(np.sum(abs(tmp),axis=1))
        if all(np.sum(abs(tmp),axis=1) == np.sum(abs(tmp),axis=1)[0]):
            print(i, j, np.sum(abs(tmp),axis=1)[0])

Submission status: Wrong Answer

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

def f():
  for xx in range(101):
    for yy in range(101):
      height = []
      for n in range(N):
        if h[n] != 0:
          height.append(abs(x[n]-xx)+abs(y[n]-yy)+h[n])
      if len(set(height)) == 1:
        return [xx, yy, height[0]]
print(*f())

Submission status: Wrong Answer

Solution code:
X = []
Y = []
L = []
N = int(input())
for i in range(N):
   x, y, l = map(int, input().split())
   X.append(x)
   Y.append(y)
   L.append(l)
for cx in range(0, 101):
    for cy in range(0, 101):
        LH = []
        for i, x in enumerate(X):
            H = L[i] + abs(x - cx) + abs(Y[i] - cy)
            LH.append(H)
        LH = list(set(LH))
        if len(LH) == 1:
            print(cx, cy, LH[0])
            exit()

Submission status: Wrong Answer

Solution code:
X = []
Y = []
L = []
N = int(input())
for i in range(N):
   x, y, l = map(int, input().split())
   X.append(x)
   Y.append(y)
   L.append(l)
minX = min(X)
maxX = max(X)
minY = min(Y)
maxY = max(Y)
for cx in range(0, 101):
    for cy in range(0, 101):
        for i, x in enumerate(X):
            H = max(L[i] + abs(x - cx) + abs(Y[i] - cy), 0)
            if i == 0:
                pH = H
                continue
            if pH != H:
                break
        if i == len(X) -1:
            print(cx, cy, H)
            exit()

Submission status: Wrong Answer

Solution code:
X = []
Y = []
L = []
N = int(input())
for i in range(N):
   x, y, l = map(int, input().split())
   X.append(x)
   Y.append(y)
   L.append(l)
minX = min(X)
maxX = max(X)
minY = min(Y)
maxY = max(Y)
for cx in range(0, 101):
    for cy in range(0, 101):
        for i, x in enumerate(X):
            H = L[i] + abs(x - cx) + abs(Y[i] - cy)
            if i == 0:
                pH = H
                continue
            if pH != H:
                break
        if i == len(X) -1:
            print(cx, cy, H)
            exit()

Submission status: Wrong Answer

Solution code:
X = []
Y = []
L = []
N = int(input())
for i in range(N):
   x, y, l = map(int, input().split())
   X.append(x)
   Y.append(y)
   L.append(l)
minX = min(X)
maxX = max(X)
minY = min(Y)
maxY = max(Y)
for cx in range(minX, maxX+1):
    for cy in range(minY, maxY+1):
        for i, x in enumerate(X):
            H = L[i] + abs(x - cx) + abs(Y[i] - cy)
            if i == 0:
                pH = H
                continue
            if pH != H:
                break
        if i == len(X) -1:
            print(cx, cy, H)
            exit()

Submission status: Wrong Answer

Solution code:
N = int(input())

position_list = []
for _ in range(N):
    position_list.append(list(map(int, input().split(' '))))

def check_position_diff(position1, position2):
    x = position1[0] - position2[0]
    y = position1[1] - position2[1]
    return x, y

for x in range(102):
    for y in range(102):
        base_position = position_list[0]
        diff_x, diff_y = check_position_diff((x,y), (base_position[0], base_position[1]))
        h = max(abs(diff_x) + abs(diff_y) + base_position[2], 0)
        collect = []
        for position in position_list:
            diff_x, diff_y = check_position_diff((x,y), (position[0], position[1]))
            hx = max(h - abs(diff_x) - abs(diff_y),0)
            collect.append(position[2]==hx)
        if all(collect):
            print(x, y, h)
            exit()
        collect=[]

Submission status: Wrong Answer

Solution code:
N = int(input())

position_list = []
for _ in range(N):
    position_list.append(list(map(int, input().split(' '))))

def check_position_diff(position1, position2):
    x = position1[0] - position2[0]
    y = position1[1] - position2[1]
    return x, y

for x in range(102):
    for y in range(102):
        base_position = position_list[0]
        diff_x, diff_y = check_position_diff((x,y), (base_position[0], base_position[1]))
        h = abs(diff_x) + abs(diff_y) + base_position[2]
        collect = []
        for position in position_list:
            diff_x, diff_y = check_position_diff((x,y), (position[0], position[1]))
            hx = abs(diff_x) + abs(diff_y) + position[2]
            collect.append(h==hx)
        if all(collect):
            print(x, y, h)
            exit()
        collect=[]

Submission status: Wrong Answer

Solution code:
N = int(input())

position_list = []
for _ in range(N):
    position_list.append(list(map(int, input().split(' '))))

def check_position_diff(position1, position2):
    x = position1[0] - position2[0]
    y = position1[1] - position2[1]
    return x, y

for x in range(101):
    for y in range(101):
        base_position = position_list[0]
        diff_x, diff_y = check_position_diff((x,y), (base_position[0], base_position[1]))
        h = abs(diff_x) + abs(diff_y) + base_position[2]
        collect = []
        for position in position_list[1:]:
            diff_x, diff_y = check_position_diff((x,y), (position[0], position[1]))
            hx = abs(diff_x) + abs(diff_y) + position[2]
            collect.append(h==hx)
        if all(collect):
            print(x, y, h)
            exit()
        collect=[]

Submission status: Wrong Answer

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

s.sort(key=lambda x:x[2], reverse=True)
print(s)
ansH = 0
x0, y0, h0 = s[0]
for cx in range(0, 101):
    for cy in range(0, 101):
        H = h0 + abs(x0 - cx) + abs(y0 - cy)
        for x, y, h in s:
            if h == max(H - abs(x - cx) - abs(y - cy), 0):
                continue
            else:
                break
        else:
            print(cx, cy, H)

Submission status: Wrong Answer

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

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

ansH = 0
x0, y0, h0 = s[0]
for cx in range(0, 101):
    for cy in range(0, 101):
        H = h + abs(x0 - cx) + abs(y0 - cy)
        for x, y, h in s:
            if h == max(H - abs(x - cx) - abs(y - cy), 0):
                continue
            else:
                break
        else:
            print(cx, cy, H)

Submission status: Wrong Answer

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

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

ansH = 0
for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True
        for x, y, h in s:
            H = h + abs(x-cx) + abs(y-cy)
            if flag:
                ansH = H
                flag = False
            elif h > 0:
                if ansH == H:
                    continue
                else:
                    break
            elif h == 0:
                if ansH == H and ansH - abs(x-cx) + abs(y-cy) <= 0:
                    continue
                else:
                    break
        else:
            print(cx, cy, ansH)
            exit(0)

Submission status: Wrong Answer

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

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

ansH = 0
for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True
        for x, y, h in s:
            H = h + abs(x-cx) + abs(y-cy)
            if flag:
                ansH = H
                flag = False
            elif h > 0:
                if ansH == H:
                    continue
                else:
                    break
            elif h == 0:
                if ansH - abs(x-cx) + abs(y-cy) <= 0:
                    continue
                else:
                    break
        else:
            print(cx, cy, ansH)
            exit(0)

Submission status: Wrong Answer

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

ansH = 0
for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True
        for x, y, h in s:
            H = h + abs(x-cx) + abs(y-cy)
            if flag:
                ansH = H
                flag = False
            elif ansH == H:
                continue
            else:
                break
        else:
            print(cx, cy, ansH)
            exit(0)

Submission status: Wrong Answer

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

for cx in range(101):
    for cy in range(101):
        height = set(hi + abs(xi-cx) + abs(yi-cy) for xi, yi, hi in xyh if hi > 0)
        if len(height) == 1:
            H = max(height)
            print(cx, cy, H)
            exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
xyh=[]
for i in range(n):
    xyh.append(list(map(int,input().split())))
x0=xyh[0][0]
y0=xyh[0][1]
h0=xyh[0][2]
count=0
while h0==0:
    count+=1
    x0=xyh[count][0]
    y0=xyh[count][1]
    h0=xyh[count][2]
for x in range(101):
    for y in range(101):
        h=h0+abs(x-x0)+abs(y-y0)
        for i in range(n):
            if h-max(0,abs(x-xyh[i][0]))-max(0,abs(y-xyh[i][1]))!=xyh[i][2]:
                break
            if i==n-1:
                print(x,y,h)
                quit()

Submission status: Wrong Answer

Solution code:
n=int(input())
xyh=[]
for i in range(n):
    xyh.append(list(map(int,input().split())))
x0=xyh[0][0]
y0=xyh[0][1]
h0=xyh[0][2]
count=0
while h0==0:
    count+=1
    x0=xyh[count][0]
    y0=xyh[count][1]
    h0=xyh[count][2]
a=0
for x in range(101):
    for y in range(101):
        h=h0+abs(x-x0)+abs(y-y0)
        for i in range(n):
            if h-abs(x-xyh[i][0])-abs(y-xyh[i][1])!=xyh[i][2]:
                break
            if i==n-1:
                print(x,y,h)
                quit()

Submission status: Wrong Answer

Solution code:
n=int(input())
xyh=[]
for i in range(n):
    xyh.append(list(map(int,input().split())))
x0=xyh[0][0]
y0=xyh[0][1]
h0=xyh[0][2]
count=0
while h0==0:
    count+=1
    x0=xyh[count][0]
    y0=xyh[count][1]
    h0=xyh[count][2]
a=0
for x in range(101):
    for y in range(101):
        h=h0+abs(x-x0)+abs(y-y0)
        for i in xyh:
            if h-abs(x-i[0])-abs(y-i[1])!=i[2]:
                break
            if i==xyh[-1]:
                print(x,y,h)
                quit()

Submission status: Wrong Answer

Solution code:
from collections import namedtuple

def main():
    Place = namedtuple('Place', ('x', 'y', 'h'))

    N = int(input())

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

    place = list(filter(lambda t:t.h != 0, place))
    place_len = len(place)

    for cy in range(101):
        for cx in range(101):
            sc0 = place[0].h + abs(cx - place[0].x) + abs(cy - place[0].y)
            for i in range(1, place_len):
                sci = place[i].h + abs(cx - place[i].x) + abs(cy - place[i].y)
                if sc0 != sci:
                    break
            else:
                print(cx, cy, sc0)
                return

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
x_list=[]
y_list=[]
h_list=[]
hantei = 0
count=0
for i in range(N):
    a,b,c=map(int,input().split())
    x_list.append(a)
    y_list.append(b)
    h_list.append(c)
    if c>0: 
        judge_x = a
        judge_y = b
        judge_h = c
for x in range(101):
    for y in range(101):
        for j in range(N):
            if h_list[j] == 0 : count+=1
            elif judge_h + abs(x-judge_x) + abs(y-judge_y) != h_list[j] + abs(x-x_list[j]) + abs(y-y_list[j]):
                break
            else: count+=1
        if count == N-1:
            hantei=1
        if(hantei):break
    if(hantei): break

print(x,y,judge_h + abs(x-judge_x) + abs(y-judge_y))

Submission status: Wrong Answer

Solution code:
N = int(input())
x_list=[]
y_list=[]
h_list=[]
hantei = 0
for i in range(N):
    a,b,c=map(int,input().split())
    x_list.append(a)
    y_list.append(b)
    h_list.append(c)
    if c>0: 
        judge_x = a
        judge_y = b
        judge_h = c
for x in range(101):
    for y in range(101):
        for j in range(N):
            if h_list[j] == 0 : continue
            elif judge_h + abs(x-judge_x) + abs(y-judge_y) != h_list[j] + abs(x-x_list[j]) + abs(y-y_list[j]):
                j-=1
                break
        if j == N-1:
            hantei=1
        if(hantei):break
    if(hantei): break

print(x,y,judge_h + abs(x-judge_x) + abs(y-judge_y))

Submission status: Wrong Answer

Solution code:
N = int(input())
x_list=[]
y_list=[]
h_list=[]
hantei = 0
for i in range(N):
    a,b,c=map(int,input().split())
    x_list.append(a)
    y_list.append(b)
    h_list.append(c)
    if c>0: 
        judge_x = a
        judge_y = b
        judge_h = c
for x in range(101):
    for y in range(101):
        for j in range(N):
            if h_list[j] == 0 : continue
            elif judge_h + abs(x-judge_x) + abs(y-judge_y) != h_list[j] + abs(x-x_list[j]) + abs(y-y_list[j]):
                break
        if j == N-1:
            hantei=1
        if(hantei):break
    if(hantei): break

print(x,y,judge_h + abs(x-judge_x) + abs(y-judge_y))

Submission status: Wrong Answer

Solution code:
N = int(input())
x_list=[]
y_list=[]
h_list=[]
hantei = 0
for i in range(N):
    a,b,c=map(int,input().split())
    x_list.append(a)
    y_list.append(b)
    h_list.append(c)
    if c>0: 
        judge_x = a
        judge_y = b
        judge_h = c
for x in range(101):
    for y in range(101):
        for j in range(N):
            if judge_h + abs(x-judge_x) + abs(y-judge_y) != h_list[j] + abs(x-x_list[j]) + abs(y-y_list[j]):
                break
        if j == N-1:
            hantei=1
        if(hantei):break
    if(hantei): break

print(x,y,judge_h + abs(x-judge_x) + abs(y-judge_y))

Submission status: Wrong Answer

Solution code:
N = int(input())
x_list=[]
y_list=[]
h_list=[]
hantei = 0
for i in range(N):
    a,b,c=map(int,input().split())
    x_list.append(a)
    y_list.append(b)
    h_list.append(c)
    if c>0: 
        judge_x = a
        judge_y = b
        judge_h = c
for x in range(101):
    for y in range(101):
        for j in range(N):
            if judge_h + abs(x-judge_x) + abs(y-judge_y) != h_list[j] + abs(x-x_list[j]) + abs(y-y_list[j]):
                break
            elif j == N-1:
                hantei=1
        if(hantei):break
    if(hantei): break

print(x,y,judge_h + abs(x-judge_x) + abs(y-judge_y))

Submission status: Wrong Answer

Solution code:
N = int(input())
 
def calc_h(H, x, y, cx, cy):
    return max(H - abs(x - cx) - abs(y - cy), 0)
 
data_ls = list()
for i in range(N):
    data_ls.append([int(i) for i in input().split()])
xs, ys, hs = zip(*data_ls)
Cx_candidate = list(range(min(xs), max(xs) + 1))
Cy_candidate = list(range(min(ys), max(ys) + 1))
flg = 0
for x in Cx_candidate:
    for y in Cy_candidate:
        h = hs[0] + abs(xs[0] - x) + abs(ys[0] - y)
        h = 0 if h < 0 else h
        for i in data_ls:
            if calc_h(h, i[0], i[1], x, y) == i[2]:
                flg = 1
                continue
            else:
                flg = 0
                break
        if flg == 1:
            break
    if flg == 1:
        break
print(x, y, h)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
def calc_h(H, x, y, cx, cy):
    return max(H - abs(x - cx) - abs(y - cy), 0)
 
data_ls = list()
for i in range(N):
    data_ls.append([int(i) for i in input().split()])
xs, ys, hs = zip(*data_ls)
Cx_candidate = list(range(0,101))
Cy_candidate = list(range(0,101))
flg = 0
for x in Cx_candidate:
    for y in Cy_candidate:
        h = hs[0] + abs(xs[0] - x) + abs(ys[0] - y)
        for i in data_ls:
            if calc_h(h, i[0], i[1], x, y) == i[2]:
                flg = 1
                continue
            else:
                flg = 0
                break
        if flg == 1:
            break
    if flg == 1:
        break
print(x, y, h)

Submission status: Wrong Answer

Solution code:
N = int(input())

def calc_h(H, x, y, cx, cy):
    return max(H - abs(x - cx) - abs(y - cy), 0)

data_ls = list()
for i in range(N):
    data_ls.append([int(i) for i in input().split()])
xs, ys, hs = zip(*data_ls)
Cx_candidate = list(range(min(xs), max(xs) + 1))
Cy_candidate = list(range(min(ys), max(ys) + 1))
flg = 0
for x in Cx_candidate:
    for y in Cy_candidate:
        h = hs[0] + abs(xs[0] - x) + abs(ys[0] - y)
        for i in data_ls:
            if calc_h(h, i[0], i[1], x, y) == i[2]:
                flg = 1
                continue
            else:
                flg = 0
                break
        if flg == 1:
            break
    if flg == 1:
        break
print(x, y, h)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    def is_match_to_samples(cx, cy, ht):
        for xi, yi, hi in zip(x, y, h):
            if hi != height(cx, cy, xi, yi, ht):
                return False
        return True

    import itertools
    for cx, cy in itertools.product(range(101), range(101)):
        ht = top_height(cx, cy, x[0], y[0], h[0])
        if is_match_to_samples(cx, cy, ht):
            print("{} {} {}".format(cx, cy, ht))
            break
    return

def height(cx, cy, xi, yi, ht):
    return max(0, ht - abs(cx - xi) - abs(cy - yi))

def top_height(cx, cy, xi, yi, hi):
    return hi + abs(cx - xi) + abs(cy - yi)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    h = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        h[i] = int(next(tokens))
    solve(N, x, y, h)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    def is_match_to_samples(cx, cy):
        ht = top_height(cx, cy, x[0], y[0], h[0])
        for xi, yi, hi in zip(x, y, h):
            if ht != top_height(cx, cy, xi, yi, hi):
                return False
        return True

    import itertools
    for cx, cy in itertools.product(range(101), range(101)):
        if is_match_to_samples(cx, cy):
            ht = top_height(cx, cy, x[0], y[0], h[0])
            print("{} {} {}".format(cx, cy, ht))
            break
    return


def top_height(cx, cy, xi, yi, hi):
    return hi + abs(cx - xi) + abs(cy - yi)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    h = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        h[i] = int(next(tokens))
    solve(N, x, y, h)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
h = []

for i in range(0, n):
    xi, yi, hi = [int(i) for i in input().split(" ")]
    x.append(xi)
    y.append(yi)
    h.append(hi)

#n = 8
#x = [10, 0, 5, 2, 1, 0, 2, 0]
#y = [10, 0, 6, 0, 1, 2, 2, 8]
#h = [0, 0, 0, 0, 2, 0, 0, 0]

for cx in range(0, 101):
    for cy in range(0, 101):
        h_max = 10**9 + 1
        hd = -1
        f = False
        for i in range(0, n):
            ht = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
            if h[i] > 0:
                if ht <= h_max and (hd == -1 or hd == ht):
                    hd = ht
                else:
                    f = True
                    break
            else:
                h_max = min(h_max, ht)
                if hd > h_max:
                    f = True
                    break
        if (not f) and hd > 0:
            print(cx, cy, hd)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
h = []

for i in range(0, n):
    xi, yi, hi = [int(i) for i in input().split(" ")]
    x.append(xi)
    y.append(yi)
    h.append(hi)

#n = 5
#x = [0, 1, 2, 0, 2]
#y = [0, 1, 0, 2, 2]
#h = [0, 2, 0, 0, 0]

for cx in range(0, 101):
    for cy in range(0, 101):
        h_max = 10**9 + 1
        hd = -1
        f = False
        for i in range(0, n):
            ht = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
            if h[i] > 0:
                if ht <= h_max and (hd == -1 or hd == ht):
                    hd = ht
                else:
                    f = True
                    break
            else:
                if h_max < ht:
                    f = True
                    break
                else:    
                    h_max = ht
                    if hd > h_max:
                        f = True
                        break
        if (not f) and hd > 0:
            print(cx, cy, hd)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
h = []

for i in range(0, n):
    xi, yi, hi = [int(i) for i in input().split(" ")]
    x.append(xi)
    y.append(yi)
    h.append(hi)

#n = 4
#x = [2, 2, 1, 3]
#y = [3, 1, 2, 2]
#h = [5, 5, 5, 5]

for cx in range(0, 101):
    for cy in range(0, 101):
        h_max = 10**9 + 1
        hd = -1
        f = False
        for i in range(0, n):
            ht = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
            if h[i] > 0:
                if ht <= h_max and (hd == -1 or hd == ht):
                    hd = ht
                else:
                    f = True
                    break
            else:
                if h_max < ht:
                    f = True
                    break
                else:    
                    h_max = ht
        if (not f) and hd > 0:
            print(cx, cy, hd)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
h = []

for i in range(0, n):
    xi, yi, hi = [int(i) for i in input().split(" ")]
    x.append(xi)
    y.append(yi)
    h.append(hi)

for cx in range(0, 101):
    for cy in range(0, 101):
        h_max = 10**9 + 1
        hd = -1
        f = False
        for i in range(0, n):
            ht = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
            if h[i] > 0:
                if hd == -1:
                    hd = ht
                else:
                    if hd != ht or h_max < ht:
                        f = True
                        break
            else:
                if h_max < ht:
                    f = True
                    break
                else:    
                    h_max = ht
        if (not f) and hd > 0:
            print(cx, cy, hd)