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:
from operator import itemgetter

N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
xyh.sort(key=itemgetter(2))
xyh.reverse()
for Cx in range(101):
    for Cy in range(101):
        H_MAX = -1
        H = -1
        for i in range(N):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            if h > 0 and i == 0:
                H = h + abs(x-Cx) + abs(y-Cy)
            elif h > 0:
                if H == h + abs(x-Cx) + abs(y-Cy):
                    pass
                else:
                    break
            elif h < 0 and i == 0:
                H_MAX = abs(x-Cx) + abs(y-Cy)
                if H_MAX == 0:
                    break
            else:
                if H_MAX == -1:
                    if H <= abs(x-Cx) + abs(y-Cy):
                        pass
                    else:
                        break
                else:
                    H_MAX = abs(x-Cx) + abs(y-Cy)
                    if H_MAX == 0:
                        break
            if i == N-1:
                print(Cx,Cy,max(H,H_MAX))
                exit()

Submission status: Accepted

Solution code:
# ABC112C - Pyramid
def main():
    N, *XYH = map(int, open(0).read().split())
    A = [(x, y, h) for x, y, h in zip(*[iter(XYH)] * 3)]
    A.sort(key=lambda x: x[2], reverse=1)
    for x in range(101):
        for y in range(101):
            i, j, k = A[0]
            h = k + abs(i - x) + abs(j - y)
            for i, j, k in A[1:]:
                if k != max(h - abs(i - x) - abs(j - y), 0):
                    break
            else:
                print(x, y, h)
                return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC112C - Pyramid
def main():
    N, *XYH = map(int, open(0).read().split())
    A = [(x, y, h) for x, y, h in zip(*[iter(XYH)] * 3)]
    A.sort(key=lambda x: x[2], reverse=1)
    for x in range(0, 101):
        for y in range(0, 101):
            i, j, k = A[0]
            h = k + abs(i - x) + abs(j - y)
            for i, j, k in A[1:]:
                if k != max(h - abs(i - x) - abs(j - y), 0):
                    break
            else:
                print(x, y, h)
                return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
p = [tuple(map(int,input().split())) for _ in range(N)]
p.sort(key=lambda x:x[2])
mx,my,mh = p[-1]

for cx in range(101):
  for cy in range(101):
    H = mh + abs(mx-cx) + abs(my-cy)
    if all(h == max(H - abs(x - cx) - abs(y - cy), 0) for x, y, h in p):
      print(cx, cy, H)
      break

Submission status: Accepted

Solution code:
N = int(input())
coordinate = []
ans = -1
for _ in range(N):
    x, y, h = map(int, input().split())
    if h == 0:
        continue
    coordinate.append([x, y, h])
N = len(coordinate)
for cx in range(101):
    for cy in range(101):
        x1, y1, h1 = coordinate[0]
        H1 = h1 + abs(cx-x1) + abs(cy-y1)
        f = 1
        if N == 1:
            f = 2
            Cx = x1
            Cy = y1
            ans = h1
            break
        for n in range(1, N):
            x, y, h = coordinate[n]
            H = h + abs(cx-x) + abs(cy-y)
            if H == H1:
                f *= 1
            else:
                f *= 0
            if f and n == N-1:
                break
        if f == 1:
            Cx = cx
            Cy = cy
            ans = H1
            break
    if f:
        break
        
print(Cx, Cy, ans)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    xyh = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    xyh.sort(key=lambda w: w[2], reverse=True)

    for cx in range(101):
        for cy in range(101):
            th = xyh[0][2] + abs(cx - xyh[0][0]) + abs(cy - xyh[0][1])
            b = True
            for x, y, h in xyh:
                if h != max(th - abs(cx - x) - abs(cy - y), 0):
                    b = False
                    break
            if b:
                print(cx, cy, th)
                exit()


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]
P.sort(key=lambda x:x[2])
a, b, c = P[-1]

for px in range(101):
    for py in range(101):
        H = abs(px - a) + abs(py - b) + c
        if all(h == max(H - abs(x - px) - abs(y - py), 0) for x, y, h in P):
            print(px, py, H)
            break

Submission status: Accepted

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

for _ in range(N):
    xx,yy,hh=map(int,input().split())
    x.append(xx)
    y.append(yy)
    h.append(hh)

for n in range(N):
    if h[n]!=0:
        sample_id=n
        break

for Cx in range(101):
    for Cy in range(101):
        ass_h=abs(x[sample_id]-Cx)+abs(y[sample_id]-Cy)+h[sample_id]
        judge=True
        for k in range(N):
            ass=abs(x[k]-Cx)+abs(y[k]-Cy)
            if max(ass_h-ass,0)!=h[k]:
                judge=False
                break
        if judge:
            print(Cx,Cy,ass_h)
            break
    if judge:
        break

Submission status: Accepted

Solution code:
"""memo:
for Cx, Cy in zip(range(0, 101), range(0, 101))
hi + abs(Xi-Cx)+abs(Yi-Cy) == hj + abs(Xj-Cx)+abs(Yj-Cy)
in All points

Complexity: 101 * 101 * N -> Max: 101 * 101 * 100 = 1020100
"""
import sys
from itertools import product

input = sys.stdin.readline

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

# There is one point where hi == 1:
non0_hhh = []
for x, y, h in xyh_list:
    if h != 0:
        non0_hhh.append([x, y, h])
if len(non0_hhh) == 1:
    print(*non0_hhh[0])
    exit()

for Cx, Cy in product(range(101), range(101)):
    last_H = None
    valid_flag = True
    for i, (xi, yi, hi) in enumerate(xyh_list):
        if hi == 0:
            continue
        currnt_H = hi + abs(xi - Cx) + abs(yi - Cy)
        if last_H is None:
            last_H = currnt_H
        elif last_H != currnt_H:
            valid_flag = False
            break

    if valid_flag:
        print(Cx, Cy, last_H)
        exit()

Submission status: Accepted

Solution code:
"""memo:
for Cx, Cy in zip(range(0, 101), range(0, 101))
hi + abs(Xi-Cx)+abs(Yi-Cy) == hj + abs(Xj-Cx)+abs(Yj-Cy)
in All points

Complexity: O(N^2) <= 10000
"""
import sys
from itertools import product

input = sys.stdin.readline

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

for Cx, Cy in product(range(101), range(101)):
    last_H = None
    valid_flag = True
    counter = 0
    h_max = 0
    for i, (xi, yi, hi) in enumerate(xyh_list):
        if hi == 0:
            continue
        currnt_H = hi + abs(xi - Cx) + abs(yi - Cy)
        counter += 1
        if last_H is None:
            last_H = currnt_H
        elif last_H != currnt_H:
            valid_flag = False
            break

    if valid_flag:
        if counter != 1:
            print(Cx, Cy, last_H)
        else:
            for xi, yi, hi in xyh_list:
                if hi == 0:
                    continue
                print(xi, yi, hi)
        exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

xyh.sort(key=lambda x: x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        x = xyh[0][0]
        y = xyh[0][1]
        h = xyh[0][2]
        ans = [cx, cy, h + abs(x - cx) + abs(y - cy)]
        for i in range(1, n):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            if h != max(ans[2] - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            print(*ans)

Submission status: Accepted

Solution code:
N = int(input())

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

for cx in range(101):
    for cy in range(101):
        needH = -1
        for x, y, h in P:
            if h == 0:
                continue
            if needH == -1:
                needH = h + abs(x - cx) + abs(y - cy)
            else:
                if needH != h + abs(x - cx) + abs(y - cy):
                    needH = -2
                    break
        if needH == -2:
            continue

        # 高さが０の場合に矛盾してないか調べる
        for x, y, h in P:
            if h == 0:
                if needH > abs(x - cx) + abs(y - cy):
                    needH = -2
                    break
        if needH == -2:
            continue

        print(cx, cy, needH)

Submission status: Accepted

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

ok = True
res = []
x0, y0, h0 = data[0]
for cx in range(101):
    for cy in range(101):
        hh = h0 + abs(cx - x0) + abs(cy - y0)
        ok = True
        for i, (x, y, h) in enumerate(data[1:]):
            if h != max(hh - abs(cx - x) - abs(cy - y), 0):
                ok = False
                continue
        if ok:
            res = [cx, cy, hh]
            break
    if ok:
        break
print(' '.join(map(str, res)))

Submission status: Accepted

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

ok = True
res = []
x0, y0, h0 = data[0]
if h0 > 0:
    for cx in range(101):
        for cy in range(101):
            hh = h0 + abs(cx - x0) + abs(cy - y0)
            ok = True
            for i, (x, y, h) in enumerate(data[1:]):
                if h != max(hh - abs(cx - x) - abs(cy - y), 0):
                    ok = False
                    continue
            if ok:
                res = [cx, cy, hh]
                break
        if ok:
            break
else:
    for cx in range(101):
        for cy in range(101):
            for x, y, _ in data:
                if cx != x and cy != y:
                    res = [cx, cy, 1]
print(' '.join(map(str, res)))

Submission status: Accepted

Solution code:
n = int(input())
pyramid = []

sx, sy, sh = 0, 0, 0

for _ in range(n):
    x, y, h = map(int, input().split())
    pyramid.append([x, y, h])
    if h > 0:
        sx, sy, sh = x, y, h

for cx in range(101):
    for cy in range(101):
        candidate = abs(sx-cx) + abs(sy-cy) + sh
        check = True

        for x, y, h in pyramid:
            H = abs(x-cx) + abs(y-cy) + h
            if h > 0:
                if candidate != H:
                    check = False
                    break
            else:
                if candidate > H:
                    check = False
                    break

        if check:
            print(cx, cy, candidate)
            exit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

for cx in range(101):
    for cy in range(101):
        H = xyh[0][2] + abs(xyh[0][0]-cx) + abs(xyh[0][1]-cy)
        Flag = True
        for i in range(1,N):
            tmp = xyh[i][2] + abs(xyh[i][0]-cx) + abs(xyh[i][1]-cy)
            if (xyh[i][2] == 0 and H > tmp) or (xyh[i][2] != 0 and H != tmp):
                Flag = False
                break
        if Flag:
            print(cx,cy,H)
            sys.exit()

Submission status: Accepted

Solution code:
N = int(input())
info = [[int(i) for i in input().split()] for i in range(N)]
for i in range(N):
    if info[i][2] != 0:
        l = i
        break
for i in range(101):
    Cx= i
    for j in range(101):
        Cy = j
        h = info[l][2] + abs(info[l][0]-Cx) + abs(info[l][1]-Cy)
        for m in range(N):
            if info[m][2] != max(h-abs(info[m][0]-Cx)-abs(info[m][1]-Cy),0):
                break
            if m == N-1:
                print(str(i)+" "+str(j)+" "+str(h))

Submission status: Accepted

Solution code:
# 解説放送を観て写経
import sys

N = int(input())
xyh = []
for _ in range(N):
  x, y, h = map(int, input().split())
  xyh.append((x, y, h))
for i in range(101):
  for j in range(101):
    needH = -1
    for x, y, h in xyh:
      if h>0:
        tmp = h+abs(i-x)+abs(j-y)
        if needH==-1:
          needH = tmp
        else:
          if needH!=tmp:
            needH = -2
            break
          
    if needH==-2:
      continue
      
    for x, y, h in xyh:
      if h==0:
        dist = abs(i-x)+abs(j-y)
        if needH>dist:
          needH = -2
          break
          
    if needH==-2:
      continue
      
    print(i, j, needH)
    sys.exit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

ans = [0] * 3
for i in range(101):
    for j in range(101):
        ansB = True
        ansh = sh[0][2] + abs(sh[0][0] - i) + abs(sh[0][1] - j)
        for k in range(N):

            tmp = max(ansh - abs(sh[k][0] - i) - abs(sh[k][1] - j), 0)

            if tmp != sh[k][2]:
                ansB = False
                break

        if ansB:
            print(i, j, ansh)
            sys.exit()

Submission status: Accepted

Solution code:
n = int(input())
C = [list(map(int,input().split()))for i in range(n)]
C.sort(key = lambda x: -x[2])
for x in range(101):
    for y in range(101):
        h = C[0][2]+abs(x-C[0][0])+abs(y-C[0][1])
        if all([c[2] == max(h-abs(x-c[0])-abs(y-c[1]),0) for c in C]):
            print(x,y,h)
            exit()

Submission status: Accepted

Solution code:
N=int(input())
ls=[[int(s) for s in input().split()] for i in range(N)]
ans=[0,0,0]
for i in range(N):
  if ls[i][2]!=0:
    a=ls[i][0]
    b=ls[i][1]
    h_base=ls[i][2]
    ls.pop(i)
    break
for x in range(101):
  for y in range(101):
    ##x,yの高さを計算
    h=h_base+abs(x-a)+abs(y-b)
    ##他の条件と合うか？
    flag=1
    for e in ls:
      if (h!=e[2]+abs(x-e[0])+abs(y-e[1]) and e[2]>0): 
        flag=0
        break
      if (h>e[2]+abs(x-e[0])+abs(y-e[1]) and e[2]==0):
        flag=0
        break
    if flag==1:
      ans=[x,y,h]
      break
  if flag==1:
    break
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
xyhs = []
for i in range(N):
  x, y, h = map(int, input().split())
  xyhs.append((x, y, h))
x0, y0, h0 = max(xyhs, key=lambda xyh: xyh[2])
for cx in range(0, 101):
  for cy in range(0, 101):
    H = h0+abs(x0-cx)+abs(y0-cy)
    ok = True
    for x, y, h in xyhs:
      if h != max(0, H-abs(x-cx)-abs(y-cy)):
        ok = False
        break
    if ok:
      print(cx, cy, H)
      exit()
print(-1)

Submission status: Accepted

Solution code:
N = int(input())
x_y_h = []
for i in range(N):
    x_y_h.append(list(map(int, input().split())))
x_y_h.sort(key=lambda x: x[2])
a, b, c = x_y_h[-1]
for x in range(101):
    for y in range(101):
        h = abs(x-a) + abs(y-b) + c
        if all(k == max(h-abs(x-i)-abs(y-j), 0) for i, j, k in x_y_h):
            print(x, y, h)
            exit()

Submission status: Accepted

Solution code:
n = int(input())

clues = [tuple(map(int, input().split()))
         for _i in range(n)]
good_clue = next(clue for clue in clues if clue[2] > 0)

centers = [(x, y)
           for x in range(101)
           for y in range(101)]
for cx, cy in centers:
    ch = good_clue[2] \
         + abs(good_clue[0] - cx) \
         + abs(good_clue[1] - cy)

    if all(h == max(ch - abs(x - cx) - abs(y - cy), 0)
           for x, y, h in clues):
        print(cx, cy, ch)
        break

Submission status: Accepted

Solution code:
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n)]
for x,y,h in l:
  if h:
    kx = x
    ky = y
    kh = h
    break

for cx in range(101):
  for cy in range(101):
    ch = kh + abs(cx-kx) + abs(cy-ky)
    for x,y,h in l:
      if max(0,ch-abs(cx-x)-abs(cy-y)) != h:
        break
    else:
      print(cx,cy,ch)
      exit(0)

Submission status: Accepted

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

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

for cx in range(101):
    for cy in range(101):
        found = True
        ans   = -1
        for i in range(N):
            x,y,h = Data[i]
            if i == 0:
                # h != 0
                ans = h + abs(x-cx)+abs(y-cy)
            else: 
                diff = ans - abs(x-cx)-abs(y-cy)
                if  diff < 0:
                    if h != 0:
                        found = False
                        break
                else: 
                    if diff != h:
                        found = False
                        break
        if found == True:
            print( '{} {} {}'.format(cx,cy,ans))
            sys.exit()

Submission status: Accepted

Solution code:
N = int(input())
XYH = [list(map(int,input().split())) for i in range(N)]
XYH = sorted(XYH, key=lambda x:x[2])
XYH = XYH[::-1]
flag2 = 0

for x in range(101):
    if flag2 == 1:
        break
    for y in range(101):
        flag = 0
        H = XYH[0][2] + abs(x-XYH[0][0]) + abs(y-XYH[0][1])
        for i in range(1,N):
            if max(H - abs(x-XYH[i][0]) - abs(y-XYH[i][1]), 0) != XYH[i][2]:
                flag = 1
        if flag == 0:
            flag2 = 1
            break
    if flag2 == 1:
        break
ans = [x,y,H]
print(*ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    xs, ys, hs = list(), list(), list()
    for i in range(n):
        x, y, h = map(int, input().split())
        xs.append(x)
        ys.append(y)
        hs.append(h)

    for cx in range(101):
        for cy in range(101):
            # In this case,
            # multiple candidates of H & 
            Hs = set()
            Hs_ub = set()
            for x, y, h in zip(xs, ys, hs):
                H_cand = h + abs(x - cx) + abs(y - cy)
                if h == 0:
                    Hs_ub.add(H_cand)
                else:
                    Hs.add(H_cand)

            if len(Hs) != 1:
                continue
            
            # accept No.9, reject 10 - 15
            Hs_rm = set()
            for H in Hs:
                if all([H <= H_ub for H_ub in Hs_ub]):
                    continue
                else:
                    Hs_rm.add(H)
            Hs = Hs - Hs_rm

            Hs = {H for H in Hs if H >= 1}
            if len(Hs) == 1:
                H = Hs.pop()
                print(cx, cy, H)
                return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# code is from https://atcoder.jp/contests/abc112/submissions/7202999
n=int(input())
xyh=[tuple(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda tup:-tup[2])
for x in range(101):
	for y in range(101):
		esth=abs(x-xyh[0][0])+abs(y-xyh[0][1])+xyh[0][2]
		for i in range(1,n):
			if xyh[i][2]==0:
				if esth>abs(x-xyh[i][0])+abs(y-xyh[i][1]):
					break
			elif esth!=abs(x-xyh[i][0])+abs(y-xyh[i][1])+xyh[i][2]:
				break
		else:
			print(x,y,esth)
			exit()
		continue

Submission status: Accepted

Solution code:
n = int(input())
XYH = [list(map(int, input().split())) for _ in range(n)]
  
XYH.sort(key=lambda x:x[2],reverse=True)
sx = XYH[0][0]
sy = XYH[0][1]
sh = XYH[0][2]
  
for i in range(0,101):
  for j in range(0,101):
    anss = sh + abs(sx-i) + abs(sy-j)
    for k in range(n):
      if XYH[k][2] == max(anss - abs(XYH[k][0]-i) - abs(XYH[k][1]-j),0):
        pass
      else:
        break
    else:
      an = [i, j, anss]
      print(*an)
      exit()

Submission status: Accepted

Solution code:
n=int(input())
xyh=[tuple(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda tup:-tup[2])
for x in range(101):
	for y in range(101):
		esth=abs(x-xyh[0][0])+abs(y-xyh[0][1])+xyh[0][2]
		for i in range(1,n):
			if xyh[i][2]==0:
				if esth>abs(x-xyh[i][0])+abs(y-xyh[i][1]):
					break
			elif esth!=abs(x-xyh[i][0])+abs(y-xyh[i][1])+xyh[i][2]:
				break
		else:
			print(x,y,esth)
			exit()
		continue

Submission status: Accepted

Solution code:
n = int(input())
x = list(range(n))
y = list(range(n))
h = list(range(n))

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

flag=0
i = 0
while(flag==0 and i < 101):
  j = 0
  while(flag==0 and j < 101):
    ans_h = abs(i-X)+abs(j-Y)+H
    for k in range(n):
      h_ = max(ans_h-abs(i-x[k])-abs(j-y[k]), 0)
      if h_ != h[k]:
        break
      if k == n-1:
        ans_x = i
        ans_y = j
        flag=1
        break
    j+=1
  i+=1

print(ans_x, ans_y, ans_h)

Submission status: Accepted

Solution code:
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
x, y, h = list(filter(lambda x: x[2], p))[0]
for i in range(101):
  for j in range(101):
    H = h + abs(x-i) + abs(y-j)
    if all(max(H-abs(t[0]-i)-abs(t[1]-j), 0) == t[2] for t in p):
      print(i,j,H)

Submission status: Accepted

Solution code:
import sys

def height(a, b, c, d, e):
    return abs(a-d)+abs(b-e)+c

n = int(input())
hint = []
q = 0
for i in range(n):
    a, b, c = map(int, input().split())
    hint.append([c, a, b])
hint.sort(reverse=True)

for i in range(101):
    for j in range(101):
        frag = True
        H = height(hint[0][1], hint[0][2], hint[0][0], i, j)
        for h in hint[1:]:
            if h[0] != max(-abs(h[1]-i)-abs(h[2]-j)+H,0):
                frag = False
                break
        if frag:
            print(i, j, H)
            sys.exit()

Submission status: Accepted

Solution code:
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(int, input().split())
data = getSomeInputListInt(n)

rng = 101

def clc(i, j, h, x, y):
    return h + abs(i-x) + abs(j-y)

def clcdis(i, j, x, y):
    return abs(i-x) + abs(j-y)

ansi = 0
ansj = 0
ansh = 0

flgBreakI = False

for i in range(rng):
    for j in range(rng):
        flg = True
        tmp = 0
        hmax = 10**10

        for k in range(n):
            if data[k][2] == 0:
                hmax = min(hmax, clcdis(i, j, data[k][0], data[k][1]))
            else:
                if tmp == 0:
                   tmp = clc(i, j, data[k][2], data[k][0], data[k][1])
                else:
                    if tmp != clc(i, j, data[k][2], data[k][0], data[k][1]):
                        flg = False
                        break

        if flg and tmp <= hmax:
            ansi = i
            ansj = j
            ansh = tmp
            flgBreakI = True
            break

    if flgBreakI:
        break

print(ansi, ansj, ansh)

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
# x, y, h のベース座標を決める
# ベース座標が満たす条件はh>0
# ベース座標から中心位置X, Y, Hを計算することができそう
# Hを決め打ちする
# Cx, Cyはたかだか100個しかないので、全探索する
N =  int(sys.stdin.readline())
L =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]

for l in L:
    if l[2] > 0:
        base = l
        break

for x in range(0, 101):
    for y in range(0, 101):
        H = abs(base[0] - x) + abs(base[1] - y) + base[2]
        correct = True
        for l in L:
            if l[2] != max((H - abs(l[0] - x) - abs(l[1] - y)), 0):
                correct = False
                break
        if correct:
            print(x, y, H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key = lambda x: -x[2])
H = 0
for i in range(101):
  for j in range(101):
    for l in xyh:
      h = abs(i - l[0]) + abs(j - l[1])
      if l[2] != 0:
        if H == 0:
          H = l[2] + h
        else:
          if l[2] + h != H:
            H = 0
            break
      else:
        if H != 0:
          if H - h > 0:
            H = 0
            break
            
    if H != 0:
      print(i, j, H)
      exit(0)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
x_li = []
y_li = []
h_li = []
for i in range(n):
    x, y, h = na()
    x_li.append(x)
    y_li.append(y)
    h_li.append(h)
ans = []
flag = False
for i in range(len(h_li)):
    if h_li[i] > 0:
        idx = i
        break
for x in range(101):
    for y in range(101):
        H = h_li[idx] + abs(x_li[idx] - x) + abs(y_li[idx] - y)
        for i in range(n):
            if h_li[i] == max(H - abs(x_li[i] - x) - abs(y_li[i] - y), 0):
                if i == n - 1:
                    flag = True
                    ans.append([x, y, H])
                    break
            else:
                break
        if flag:
            break
    if flag:
        break
print(*ans[0])

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
x_li = []
y_li = []
h_li = []
for i in range(n):
    x, y, h = na()
    x_li.append(x)
    y_li.append(y)
    h_li.append(h)
H = -1
ansX = -1
ansY = -1
flag = False
if h_li.count(0) == len(h_li) - 1:
    idx = h_li.index(1)
    print(x_li[idx], y_li[idx], h_li[idx])
else:
    for x in range(101):
        for y in range(101):
            for i in range(n):
                tmp = h_li[i] + abs(x_li[i] - x) + abs(y_li[i] - y)
                if H == -1 and h_li[i] != 0:
                    H = tmp
                    ansX = x
                    ansY = y
                elif H == tmp or h_li[i] == 0:
                    if i == n - 1:
                        flag = True
                        break
                else:
                    H = -1
                    break
            if flag:
                break
        if flag:
            break

    print(ansX, ansY, H)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
pira = [[] for i in range(N)]
for i in range(N):
	pira[i] = list(map(int, input().split()))
	if pira[i][2] != 0:
		k = pira[i]

for x in range(101):
	for y in range(101):
		tmp = k[2] + abs(x-k[0]) + abs(y-k[1])
		for i in range(len(pira)):
			if pira[i][2] != max(tmp-abs(x-pira[i][0])-abs(y-pira[i][1]),0):
				break
			if i == len(pira)-1:
				print(x,y,tmp)
				exit()

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

# https://atcoder.jp/contests/abc112/submissions/4015190

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

confirmed = []
for cx in range(100+1):
    for cy in range(100+1):
        before = None
        for X, Y, H in src:
            if H == 0:
                continue

            tmp = H + abs(X-cx) + abs(Y-cy)
            if tmp < 0:
                continue

            if before == None:
                before = tmp
            elif before != tmp:
                break
        else:
            confirmed.append((cx, cy, tmp))

#print(confirmed)

for cx,cy,ch in confirmed:
    for x,y,h in src:
        if h != max(ch - abs(x-cx) - abs(y-cy), 0): break
    else:
        print(cx,cy,ch)
        exit()

Submission status: Accepted

Solution code:
import sys


n = int(input())
xyh = []
for i in range(n):
    xyh.append(list(map(int, input().split())))
    if xyh[-1][2] >= 1:
        G = xyh[-1]

for cx in range(0, 101):
    for cy in range(0, 101):
        hs = []
        x, y, h = G
        H = h + abs(x - cx) + abs(y - cy)
        H = max(H, 0)
        invalid = False
        for i in range(n):
            x, y, h = xyh[i]
            hh = H - abs(x - cx) - abs(y - cy)
            hh = max(hh, 0)
            if hh != h:
                invalid = True
                break
        if invalid is False:
            print("{} {} {}".format(cx, cy, H))
            sys.exit()