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())
coord = []

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

coord.sort()

flag = False

for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True

        if coord[0][0] == 0:
            H = abs(coord[0][1] - cx) + abs(coord[0][2] - cy)

            for i in range(1, n):
                H = min(H, abs(coord[i][1] - cx) + abs(coord[i][2] - cy))

            print(cx, cy, H)
            exit(0)

        else:
            H = coord[0][0] + abs(coord[0][1] - cx) + abs(coord[0][2] - cy)

            for i in range(1, n):
                if H != coord[i][0] + abs(coord[i][1] - cx) + abs(coord[i][2] - cy):
                    flag = False
                    break

            if flag is True:
                print(cx, cy, H)
                exit(0)

print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
xx = [0] * n
yy = [0] * n
hh = [0] * n
for i in range(n):
    x, y, h = map(int, input().split())
    xx[i], yy[i], hh[i] = x, y, h
    if h > 0:
        x0, y0, h0 = x, y, h
print([x0, y0, h0])

for cx in range(101):
    for cy in range(101):
        f = True
        h = h0 + abs(x0 - cx) + abs(y0 - cy)
        for i in range(n):
            if hh[i] != max(h - abs(xx[i] - cx) - abs(yy[i] - cy), 0):
                f = False
                break
        if f:
            print("{} {} {}".format(cx, cy, h))
            exit(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
xx = [0] * n
yy = [0] * n
hh = [0] * n
for i in range(n):
    x, y, h = map(int, input().split())
    xx[i], yy[i], hh[i] = x, y, h
    if h > 0:
        x0, y0, h0 = x, y, h

for cx in range(101):
    for cy in range(101):
        f = True
        h = h0 + abs(x0 - cx) + abs(y0 - cy)
        for i in range(1, n):
            if hh[i] != max(h - abs(xx[i] - cx) - abs(yy[i] - cy), 0):
                f = False
                break
        if f:
            print("{} {} {}".format(cx, cy, h))
            exit(0)

Submission status: Wrong Answer

Solution code:
points=[]
n=int(input())
for _ in range(n):
    data=list(map(int,input().split()))
    points.append(data)
for i in range(101):
    for j in range(101):
        temp=-1
        check=True
        for point in points:
            x,y,h=point
            if temp==-1:
                temp=abs(x-i)+abs(y-j)+h
            if temp!=abs(x-i)+abs(y-j)+h:
                check=False
                break
        if check:
            print(i,j,temp)
            exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
xx = [0] * n
yy = [0] * n
hh = [0] * n
for i in range(n):
    x, y, h = map(int, input().split())
    xx[i] = x
    yy[i] = y
    hh[i] = h

for cx in range(101):
    for cy in range(101):
        f = True
        h = hh[0] + abs(xx[0] - cx) + abs(yy[0] - cy)
        for i in range(1, n):
            if hh[i] != max(h - abs(xx[i] - cx) - abs(yy[i] - cy), 0):
                f = False
                break
        if f:
            print("{} {} {}".format(cx, cy, h))
            exit(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  if X[i][2] > 0:
    x, y, h = X[i][0], X[i][1], X[i][2]
    break
for i in range(0, 101):
  for j in range(0, 101):
    H = h + abs(x-i) + abs(y-j)
    a = 0
    for k in range(N):
      if X[k][2] == H - abs(X[k][0]-i) - abs(X[k][1]-j):
        continue
      else:
        a = 1
        break
    if a == 0:
      print(i, j, H, sep=' ')
      break
  else:
    continue
  break

Submission status: Wrong Answer

Solution code:
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  if X[i][2] > 0:
    x, y, h = X[i][0], X[i][1], X[i][2]
    break
for i in range(0, 101):
  for j in range(0, 101):
    H = h + abs(x-i) + abs(y-j)
    a = 0
    for k in range(N):
      if X[k][2] == H - abs(X[k][0]-i) - abs(X[k][1]-j):
        continue
      else:
        a = 1
        break
    if a == 0:
      print(i, j, H, sep=' ')
      break

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,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
#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
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
X = [];Y = [];H = []
for i in range(n):
    x,y,h = readInts()
    X.append(x)
    Y.append(y)
    H.append(h)
    if h > 0:
        si = i
resx=-1;resy=-1;resh=-1;
for cx in range(101):
    for cy in range(101):
        judge = True
        h = H[si] + abs(X[si] - cx) + abs(Y[si] - cy)
        for i in range(n):
            if H[i] == 0:
                if h != abs(X[i] - cx) + abs(Y[i] - cy):
                    judge ^=True
                    break
            else:
                if h - H[i] != abs(X[i]-cx) + abs(Y[i]-cy):
                    judge ^= True
                    break
        if judge:
            resx =cx;resy=cy;resh=h;
print(resx,resy,resh)

Submission status: Wrong Answer

Solution code:
import sys
MOD = 10**9 + 7
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    p = [list(map(int,input().split())) for _ in range(n)]
    for x in range(0,101):
        for y in range(0,101):
            h = p[0][2] + abs(x-p[0][0])+abs(y-p[0][1])
            flag = 1
            for (a,b,c) in p:
                if c != max(0,h-abs(x-a)-abs(y-b)):
                    flag = 0
                    break
            if flag == 1:
                print(x,y,h)
                exit(0)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
MOD = 10**9 + 7
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    p = [list(map(int,input().split())) for _ in range(n)]
    for x in range(0,101):
        for y in range(0,101):
            h = p[0][2] + abs(x-p[0][0])+abs(y-p[0][1])
            flag = 1
            for (a,b,c) in p:
                if abs(x-a)+abs(y-b) != max(0,h-c):
                    flag = 0
                    break
            if flag == 1:
                print(x,y,h)
                exit(0)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

XYH.sort()


for i in range(101):
    for j in range(101):
        H = -1
        flag = True
        for k in range(n):
            h, x, y = XYH[k]
            if H == -1:
                H = abs(x-i)+abs(y-j)+h
            else:
                if max(H-abs(x-i)-abs(y-j), 0) != h:
                    flag = False
        if flag:
            print(i, j, H)
            exit()

Submission status: Wrong Answer

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

for cx in range(101):
    for cy in range(101):
        wa_flag = False
        for i in range(n):
            x1, y1, h1 = l[i]
            for j in range(i+1, n):
                x2, y2, h2 = l[j]
                if h1 > 0 and h2 > 0:
                    if (abs(x2 - cx) + abs(y2 - cy)) - (abs(x1 - cx) + abs(y1 - cy)) != h1 - h2:
                        wa_flag = True
                        break
            if wa_flag:
                break

        if not wa_flag:
            for i in range(n):
                x, y, h = l[i]
                if h > 0:
                    res_h = abs(x - cx) + abs(y - cy) + h
                    break
            for i in range(n):
                x, y, h = l[i]
                if h == 0:
                    if res_h - abs(x - cx) - abs(y - cy) > 0:
                        wa_flag = True
                        break
        
        if not wa_flag:
            res_x, res_y = cx, cy

print(res_x, res_y, res_h)

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    x = [0 for _ in range(n)]
    y = [0 for _ in range(n)]
    h = [0 for _ in range(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 = h[0] + abs(x[0] - cx) + abs(y[0] - cy)
            if all(h[i] == max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) for i in range(n)):
                print(cx, cy, H)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    x = [0 for _ in range(n)]
    y = [0 for _ in range(n)]
    h = [0 for _ in range(n)]
    for i in range(n):
        x[i], y[i], h[i] = map(int, input().split())

    for cx in range(0, 101):
        for cy in range(0, 101):
            H = h[0] + abs(x[0] - cx) + abs(y[0] - cy)
            if all(H == h[i] + abs(x[i] - cx) + abs(y[i] - cy) for i in range(n)):
                print(cx, cy, H)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    XYH = [list(map(int, input().split())) for _ in range(n)]

    for Cx in range(100 + 1):
        for Cy in range(100 + 1):
            tmp = set()
            for x, y, h in XYH:
                if h == 0:
                    continue
                H = h + abs(x - Cx) + abs(y - Cy)
                tmp.add(H)
            if len(tmp) == 1:
                print(Cx, Cy, *list(tmp))
                exit()


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product

N = int(input())

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

points = np.array(points)

for cx, cy in product(range(0, 101), repeat=2):
    ch = np.abs(points[:, 0] - cx) + np.abs(points[:, 1] - cy) + points[:, 2]
    if np.all(ch == ch[0]):
        print(cx, cy, ch[0])
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product

N = int(input())

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

points = np.array(points)

for cx, cy in product(range(0, 101), repeat=2):
    ch = np.abs(points[:, 0] - cx) + np.abs(points[:, 1] - cy) + points[:, 2]
    if np.all(ch == ch[0]):
        print(cx, cy, ch[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product

N = int(input())

x_values = set()
y_values = set()
h_values = set()
points = []
for _ in range(N):
    x, y, h = map(int, input().split(' '))
    points.append((x, y, h))

points = np.array(points[:10])

for cx, cy in product(range(0, 101), repeat=2):
    ch = np.abs(points[:, 0] - cx) + np.abs(points[:, 1] - cy) + points[:, 2]
    if np.all(ch == ch[0]):
        print(cx, cy, ch[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product

N = int(input())

x_values = set()
y_values = set()
h_values = set()
points = []
for _ in range(N):
    x, y, h = map(int, input().split(' '))
    if x not in x_values or y not in y_values or h not in h_values:
        x_values.add(x)
        y_values.add(y)
        h_values.add(h)
        points.append((x, y, h))
    if len(x_values) >= 2 and len(y_values) >= 2 and len(h_values) >= 2 and len(points) >= 4:
        break

points = np.array(points)

for cx, cy in product(range(0, 101), repeat=2):
    ch = np.abs(points[:, 0] - cx) + np.abs(points[:, 1] - cy) + points[:, 2]
    if np.all(ch == ch[0]):
        print(cx, cy, ch[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product

N = int(input())

x_values = set()
y_values = set()
h_values = set()
points = []
for _ in range(N):
    x, y, h = map(int, input().split(' '))
    if x not in x_values or y not in y_values or h not in h_values:
        x_values.add(x)
        y_values.add(y)
        h_values.add(h)
        points.append((x, y, h))
    if len(x_values) >= 2 and len(y_values) >= 2 and len(h_values) >= 2:
        break

points = np.array(points)

for cx, cy in product(range(0, 101), repeat=2):
    ch = np.abs(points[:, 0] - cx) + np.abs(points[:, 1] - cy) + points[:, 2]
    if np.all(ch == ch[0]):
        print(cx, cy, ch[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product

N = int(input())
points = np.array([list(map(int, input().split(' '))) for _ in range(N)])
points = points[:4]

for cx, cy in product(range(0, 101), repeat=2):
    ch = np.abs(points[:, 0] - cx) + np.abs(points[:, 1] - cy) + points[:, 2]
    if np.all(ch == ch[0]):
        print(cx, cy, ch[0])
        break

Submission status: Wrong Answer

Solution code:
N, *_XYH = map(int, open(0).read().split())
XYH = list(zip(*[iter(_XYH)]*3))

C = [(x, y) for x in range(101) for y in range(101)]

for c in C:
    for i, xyh in enumerate(XYH):
        if i==0:
            H = xyh[2] + abs(xyh[0] - c[0]) + abs(xyh[1] - c[1])
        elif max(H - abs(xyh[0] - c[0]) - abs(xyh[1] - c[1]), 0) == xyh[2]:
            is_ans = True
        else:
            is_ans = False
            break
        
    if is_ans:
        break
print(*c, H)

Submission status: Wrong Answer

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

ans = []
for i in range(101):
  for j in range(101):
    h.sort(key=lambda x: -x[2])
    hmax = h[0][2] + abs(i-h[0][0]) + abs(j-h[0][1])
    for k in range(1,n):
      if h[k][2] + abs(i-h[k][0]) + abs(j-h[k][1]) != hmax:
        break
    else:
      ans = [i,j,hmax]
    
    if(len(ans)):
      break
  if(len(ans)):
    break

ans = map(str,ans)
print(' '.join(ans))

Submission status: Wrong Answer

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

ans = []
for i in range(101):
  for j in range(101):

    hmax = h[0][2] + abs(i-h[0][0]) + abs(j-h[0][1])
    for k in range(1,n):
      if h[k][2] + abs(i-h[k][0]) + abs(j-h[k][1]) != hmax:
        break
    else:
      ans = [i,j,hmax]
    
    if(len(ans)):
      break
  if(len(ans)):
    break

ans = map(str,ans)
print(' '.join(ans))

Submission status: Wrong Answer

Solution code:
# 参考:https://atcoder.jp/contests/abc112/submissions/14491766
import sys
input = lambda: sys.stdin.readline().rstrip()

l = []
for _ in range(int(input())):
    t = list(map(int,input().split()))
    l.append(t)
    if t[2]: 
        x,y,h = t[0], t[1], t[2]

print(l)
for X in range(101):
    for Y in range(101):
        H = h + abs(x - X) + abs(y - Y)
        if all(h==max(H - abs(x-X) - abs(y-Y), 0) for x,y,h in l): print(X, Y, H)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X, Y, H = [], [], []
    for _ in range(N):
        x, y, h = LI()
        X.append(x)
        Y.append(y)
        H.append(h)
    def f(x, Cx, y, Cy, h):
        return h + abs(x - Cx) + abs(y - Cy)

    for cx in range(101):
        for cy in range(101):
            zeros = 0
            H_set = set()
            zero_h = []
            for x, y, h in zip(X, Y, H):
                if h == 0:
                    zeros += 1
                    cur_h = f(x, cx, y, cy, h)
                    zero_h.append(cur_h)
                    continue
                cur_h = f(x, cx, y, cy, h)
                H_set.add(cur_h)
            if len(H_set) > 1:
                continue
            if len(H_set) == 1:
                print(cx, cy, cur_h)
                return
            if zeros == N:
                H = min(zero_h)
                if H < 1:
                    continue
                print(cx, cy, H)
                return

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X, Y, H = [], [], []
    for _ in range(N):
        x, y, h = LI()
        X.append(x)
        Y.append(y)
        H.append(h)
    def f(x, Cx, y, Cy, h):
        return h + abs(x - Cx) + abs(y - Cy)

    for cx in range(101):
        for cy in range(101):
            zeros = 0
            H_set = set()
            for x, y, h in zip(X, Y, H):
                if h == 0:
                    zeros += 1
                    continue
                cur_h = f(x, cx, y, cy, h)
                H_set.add(cur_h)
            if len(H_set) > 1:
                continue
            if len(H_set) == 1:
                print(cx, cy, cur_h)
                return
            if zeros == N:
                H = f(x, cx, y, cy, 0)
                print(cx, cy, H)
                return

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X, Y, H = [], [], []
    for _ in range(N):
        x, y, h = LI()
        X.append(x)
        Y.append(y)
        H.append(h)
    def f(x, Cx, y, Cy, h):
        return h + abs(x - Cx) + abs(y - Cy)

    def ok(cur_h, cx, cy, X, Y, H):
        for x, y, _ in zip(X, Y, H):
            if cur_h - abs(cx - x) - abs(cy - y) > 0:
                return False
        return True

    for cx in range(101):
        for cy in range(101):
            H_set = set()
            zero_x, zero_y, zero_h = [], [], []
            for x, y, h in zip(X, Y, H):
                cur_h = f(x, cx, y, cy, h)
                if h == 0:
                    continue
                H_set.add(cur_h)

            # if len(H_set) > 1:
            #     continue

            if len(H_set) == 1:
                print(cx, cy, cur_h)
                return

#             else:
#                 continue
#             h_arr = []
#             for x, y, h in zip(zero_x, zero_y, zero_h):
#                 h_arr.append(f(x, cx, y, cy, 0))
#             c = min(h_arr)
#             if c < 1:
#                 continue
#             print(cx, cy, c)

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X, Y, H = [], [], []
    for _ in range(N):
        x, y, h = LI()
        X.append(x)
        Y.append(y)
        H.append(h)
    def f(x, Cx, y, Cy, h):
        return h + abs(x - Cx) + abs(y - Cy)

    def ok(cur_h, cx, cy, X, Y, H):
        for x, y, _ in zip(X, Y, H):
            if cur_h - abs(cx - x) - abs(cy - y) > 0:
                return False
        return True

    for cx in range(101):
        for cy in range(101):
            H_set = set()
            zero_x, zero_y, zero_h = [], [], []
            for x, y, h in zip(X, Y, H):
                cur_h = f(x, cx, y, cy, h)
                if h == 0:
                    continue
                H_set.add(cur_h)

            if len(H_set) > 1:
                continue

            if len(H_set) == 1:
                print(cx, cy, cur_h)
                return

#             else:
#                 continue
#             h_arr = []
#             for x, y, h in zip(zero_x, zero_y, zero_h):
#                 h_arr.append(f(x, cx, y, cy, 0))
#             c = min(h_arr)
#             if c < 1:
#                 continue
#             print(cx, cy, c)

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X, Y, H = [], [], []
    for _ in range(N):
        x, y, h = LI()
        X.append(x)
        Y.append(y)
        H.append(h)
    def f(x, Cx, y, Cy, h):
        return h + abs(x - Cx) + abs(y - Cy)

    def ok(cur_h, cx, cy, X, Y, H):
        for x, y, _ in zip(X, Y, H):
            if cur_h - abs(cx - x) - abs(cy - y) > 0:
                return False
        return True

    for cx in range(101):
        for cy in range(101):
            H_set = set()
            zero_x, zero_y, zero_h = [], [], []
            for x, y, h in zip(X, Y, H):
                cur_h = f(x, cx, y, cy, h)
                if h == 0:
                    zero_x.append(x)
                    zero_y.append(y)
                    zero_h.append(h)
                else:
                    H_set.add(cur_h)

            if len(H_set) > 1:
                continue

            if len(H_set) == 1:
                print(cx, cy, cur_h)
                return

#             else:
#                 continue
#             h_arr = []
#             for x, y, h in zip(zero_x, zero_y, zero_h):
#                 h_arr.append(f(x, cx, y, cy, 0))
#             c = min(h_arr)
#             if c < 1:
#                 continue
#             print(cx, cy, c)

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X, Y, H = [], [], []
    for _ in range(N):
        x, y, h = LI()
        X.append(x)
        Y.append(y)
        H.append(h)
    def f(x, Cx, y, Cy, h):
        return h + abs(x - Cx) + abs(y - Cy)

    def ok(cur_h, cx, cy, X, Y, H):
        for x, y, _ in zip(X, Y, H):
            if cur_h - abs(cx - x) - abs(cy - y) > 0:
                return False
        return True

    for cx in range(101):
        for cy in range(101):
            zeros = 0
            H_set = set()
            zero_x, zero_y, zero_h = [], [], []
            for x, y, h in zip(X, Y, H):
                cur_h = f(x, cx, y, cy, h)
                if h == 0:
                    zero_x.append(x)
                    zero_y.append(y)
                    zero_h.append(h)
                else:
                    H_set.add(cur_h)

            if len(H_set) > 1:
                continue

            if len(H_set) == 1:
                # if not ok(cur_h, cx, cy, zero_x, zero_y, zero_h):
                #     continue
                print(cx, cy, cur_h)
                return

            else:
                continue
            h_arr = []
            for x, y, h in zip(zero_x, zero_y, zero_h):
                h_arr.append(f(x, cx, y, cy, 0))
            c = min(h_arr)
            if c < 1:
                continue
            print(cx, cy, c)

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X, Y, H = [], [], []
    for _ in range(N):
        x, y, h = LI()
        X.append(x)
        Y.append(y)
        H.append(h)
    def f(x, Cx, y, Cy, h):
        return h + abs(x - Cx) + abs(y - Cy)

    def ok(cur_h, cx, cy, X, Y, H):
        for x, y, _ in zip(X, Y, H):
            if cur_h - abs(cx - x) - abs(cy - y) > 0:
                return False
        return True

    for cx in range(101):
        for cy in range(101):
            zeros = 0
            H_set = set()
            zero_x, zero_y, zero_h = [], [], []
            for x, y, h in zip(X, Y, H):
                cur_h = f(x, cx, y, cy, h)
                if h == 0:
                    zero_x.append(x)
                    zero_y.append(y)
                    zero_h.append(h)
                else:
                    H_set.add(cur_h)

            if len(H_set) > 1:
                continue

            if len(H_set) == 1:
                if not ok(cur_h, cx, cy, zero_x, zero_y, zero_h):
                    continue
                print(cx, cy, cur_h)
                return

            else:
                continue
            h_arr = []
            for x, y, h in zip(zero_x, zero_y, zero_h):
                h_arr.append(f(x, cx, y, cy, 0))
            c = min(h_arr)
            if c < 1:
                continue
            print(cx, cy, c)

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X, Y, H = [], [], []
    for _ in range(N):
        x, y, h = LI()
        X.append(x)
        Y.append(y)
        H.append(h)
    def f(x, Cx, y, Cy, h):
        return h + abs(x - Cx) + abs(y - Cy)

    def ok(cur_h, cx, cy, X, Y, H):
        for x, y, _ in zip(X, Y, H):
            if cur_h - abs(cx - x) - abs(cy - y) > 0:
                return False
        return True

    for cx in range(101):
        for cy in range(101):
            zeros = 0
            H_set = set()
            zero_x, zero_y, zero_h = [], [], []
            for x, y, h in zip(X, Y, H):
                cur_h = f(x, cx, y, cy, h)
                if h == 0:
                    zero_x.append(x)
                    zero_y.append(y)
                    zero_h.append(h)
                else:
                    H_set.add(cur_h)

            if len(H_set) > 1:
                continue

            if len(H_set) == 1:
                # if not ok(cur_h, cx, cy, zero_x, zero_y, zero_h):
                #     continue
                print(cx, cy, cur_h)
                return

            h_arr = []
            for x, y, h in zip(zero_x, zero_y, zero_h):
                h_arr.append(f(x, cx, y, cy, 0))
            c = min(h_arr)
            if c < 1:
                continue
            print(cx, cy, c)

main()