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:
import sys

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

for cx in range(0, 100+1):
    for cy in range(0, 100+1):
        Hs = set()
        for i in range(N):
            if hs[i] != 0:
                calcH = abs(xs[i]-cx) + abs(ys[i]-cy) + hs[i]
                Hs.add(calcH)
        if len(Hs) == 1:
            # 検証
            H = Hs.pop()
            if 0 <= H <= 10 ** 9:
                for i in range(N):
                    x, y, h = xs[i], ys[i], hs[i]
                    height = max(H - abs(x-cx) - abs(y-cy), 0)
                    if height != h:
                        break
                else:
                    print(cx, cy, H)
                    sys.exit(0)

Submission status: Wrong Answer

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

for cx in range(0, 100+1):
    for cy in range(0, 100+1):
        Hs = set()
        flag = True
        for i in range(N):
            calcH = abs(xs[i]-cx) + abs(ys[i]-cy) + hs[i]
            if hs[i] != 0 and calcH < 0:
                # 不正なデータ(hiが0ではないと言っているのに地面判定
                # この(cx,cy)はあり得ない
                flag = False
                break
            Hs.add(calcH)
        if flag and len(Hs) == 1:
            print(cx, cy, Hs.pop())

Submission status: Wrong Answer

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

for cx in range(0, 100+1):
    for cy in range(0, 100+1):
        Hs = set()
        for i in range(N):
            calcH = abs(xs[i]-cx) + abs(ys[i]-cy) + hs[i]
            if calcH < 0:
                continue
            Hs.add(calcH)
        if len(Hs) == 1:
            print(cx, cy, Hs.pop())

Submission status: Wrong Answer

Solution code:
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)
field=[[-1 for i in range(101)] for i in range(101)]
for i in range(N):
  for j in range(101):
    for k in range(101):
      if(h[i]!=0):
        if(field[j][k]==-1):
          field[j][k]=h[i]+abs(j-x[i])+abs(k-y[i])
        elif(field[j][k]!=h[i]+abs(j-x[i])+abs(k-y[i])):
          field[j][k]=-2
cx=0
cy=0
H=0
for i in range(101):
  for j in range(101):
    if(field[i][j]>=0):
      cx=i
      cy=j
      H=field[i][j]
print(cx,cy,H)

Submission status: Wrong Answer

Solution code:
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)
field=[[-1 for i in range(101)] for i in range(101)]
for i in range(N):
  for j in range(101):
    for k in range(101):
      if(field[j][k]==-1):
        field[j][k]=h[i]+abs(j-x[i])+abs(k-y[i])
      elif(field[j][k]!=h[i]+abs(j-x[i])+abs(k-y[i])):
        field[j][k]=-2
cx=0
cy=0
H=0
for i in range(101):
  for j in range(101):
    if(field[i][j]>=0):
      cx=i
      cy=j
      H=field[i][j]
print(cx,cy,H)

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
xyh = LI(n)

xyh = mysort(xyh,2,True)
pprint(xyh)

for i in range(101):
    for j in range(101):
        flag = True
        for k in range(n):
            x = xyh[k][0]
            y = xyh[k][1]
            h = xyh[k][2]
            if k==0: 
                H = h + abs(x-i) + abs(y-j)
            elif k==(n-1):
                l = max( H - abs(x-i) - abs(y-j), 0 )
                if l==h:
                    ans = [i,j,H]
                else:
                    flag = False
            else:
                l = max( H - abs(x-i) - abs(y-j), 0 )
                if l==h:
                    pass
                else:
                    flag = False
        if flag:
            myoutput(ans,True)
            exit()
        else:
            continue
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):
        needH=-1
        for i in range(n):
            if xyh[i][0]>0:
                tmp=xyh[i][0]+abs(cx-xyh[i][1])+abs(cy-xyh[i][2])
                if needH==-1:
                    needH=tmp
                else:
                    if needH !=tmp:
                        needH=-2
                        break
        if needH==-2:
            continue
        for i in range(n):
            if xyh[i][0]==0:
                dist=abs(cx-xyh[i][1])+abs(cy-xyh[i][2])
                if needH>dist:
                    needH=-2
                    break
        if needH==-2:
            continue
        else:
            print(cx,cy,needH)
            exit(0)

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):
        i=0
        while True:
            hb=xyh[i][2]+abs(cx-xyh[i][0])+abs(cy-xyh[i][1])
            ha=xyh[i+1][2]+abs(cx-xyh[i+1][0])+abs(cy-xyh[i+1][1])

            if ha==hb and ha>=1:
                for fm in xyh:
                    if fm[2]==max(ha-abs(cx-fm[0])-abs(cy-fm[1]),0):
                        i+=1
                        if i==n-1:
                            print(cx,cy,xyh[i][2]+abs(cx-xyh[i][0])+abs(cy-xyh[i][1]))
                            exit(0)
                    else:
                        break
                else:
                    continue
                break
            else:
                break

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):
        i=0
        while True:
            hb=xyh[i][2]+abs(cx-xyh[i][0])+abs(cy-xyh[i][1])
            ha=xyh[i+1][2]+abs(cx-xyh[i+1][0])+abs(cy-xyh[i+1][1])

            if ha==hb and ha>=1:
                for fm in xyh:
                    if fm[2]==max(ha-abs(cx-fm[0])-abs(cy-fm[1]),0):
                        i+=1
                        if i==n-1:
                            print(cx,cy,xyh[i][2]+abs(cx-xyh[i][0])+abs(cy-xyh[i][1]))
                            exit(0)
                    else:
                        break
            else:
                break

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):
        i=0
        while True:
            if xyh[i][2]+abs(cx-xyh[i][0])+abs(cy-xyh[i][1])==xyh[i+1][2]+abs(cx-xyh[i+1][0])+abs(cy-xyh[i+1][1]):
                if xyh[i][2]+abs(cx-xyh[i][0])+abs(cy-xyh[i][1])>=1:
                    i+=1
                    if i==n-1:
                        print(cx,cy,xyh[i][2]+abs(cx-xyh[i][0])+abs(cy-xyh[i][1]))
                        exit(0)
            else:
                break

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):
        i=0
        while True:
            if xyh[i][2]+abs(cx-xyh[i][0])+abs(cy-xyh[i][1])==xyh[i+1][2]+abs(cx-xyh[i+1][0])+abs(cy-xyh[i+1][1]):
                i+=1
                if i==n-1:
                    print(cx,cy,xyh[i][2]+abs(cx-xyh[i][0])+abs(cy-xyh[i][1]))
                    exit(0)
            else:
                break

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x:x[2],reverse=True)
sx,sy,sh=l[0]
for xx in range(0,101):
  for yy in range(0,101):
    hh=sh+abs(sx-xx)+abs(sy-yy)
    for ll in l[1:]:
      if ll[2]!=hh-abs(ll[0]-xx)-abs(ll[1]-yy):
        break
    else:
      print(xx,yy,hh)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x:x[2],reverse=True)
sx,sy,sh=l[0]
for xx in range(0,101):
  for yy in range(0,101):
    hh=sh+abs(sx-xx)+abs(sy-yy)
    for ll in l[1:]:
      if ll[2]!=hh-abs(sx-xx)-abs(sy-yy):
        break
    else:
      print(xx,yy,hh)

Submission status: Wrong Answer

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

for cy in range(101):
    for cx in range(101):
        x, y, h = [p for p in P if 0 < p[2]][0]
        H = h + abs(x - cx) + abs(y - cy)

        if all(h == H - abs(x - cx) - abs(y - cy) for x, y, h in P):
            print(cx, cy, H)
            break
    else:
        continue
    break

Submission status: Wrong Answer

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

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

        if all(h == H - abs(x - cx) - abs(y - cy) for x, y, h in P):
            print(cx, cy, H)
            break
    else:
        continue
    break

Submission status: Wrong Answer

Solution code:
n = int(input())

x = []
y = []
h = []
for i in range(n):
    a = list(map(int, input().split(' ')))
    x.append(a[0])
    y.append(a[1])
    h.append(a[2])

for cx in range(101):
    for cy in range(101):
        ok = True
        now = -1
        lower = 0
        for i in range(n):
            if h[i] == 0:
                # H >= abs(cx - x[i]) + abs(cy - y[i])
                lower = abs(cx - x[i]) + abs(cy - y[i])
                continue

            H = abs(cx - x[i]) + abs(cy - y[i]) + h[i]
            if now == -1:
                now = H
            else:
                if now != H:
                    ok = False
                    break
        if ok and now >= lower:
            print(cx, cy, now)

Submission status: Wrong Answer

Solution code:
n = int(input())

x = []
y = []
h = []
for i in range(n):
    a = list(map(int, input().split(' ')))
    x.append(a[0])
    y.append(a[1])
    h.append(a[2])

for cx in range(101):
    for cy in range(101):
        ok = True
        now = -1
        lower = 0
        for i in range(n):
            if h[i] == 0:
                # H >= abs(cx - x[i]) + abs(cy - y[i])
                lower = abs(cx - x[i]) + abs(cy - y[i])

            H = abs(cx - x[i]) + abs(cy - y[i]) + h[i]
            if now == -1:
                now = H
            else:
                if now != H:
                    ok = False
                    break
        if ok and now >= lower:
            print(cx, cy, now)

Submission status: Wrong Answer

Solution code:
n = int(input())

x = []
y = []
h = []
for i in range(n):
    a = list(map(int, input().split(' ')))
    x.append(a[0])
    y.append(a[1])
    h.append(a[2])

for cx in range(101):
    for cy in range(101):
        ok = True
        now = -1
        lower = 1
        for i in range(n):
            if h[i] == 0:
                # H >= abs(cx - x[i]) + abs(cy - y[i])
                lower = abs(cx - x[i]) + abs(cy - y[i])

            H = abs(cx - x[i]) + abs(cy - y[i]) + h[i]
            if now == -1:
                now = H
            else:
                if now != H:
                    ok = False
                    break
        if ok and now >= lower:
            print(cx, cy, now)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
xyh = []
for _ in range(n):
    xyh.append(list(map(int, input().split())))
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = None
        maxh = 10**10
        for x, y, h in xyh:
            if h == 0:
                maxh = min(maxh, abs(x - cx) + abs(y - cy))
            else:
                if H is None:
                    H = h + abs(x - cx) + abs(y - cy)
                    if H > maxh:
                        flag = 0
                        break
                else:
                    if H != h + abs(x - cx) + abs(y - cy):
                        flag = 0
                        break
        if flag and H >= maxh:
            print(cx, cy, H)
            sys.exit()

Submission status: Wrong Answer

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
x = [];y=[];h=[]
sh = -1
for i in range(n):
    xa,ya,ha = readInts()
    x.append(xa);y.append(ya);h.append(ha);
    if ha > 0:
        sh = i
# CxとCyを特定しておく すべてにおいて合致するかを考える
resx = -1;resy =-1;resh=-1;
for Cx in range(101):
    for Cy in range(101):
        ok = True
        H = h[sh] + abs(x[sh] - Cx) + abs(y[sh] - Cy)
        # 全操作して合致するようにする
        for i in range(n):
            if h[i] == 0:
                if H != abs(x[i] - Cx) + abs(y[i] - Cy):
                    ok = False
                    break
            else:
                if H != h[i] + abs(x[i] - Cx) + abs(y[i] - Cy):
                    ok = False
                    break
        if ok:
            resx = Cx;resy = Cy;resh = H;

print(resx,resy,resh)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
xyh = []
for _ in range(n):
    xyh.append(list(map(int, input().split())))
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = None
        maxh = 10**10
        for x, y, h in xyh:
            if h == 0:
                maxh = min(maxh, abs(x - cx) + abs(y - cy))
            else:
                if H is None:
                    H = h + abs(x - cx) + abs(y - cy)
                    if H > maxh:
                        flag = 0
                        break
                else:
                    if H != h + abs(x - cx) + abs(y - cy):
                        flag = 0
                        break
                    if H > maxh:
                        flag = 0
                        break
        if flag and H >= 1:
            print(cx, cy, H)
            sys.exit()
        if H is None and maxh >= 1 and maxh != 10**10:
            print(maxh)
            sys.exit()

Submission status: Wrong Answer

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

cands = []
for cx in range(101):
    for cy in range(101):
        ch = None
        for x,y,h in XYH:
            if h==0: continue
            d = abs(cx-x) + abs(cy-y)
            if ch is None:
                ch = h + d
                if ch > 10**9: break
            else:
                if h + d != ch:
                    break
        else:
            cands.append((cx,cy,ch))

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

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
xyh = []
for _ in range(n):
    xyh.append(list(map(int, input().split())))
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = None
        maxh = 10**10
        for x, y, h in xyh:
            if h == 0:
                maxh = min(maxh, abs(x - cx) + abs(y - cy))
            else:
                if H is None:
                    H = h + abs(x - cx) + abs(y - cy)
                    if H > maxh:
                        flag = 0
                        break
                else:
                    if H != h + abs(x - cx) + abs(y - cy):
                        flag = 0
                        break
                    if H > maxh:
                        flag = 0
                        break
        if flag and H >= 1:
            print(cx, cy, H)
            sys.exit()
        if H is None and maxh >= 1:
            print(maxh)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
xyh = []
for _ in range(n):
    xyh.append(list(map(int, input().split())))
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = None
        maxh = 10**10
        for x, y, h in xyh:
            if h == 0:
                maxh = min(maxh, abs(x - cx) + abs(y - cy))
            else:
                if H is None:
                    H = h + abs(x - cx) + abs(y - cy)
                    if H > maxh:
                        flag = 0
                        break
                else:
                    if H != h + abs(x - cx) + abs(y - cy):
                        flag = 0
                        break
                    if H > maxh:
                        flag = 0
                        break
        if flag and H >= 1:
            print(cx, cy, H)
            sys.exit()

Submission status: Wrong Answer

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

cands = []
for cx in range(101):
    for cy in range(101):
        ch = None
        for x,y,h in XYH:
            d = abs(cx-x) + abs(cy-y)
            if ch is None:
                if h==0: continue
                ch = h + d
                if ch > 10**9: break
            else:
                if h and h + d != ch:
                    break
        else:
            cands.append((cx,cy,ch))

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

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
xyh = []
for _ in range(n):
    xyh.append(list(map(int, input().split())))
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = None
        maxh = 10**10
        for x, y, h in xyh:
            if h == 0:
                maxh = min(maxh, abs(x - cx) + abs(y - cy))
            else:
                if H is None:
                    H = h + abs(x - cx) + abs(y - cy)
                    if H > maxh:
                        flag = 0
                        break
                else:
                    if H != h + abs(x - cx) + abs(y - cy):
                        flag = 0
                        break
                    if H > maxh:
                        flag = 0
                        break
        if flag:
            print(cx, cy, H)
            sys.exit()

Submission status: Wrong Answer

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

cands = []
for cx in range(101):
    for cy in range(101):
        ch = None
        for x,y,h in XYH:
            d = abs(cx-x) + abs(cy-y)
            if ch is None:
                if h==0: continue
                ch = h + d
                if ch > 10**9: break
            else:
                if h + d > ch:
                    break
        else:
            cands.append((cx,cy,ch))

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

Submission status: Wrong Answer

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

for h in range(P[0][2]+1,P[0][2]+201):
    for x in range(101):
        for y in range(101):
            f = 1
            for e in P:
                if e[2] != max(0,h-abs(e[0]-x)-abs(e[1]-y)):
                    f = 0
                    break
            if f == 1:
                print(x,y,h)
                exit(0)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
xyh = []
for _ in range(n):
    xyh.append(list(map(int, input().split())))
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = None
        maxh = 10**10
        for x, y, h in xyh:
            if h == 0:
                maxh = min(maxh, abs(x - cx) + abs(y - cy))
            else:
                if H is None:
                    H = h + abs(x - cx) + abs(y - cy)
                else:
                    if H != h + abs(x - cx) + abs(y - cy):
                        flag = 0
                        break
                    if H > maxh:
                        flag = 0
                        break
        if flag:
            print(cx, cy, H)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
xyh = []
for _ in range(n):
    xyh.append(list(map(int, input().split())))
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = None
        maxh = 10**10
        for x, y, h in xyh:
            if h == 0:
                maxh = min(maxh, abs(x - cx) + abs(y - cy))
            else:
                if H is None:
                    H = h + abs(x - cx) + abs(y - cy)
                else:
                    if H != h + abs(x - cx) + abs(y - cy):
                        flag = 0
                        break
        if flag:
            print(cx, cy, H)
            sys.exit()

Submission status: Wrong Answer

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

cands = []
for cx in range(101):
    for cy in range(101):
        ch = None
        for x,y,h in XYH:
            d = abs(cx-x) + abs(cy-y)
            if ch is None:
                ch = h + d
                if ch > 10**9: break
            else:
                if h + d > ch:
                    break
        else:
            cands.append((cx,cy,ch))

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

Submission status: Wrong Answer

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

for h in range(max(1,P[0][2]-100),P[0][2]+101):
    for x in range(101):
        for y in range(101):
            f = 1
            for e in P:
                if e[2] != max(0,h-abs(e[0]-x)-abs(e[1]-y)):
                    f = 0
                    break
            if f == 1:
                print(x,y,h)
                exit(0)

Submission status: Wrong Answer

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

for cx in range(101):
    for cy in range(101):
        h = -1
        for i in range(n):
            xi, yi, hi = lst[i]
            if hi == 0: continue
            if h == -1:
                h = hi + abs(xi-cx) + abs(yi-cy)
                continue
            if h != hi + abs(xi-cx) + abs(yi-cy):
                h = -1
                break
        if h != -1:
            print(cx, cy, h)
            exit()

Submission status: Wrong Answer

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

flag = 0
for Cx in range(101):
    for Cy in range(101):
        Hcands = []
        for i in range(N):
            X = XYH[i][0]
            Y = XYH[i][1]
            h = XYH[i][2]
            if h>=0:
                Hcand = abs(Cx-X)+abs(Cy-Y)+h
                Hcands.append(Hcand)
        if len(set(Hcands))==1 and Hcand>0:
            flag = 1
            print(Cx,Cy,Hcand)
            break
    if flag==1:
        break

Submission status: Wrong Answer

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

flag = 0
for Cx in range(101):
    for Cy in range(101):
        Hcands = []
        for i in range(N):
            X = XYH[i][0]
            Y = XYH[i][1]
            h = XYH[i][2]
            if h>0:
                Hcand = abs(Cx-X)+abs(Cy-Y)+h
                Hcands.append(Hcand)
        if len(set(Hcands))==1:
            flag = 1
            print(Cx,Cy,Hcand)
            break
    if flag==1:
        break

Submission status: Wrong Answer

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

for Cx in range(101):
    for Cy in range(101):
        flag = 0
        first = 1
        for i in range(N):
            X = XYH[i][0]
            Y = XYH[i][1]
            H = XYH[i][2]
            if H!=0:
                if first==1:
                    h1 = abs(X-Cx)+abs(Y-Cy)+H
                    first=0
                else:
                    if h1!=abs(X-Cx)+abs(Y-Cy)+H:
                        flag=1
        if flag==0:
            break
    if flag==0:
        break
print(Cx,Cy,h1)

Submission status: Wrong Answer

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

for Cx in range(101):
    for Cy in range(101):
        flag = 0
        first = 1
        for i in range(N):
            X = XYH[i][0]
            Y = XYH[i][1]
            H = XYH[i][2]
            if H!=0:
                if first==1:
                    h1 = abs(X-Cx)+abs(Y-Cy)+H
                    first=0
                else:
                    if h1!=abs(X-Cx)+abs(Y-Cy)+H:
                        flag=1
                        break
        if flag==0:
            break
    if flag==0:
        break
print(Cx,Cy,h1)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
xyh = [LIST() for _ in range(N)]

h_dict = defaultdict(int)
xyh.sort(key = lambda x:[x[0], x[1]])

for Cx in range(101):
	for Cy in range(101):
		H = 0
		H_max = INF
		for x, y, h in xyh:
			if h == 0:
				H_max = max(H_max, h + abs(x-Cx) + abs(y-Cy))
			else:
				if H == 0:
					H = h + abs(x-Cx) + abs(y-Cy)
				else:
					if H != h + abs(x-Cx) + abs(y-Cy):
						break

		else:
			if H <= H_max:
				print(Cx, Cy, H)
				break
	else:
		continue
	break