Problem:


Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).  

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:  

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.  

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."  

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.  

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:  

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.  

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.  

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.  



Sample input:
4
2 3 5
2 1 5
1 2 5
3 2 5


Sample output:
2 2 6

Submission status: Accepted

Solution code:
n = input()
arr = []
for i in range(n):
    xi, yi, hi = map(int, raw_input().split())
    arr.append((xi, yi, hi))

for cx in range(101):
    for cy in range(101):
        for k in range(n):
            if arr[k][2] > 0:
                H = abs(arr[k][0]-cx)+abs(arr[k][1]-cy) + arr[k][2]
                break
        flag = 0
        for k in range(n):
            if arr[k][2] != max(H - abs(arr[k][0]-cx) - abs(arr[k][1]-cy), 0):
                flag = 1
                break
        if flag == 0:
            print cx, cy, H
        else:
            continue

Submission status: Accepted

Solution code:
n = input()
arr = []
for i in range(n):
    xi, yi, hi = map(int, raw_input().split())
    arr.append((xi, yi, hi))

for cx in range(101):
    for cy in range(101):
        for k in range(n):
            if arr[k][2] > 0:
                H = abs(arr[k][0]-cx)+abs(arr[k][1]-cy) + arr[k][2]
                break
        flag = 0
        for k in range(n):
            if arr[k][2] != max(H - abs(arr[k][0]-cx) - abs(arr[k][1]-cy), 0):
                flag = 1
                break
        if flag == 0:
            print cx, cy, H
        else:
            continue

Submission status: Accepted

Solution code:
n = input()
arr = []
for i in range(n):
    xi, yi, hi = map(int, raw_input().split())
    arr.append((xi, yi, hi))

for cx in range(101):
    for cy in range(101):
        for k in range(n):
            if arr[k][2] > 0:
                H = abs(arr[k][0]-cx)+abs(arr[k][1]-cy) + arr[k][2]
                break
        flag = 0
        for k in range(n):
            if arr[k][2] != max(H - abs(arr[k][0]-cx) - abs(arr[k][1]-cy), 0):
                flag = 1
                break
        if flag == 0:
            print cx, cy, H

Submission status: Accepted

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

for x, y, h in lst:
    if h > 0:
        base = (x, y, h)
        break

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

Submission status: Accepted

Solution code:
import sys

def solve(n, ls_xyh):
    x0 = None
    for i in range(n):
        if ls_xyh[i][2] > 0:
            [x0,y0,h0] = ls_xyh[i]
            break
    cands = [(cx, cy, h0 + abs(cx - x0) + abs(cy - y0))
             for cx in range(101) for cy in range(101)]
    for [x,y,h] in ls_xyh:
        cands = [(cx, cy, ch) for (cx, cy, ch) in cands
                    if max(ch - abs(cx - x) - abs(cy - y), 0) == h]
    (xx, yy, hh) = cands[0]
    return ' '.join([str(xx), str(yy), str(hh)])

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    n = int(ws[0])
    ls_xyh = [list(map(int, sys.stdin.readline().strip().split()))
              for j in range(n)]
    return (n, ls_xyh)

def main():
    print(solve(*readQuestion()))

# Uncomment before submission
main()

Submission status: Accepted

Solution code:
N=int(input().strip())
xyh=[]
for i in range(N):
    xi,yi,hi = map(int, input().split(' '))
    xyh.append([xi,yi,hi])
    if hi>=1:
        xyhset=[xi,yi,hi]
        
for nx in range(101):
    for ny in range(101):
        He = xyhset[2]+abs(xyhset[0]-nx)+abs(xyhset[1]-ny)
        He=max(0,He)
        flag=True
        for i in range(N):
            h=He-abs(xyh[i][0]-nx)-abs(xyh[i][1]-ny)
            h=max(0,h)
            if xyh[i][2]!=h:
                flag=False
        if flag:
            ax=nx
            ay=ny
            ah=He

print("{} {} {}".format(ax,ay,ah))

Submission status: Accepted

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

nonzero = [i for i in range(0, N) if h[i] != 0]

for cx in range(0, 100+1):
	for cy in range(0, 100+1):
		H =  h[nonzero[0]] + abs(x[nonzero[0]] - cx) + abs(y[nonzero[0]] - cy)
		error = False
		for i in range(0, N):
			if h[i] != max([H - abs(x[i]-cx) - abs(y[i]-cy), 0]):
				error = True
				break
		if not error:
			print("{} {} {}".format(cx, cy, H))
			exit()

Submission status: Accepted

Solution code:
import sys

n = int(input())

xyh = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

isOk = False
i = 0
j = 0
constant = -1

for i in range(101):
    for j in range(101):

        constant = -1
        for xyhTemp in xyh:
            if xyhTemp[2] != 0:
                temp = xyhTemp[2] + abs(i - xyhTemp[0]) + abs(j - xyhTemp[1])

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for p in xyh:
                if p[2] == 0 and constant - abs(i - p[0]) - abs(j - p[1]) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)

Submission status: Accepted

Solution code:
n = int(input())

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

isOk = False
i = 0
j = 0
constant = -1

for i in range(101):
    for j in range(101):

        constant = -1
        for xyhTemp in xyh:
            if xyhTemp[2] != 0:
                temp = xyhTemp[2] + abs(i - xyhTemp[0]) + abs(j - xyhTemp[1])

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for p in xyh:
                if p[2] == 0 and constant - abs(i - p[0]) - abs(j - p[1]) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)

Submission status: Accepted

Solution code:
n = int(input())

xyh = [None] * n 

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

isOk = False
i = 0
j = 0
constant = -1

for i in range(101):
    for j in range(101):

        constant = -1
        for xyhTemp in xyh:
            if xyhTemp[2] != 0:
                temp = xyhTemp[2] + abs(i - xyhTemp[0]) + abs(j - xyhTemp[1])

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for p in xyh:
                if p[2] == 0 and constant - abs(i - p[0]) - abs(j - p[1]) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)

Submission status: Accepted

Solution code:
n = int(input())

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

isOk = False
i = 0
j = 0
constant = -1

for i in range(101):
    for j in range(101):

        constant = -1
        for xi, yi, hi in zip(x, y, h):
            if hi != 0:
                temp = hi+ abs(i - xi) + abs(j - yi)

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for xj, yj, hj in zip(x, y, h):
                if hj == 0 and constant - abs(i - xj) - abs(j - yj) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)

Submission status: Accepted

Solution code:
class xyh_list:
    def __init__(self, xyh):
        self.x = xyh[0]
        self.y = xyh[1]
        self.h = xyh[2]

n = int(input())

xyh = []

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

isOk = False
i = 0
j = 0
constant = -1

for i in range(101):
    for j in range(101):

        constant = -1
        for xyhTemp in xyh:
            if xyhTemp.h != 0:
                temp = xyhTemp.h + abs(i - xyhTemp.x) + abs(j - xyhTemp.y)

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for p in xyh:
                if p.h == 0 and constant - abs(i - p.x) - abs(j - p.y) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)

Submission status: Accepted

Solution code:
n = int(input())

xyh = []

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

isOk = False
i = 0
j = 0
constant = -1

for i in range(101):
    for j in range(101):

        constant = -1
        for xyhTemp in xyh:
            if xyhTemp[2] != 0:
                temp = xyhTemp[2] + abs(i - xyhTemp[0]) + abs(j - xyhTemp[1])

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for p in xyh:
                if p[2] == 0 and constant - abs(i - p[0]) - abs(j - p[1]) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    tuples = []
    for _ in range(N):
        x, y, h = [int(e) for e in input().split()]
        tuples.append((x, y, h))
        if h > 0:
            x_, y_, h_ = x, y, h

    # 適当な中心座標を用意
    for cs in range(101):
        for cy in range(101):
            # 一つの座標、その高さ、中心座標から、ピラミッドの高さを計算
            H = h_ + abs(cs - x_) + abs(cy - y_)
            flag = True
            # 別の検証値を使って正当性を確認（全てOKならそれが答えになる）
            for t in tuples:
                # 中心座標と検証値から座標の高さを計算
                h = H - abs(cs - t[0]) - abs(cy - t[1])
                h = max([h, 0])
                # その高さが検証値の高さと一致すればOK（違ったらダメ）
                if t[2] != h:
                    flag = False
            if flag:
                print(cs, cy, H)
                break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
l = ils(n, "il()")

for i in range(101):
    for j in range(101):
        zero = []
        height = -1
        ok = 1
        for k in range(n):
            if l[k][2] == 0:
                zero.append(k)
                continue
            if height == -1:
                height = abs(i-l[k][0]) + abs(j-l[k][1]) + l[k][2]
            if height != abs(i-l[k][0]) + abs(j-l[k][1]) + l[k][2]:
                ok = 0
                break
        for k in zero:
            if height == -1:
                height = abs(i-l[k][0]) + abs(j-l[k][1]) + l[k][2]
            if height > abs(i-l[k][0]) + abs(j-l[k][1]) + l[k][2]:
                ok = 0
                break
        if ok:
            print(i, j, height)

Submission status: Accepted

Solution code:
n = int(input())

info = [[int(x) for x in input().split()] for _ in range(n)]

def height(point, info):
    cx, cy = point[0], point[1]
    ch = None
    theo_max = float('inf')
    for i,p in enumerate(info):
        x, y, h= p[0], p[1], p[2]
        tmp = abs(cx-x) + abs(cy-y) + h
        if h == 0:
            theo_max = min(theo_max, tmp)
            if ch:
                if theo_max < ch:
                    return None
                    break
        else:
            if not ch:
                ch = tmp
                if theo_max < ch:
                    return None
                    break
            else:
                if ch != tmp:
                    return None
                    break
                if theo_max < ch:
                    return None
                    break
    return ch

t = None
ans = None
for x in range(101):
    if t:
        break
    for y in range(101):
        if t:
            break
        point = (x,y)
        t = height(point, info)
        if t :
            ans = [x,y,t]

print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
N = int(input())
rec = []
for i in range(N):
    x, y, h = map(int, input().split())
    rec.append((x, y, h))
    if h >= 1:
        q = [x, y, h]


for i in range(101):
    for j in range(101):
        cx, cy = i, j
        h = q[2] + abs(i - q[0]) + abs(j - q[1])
        flag = True
        for k in range(N):
            if max(h - abs(i - rec[k][0]) - abs(j - rec[k][1]), 0) != rec[k][2]:
                flag = False
                break

        if flag:
            print(i, j, h)
            break

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    p = [list(map(int, input().split())) for _ in range(N)]
    for i in range(N):
        if p[i][2] > 0:
            break
    x0, y0, h0 = p[i]
    for cx in range(101):
        for cy in range(101):
            H = h0 + abs(x0 - cx) + abs(y0 - cy)
            for x, y, h in p:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                print(cx, cy, H)
                exit(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

i = 0
while 1:
    if P[i][2] > 0:
        break
    i += 1
x0, y0, h0 = P[i]
for cy in range(101):
    for cx in range(101):
        h = h0 + abs(cx - x0) + abs(cy - y0)
        for x, y, h1 in P:
            if h1 != max(h - abs(cx - x) - abs(cy - y), 0):
                break
        else:
            print(cx, cy, h)
            exit(0)
exit(1)

Submission status: Accepted

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

lx, ly, lh = data[-1]

for cy in range(101):
    for cx in range(101):
        H = lh + abs(cx - lx) + abs(cy - ly)

        if all(h == max(H - abs(cx - x) - abs(cy - y), 0) for x, y, h in data):
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N
for index in range(N):
    x[index],y[index],h[index] = map(int,input().split())
for i in range(101):
   for j in range(101):
      result = []
      for index in range(N):
         result_H = h[index]+ abs(x[index]- i)+abs(y[index]-j)
         if result_H-abs(x[index]- i)-abs(y[index]-j) > 0:
            result.append(result_H)
      tmp = result[0]
      if all(tmp==num for num in result) == True:
         check = []
         for check_index in range(N):
            check.append((tmp - abs(x[check_index]- i) - abs(y[check_index]-j))-h[check_index])
         if all(z <= 0 for z in check) == True:
            print(i,' ',j,' ',tmp)
            break
   else:
      continue
   break

Submission status: Accepted

Solution code:
n = int(input())

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

for x in range(101):
  for y in range(101):
    for i in range(n):
      if hs[i] >0:
        H = hs[i] + abs(xs[i]-x)+abs(ys[i]-y)
    for i in range(n):
      if hs[i] != max(0, H-abs(xs[i]-x)-abs(ys[i]-y)):
        break
    else:
      print(x,y,H)
      exit()

Submission status: Accepted

Solution code:
# abc112_c

def main():
    N=int(input())
    xyh=[]
    
    for i in range(N):
        a=[int(i) for i in input().split()]
        xyh.append(a)
    
    xyh.sort(key=lambda x:x[2],reverse=True)
    
    flag2=True
    for i in range(0,101):
        for j in range(0,101):
            flag=True
            H=xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
            for k in range(1,N):
                if xyh[k][2]!=max(0,H-abs(xyh[k][0]-i)-abs(xyh[k][1]-j)):
                    flag=False
                    break
            
            if flag:
                print("{} {} {}".format(i,j,H))
                flag2=False
                break
        if not flag2:
            break

if __name__ == "__main__": main()

Submission status: Accepted

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

for cx in range(0, 101):
    for cy in range(0, 101):
        for i in range(N):
            if h[i] > 0:
                H = h[i] + abs(x[i]-cx)+abs(y[i]-cy)
        
        for i in range(N):
            if h[i] != max(0, H-abs(x[i]-cx)-abs(y[i]-cy)):
                break
        else:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
import sys

N = int(input())

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

for X in range(0, 101):
    for Y in range(0, 101):
        b = True
        H = 0
        for Cx, Cy, Ch in list:
            if Ch != 0:
                H = Ch + abs(X - Cx) + abs(Y - Cy)
        for Cx, Cy, Ch in list:
            h = max(H - abs(X - Cx) - abs(Y - Cy), 0)
            if Ch != h:
                b = False
        if b == True:
            print(X, Y, H)
            sys.exit(0)

Submission status: Accepted

Solution code:
import sys

N = int(input())

list = []
for i in range(0, N):
    x, y, h = [int(x) for x in input().split()]
    list.append((x, y, h))
    # if (h != 0):
    # list.append((x, y, h))

for X in range(0, 101):
    for Y in range(0, 101):
        b = True
        H = 0
        for Cx, Cy, Ch in list:
            if Ch != 0:
                H = Ch + abs(X - Cx) + abs(Y - Cy)
        for Cx, Cy, Ch in list:
            h = max(H - abs(X - Cx) - abs(Y - Cy), 0)
            if Ch != h:
                b = False
        if b == True:
            print(X, Y, H)
            sys.exit(0)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
e = [[int(_) for _ in input().split()] for _ in range(n)]

for xi, yi, hi in e:
    if hi > 0:
        xp = xi
        yp = yi
        hp = hi
        break

for cx, cy in itertools.product(range(101), range(101)):
    ch = abs(cx - xp) + abs(cy - yp) + hp
    flag = True
    for xi, yi, hi in e:
        flag = flag and max(ch - abs(cx - xi) - abs(cy - yi), 0) == hi
    if flag:
        print("%d %d %d" % (cx, cy, ch))

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        try_H = 0
        for x, y, h in x_y_h:
            if h > 0:
                try_H = h + abs(x - cx) + abs(y - cy)
                break

        wrong = False
        for x, y, h in x_y_h:
            tmp_H = max(try_H - abs(x - cx) - abs(y - cy), 0)
            if tmp_H != h:
                wrong = True
                break
        if wrong:
            continue
        print(cx, cy, try_H)
        exit()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    x_y_h = [tuple(map(int, input().split())) for _ in range(N)]

    cx, cy, H = solve(x_y_h)
    print(cx, cy, H)


def height(cx, cy, x_y_h):
    for x, y, h in x_y_h:
        if h <= 0:
            continue
        return h + abs(x - cx) + abs(y - cy)
    return 0


def valid(cx, cy, H, x_y_h):
    for x, y, h in x_y_h:
        if h != max(H - abs(x - cx) - abs(y - cy), 0):
            return False
    return True


def solve(x_y_h):
    for cx in range(101):
        for cy in range(101):
            try_H = height(cx, cy, x_y_h)
            if valid(cx, cy, try_H, x_y_h):
                return cx, cy, try_H
    return 0, 0, 0


main()

Submission status: Accepted

Solution code:
def height(cx, cy, D):
    for x, y, h in D:
        if h <= 0: continue
        return h + abs(x-cx) + abs(y-cy)
    return 0

def valid(cx, cy, H, D):
    for x, y, h in D:
        if h != max(H - abs(x-cx) - abs(y-cy), 0):
            return False
    return True

def solve():
    for cy in range(0, 101):
        for cx in range(0, 101):
            H = height(cx, cy, D)
            if valid(cx, cy, H, D):
                return (cx, cy, H)
    return (0, 0, 0)

N = int(input())
D = []
for i in range(N):
    x, y, h = map(int, input().split())
    D.append((x, y, h))
cx, cy, H = solve()
print(cx, cy, H)

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        flag=1
        tmp=abs(xyh[0][0]-cx)+abs(xyh[0][1]-cy)+xyh[0][2]
        for i in range(1,N):
            if xyh[i][2]==0 and abs(xyh[i][0]-cx)+abs(xyh[i][1]-cy)<tmp:
                flag=0
                break
            if tmp!=abs(xyh[i][0]-cx)+abs(xyh[i][1]-cy)+xyh[i][2] and xyh[i][2]!=0:
                flag=0
                break
        if flag:
            print(cx, cy, tmp)
            exit(0)

Submission status: Accepted

Solution code:
n = int(input())
data=[]
for i in range(0,n):
    x, y, h = map(int,input().split())
    data.append((x,y,h))
data = sorted(data,key=lambda x:x[2],reverse=True)
st_x, st_y, st_h = data[0]
 
 
def get_search_area(x,y,n):
    area_list=[]
    for i in range(-n,n+1):
        for j in range(-n,n+1):
            if abs(i) == n or abs(j) == n:
                xi = x+i
                yi = y+j
                if 0<= xi <= 100 and 0 <= yi <= 100:
                    area_list.append((x+i, y+j, abs(i)+abs(j) ))
    return area_list
 
def meets_all_conditions(top, top_h,data):
    top_x, top_y, top_z = top
    top_h += top_z
    for item in data:
        pt_x, pt_y, pt_h = item
        tmp = max(top_h - abs(pt_x - top_x) - abs(pt_y - top_y), 0)       
        if pt_h != tmp:
            #print(pt_h, tmp ,"False")
            return False    
    #print("True")
    return True
    
def main():    
    for i in range(200):
        #print(i)
        a = get_search_area(st_x,st_y,i)
        #print(a)
        for item in a:
            if meets_all_conditions(item, st_h , data):
                print("{} {} {}".format(item[0],item[1],st_h+item[2]))
                return
    return
main()

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input().strip())

input_tuples = []
selected_tuple = None

for _ in range(N):
    x, y, h = [int(s) for s in input().strip().split()]
    if selected_tuple is None and h > 0:
        selected_tuple = ((x, y, h))
    else:
        input_tuples.append((x, y, h))

for cx in range(0, 101):
    for cy in range(0, 101):
        H = selected_tuple[2] + \
            abs(selected_tuple[0] - cx) + abs(selected_tuple[1] - cy)

        for x, y, h in input_tuples:
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            break
        continue
    else:
        continue
    break

print("{} {} {}".format(cx, cy, H))

Submission status: Accepted

Solution code:
N = int(input())
x = [None for _ in range(N)]
y = [None for _ in range(N)]
h = [None for _ in range(N)]
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())
    if h[i] > 0:
        a = [x[i], y[i], h[i]]
for cx in range(0, 101):
    for cy in range(0, 101):
        hh = a[2] + abs(a[0] - cx) + abs(a[1] - cy)
        flag = True
        for i in range(N):
            h_i = max(hh - abs(x[i] - cx) - abs(y[i] - cy), 0)
            if h_i != h[i]:
                flag = False
        if flag:
            print(cx, cy, hh)
            exit()

Submission status: Accepted

Solution code:
import sys
N = int(input())
points = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda p: -p[2])
for c_x in range(101):
    for c_y in range(101):
        h = points[0][2] + abs(points[0][0] - c_x) + abs(points[0][1] - c_y)
        for point in points[1:]:
            if max(h - abs(point[0] - c_x) - abs(point[1] - c_y), 0) != point[2]:
                break
        else:
            print(c_x, c_y, h)
            sys.exit()

Submission status: Accepted

Solution code:
# coding: utf-8


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

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

    for coordinate in coordinates:
        if coordinate[2] > 0:
            xx = coordinate[0]
            yy = coordinate[1]
            hh = coordinate[2]
            break

    for px in range(101):
        for py in range(101):
            ph = hh + abs(xx - px) + abs(yy - py)

            suit = True
            for x, y, h in coordinates:
                if h != max(ph - abs(x - px) - abs(y - py), 0):
                    suit = False
                    break

            if suit == True:
                print(px, py, ph)
                return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

xyh = [[0, 0, 0] for i in range(N)]

for i in range(N):
    x, y, h = input().split(' ')
    xyh[i][0] = int(x)
    xyh[i][1] = int(y)
    xyh[i][2] = int(h)

finish = False
for cx in range(101):
    for cy in range(101):
        top = 0
        for x, y, h in xyh:
            if h != 0:
                top = abs(x-cx)+abs(y-cy)+h
        for x, y, h in xyh:
            finish = True
            if max(top - abs(x-cx)-abs(y-cy), 0) != h:
                finish = False
                break
        if finish == True:
            print ('{} {} {}'.format(cx, cy, top))
            exit()

Submission status: Accepted

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

N = int(input())

FIELD_SIZE = 101

x = []
y = []
h = []
for n in range(N):
    inputs = input().split()
    x.append(int(inputs[0]))
    y.append(int(inputs[1]))
    h.append(int(inputs[2]))

H = [[0] * FIELD_SIZE for n in range(FIELD_SIZE)]
determined_flag = False

for n in range(N):
    for cx in range(FIELD_SIZE):
        for cy in range(FIELD_SIZE):

            ch = h[n] + abs(x[n] - cx) + abs(y[n] - cy)
            if n == 0:
                H[cx][cy] = ch

            elif determined_flag:
                if h[n] != 0:
                    if ch == H[cx][cy]:
                        pass
                    else:
                        H[cx][cy] = 0
                else:
                    if ch >= H[cx][cy]:
                        pass
                    else:
                        H[cx][cy] = 0

            else:
                if h[n] != 0:
                    if ch <= H[cx][cy]:
                        H[cx][cy] = ch
                    else:
                        H[cx][cy] = 0
                else:
                    H[cx][cy] = min(H[cx][cy], ch)
    if h[n] != 0:
        determined_flag = True


for cx in range(FIELD_SIZE):
    for cy in range(FIELD_SIZE):
        if H[cx][cy] >= 1:
            print(cx, cy, H[cx][cy])

Submission status: Accepted

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

for cx in range(0, 101):
    for cy in range(0, 101):
        for i in range(N):
            if h[i] > 0:
                H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)

        for i in range(N):
            if h[i] != max(0, H - abs(x[i] - cx) - abs(y[i] - cy)):
                break
        else:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
    sols = []
    for _ in range(GI()):
        x, y, h = LGIS()
        if h:
            sols.append((x, y, h))

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

    for cx in range(0, 101):
        for cy in range(0, 101):
            lastH = None
            for x, y, h in sols:
                H = h + abs(x - cx) + abs(y - cy)
                if H < 1:
                    continue
                if lastH:
                    if H != lastH:
                        break
                lastH = H
            else:
                print(cx, cy, H)
                return

main()

Submission status: Accepted

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

arr = [[-1] * 101 for i in range(101)]
arr0 = [[False] * 101 for i in range(101)]
for xi in range(101):
  for yi in range(101):
    arr[xi][yi] = ina[0][2]+abs(ina[0][0]-xi)+abs(ina[0][1]-yi)
    if ina[0][2] == 0:
      arr0[xi][yi] = True

arrTF = [[True] * 101 for i in range(101)]
for i in range(1,inn):
  for xi in range(101):
    for yi in range(101):
      if arrTF[xi][yi]:
        if arr0[xi][yi]:
          if ina[i][2] == 0:
            if arr[xi][yi] > ina[i][2] + abs(ina[i][0]-xi)+abs(ina[i][1]-yi):
              arr[xi][yi] = ina[i][2] + abs(ina[i][0]-xi)+abs(ina[i][1]-yi)
          else:
            if arr[xi][yi] < ina[i][2] + abs(ina[i][0]-xi)+abs(ina[i][1]-yi):
              arrTF[xi][yi] = False
            else:
              arr[xi][yi] = ina[i][2] + abs(ina[i][0]-xi)+abs(ina[i][1]-yi)
              arr0[xi][yi] = False
        else:
          if ina[i][2] == 0:
            if arr[xi][yi] > ina[i][2] + abs(ina[i][0]-xi)+abs(ina[i][1]-yi):
              arrTF[xi][yi] = False
          else:
            if arr[xi][yi] != ina[i][2] + abs(ina[i][0]-xi)+abs(ina[i][1]-yi):
              arrTF[xi][yi] = False

for xi in range(101):
  for yi in range(101):
    if arrTF[xi][yi]:
      print(str(xi)+" "+str(yi)+" "+str(arr[xi][yi]))