Problem:


Score: 300 points

Problem Statement

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

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

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

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

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

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

Constraints

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

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

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

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

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

Input

Input is given from Standard Input in the following format:  

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

Output

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

Sample Input 1

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

Sample Output 1

2 2 6

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

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

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

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

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

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



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


Sample output:
2 2 6

Submission status: Wrong Answer

Solution code:
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())

marker = [0]*101
for Cx in range(101):
  marker[Cx] = [True]*101
  for Cy in range(101):
    h = -1
    for i in range(N):
      if H[i]==0:
        continue
      a = H[i]+abs(Cx-X[i])+abs(Cy-Y[i])
      if h == -1:
        h = a
      elif h != a:
        marker[Cx][Cy] = False
        break
    if marker[Cx][Cy] == True:
      ans = [Cx,Cy,h]
      print(*ans)
      exit()

Submission status: Wrong Answer

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] = map(int, input().split())

marker = [0]*101
for Cx in range(101):
  marker[Cx] = [False]*101
  for Cy in range(101):
    h = -1
    for i in range(N):
      if H[i]==0:
        continue
      a = H[i]+abs(Cx-X[i])+abs(Cy-Y[i])
      if h == -1:
        h = a
        marker[Cx][Cy] = True
      elif h != a:
        marker[Cx][Cy] = False
        break
    if marker[Cx][Cy] == True:
      ans = [Cx,Cy,h]
      print(*ans)
      exit()

Submission status: Wrong Answer

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] = map(int, input().split())
  
for Cx in range(101):
  for Cy in range(101):
    marker = True
    for i in range(N):
      a = H[i]+abs(Cx-X[i])+abs(Cy-Y[i])
      if i == 0:
        h = a
      elif h != a:
        marker = False
        break
    if marker == True:
      ans = [Cx,Cy,h]
      print(*ans)
      exit()

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
query = []
for _ in range(n):
    x,y,h = map(int,input().split())
    if h != 0:
        query.append((x,y,h))
tx = query[0][0]
ty = query[0][1]
th = query[0][2]
query.pop(0)
c = [i for i in range(101)]
cc = list(itertools.product(c, repeat=2))
for X,Y in cc:
    H = th + abs(tx-X) + abs(ty-Y)
    Flag = True
    for x,y,h in query:
        if max(H - abs(x-X) - abs(y-Y),0) != h:
            Flag = False
            break
    if Flag:
        print(X,Y,H)
        exit()

Submission status: Wrong Answer

Solution code:
from itertools import product

n = int(input())
data = [[int(i) for i in input().split()] for _ in range(n)]

for cx, cy in product(range(101), repeat=2):
    ch = 0
    is_stored = False
    for x, y, h in data:
        if h == 0:
            continue
        val = h + abs(x-cx) + abs(y-cy)
        if is_stored:
            if ch != val:
                break
        else:
            ch = val
            is_stored = True
    else:
        print(cx, cy, ch)
        break

Submission status: Wrong Answer

Solution code:
N = int(input())

xyh = [list(map(int, input().split())) for i in range(N)]
Hmap = [[-1]*101 for i in range(101)]
for cx in range(101):
  for cy in range(101):
    H = -1
    Hmax = float('inf')
    is_determined = True
    for x, y, h in xyh:
      if h:
        _h = h + abs(x-cx) + abs(y-cy)
        if H < 0:
          H = _h
        else:
          if H != _h:
            is_determined = False
            break
      else:
        Hmax = min(Hmax, abs(x-cx) + abs(y-cy))
    if is_determined and H>0:
      Hmap[cx][cy] = H
    elif Hmax < float('inf'):
      Hmap[cx][cy] = Hmax

for cx in range(101):
  for cy in range(101):
    H = Hmap[cx][cy]
    if H > 0:
      print(cx, cy, H)
      quit()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for cx in range(101):
  for cy in range(101):
    H = -1
    is_determined = True
    for x, y, h in xyh:
      if h:
        _h = h + abs(x-cx) + abs(y-cy)
        if H < 0:
          H = _h
        else:
          if H != _h:
            is_determined = False
            break
    if is_determined and H>0:
      print(cx, cy, H)
      quit()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(input = sys.stdin.readline):
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())

    N = II()
    info = []
    for _ in range(N):
        info.append(LMIIS())
    x0,y0,h0 = info[0]
    for Cy in range(101):
        for Cx in range(101):
            H = h0 + abs(x0 - Cx) + abs(y0 - Cy)
            for xi, yi, hi in info:
                tmp_H = hi + abs(Cy-yi) + abs(Cx-xi)
                # print(H,tmp_H,Cx,Cy,xi,yi,hi)
                if hi != 0:
                    if H < tmp_H:
                        H = 0
                        break
                    else:
                        H =  tmp_H
            if H != 0:
                # print('found')
                print('{} {} {}'.format(Cx,Cy,H))
                return



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(input = sys.stdin.readline):
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())

    N = II()
    info = []
    for _ in range(N):
        info.append(LMIIS())
    x0,y0,h0 = info[0]
    for Cy in range(101):
        for Cx in range(101):
            H = h0 + abs(x0 - Cx) + abs(y0 - Cy)
            for xi, yi, hi in info:
                tmp_H = hi + abs(Cy-yi) + abs(Cx-xi)
                if tmp_H > H:
                    H = 0
                    break
                else:
                    H =  min(H,tmp_H)
            if H != 0:
                print('{} {} {}'.format(Cx,Cy,H))
                return



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(input = sys.stdin.readline):
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())

    N = II()
    info = []
    for _ in range(N):
        info.append(LMIIS())
    for Cy in range(101):
        for Cx in range(101):
            H = 0
            for xi, yi, hi in info:
                max_H = hi + abs(Cy-yi) + abs(Cx-xi)
                if H > max_H:
                    H = 0
                    break
                else:
                    H =  max(H,max_H)
            if H != 0:
                print('{} {} {}'.format(Cx,Cy,H))
                return



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(101):
    for j in range(101):
        for k in range(n):
            x, y, h = xyh[k]
            if h:
                H = h + abs(x - i) + abs(y - j)
                break

        ans = True
        for k in range(n):
            x, y, h = xyh[k]
            if h != max(H - abs(x - i) - abs(y - i), 0):
                ans = False
                break
        if ans:
            print(i, j, H)
            exit()

Submission status: Wrong Answer

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

for i in range(101):
    for j in range(101):
        ans = []
        for k in range(n):
            x, y, h = xyh[k]
            if h != 0:
                H = h + abs(x - i) + abs(y - j)
                ans.append(H)
        if len(list(set(ans))) == 1:
            print(i, j, ans[0])
            exit()

Submission status: Wrong Answer

Solution code:
INF=10**20
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)
for i in range(101):#Cx
    for j in range(101):#Cy
        res=-INF
        T=True
        for k in range(N):
            tmp=h[k]+abs(x[k]-i)+abs(y[k]-j)
            if(h[k]>0):
                if(res==-INF):
                    res=tmp
                elif(res!=tmp):
                    T=not T
                    break
            elif(h[k]==0):
                if(tmp<res):
                    T=not T
                    break
        if T:
            print(i,j,res)
            exit()

Submission status: Wrong Answer

Solution code:


def read_input():
    n = int(input())
    conds = []
    for _ in range(n):
        x, y, h = map(int, input().split())
        conds.append(((x, y), h))

    return n, conds


def manhattan(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


def submit():
    n, conds = read_input()    

    if n == 1:
        p, h = conds[0]
        print("{} {} {}".format(p[0], p[1], h))
        return

    center_cands = {}
    for i in range(101):
        for j in range(101):
            center_cands[(i, j)] = None

    for p, h in conds:
        for i in range(101):
            for j in range(101):
                if center_cands[(i, j)] == -1:
                    continue
                
                d = manhattan(p, (i, j))
                if not center_cands[(i, j)]:    
                    center_cands[(i, j)] = (h - d, h + d)
                else:
                    if center_cands[(i, j)][0] == h - d:
                        center_cands[(i, j)] = (h - d, -1)
                    elif center_cands[(i, j)][1] == h + d :
                        center_cands[(i, j)] = (-1, h + d)
                    else:
                        center_cands[(i, j)] = -1

    for k, h in center_cands.items():
        if h == None or h == -1:
            continue
    
        if h[0] > 0:
            print("{} {} {}".format(k[0], k[1], h[0]))
        else:
            print("{} {} {}".format(k[0], k[1], h[1]))
            
            
if __name__ == "__main__":
    submit()

Submission status: Wrong Answer

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

def check(x,y):

    count = 0
    while l[count][2] == 0:
        count += 1
    h = l[count][2] + abs(x-l[count][0])+abs(y-l[count][1])

    for i,j,k in l[count:]:
        if k != max(h-abs(x-i)-abs(y-j),0):
            return False

    return x,y,h

for i in range(101):
    for j in range(101):
        if check(i,j):
            print(*check(i,j))

Submission status: Wrong Answer

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)
for cx in range(0,101):
  for cy in range(0,101):
    x0,y0,h0=xyh[0]
    H=h0+abs(x0-cx)+abs(y0-cy)
    if H==0:
      continue
    flag=True
    for x,y,h in xyh:
      if H!=h+abs(x-cx)+abs(y-cy):
        flag=False
    if flag:
      print(cx,cy,H)
      exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)
for cx in range(1,101):
  for cy in range(1,101):
    x0,y0,h0=xyh[0]
    H=h0+abs(x0-cx)+abs(y0-cy)
    flag=True
    for x,y,h in xyh:
      if H!=h+abs(x-cx)+abs(y-cy):
        flag=False
    if flag:
      print(cx,cy,H)
      exit()

Submission status: Wrong Answer

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


for i in range(N):
    if xyh[i][0] > 0:
        xx, yy, hh = xyh[i][0], xyh[i][1], xyh[i][2]
        break

for cx in range(101):
    for cy in range(101):
        H = hh + abs(cx-xx) + abs(cy-yy)
        count = 0
        for i in range(N):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            if max(H - abs(x - cx) - abs(y - cy), 0) == h:
                count += 1
        if count == N:
            print(cx, cy, H)
            exit()

Submission status: Wrong Answer

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


for i in range(N):
    if xyh[i][0] > 0:
        xx, yy, hh = xyh[i][0], xyh[i][1], xyh[i][2]
        break

for cx in range(101):
    for cy in range(101):
        H = hh + abs(cx-xx) + abs(cy-yy)
        count = 1
        for i in range(1, N):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            if max(H - abs(x - cx) - abs(y - cy), 0) == h:
                count += 1
        if count == N:
            print(cx, cy, H)
            exit()

Submission status: Wrong Answer

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


for cx in range(101):
    for cy in range(101):
        x = xyh[0][0]
        y = xyh[0][1]
        h = xyh[0][2]
        hi = h + abs(x - cx) + abs(y - cy)
        count = 1
        for i in range(1, N):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            if max(hi - abs(x - cx) - abs(y - cy), 0) == h:
                count += 1
        if count == N:
            print(cx, cy, hi)
            exit()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    XYH = [[int(e) for e in input().split()] for i in range(n)]

    for xi in range(101):
        for yi in range(101):
            top = 1
            for x, y, h in XYH:
                if h > 0:
                    top = h + abs(xi - x) + abs(yi - y)

            topf = True
            for x, y, h in XYH:
                if (h == 0 and top < abs(xi - x) + abs(yi - y)) \
                        or (h > 0 and top != h + abs(xi - x) + abs(yi - y)):
                    topf = False
                    break

            if(topf):
                print(xi, yi, top)
                exit()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    XYH = [[int(e) for e in input().split()] for i in range(n)]

    for xi in range(101):
        for yi in range(101):
            top = XYH[0][2] + abs(xi - XYH[0][0]) + abs(yi - XYH[0][1])
            topf = True
            for i in range(1, n):
                if top != XYH[i][2] + abs(xi - XYH[i][0]) + abs(yi - XYH[i][1]):
                    topf = False
                    break

            if(topf):
                print(xi, yi, top)
                exit()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh=sorted(xyh,reverse=True,key=lambda x:x[2])
#print(xyh)
for cx in range(0,101):
    for cy in range(0,101):
        H = 0
        for x,y,h in xyh:
            if H == 0:
                H = h + abs(x - cx) + abs(y - cy)
            else:
                temp_H = h + abs(x - cx) + abs(y - cy)
                if temp_H != H:break
        else:
            if H>=1:
                print(cx,cy,H)
                exit()

Submission status: Wrong Answer

Solution code:
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)

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

Submission status: Wrong Answer

Solution code:
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)

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

Submission status: Wrong Answer

Solution code:
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)

for cx in range(0,101):
    for cy in range(0,101):
        H = 0
        cnt=0
        for i in range(n):
            if H==0 and h[i]!=0:
                cnt+=1
                H= h[i] + abs(x[i] - cx) + abs(y[i] - cy)
            elif h[i] == 0:
                cnt += 1
            else:
                temp_H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                if temp_H!=H:break
                cnt += 1
        if cnt == n:
            print(cx,cy,H)
            exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(list(map(int,input().split()))for _ in range(N))

for i in range(N):
    if p[i][2]:
        tmp = i
        break

for Cx in range(101):
    for Cy in range(101):
        H = p[tmp][2] + abs(Cx-p[tmp][0]) + abs(Cy-p[tmp][1])
        flag = True
        for x,y,h in p:
            if h != max(abs(Cx-x) + abs(Cy-y) + H , 0):
                flag = False
                break
        if flag:
            print(Cx,Cy,H)

Submission status: Wrong Answer

Solution code:
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)

for cx in range(0,101):
    for cy in range(0,101):
        H = h[0] + abs(x[0] - cx) + abs(y[0] - cy)
        cnt=0
        for i in range(1,n):
            if h[i]==0:
                cnt+=1
            else:
                temp_H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                if temp_H!=H or H == 0:break
                cnt += 1
        if cnt == n-1 and H>=1:
            print(cx,cy,H)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    xyh = [tuple(map(int, input().split())) for _ in range(N)]

    def check(cx, cy):
        def dist(x, y): return abs(x-cx) + abs(y-cy)
        tmp = 0
        for x, y, h in xyh:
            d = dist(x,y)
            if h == 0:
                if tmp > d: return -1
            else:
                if tmp != 0 and tmp != h+d: return -1
                tmp = h+d
        return tmp
    
    for x in range(101):
        for y in range(101):
            H = check(x,y)
            if H >= 0:
                print('{} {} {}'.format(x,y,H))
                return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(list(map(int,input().split()))for _ in range(N))
for Cx in range(101):
    for Cy in range(101):
        H = -1
        for x,y,h in p:
            if H != abs(Cx-x) + abs(Cy-y) + h:
                if h == 0 and H < abs(Cx-x) + abs(Cy-y) + h:
                    continue
                elif H == -1:
                    if h == 0:
                        H = abs(Cx-x) + abs(Cy-y) + h
                else:
                    H = 0
                    break
        if H:
            print(Cx,Cy,H)

Submission status: Wrong Answer

Solution code:
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)

for cx in range(0,101):
    for cy in range(0,101):
        H = h[0] + abs(x[0] - cx) + abs(y[0] - cy)
        cnt=0
        for i in range(1,n):
            temp_H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
            if temp_H!=H:break
            cnt+=1
        if cnt==n-1:
            print(cx,cy,H)
            exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(list(map(int,input().split()))for _ in range(N))
for Cx in range(101):
    for Cy in range(101):
        H = -1
        for x,y,h in p:
            if H != abs(Cx-x) + abs(Cy-y) + h:
                if h == 0 and H < abs(Cx-x) + abs(Cy-y) + h:
                    continue
                elif H == -1:
                    H = abs(Cx-x) + abs(Cy-y) + h
                else:
                    H = 0
                    break
        if H:
            print(Cx,Cy,H)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(list(map(int,input().split()))for _ in range(N))
for Cx in range(101):
    for Cy in range(101):
        H = -1
        for x,y,h in p:
            if H != abs(Cx-x) + abs(Cy-y) + h:
                if h == 0:
                    continue
                elif H == -1:
                    H = abs(Cx-x) + abs(Cy-y) + h
                else:
                    H = 0
                    break
        if H:
            print(Cx,Cy,H)

Submission status: Wrong Answer

Solution code:
n = int(input())

L = [[0, 0, 0] for _ in range(n)]
for i in range(n):
    x, y, h = map(int, input().split())
    L[i][0] = x
    L[i][1] = y
    L[i][2] = h

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

for i in range(0, 101):
    for j in range(0, 101):
        for k in range(n):
            x = L[k][0]
            y = L[k][1]
            h = L[k][2]
            if k == 0:
                H = abs(i-x)+abs(j-y)+h
            else:
                if h == 0:
                    continue
                else:
                    if H != abs(i-x)+abs(j-y)+h:
                        break
        else:
            ans = [i, j, H]
print(*ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    XYH = [[int(i) for i in input().split()] for j in range(N)]

    for cy in range(101):
        for cx in range(101):
            ch = XYH[0][2] + abs(XYH[0][0] - cx) + abs(XYH[0][1] - cy)
            for x, y, h in XYH[1:]:
                if ch != h + abs(x - cx) + abs(y - cy):
                    break
            else:
                if ch != 0:
                    return print(cx, cy, ch)
    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    XYH = [[int(i) for i in input().split()] for j in range(N)]

    for cy in range(101):
        for cx in range(101):
            ch = 0
            for x, y, h in XYH:
                if ch == 0:
                    ch = h + abs(x - cx) + abs(y - cy)
                elif ch != h + abs(x - cx) + abs(y - cy):
                    break
            else:
                return print(cx, cy, ch)
    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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] = map(int, input().split())
for cx in range(101):
    for cy in range(101):
        H = set()
        for i in range(N):
            H.add(h[i]+abs(cx-x[i])+abs(cy-y[i]))
        if len(H) == 1:
            print(cx, cy, list(H)[0])
            exit()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter


def main():
    n = int(input())
    data = [[int(i) for i in input().split()] for _ in range(n)]
    maximum = max(data, key=itemgetter(2))
    if maximum[2] == 1:
        print(*maximum)
        return
    test, *valid = data

    for x in range(101):
        for y in range(101):
            h = abs(test[0] - x) + abs(test[1] - y) + test[2]
            for v in valid:
                if max(h - abs(x - v[0]) - abs(y - v[1]), 0) != v[2]:
                    break
            else:
                print(x, y, h)
                return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter


def main():
    n = int(input())
    data, *test = [[int(i) for i in input().split()] for _ in range(n)]
    if data[2] == 1:
        print(*data)
        return
    m = max(test, key=itemgetter(2))
    if m[2] == 1:
        print(*m)
        return

    c = []
    for x in range(101):
        for y in range(101):
            h = abs(data[0] - x) + abs(data[1] - y) + data[2]
            for t in test:
                if max(h - abs(x - t[0]) - abs(y - t[1]), 0) != t[2]:
                    break
            else:
                print(x, y, h)
                return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    data, *test = [[int(i) for i in input().split()] for _ in range(n)]

    for x in range(101):
        for y in range(101):
            h = abs(data[0] - x) + abs(data[1] - y) + data[2]
            for t in test:
                if max(h - abs(x - t[0]) - abs(y - t[1]), 0) != t[2]:
                    break
            else:
                print(x, y, h)
                return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

#サンプルを用意
for x,y,h in xyh:
    if h!=0:
        xs,ys,hs=x,y,h


for cx in range(100+1):
    for cy in range(100+1):
        guessed_H = hs+abs(xs-cx)+abs(ys-cy)
        if all([h+abs(x-cx)+abs(y-cy)==guessed_H for x,y,h in xyh]):
            print(cx,cy,guessed_H)

Submission status: Wrong Answer

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

#H=0を排除,Nも減らす
xyh = [i for i in xyh if (lambda x:x[2])(i)!=0]

#print(xyh)

for cx in range(100+1):
    for cy in range(100+1):
        guessed_H = []
        for x,y,h in xyh:
            H = h+abs(cx-x)+abs(cy-y)
            guessed_H.append(H)
        guessed_H.sort()
        if guessed_H[0]==guessed_H[-1]:
            print(cx,cy,guessed_H[0])
            exit()
print("incorrect")

Submission status: Wrong Answer

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

for x in range(101):
    for y in range(101):
        h=xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
        flag = True
        for X,Y,H in xyh[1:]:
            if H != max(h-abs(x-X)-abs(y-Y),0):
                flag = False
                break
        if flag:
            print(x,y,h)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
xyh = []
for i in range(n):
    X,Y,H = map(int,input().split())
    xyh.append([X,Y,H])

for x in range(101):
    for y in range(101):
        h=xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
        flag = True
        for X,Y,H in xyh:
            if not H==max(h-abs(x-X)-abs(y-Y),0):
                flag = False
                break
        if flag:
            print(x,y,h)
            sys.exit()

Submission status: Wrong Answer

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

for x in range(101):
    for y in range(101):
        h=xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
        cnt=0
        for X,Y,H in xyh:
            if h==H+abs(x-X)+abs(y-Y): cnt+=1
            else: break
        if cnt==len(xyh):
            print(x,y,h)
            break

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
hh = []
vec = list()
G = (-1,-1,-1)

for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    hh.append(h)
    # 高さが1以上の三組を一つ取る(この場合, hi = H - |Xi - Cx| - |Yi - Cy|が成立する)
    if h >= 1:
        G = (x, y, h)

for i in range(0,101):
    for j in range(0,101):
        # 最初にHを固定する
        H = G[2] + abs(G[0] - i) + abs(G[1] - j)
        H = max(H, 0)
        flag = True
        for k in range(N):
            key = H - abs(X[k] - i) - abs(Y[k] - j)
            if key != hh[k]:
                flag = False
        # 全てのkについてHが成立するとき, append
        if flag:
            vec.append((i,j,H))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
hh = []
vec = list()
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    hh.append(h)

for i in range(0,101):
    for j in range(0,101):
        s = set()
        for k in range(N):
            key = abs(X[k] - i) + abs(Y[k] - j) + hh[k]
            s.add(key)
        if len(s) == 1:
            vec.append((i,j,list(s)[0]))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
hh = []
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    hh.append(h)

Hmax = float("inf")
allZero = True
for i in range(0,101):
    for j in range(0,101):
        s = set()
        for k in range(N):
            key = abs(X[k] - i) + abs(Y[k] - j) + hh[k]
            if hh[k] == 0:
                # H <= abs(X[k]-i) + abs(Y[k]-j)であることがわかる
                if abs(X[k]-i) + abs(Y[k]-j) <= Hmax:
                    Hmax = abs(X[k]-i) + abs(Y[k]-j)
                    Hmaxx = i
                    Hmaxy = j
            else:
                allZero = False
                s.add(key)
        if len(s) == 1:
            H = key
            Cx = i
            Cy = j

if allZero:
    print(Hmaxx, Hmaxy, Hmax)
else:
    print(Cx, Cy, H)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

x_, y_, h = sorted(dots, key=lambda x: x[2], reverse=True)[1]

for cx in range(101):
    for cy in range(101):
        H = h+abs(x_ - cx) + abs(y_ - cy)

        ans = []
        for x, y, h in dots:
            if max(H - abs(x-cx)-abs(y-cy), 0) == h:
                ans.append((cx, cy, H))

        if len(ans) == n:
            print(*ans[0])
            exit()