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 = int(input())
tmp = [int(i) for _ in range(n) for i in input().split()]

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

hmax = max(hs)
index = hs.index(max(hs))
xmax = xs[index]
ymax = ys[index]

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

s = 0
flag = 0
s_max=2000000000
x_a=0
y_a=0
h_a=0

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

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

Submission status: Accepted

Solution code:
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
arr.sort(key=lambda l:-l[2])
 
for cx in range(101):
  for cy in range(101):
    ch = None
    for x, y, h in arr:
      t = h + abs(cx-x) + abs(cy-y)
      if h > 0:
        if ch is not None and t != ch:
          break
        ch = t
      else:
        if t < ch:
          break
    else:
      print(cx, cy, ch)
      exit()

Submission status: Accepted

Solution code:

def main():
    buf = input()
    N = int(buf)
    x = []
    y = []
    h = []
    for i in range(N):
        buf = input()
        buflist = buf.split()
        x.append(int(buflist[0]))
        y.append(int(buflist[1]))
        h.append(int(buflist[2]))
    x = [z for _, z in sorted(zip(h,x), key=lambda pair: pair[0])][::-1]
    y = [z for _, z in sorted(zip(h,y), key=lambda pair: pair[0])][::-1]
    h = sorted(h)[::-1]
    for cx in range(101):
        for cy in range(101):
            H = h[0] + dist(cx, cy, x[0], y[0])
            correct = True
            for i in range(1, N):
                if h[i] + dist(cx, cy, x[i], y[i]) != H:
                    if dist(cx, cy, x[i], y[i]) <= H:
                        correct = False
                        break
                    else:
                        if h[i] != 0:
                            correct = False
                            break
            if correct == True:
                print(cx, cy, H)
                return


def dist(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

j = -1
for i in range(N):
    x[i],y[i],h[i] = map(int,input().split(" "))
    if h[i] !=  0:
        j = i

for cx in range(0,101):
    for cy in range(0,101):
        H = h[j] + abs(x[j]-cx) + abs(y[j]-cy)
        flg = True
        for i in range(N):
            if (h[i] == 0 and ((abs(x[i]-cx) + abs(y[i]-cy))) < H):
                flg = False
                break
            if (h[i] != 0 and H != (h[i] + abs(x[i]-cx) + abs(y[i]-cy))):
                flg = False
                break
        if flg:
            print("{0} {1} {2}".format(cx,cy,H))
            exit(0)

Submission status: Accepted

Solution code:
n = int(input())

x = [int(i) for i in range(n)]
y = [int(i) for i in range(n)]
h = [int(i) for i in range(n)]
for i in range(n):
  x[i], y[i], h[i] = [int(i) for i in input().split()]
for i in range(101):
  for j in range(101):
    for k in range(n):
      if h[k] != 0:
        H = abs(i - x[k]) + abs(j - y[k]) + h[k] 
    for k in range(n):
      if H - abs(i - x[k]) - abs(j - y[k]) <=0:
        if h[k] != 0:
          break
      elif  H != abs(i - x[k]) + abs(j - y[k]) + h[k]:
        break
    else:
      ansx = i
      ansy = j
      ansH = H
      
print(ansx, ansy, ansH)

Submission status: Accepted

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


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

if len(h) == 1:
    print(x[0], y[0], h[0])
    exit()

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
X = []
Y = []
H = []
for i in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
while H[0] == 0:
    X.append(X[0])
    Y.append(Y[0])
    H.append(H[0])
    X = X[1:]
    Y = Y[1:]
    H = H[1:]
x1 = X[0]
y1 = Y[0]
h1 = H[0]
for Cx in range(101):
    for Cy in range(101):
        h = h1 + abs(x1-Cx) + abs(y1-Cy)
        i = 1
        while i < N and H[i] == max(h - abs(X[i]-Cx) - abs(Y[i]-Cy), 0):
            i += 1
        if i == N:
            print(Cx, Cy, h)
            sys.exit()

Submission status: Accepted

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

N = int(Input())
x_y_h = [list(map(int, Input().split())) for _ in range(N)]
Cx = None
Cy = None
H = float("inf")
H_temp = None
 
x_y_h_tmp = [xyh for xyh in x_y_h if xyh[2] > 0]
if N == 1:
    print("{0} {1} {2}".format(x_y_h[0][0], x_y_h[0][1], x_y_h[0][2]))
else:
    for c_x in range(0, 100+1):
        for c_y in range(0, 100+1):
            for i, (x, y, h) in enumerate(x_y_h_tmp):
                if i == 0:
                    H_temp = abs(c_x - x) + abs(c_y - y) + h
                elif H_temp != abs(c_x - x) + abs(c_y - y) + h:
                    break
            else:
                if H_temp < H:
                    Cx = c_x
                    Cy = c_y
                    H = H_temp
                    
print("{0} {1} {2}".format(Cx, Cy, H))

Submission status: Accepted

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

flag = False
flag2 = True
firsst = True
for x in range(0,101):
    for y in range(0,101):
        flag = False
        flag2 = True
        first = True
        for i in range(0,N):
            if INFO[i][2] == 0:
                flag = True
                continue
            if first:
                first = False
                elseH = abs(x-INFO[i][0]) + abs(y-INFO[i][1]) + INFO[i][2]
            H = abs(x-INFO[i][0]) + abs(y-INFO[i][1]) + INFO[i][2]
            if H != elseH:
                flag2 = False
                break
        if flag:
            for i in range(0,N):
               if max(elseH - abs(x-INFO[i][0]) - abs(y-INFO[i][1]),0) != INFO[i][2]:
                   flag2 = False
        if flag2:
            break
    if flag2:
        break
print(x,y,H)

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)


cxyl = []
for i in range(101):
    for j in range(101):
        cxyl.append((i,j))
cxy = set(cxyl)
hd = {}
hzero = set([])
for i in range(n):
    for c in list(cxy):
        H = abs(x[i]-c[0]) + abs(y[i]-c[1]) + h[i]
        if h[i] == 0:
            hzero.add((x[i],y[i]))
            if 1 > H:
                cxy.remove(c)
                continue
        else:
            if c in hd:
                if hd[c] != H:
                    cxy.remove(c)
                    continue
            else:
                hd[c] = H

for xy in list(hzero):
    xi = xy[0]
    yi = xy[1]
    for c in list(cxy):
        H = abs(xi-c[0]) + abs(yi-c[1])
        if hd[c] - H > 0:
            cxy.remove(c)

ret = cxy.pop()
print(str(ret[0]) + ' ' + str(ret[1]) + ' ' + str(hd[ret]))

Submission status: Accepted

Solution code:
n = int(input())

x = []

for i in range(n):
	a,b,c = map(int,input().split())
	x.append([c,a,b])
x.sort()
x.reverse()
a = 0
b = 0
for i in range(101):
	for j in range(101):
		for k in range(n):
			if x[k][0] != 0:
				if k == 0:
					a = x[k][0] + abs(i-x[k][1]) + abs(j-x[k][2])
					b += 1
				else:
					if a == x[k][0] + abs(i-x[k][1]) + abs(j-x[k][2]):
						b += 1
			else:
				if a- abs(i-x[k][1]) - abs(j-x[k][2]) <= 0:
					b += 1
		if b == n:
			print(i,j,a)
		b = 0

Submission status: Accepted

Solution code:
n = int(input())

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

info = sorted(info,key = lambda x: x[2])
end = 0

for x in range(101):
    for y in range(101):
        H = info[n-1][2] + abs(x-info[n-1][0]) + abs(y-info[n-1][1])
        for i in range(n-1):
            if info[i][2] != max(0,H - abs(x-info[i][0]) - abs(y- info[i][1])):
                break
        else:
            print(x,y,H)
            end = 1
            
        if end == 1:
            break
    if end == 1:
        break

Submission status: Accepted

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

N = int(input())

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


ans_list = []
for xi in range(101):
    for yi in range(101):
        H_list = []
        for x,y,h in xyhn:
            if h > 0:
                H = h + abs(x - xi) + abs(y - yi)
                H_list.append(H)

        if min(H_list) == max(H_list):
            ans_list.append([xi,yi,H_list[0]])
            # print("%d %d %d"%(xi,yi,H_list[0]))
            # exit()

ans_list.sort(key=lambda x:x[2])
print("%d %d %d"%(ans_list[0][0],ans_list[0][1],ans_list[0][2]))

Submission status: Accepted

Solution code:
n = int(input())
xlist = []
ylist = []
hlist = []
for _ in range(n):
    x, y, h =list(map(int, input().split()))
    xlist.append(x)
    ylist.append(y)
    hlist.append(h)

def cond(cx, cy):
    same = None
    for i in range(n):
        if hlist[i] == 0:
            continue
        h = hlist[i] + abs(xlist[i] - cx) + abs(ylist[i] - cy)
        if same == None:
            same = h
            continue
        if same != h:
            return False
    for i in range(n):
        if hlist[i] == 0:
            if same - abs(xlist[i] - cx)  - abs(ylist[i] - cy) > 0:
                return False
    return True
        
rescx, rescy = 0, 0
label = False
for cx in range(101):
    for cy in range(101):
        if cond(cx, cy):
            rescx = cx
            rescy = cy
            label = True
            break
    if label:
        break

resh = 0
for i in range(n):
    if hlist[i] > 0:
        resh = abs(xlist[i] - rescx) + abs(ylist[i] - rescy) + hlist[i]
        break

print(rescx, rescy, resh)

Submission status: Accepted

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

for i in range(n):
    q,w,e = map(int, input().split())
    x[i]=q
    y[i]=w
    h[i]=e

for i in range(n):
    if h[i]>0:
        ii = i
    
        
ran = list(range(0,n))
ran.remove(ii)

for cx in range(101):
    for cy in range(101):
        hight = abs(cx-x[ii]) + abs(cy-y[ii]) + h[ii]        
        flag=1
        for i in ran:
            if max(hight - (abs(cx-x[i]) + abs(cy-y[i])), 0) != h[i]:
                flag=0
        if flag==1:
            print("{} {} {}".format(cx, cy, hight))

Submission status: Accepted

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

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

#print(A)

a1=0
a2=0
a3=0

for i in range(0,101):
    for j in range(0,101):
        col=0
        h=abs(A[0][0]-i)+abs(A[0][1]-j)+A[0][2]
        for k in range(1,n):
            if max(0,h-abs(A[k][0]-i)-abs(A[k][1]-j))!=A[k][2] :
                col=1
        if col==0 :
            a1=i
            a2=j
            a3=h

print(str(a1)+" "+str(a2)+" "+str(a3))

Submission status: Accepted

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

if N == 1:
    print(G[0][0],G[0][1],G[0][2])
    exit(0)

G = sorted(G, key=lambda x: -x[2])
for Cx in range(101):
    for Cy in range(101):
        f = 1
        H = G[0][2] + abs(Cx-G[0][0]) + abs(Cy-G[0][1])
        for k in range(1,N):
            if max(0,H-abs(G[k][0]-Cx)-abs(G[k][1]-Cy)) != G[k][2]:
                f = 0
        if f:
            print(Cx,Cy,H)

Submission status: Accepted

Solution code:
n = int(input())
l = [list(map(int, input().split())) for i in range(0, n) ]

for i in range(0, n):
    if l[i][2] != 0:
        p = l[i]
        break

for x in range(0, 101):
    for y in range(0, 101):
        h = p[2] + abs(x-p[0]) + abs(y-p[1])
        for i in range(0, n):
            if l[i][2] != max(h - abs(x-l[i][0]) - abs(y-l[i][1]), 0):
                break
        else:
            print(x, y, h)
            exit()

Submission status: Accepted

Solution code:
N = int(input())

X = [None] * N
Y = [None] * N
H = [None] * N

x_max = 0
y_max = 0
h_max = 0
R = []

for n in range(N):
    X[n], Y[n], H[n] = map(int, input().split())
    if h_max <= H[n]:
        x_max, y_max, h_max = X[n], Y[n], H[n]

for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True
        for n in range(N):
            if H[n] != 0:
                ch = H[n] + abs(X[n] - cx) + abs(Y[n] - cy)
        for n in range(N):
            if max(ch - abs(X[n] - cx) - abs(Y[n] - cy), 0) != H[n]:
                flag = False
                break
        if flag == True:
            R.append([cx, cy, ch])

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

Submission status: Accepted

Solution code:
n=int(input())
x,y,h=[],[],[]
for _ in [0]*n:
    xi,yi,hi=[int(x) for x in input().split()]
    x.append(xi)
    y.append(yi)
    h.append(hi)
diff = 0
if min(h)>=10:
    diff=min(h)-5
h=[i-diff for i in h]
# print(h)
def pattern(cx,cy,H):
    for i in range(n):
        # print(cx,x[i],cy,y[i],H,h[i],max(H-abs(x[i]-cx)-abs(y[i]-cy),0))
        if max(H-abs(x[i]-cx)-abs(y[i]-cy),0)!=h[i]:
            return False
    return True
from itertools import product
for H in range(1,1000):
    for cx,cy, in product(range(101),range(101)):
        if pattern(cx,cy,H):
            print(cx,cy,H+diff)
            import sys
            sys.exit()

Submission status: Accepted

Solution code:

def check(cx, cy, H, x, y, h):
    if (h == 0) and (abs(cx-x)+abs(cy-y) > H):
        return True
    if H-h == abs(cx-x)+abs(cy-y):
        return True
    else:
        return False

def a():
    N = int(input())
    xs = []
    ys = []
    hs = []
    for _ in range(N):
        i = input().split(' ')
        xs.append(int(i[0]))
        ys.append(int(i[1]))
        hs.append(int(i[2]))
    
    for i, h in enumerate(hs):
        if h==0:
            continue
        else:
            init_x = xs[i]
            init_y = ys[i]
            init_h = h
            break
    for cx in range(101):
        for cy in range(101):
            H = abs(cx-init_x)+abs(cy-init_y)+init_h
            flag_stop = False
            for x, y, h in zip(xs, ys, hs):
                if not check(cx, cy, H, x, y, h):
                    flag_stop = True
                    break
            if flag_stop:
                continue
            else:
                print('{} {} {}'.format(cx, cy, H))
                return
a()

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []
h = []
for i in range(n):
    temp = [int(_) for _ in input().split(' ')]
    x.append(temp[0])
    y.append(temp[1])
    h.append(temp[2])

for cx in range(101):
    for cy in range(101):
        correctness = True
        for i in range(n):
            if h[i] > 0:
                ch = h[i] + abs(cx - x[i]) + abs(cy - y[i])
        for i in range(n):
            if h[i] != max(ch - abs(cx - x[i]) - abs(cy - y[i]), 0):
                correctness = False
        if correctness:
            print('{0} {1} {2}'.format(cx, cy, ch))

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())
xs, ys, hs = zip(*[[int(x) for x in input().split()] for _ in range(n)])

for i, j in product(range(0,101), repeat=2):
    k = -1
    l = 1 << 32
    for x, y, h in zip(xs, ys, hs):
        if h == 0:
             l = min(l, abs(x-i) + abs(y-j))
        elif k == -1:
             k = abs(x-i) + abs(y-j) + h
        elif k!=-1 and k - h != abs(x-i) + abs(y-j):
            break
        if k > l:
            break
    else:
        if k!=-1:
            print(i, j, k)
        elif l==1:
            print(i, j, 1)
        break

Submission status: Accepted

Solution code:
n = int(input())
x=[]
y=[]
h=[]
for i in range(0,n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    h.append(c)
 
 
 
for i in range(0,101):
    for j in range(0,101):
        tmph=0
        flag = True
        for k in range(0,n):
            if tmph == 0 and h[k] != 0:
                tmph=abs(x[k]-i)+abs(y[k]-j)+h[k]
                break
        for k in range(0,n):
            calch = tmph - abs(x[k]-i)-abs(y[k]-j)
            if h[k] != max(calch,0):
                flag = False
                break
        if flag == False:
            continue
        elif tmph == 0:
            flag2 = True
            for c in range(0,101):
                if i == x[c] and j == y[c]:
                    flag2 = False
                    break
            if flag2:
                ansx = i
                ansy = j
                ansh = 1
        else:
            ansx=i
            ansy=j
            ansh=tmph
 
print(ansx,ansy,ansh)

Submission status: Accepted

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N
for i in range(N):
    x[i], y[i], h[i] = list(map(int, input().split()))
min_min_h = 10**9+1
for i in range(101):
    for j in range(101):
        tmp = []
        tmp2 = []
        for k in range(N):
            if h[k] !=0:
                tmp.append(abs(i-x[k])+abs(j-y[k])+h[k])
            else:
                tmp2.append(abs(i-x[k])+abs(j-y[k]))
        if len(set(tmp)) == 1:
            for l in range(len(tmp2)):
                if tmp[0]>tmp2[l]:
                    break
            else:
                print(i,j,tmp[0])

Submission status: Accepted

Solution code:
def get_coord(C):
    for xi in range(0, 101):
        for yi in range(0, 101):
            H = 10 ** 9 + 1
            success = True
            for i in range(0, len(C)):
                d = abs(xi - C[i][0]) + abs(yi - C[i][1])
                if i == 0:
                    th = H - d
                    H -= th - C[i][2]
                else:
                    nh = H - d
                    if nh >= 0:
                        if C[i][2] == nh:
                            continue
                        else:
                            success = False
                            break
                    else:
                        if C[i][2] == 0:
                            continue
                        else:
                            success = False
                            break

            if success:
                return (xi, yi)
    return (-1, -1)


def solve(C):
    C.sort(key=lambda x: x[2], reverse=True)
    x, y = get_coord(C)
    for c in C:
        if c[2] != 0:
            h = abs(x - c[0]) + abs(y - c[1]) + c[2]
            return [str(x), str(y), str(h)]


if __name__ == "__main__":
    N = int(input())
    C = []
    for n in range(N):
        d = input().split(" ")
        C.append((int(d[0]), int(d[1]), int(d[2])))
    print(" ".join(solve(C)))

Submission status: Accepted

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


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

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

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

Submission status: Accepted

Solution code:
N = int(input())
p = [list(map(int, input().split())) for _ in range(N)]
def find(H):
    for cx in range(101):
        for cy in range(101):
            for x, y, h in p:
                if h > max(H - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                return True
    return False

lo = 0
hi = 10 ** 10
while hi - lo > 1:
    mid = (hi + lo) // 2
    if find(mid):
        hi = mid
    else:
        lo = mid

for cx in range(101):
    for cy in range(101):
        for x, y, h in p:
            if h != max(hi - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            print(cx, cy, hi)
            exit()

Submission status: Accepted

Solution code:
n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]
xyh = sorted(xyh, reverse = True, key = lambda z: z[2])
# print(xyh)

for i in range(101):
    for j in range(101):
        x_0, y_0, h_0 = xyh[0]
        H = h_0 + abs(y_0-i) + abs(x_0-j)
        valid = True
        for x, y, h in xyh[1:]:
            if max(H-abs(y-i)-abs(x-j), 0) != h:
                valid = False
                break
        if valid:
            ans = str(j)+' '+str(i)+' '+str(H)
            print(ans)
            exit()

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
XYH = [list(map(int,input().split())) for _ in range(N)]

Cxy = defaultdict(int)

#-1 NG
# 0 default
#1+ ok
verify =[]
XYH.sort(key=lambda x:-x[2])

for x,y,h in XYH:
    for cx in range(101):
        for cy in range(101):
            val = Cxy[(cx,cy)]
            if val<0:
                continue
            tmp_H = abs(x-cx)+abs(y-cy)+h
            if h==0:
                if tmp_H < Cxy[(cx,cy)]:
                    Cxy[((cx, cy))]=-1
                continue

            if val==0:
                Cxy[(cx,cy)] = tmp_H
            elif val != tmp_H:
                Cxy[(cx, cy)] =-1

def find(d):
    for key in d.keys():
        if d[key] >0:

            return key,d[key]

(X,Y),H = find(Cxy)
print(X,Y,H)

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
h = []
for i in range(N):
    a,b,c = map(int,input().split())
    if c>0: idx_0 = i
    x.append(a)
    y.append(b)
    h.append(c)
for cx in range(101):
    for cy in range(101):
        H = h[idx_0] + abs(x[idx_0]-cx) + abs(y[idx_0]-cy)
        cnt = 0
        for k in range(N):
            if h[k]==max(H - abs(x[k]-cx) - abs(y[k]-cy), 0): cnt+=1
        if cnt==N:
            print(cx,cy,H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())

#def height(x, y, h, cx, cz):

def city_dist(x1, y1, x2, y2):
    return(abs(x1-x2)+abs(y1-y2))

def height(x1, y1, cx, cy, H):
    return max(H-city_dist(x1, y1, cx, cy), 0)

x = []
y = []
h = []
non_zero_index = -1

for i in range(N):
    line = [int(a) for a in input().split()]
    x.append(line[0])
    y.append(line[1])
    h.append(line[2])
    if line[2] != 0:
        non_zero_index = i


for cx in range(101):
    for cy in range(101):
        H = h[non_zero_index] + city_dist(x[non_zero_index], y[non_zero_index], cx, cy)
        answer = True
        for i in range(N):
            #print(cx, cy, H, i, x[i], y[i], h[i], height(x[i], y[i], cx, cy, H))
            if h[i] != height(x[i], y[i], cx, cy, H):
                answer = False
                break
        if answer:
            print("{} {} {}".format(cx, cy, H))
            break            
    if answer:
        break

Submission status: Accepted

Solution code:
import math
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
h = [0 for i in range(n)]
judge = False
for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())
for i in range(0, 101):
    for j in range(0, 101):
        for k in range(0, n):
            if h[k] != 0:
                true_h = h[k] + int(math.fabs(x[k]-i)) + int(math.fabs(y[k]-j))
                break
        judge = True
        for k in range(n):
            dum_h = max(true_h-int(math.fabs(x[k]-i)) - int(math.fabs(y[k]-j)), 0)
            if h[k] != dum_h:
                judge = False
                break
        # print(k)
        if judge is True:
            break
    if judge is True:
        break

print("{} {} {}".format(i, j, true_h))

Submission status: Accepted

Solution code:
n = input()
l = []
isz = 0
for i in xrange(n):
    x, y, h = map(int, raw_input().strip().split())
    if h == 0: isz += 1
    l.append([x, y, h])

assert isz != n

ans = [0,0,0]

for cx in xrange(101):
    for cy in xrange(101):
        H = 0
        zH = int(1e18)
        poss = True
        for xyh in l:
            x, y, h = xyh
            tx = abs(cx - x) + abs(cy - y)
            if h != 0:
                nH = tx + h
                if H != 0 and nH != H:
                    poss = False
                    break
                elif H == 0: H = nH
            elif h == 0:
                zH = min(zH, tx)

        if poss:
            if H > zH: poss = False
             
        if poss:
            ans = [cx, cy, H]
            break
        
    if poss: break
    
if ans != [0, 0, 0]:
    check = True
    for xyh in l:
        x, y, h = xyh
        tx = abs(cx - x) + abs(cy - y)
        assert h == max(ans[2] - tx, 0)

print ans[0], ans[1], ans[2]

Submission status: Accepted

Solution code:
N = int(input())
lis = []
rem = 0
for i in range(N):
    x,y,h = map(int,input().split())
    if h != 0:
        rem = i
    lis.append((x,y,h))
flag = 1
for i in range(101):
    for j in range(101):
        flag = 1
        H = lis[rem][2]+abs(lis[rem][0]-i)+abs(lis[rem][1]-j)
        for k in range(N):
            if lis[k][2] != max(H-abs(lis[k][0]-i)-abs(lis[k][1]-j),0):
                flag = 0
                break
        if flag == 1:
            break
    if flag == 1:
        break
print(str(i)+" "+str(j)+" "+str(H))

Submission status: Accepted

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

for x in range(101):
    for y in range(101):
        h_must = 0
        h_max = 1000000000
        for k in range(N):
            h_tmp = xyh[k][2]+abs(x-xyh[k][0])+abs(y-xyh[k][1])
            if h_must == 0:
                if xyh[k][2] != 0:
                    h_must = h_tmp
                else:
                    h_max = min(h_max,h_tmp)
            else:
                if xyh[k][2] != 0:
                    if h_must != h_tmp:
                        break
                else:
                    h_max = min(h_max,h_tmp)
                    if h_must > h_max:
                        break
        else:
            if h_must == 0:
                h_must = h_max
            print("{} {} {}".format(x,y,h_must))
            break
    else:
        continue
    break

Submission status: Accepted

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

for x in range(101):
    for y in range(101):
        h = [0]*n
        ans = 0
        for i in range(n):
            if xyh[i][2]!=0:
                h[i] = abs(xyh[i][0] - x) + abs(xyh[i][1] - y) + xyh[i][2]
                if ans == h[i] or ans ==0:
                    ans =h[i]
                else:
                    break
            if i ==n-1:
                a = 0
                for j in range(n):
                    if xyh[j][2]!= max(ans- abs(xyh[j][0] - x) - abs(xyh[j][1] - y),0):
                        a=1
                        break
                if a==0:
                    print(x, y, ans)

Submission status: Accepted

Solution code:
N = int(raw_input())
data = []
for i in range(N):
    v = map(int, raw_input().split())
    data.append(v)

cond = []
for x in range(100+1):
    for y in range(100+1):
        h = []
        for d in data:
            if d[2] != 0:
                h.append(d[2] + abs(d[0]-x) + abs(d[1]-y))
        if len(set(h)) == 1:
            cond.append((x, y, h[0]))

if len(cond) == 1:
    print cond[0][0], cond[0][1], cond[0][2]
else:
    for c in cond:
        res = []
        for d in data:
            if d[2] == 0:
                if c[2] - (abs(d[0]-c[0]) + abs(d[1]-c[1])) <= 0:
                    res.append(True)
                else:
                    res.append(False)
        if all(res):
            print c[0], c[1], c[2]
            exit(0)