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 .

Solution (Python):
N = int(input())
X_h = []
Y_h = []
H = []
X_0 = []
Y_0 = []
for i in range(N):
    x, y, h = map(int, input().split())
    if h == 0:
        X_0.append(x)
        Y_0.append(y)
    else:
        X_h.append(x)
        Y_h.append(y)
        H.append(h)


def solve(H, X_h, Y_h, X_0, Y_0):
    for C_x in range(101):
        for C_y in range(101):
            h = H[0] + abs(X_h[0] - C_x) + abs(Y_h[0] - C_y)
            flag = True
            for i in range(1, len(X_h)):
                if h != H[i] + abs(X_h[i] - C_x) + abs(Y_h[i] - C_y):
                    flag = False
                    break
            if flag:
                for j in range(len(X_0)):
                    if h - abs(X_0[j] - C_x) - abs(Y_0[j] - C_y) > 0:
                        flag = False
                        break
                if flag:
                    return C_x, C_y, h


C_x, C_y, H = solve(H, X_h, Y_h, X_0, Y_0)
print(C_x, C_y, H)

Solution (Python):
N=int(input())
x=[0]*N
y=[0]*N
h=[0]*N
for i in range(N):
    x[i],y[i],h[i]=map(int,input().split())
ansx=-1
ansy=-1
ansh=-1
for i in range(101):
    for j in range(101):
        P=True
        tmph=-1
        for k in range(N):
            if h[k]>0:
                tmph=h[k]+abs(i-x[k])+abs(j-y[k])
                break
        for l in range(N):
            if h[l]!=max(0,tmph-abs(i-x[l])-abs(j-y[l])):
                P=False
        if P==True:
            ansx=i
            ansy=j
            ansh=tmph
print(ansx,ansy,ansh)

Solution (Python):
N = int(input())
xyh = sorted([list(map(int,input().split())) for _ in range(N)], key = lambda x: -x[2])
for Cx in range(101):
  mx, my, mh = xyh[0]
  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 xyh)):
      print(Cx, Cy, H)
      exit()

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

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

Solution (Python):


def main():
    N = int(input())
    conditions = []
    for i in range(N):
        conditions.append(list(map(int, input().split())))

    conditions.sort(key = lambda v: v[2], reverse = True)

    rcx, rcy = -1, -1
    rH = 0
    for cx in range(101):
        for cy in range(101):
            f = True
            max_H = 10 ** 10
            H = 0
            for i in range(N):
                x, y, h = conditions[i]
                if 0 < h:
                    if H == 0:
                        H = h + abs(x - cx) + abs(y - cy)
                    elif H != h + abs(x - cx) + abs(y - cy):
                        f = False
                        break
                else:
                    if x == cx and y == cy:
                        f = False
                        break
                    max_H = min(max_H, abs(x - cx) + abs(y - cy))
                    if max_H < H:
                        f = False
                        break
            if f:
                rcx, rcy, rH = cx, cy, H
                break
        if 0 < rH:
            break


    print('{} {} {}'.format(rcx, rcy, rH))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
x = []
y = []
h = []
for i in range(n):
    a,b,c = map(int, input().split())
    x.append(a)
    y.append(b)
    h.append(c)
kk = h.index(max(h))
for i in range(101):
    for j in range(101):
        H = h[kk] + abs(x[kk] - i) + abs(y[kk] - j)
        for k in range(n):
            if h[k] > 0:
                if H != abs(x[k]-i)+abs(y[k]-j)+h[k]:
                    H = -1
            if h[k] == 0:
                if H > abs(x[k] - i) + abs(y[k] - j):
                    H = -1
        if H != -1:
            print(i, j, H)

Solution (Python):
from itertools import product

n = int(input())
query = []
for i in range(n):
    query.append(list(map(int, input().split())))
query.sort(key=lambda x: x[2], reverse=True)

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

Solution (Python):
def manhattan(i, j, x, y):
    
    return abs(i-x) + abs(j-y)

def main(N, X, Y, H):
    cand = [0, 0, 0]
    for i in range(101):
        for j in range(101):
            
            for k in range(N):
                if H[k] != 0:
                    x, y, h = X[k], Y[k], H[k]
                    hmax = h + manhattan(i, j, x, y)
                    break
            
            for k in range(N):
                x, y, h = X[k], Y[k], H[k]
                if h == 0:
                    if hmax > manhattan(i, j, x, y):
                        break
                else:
                    if hmax - h != manhattan(i, j, x, y):
                        break
            else:
                if cand[2] < hmax:
                    cand = [i, j, hmax]
    return cand

N = int(input())
X, Y, H = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
i, j, hmax = main(N, X, Y, H)
print(str(i) + ' ' + str(j) + ' ' + str(hmax))

Solution (Python):
n = int(input())
infolist = []
for i in range(n):
    infolist.append([int(x) for x in input().split()])
center = []
for x in infolist:
    if x[2] != 0:
        x1, y1, h1 = x
        break
for i in range(101):
    for j in range(101):
        H = h1 + abs(x1-i) + abs(y1-j)
        if all(h == max((H - abs(x-i) - abs(y-j)) ,0) for x, y, h in infolist):
            print(i, j, H)

Solution (Python):
n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]
A.sort(reverse = True, key = lambda x: x[2])

for i in range(101):
    for j in range(101):
        px, py, ph = A[0] 
        H = ph + abs(px - i) + abs(py - j)
        if all(h == max(H - abs(x - i) - abs(y - j) , 0) for x, y, h in A):
            print(i, j, H)

Solution (Python):


def possible_height(cx, cy, infos):
    maxmin = 1
    minmax = 99999999999
    for i in infos:
        hmin, hmax = get_height(cx, cy, *i)
        maxmin = max(maxmin, hmin)
        minmax = min(minmax, hmax)
    if maxmin == minmax:
        return maxmin
    elif maxmin < minmax:  
        raise Exception
    else:  
        return None

def get_height(cx, cy, xi, yi, hi):
    hmax = abs(cx - xi) + abs(cy - yi) + hi
    hmin = 1 if hi == 0 else hmax
    return hmin, hmax

def main():
    n = int(input())
    infos = []
    for i in range(n):
        x, y, h = map(int, input().split())
        infos.append((x, y, h))

    for cx in range(101):
        for cy in range(101):
            h = possible_height(cx, cy, infos)
            if h is not None:
                print(cx, cy, h)
                return
    raise Exception

main()

Solution (Python):
n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]
A.sort(reverse = True, key = lambda x: x[2])

for i in range(101):
    for j in range(101):
        px, py, ph = A[0]
        H = ph + abs(px - i) +abs(py - j)
        if all(h == max(H - abs(x - i) - abs(y - j) , 0) for x, y, h in A):
            print(i, j, H)

Solution (Python):
def main():
    n = int(input())
    x = []
    y = []
    h = []
    for i in range(n):
        xx, yy, zz = map(int, input().split())
        x.append(xx)
        y.append(yy)
        h.append(zz)
    for i in range(n):
        if h[i] != 0:
            idx = i
    for xx in range(101):
        for yy in range(101):
            H = h[idx] + abs(xx - x[idx]) + abs(yy - y[idx])
            flag = True
            for i in range(n):
                if h[i] != max(H - abs(xx - x[i]) - abs(yy - y[i]), 0):
                    flag = False
                    break
            if flag:
                print(xx, yy, H)
                return

    
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
 

zahyo = [list(map(int,input().split())) for i in range(n)] 
 
for cx in range(101):
  for cy in range(101):
    flag =0
    for i in range(n):
      if zahyo[i][2]>0:
        H0 = abs(cx-zahyo[i][0])+abs(cy-zahyo[i][1])+zahyo[i][2]
        break
    for i in range(n):
      if zahyo[i][2] != max(0, H0-abs(cx-zahyo[i][0])-abs(cy-zahyo[i][1])):  
        flag=1
        break
    if flag==0:
      print(cx,cy,H0)
      exit()

Solution (Python):
N = int(input())
xyh = [[int(i) for i in input().split()] for i in range(N)]

tmpx,tmpy,tmph=0,0,0
for x,y,h in xyh:
    if h>0:
        tmpx,tmpy,tmph=x,y,h
        break

truecx,truecy,trueh=0,0,0
for cx in range(101):
    for cy in range(101):
        largeh=tmph+abs(tmpx-cx)+abs(tmpy-cy)
        flag=True
        for x,y,h in xyh:
            if h != max(largeh-abs(x-cx)-abs(y-cy),0):
                flag = False
                break
        if flag:
            truecx,truecy,trueh=cx,cy,largeh
            break
print(truecx,truecy,trueh)

Solution (Python):
N = int(input())
xyr = [list(map(int, input().split())) for _ in range(N)]


def m():
    tmpx, tmpy, tmpr = 0, 0, 0
    for a,b,c in xyr:
        if c != 0:
            tmpx = a
            tmpy = b
            tmpr = c
            break

    for cx in range(0, 101):
        for cy in range(0, 101):
            h = max(0, tmpr + abs(tmpx - cx) + abs(tmpy - cy))
            f = 0
            for x, y, r in xyr:
                if not (r == max(h - abs(x - cx) - abs(y - cy), 0)):
                    f = 1
                    break
            if f == 0:
                return "{} {} {}".format(cx, cy, h)


print(m())

Solution (Python):
N = int(input().strip())
xyh = []
for i in range(0, N):
    xi, yi, hi= [int(a) for a in input().strip().split()]
    xyh.append((xi, yi, hi))

xyh.sort(key = lambda t: t[2], reverse = True)

def calc_H():
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H = -1
            for i in range(0, N):
                Hi = xyh[i][2] + abs(xyh[i][0]-Cx) + abs(xyh[i][1]-Cy)
                if H == -1:
                    H = Hi

                if xyh[i][2] == 0:
                    if H > Hi:
                        break
                elif H != Hi:
                    break

                if i == N-1:
                    return Cx, Cy, H

print(*calc_H())

Solution (Python):
def main():
    N = int(input())
    points = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        points.append((x, y, h))

    for xx, yy, hh in points:
        if hh > 0:
            break
    for cx in range(101):
        for cy in range(101):
            f = True
            H = hh + abs(xx - cx) + abs(yy - cy)
            for x, y, h in points:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    f = False
                    break
            if f is True:
                print(cx, cy, H)
                return


if __name__ == '__main__':
    main()

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

cands = []
for cx in range(0,101):
    for cy in range(0,101):
        tmph = None
        for x,y,h in src:
            if h == 0: continue
            ch = h + abs(x-cx) + abs(y-cy)
            if ch < 0: break
            if tmph is None:
                tmph = ch
            elif tmph != ch:
                break
        else:
            cands.append((cx,cy,tmph))

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

Solution (Python):
def abc(n:int,lst:list):
    l0=list(filter(lambda x:x[2]==0,lst))
    l=list(filter(lambda x:x[2]!=0,lst))
    if len(l0):
        x0 =l[0][0]
        y0=l[0][1]
        h0 =l[0][2]
        ans=[]
        for x in range(101):
            for y in range(101):
                for i in range(len(l)):
                    if abs(x0-x)+abs(y0-y)-abs(l[i][0]-x)-abs(l[i][1]-y) == l[i][2]-h0:
                        if i ==len(l)-1:
                            for k in range(len(l0)):
                                if abs(l0[k][0]-x)+abs(l0[k][1]-y)>=h0+abs(x0-x)+abs(y0-y):
                                    if k == len(l0)-1:
                                        return x,y,h0+abs(x0-x)+abs(y0-y)
                                else:
                                    break
                    else:
                        break

    else:
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)

Solution (Python):
def abc(n:int,lst:list):
    l0=list(filter(lambda x:x[2]==0,lst))
    l=list(filter(lambda x:x[2]!=0,lst))
    if len(l0):
        x0 =l[0][0]
        y0=l[0][1]
        h0 =l[0][2]
        ans=[]
        for x in range(101):
            for y in range(101):
                for i in range(len(l)):
                    if abs(x0-x)+abs(y0-y)-abs(l[i][0]-x)-abs(l[i][1]-y) == l[i][2]-h0:
                        if i ==len(l)-1:
                            ans.append([x,y,h0+abs(x0-x)+abs(y0-y)])
                    else:
                        break
        for xyh in ans:
            for i in range(len(l0)):
                if abs(l0[i][0]-xyh[0])+abs(l0[i][1]-xyh[1])>=xyh[2]:
                    if i == len(l0)-1:
                        return xyh
                else:
                    break
    else:
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)

Solution (Python):
n = int(input())
xyh = [[int(i) for i in input().split()] for i in range(n)]
xyh.sort(reverse=True, key=lambda x:x[2])

for i in range(101):
    for j in range(101):
        px, py, ph = xyh[0]
        H = ph + abs(px - i) + abs(py - j)
        if all(h == max(H - abs(x - i) - abs(y - j), 0) for x, y, h in xyh):
            print(i, j, H)

Solution (Python):
N = int(input())
X = list()
Y = list()
H = list()
i = 0
for n in range(0,N):
    S = list(map(int,input().split()))
    X.append(S[0])
    Y.append(S[1])
    H.append(S[2])
for x in range(0,101):
    for y in range(0,101):
        while H[i] == 0:
            i = i+1 
            if i == N-1:
                break
        else:
            sub = abs(x - X[i]) + abs(y - Y[i]) + H[i]
        for n in range(0,N):
            h = sub - abs(x-X[n]) - abs(y-Y[n])
            if not H[n] == max(h,0):
                break
            else:
                if n == N-1:
                    print(x, y, sub)

Solution (Python):
N = int(input())
xyh = []

for i in range(N):
    ent = input().split()
    xyh.append((int(ent[0]), int(ent[1]), int(ent[2])))

sortedxyh = sorted(xyh, key=lambda x:int(x[2]))

pointA = None
pointB = None
for x in xyh:
    if x[2] != 0:
        if pointA == None:
            pointA = x
        else:
            pointB = x
            break

endflg = False
if pointB == None:
    
    print(str(pointA[0]) + ' ' + str(pointA[1]) + ' ' + str(pointA[2]))
else:
    
    
    for cx in range(0, 101):
        for cy in range(0, 101):
            AH = pointA[2] + max( ( abs(pointA[0] - cx) + abs(pointA[1] - cy) ), 0)
            BH = pointB[2] + max( ( abs(pointB[0] - cx) + abs(pointB[1] - cy) ), 0)
            if AH == BH and AH != 0 and BH != 0:
                H = AH
                continueflg = False
                for other in xyh:
                    if other[2] != max((H - abs(other[0] - cx) - abs(other[1] - cy)), 0):
                        continueflg = True
                        break
                if continueflg:
                    continue
                print(str(cx) + ' ' + str(cy) + ' ' + str(H))
                endflg = True
                break
            else:
                continue
        if endflg:
            break

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

for i in range(N):
    if data[i][2] >0:
        base=i
        break

for cx in range(101):
    for cy in range(101):
        h = data[base][2] + abs(cx-data[base][0]) + abs(cy - data[base][1])
        flag=0
        for i in range(N):
            if data[i][2] != max(h - abs(cx-data[i][0]) - abs(cy-data[i][1]),0):
                flag=1
                break
        if flag==0:
            ans = [cx,cy,h]
            
print('{0[0]} {0[1]} {0[2]}'.format(ans))

Solution (Python):
N = int(input())
data = [[0 for i in range(3)] for j in range(N)]
for i in range(N):
    data[i][0],data[i][1],data[i][2] = [int(s) for s in input().split()]


for p in data:
    if p[2] != 0:
        base_x = p[0]
        base_y = p[1]
        base_height = p[2]


for Cx in range(0,101):
    for Cy in range(0,101):
        height = abs(base_x-Cx)+abs(base_y-Cy)+base_height
        for p in data:
            if p[2] != max([height-abs(Cx-p[0])-abs(Cy-p[1]),0]):
                break
        else:
            print(str(Cx)+' '+str(Cy)+' '+str(height))
            exit()

Solution (Python):
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 lastH:
                    if H != lastH:
                        break
                lastH = H
            else:
                print(cx, cy, H)
                return
 
main()

Solution (Python):
n = int(input())
hxy = []
for i in range(n):
    x, y, h = map(int, input().split())
    hxy.append([h, x, y])
    
hxy.sort(reverse=True)

for i in range(101):
    for j in range(101):
        h0, x0, y0 = hxy[0]
        H = h0 + abs(x0-i) + abs(y0-j)
        if all(h == max(H - abs(x-i) - abs(y-j), 0) for h, x, y in hxy):
            print(i, j, H)
            break

Solution (Python):
n=int(input())
l=[]
for i in range(n):
    x,y,h = map(int, input().split())
    l.append([x,y,h])
l.sort(reverse=True, key=lambda x: x[2])
for i in range(101):
    for j in range(101):
        px, py, ph = l[0]
        H = ph + abs(px-i) + abs(py-j)
        if all(h == max(H-abs(x - i) - abs(y - j),0) for x, y, h in l):
            print(i,j,H)
            break

Solution (Python):
n = int(input())
x = [0] * n
y = [0] * n
h = [0] * n
for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())
for a in range(101):
    for b in range(101):
        hset = set()
        for i in range(n):
            if h[i] != 0:
                hset.add(h[i] + abs(x[i]-a) + abs(y[i]-b))
        if len(hset) == 1:
            height = hset.pop()
            check = True
            for i in range(n):
                if h[i] == 0:
                    if height - abs(x[i]-a) - abs(y[i]-b) > 0:
                        check = False
                        break
            if check:
                print(a,b,height)
                exit()
print('ERROR EXIT')

Solution (Python):
N = int(input())
S = [[int(i) for i in input().split()] for j in range(N)]
SS = sorted(S,key=lambda x: x[2], reverse=True)


def firstlook(si, kohod): 
    for x in range(0, 100+1):
        for y in range(0, 100+1):
            h = si[2]+abs(si[0]-x)+abs(si[1]-y)
            kohod[(x,y)] = h
    return kohod

def lastlook(si, kohod):
    for (x, y) in list(kohod.keys()):
        h = max(kohod[(x,y)]-abs(si[0]-x)-abs(si[1]-y),0)
        if si[2] != h:
            del kohod[(x,y)]
    return kohod

ans = firstlook(SS[0], dict())
for Si in SS[1:]:
    ans = lastlook(Si, ans)

[xy] = list(ans.keys())
print(str(xy[0]) + " " + str(xy[1]) + " "+ str(ans[xy]))

Solution (Python):
W = 101

def solve(xyh):
    for bx, by, bh in xyh:
        if bh > 0:
            break
    for yy in range(W):
        for xx in range(W):
            H = bh + abs(bx - xx) + abs(by - yy)
            for x, y, h in xyh:
                if max(H - abs(xx - x) - abs(yy - y), 0) != h:
                    break
            else:
                return (xx, yy, H)

N = int(input())
xyh = [tuple(map(int, input().split())) for i in range(N)]
print(*solve(xyh))

Solution (Python):
N=input()

Data=[]
for i in range(N):
    Data.append(map(int,raw_input().split()))
    
Data.sort(key=lambda x:x[2], reverse=True)
for i in range(0,101):
    for j in range(0,101):
        H=Data[0][2]+abs(Data[0][0]-i)+abs(Data[0][1]-j)
        k=1
        while k<N:
            if (H-abs(Data[k][0]-i)-abs(Data[k][1]-j)<=0 and Data[k][2]==0)\
             or H==Data[k][2]+abs(Data[k][0]-i)+abs(Data[k][1]-j):
                k+=1
            else:
                break
        if k==N:
            print i,j,H
            exit()

Solution (Python):
n = int(input())
positions = [list(map(int, input().split())) for _ in range(n)]
for position in positions:
  if position[2] != 0:
    base = position
    break
base_height = base[2]
base_x = base[0]
base_y = base[1]
for x in range(101):
  for y in range(101):
    height = abs(base_x-x)+abs(base_y-y)+base_height
    for position in positions[:]:
      if position[2] != max([height-abs(x-position[0])-abs(y-position[1]),0]):
        break
    else:
      print(str(x) + ' ' + str(y) + ' ' + str(height))
      exit()

Solution (Python):
N = int(input())

xyh = []

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

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

for i in range(101):
    for j in range(101):
        px, py, ph = xyh[0]
        H = ph + abs(px-i) + abs(py-j)
        if all(h == max(H-abs(x - i) - abs(y - j),0) for x, y, h in xyh):
            print(i,j,H)
            break

Solution (Python):
import sys
import itertools

cols = []
for line in sys.stdin:
  col = line.strip().split(' ')
  col = [int(c) for c in col]
  cols.append(col)

cols = cols[1:]
for cx,cy in itertools.product(list(range(101)), list(range(101))):
  H, H_max, flag = None, None, True
  for x,y,h in cols:
    if h <= 0:
      tmp_H_max = abs(x-cx) + abs(y-cy)
      if tmp_H_max < 1:
        flag = False
        break
      else:
        H_max = min(H_max, tmp_H_max) if H_max else tmp_H_max
      if H and H_max < H:
        flag = False
        break
    else:
      tmp_H = h + abs(x-cx) + abs(y-cy)
      if not H:
        H = tmp_H
      elif H and H != tmp_H:
        flag = False
        break
      if H_max and H_max < tmp_H:
        flag = False
        break
  if flag:
    print(cx,cy,H)

Solution (Python):
n = int(input())

xyh = []

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

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

for i in range(101):
    for j in range(101):
        px, py, ph = xyh[0]
        H = ph + abs(px - i) + abs(py - j)
        if all(h == max(H - abs(x - i) - abs(y -j), 0) for x, y, h in xyh):
            print(i, j, H)
            break

Solution (Python):
n = int(input())
A = [list(map(int,input().split())) for _ in range(n)]
X = [0,0,0]
for i in range(n):
    if A[i][2]>0:
        X = A[i]
        break


for x in range(101):
    for y in range(101):
        h = X[2] + abs(x-X[0]) + abs(y-X[1])
        flag = 1
        for i in range(n):
            if A[i][2] != max(h - abs(x-A[i][0]) - abs(y-A[i][1]),0):
                flag = 0
        if flag == 1:
            print(x,y,h)

Solution (Python):


def validate(N, points, c_x, c_y):
    
    for n in range(N):
        h = points[n][2]
        if h != 0:
            x = points[n][0]
            y = points[n][1]
            estimated_height = h + abs(c_x - x) + abs(c_y - y)

    
    for n in range(N):
        x = points[n][0]
        y = points[n][1]
        h = points[n][2]
        height = max(estimated_height - abs(c_x - x) - abs(c_y - y), 0)

        if h != height:
            return -1
    return estimated_height

if __name__ == "__main__":
    N = int(input())
    points = [None] * N
    for n in range(N):
        x, y, h = map(int, input().split())
        points[n] = [x, y, h]

    candidates = [i for i in range(101)]
    for c_x in candidates:
        for c_y in candidates:
            height = validate(N, points, c_x, c_y)
            if height != -1:
                print(c_x, c_y, height)
                break

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

for i in range(101):
  for j in range(101):
    for k in range(N):
      if xyh[k][2] != 0:
        H = xyh[k][2] + abs(i-xyh[k][0]) + abs(j-xyh[k][1])
        break
    is_h = True
    for k in range(N):
      if max(0, H-abs(i-xyh[k][0])-abs(j-xyh[k][1])) != xyh[k][2]:
        is_h = False
        break
    if is_h:
      print(i, j, H)

Solution (Python):
N = int(input())

arr = []

for i in range(N):
    arr.append(list(map(int, input().split())))
    
for x in range(101):
    for y in range(101):
        for i in range(N):
            if arr[i][2]:
                H = arr[i][2] + abs(x-arr[i][0]) + abs(y-arr[i][1])
                break
        ok = True
        for i in range(N):
            price = H-abs(x-arr[i][0])-abs(y-arr[i][1])
            if max(price,0) != arr[i][2]:
                ok = False
        if ok :
            print(x,y,H)

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

    if h == 0:
        continue
    XYHA.append([x,y,h])

if len(XYHA) == 1:
    print(XYHA[0][0],XYHA[0][1],XYHA[0][2])
    exit()

for i in range(101):
    for j in range(101):
        HC = max(XYHA[0][2] + abs(XYHA[0][0] - i) + abs(XYHA[0][1] - j), 0)
        for k in range(1, len(XYHA)):

            H = max(XYHA[k][2] + abs(XYHA[k][0] - i) + abs(XYHA[k][1] - j), 0)

            if HC != H:
                break
            elif k == len(XYHA) - 1:
                print(i,j,HC)
                exit()

Solution (Python):
N = int(input())
 
XYHA = []
 
for i in range(N):
    x,y,h = map(int,input().split())
    if h == 0:
        continue
    XYHA.append([x,y,h])

for i in range(101):
    for j in range(101):
        HC = XYHA[0][2] + abs(XYHA[0][0] - i) + abs(XYHA[0][1] - j)
        for k in range(1, len(XYHA)):

            H = XYHA[k][2] + abs(XYHA[k][0] - i) + abs(XYHA[k][1] - j)

            if HC != H:
                break
            elif k == len(XYHA) - 1:
                print(i,j,HC)
                exit()

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

Solution (Python):
N = int(input())
 
info = []
 
for i in range(N):
    x,y,h = map(int,input().split())
    if h == 0:
        N -= 1
        continue
    info.append([x,y,h])
 
for i in range(101):
    for j in range(101):
        H_0 = info[0][2] + abs(info[0][0] - i) + abs(info[0][1] - j)
        
        for k in range(1, N):
            H = info[k][2] + abs(info[k][0] - i) + abs(info[k][1] - j)
            
            if H_0 != H:
                break
            elif k == N - 1:
                print(i,j,H_0)
                exit()
 
print(info[0][0],info[0][1],info[0][2])

Solution (Python):
N = int(input())
info = []
for i in range(N):
    x,y,h = map(int,input().split())
    if h == 0:
        N -= 1
        continue
    info.append([x,y,h])
for i in range(101):
    for j in range(101):
        H_0 = info[0][2] + abs(info[0][0] - i) + abs(info[0][1] - j)
        for k in range(1,N):
            H = info[k][2] + abs(info[k][0] - i) + abs(info[k][1] - j)
            if H_0 != H:
                break
            elif k == N-1:
                print(i,j,H_0)
                exit()
print(info[0][0],info[0][1],info[0][2])

Solution (Python):
N=int(input())
A=[[]for i in range(N)]
for i in range(N):
    a,b,c=map(int,input().split())
    A[i].append(a)
    A[i].append(b)
    A[i].append(c)
A.sort(key=lambda x:x[2],reverse=True)
c=0
h=0
X=0
Y=0
for x in range(101):
    for y in range(101):
        c=0
        for i in range(N):
            H=abs(A[i][0]-x)+abs(A[i][1]-y)+A[i][2]
            if H>=abs(A[i][0]-x)+abs(A[i][1]-y):
                break
        for i in range(N):
            if max(H-abs(A[i][0]-x)-abs(A[i][1]-y),0)!=A[i][2]:
                c=1
                break
        if c==0:
            h=H
            X=x
            Y=y
            break
    if c==0:
        break
print(X,Y,h)