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())
xyh = [list(map(int,input().split())) for _ in range(n)]

for i in range(0,101):
    for j in range(0,101):
        hlist = []
        for k in range(n):
            hlist += [xyh[k][2] + abs(i-xyh[k][0]) + abs(j-xyh[k][1])]
        if len(set(hlist)) == 1:
            print(i,j,hlist[0])

Submission status: Wrong Answer

Solution code:
n,*xyh = map(int,open(0).read().split())
xyh = [(xyh[i*3],xyh[i*3+1],xyh[i*3+2]) for i in range(n)]
for i in range(101):
  for j in range(101):
    h = {abs(x-i)+abs(y-j)+h for x,y,h in xyh}
    if len(h) == 1:
      print(i,j,h.pop())
      exit()

Submission status: Wrong Answer

Solution code:
n,*xyh = map(int,open(0).read().split())
xyh = sorted([(xyh[i*3],xyh[i*3+1],xyh[i*3+2]) for i in range(n)],key=lambda x:x[2],reverse=True)
dx = xyh[0][0]
dy = xyh[0][1]
lx,ly,rx,ry = 0,0,100,100
for i,j,_ in xyh[1:]:
  if i > dx:
    rx = min(rx,i)
  elif i<dx:
    lx = max(lx,i)
  if j > dy:
    ry = min(ry,j)
  elif j<dy:
    ly = max(ly,j)
for i in range(lx,rx+1):
  for j in range(ly,ry+1):
    h = {abs(x-i)+abs(y-j)+h for x,y,h in xyh}
    if len(h) == 1:
      print(i,j,h.pop())
      exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
exprs = []

for _ in range(n):
    exprs.append([int(i) for i in input().split()])


for cx in range(0, 101):
    for cy in range(0, 101):
        for x0, y0, h0 in exprs:
            if h0 == 0:
                continue
            else:
                ch = h0 + abs(x0 - cx) + abs(y0 - cy)
                break

        for x, y, h in exprs[1:]:
            if h != max(ch - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            print(cx, cy, ch)
            quit()

Submission status: Wrong Answer

Solution code:
n = int(input())
exprs = []

for _ in range(n):
    exprs.append([int(i) for i in input().split()])


for cx in range(0, 101):
    for cy in range(0, 101):
        x0, y0, h0 = exprs[0]
        h_max = h0 + abs(x0 - cx) + abs(y0 - cy)
        for x, y, h in exprs:
            if h != max(h_max - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            print(cx, cy, h_max)
            quit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      if H ==0:
        tmp = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
        if tmp>0 and info[i][2] > 0:
          H = tmp
      else:
        h = max(H -  abs(info[i][0]-cx) - abs(info[i][1] -cy),0)
        if h != info[i][2]:
          break
    else:
      if H > 0:
        print(cx,cy,H)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      if H ==0:
        tmp = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
        if tmp > 0:
          H = tmp
      else:
        h = max(H -  abs(info[i][0]-cx) - abs(info[i][1] -cy),0)
        if h != info[i][2]:
          break
    else:
      if H > 0:
        print(cx,cy,H)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      if i==0:
        H = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
      else:
        h = max(H -  abs(info[i][0]-cx) - abs(info[i][1] -cy),0)
        if h != info[i][2]:
          break
    else:
      if H > 0:
        print(cx,cy,H)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      if i==0:
        H = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
      else:
        h = H -  abs(info[i][0]-cx) - abs(info[i][1] -cy)
        if h != info[i][2]:
          break
    else:
      if H > 0:
        print(cx,cy,H)
        sys.exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
exprs = []

for _ in range(n):
    exprs.append([int(i) for i in input().split()])

h = -1

for cx in range(0, 101):
    for cy in range(0, 101):
        _prev_h = None
        flag = True
        for x, y, h in exprs:
            if h == 0:
                continue
            h_max = h + abs(x - cx) + abs(y - cy)
            if not _prev_h:
                _prev_h = h_max
            else:
                if _prev_h == h_max:
                    continue
                else:
                    flag = False
                    break
        if flag:
            print(cx, cy, h_max)
            quit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      H_c = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
      if H == 0 and H_c >0 and info[i][2]>0:
        H = H_c
      elif H*H_c > 0 and H != H_c:
        break
    else:
      if H > 0:
        print(cx,cy,H)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      H_c = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
      if H == 0 and H_c >0 and info[i][2]>0:
        H = H_c
      elif H > 0 and H != H_c:
        break
    else:
      if H > 0:
        print(cx,cy,H)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      H_c = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
      if H == 0 and H_c >0 and info[i][2]>0:
        H = H_c
      elif H > 0 and H != H_c:
        break
    else:
      print(cx,cy,H)
      sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      H_c = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
      if H == 0 and H_c * info[i][2]>0:
        H = H_c
      elif H > 0 and H != H_c:
        break
    else:
      print(cx,cy,H)
      sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      H_c = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
      if H == 0 and H_c * info[0][2]>0:
        H = H_c
      elif H > 0 and H != H_c:
        break
    else:
      print(cx,cy,H)
      sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
info=[list(map(int,input().split())) for _ in range(n)]
for cx in range(0,101):
  for cy in range(0,101):
    H=0
    for i in range(n):
      H_c = info[i][2] + abs(info[i][0]-cx) + abs(info[i][1] -cy)
      if H == 0 and info[0][2]>0:
        H = H_c
      elif H > 0 and H != H_c:
        break
    else:
      print(cx,cy,H)
      sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def judge(id, sho, n):
    hito = [0]
    for i in range(n):
        if id % 2 == 1:
            hito.append(1)
        else:
            hito.append(0)
        id //= 2

    for i, h in enumerate(hito):
        if i == 0:
            continue
        if h == 1:
            for x, y in sho[i-1]:
                if hito[x] != y:
                    return -1

    return sum(hito)


def solve():
    n = getN()
    q = []
    for i in range(n):
        q.append(getList())

    for i in range(0, 101):
        for j in range(0, 101):
            ch = -1
            ok = True
            fzero = False
            for x, y, h in q:
                if h == 0:
                    continue
                ins = h + abs(x-i) + abs(y-j)
                if ch == -1:
                    ch = ins
                else:
                    if ch != ins:
                        ok = False
                        break
            if ok:
                print(i, j, ch)
                return



def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def judge(id, sho, n):
    hito = [0]
    for i in range(n):
        if id % 2 == 1:
            hito.append(1)
        else:
            hito.append(0)
        id //= 2

    for i, h in enumerate(hito):
        if i == 0:
            continue
        if h == 1:
            for x, y in sho[i-1]:
                if hito[x] != y:
                    return -1

    return sum(hito)


def solve():
    n = getN()
    q = []
    for i in range(n):
        q.append(getList())

    for i in range(0, 101):
        for j in range(0, 101):
            ch = -1
            ok = True
            fzero = False
            for x, y, h in q:
                ins = h + abs(x-i) + abs(y-j)
                if ch == -1:
                    ch = ins
                    if h == 0:
                        fzero = True
                else:
                    if ch != ins:
                        if fzero:
                            if h == 0:
                                if ins < ch:
                                    ch = ins
                            else:
                                if ins > ch:
                                    ok = False
                                    break
                                ch = ins
                            fzero = h == 0
                        elif h != 0:
                            ok = False
                            break
            if ok:
                print(i, j, ch)
                return



def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
xyh=[[] for i in range(n)]
for i in range(n):
    x,y,h=map(int,input().split())
    xyh[i].append(x)
    xyh[i].append(y)
    xyh[i].append(h)
for i in range(101):
    for j in range(101):
        f=0
        dis=[[i] for i in range(205)]
        for q in range(n):
            x=xyh[q][0]
            y=xyh[q][1]
            h=xyh[q][2]
            d=abs(x-i)+abs(y-j)
            
            if len(dis[d])==1 and h!=0:
                dis[d].append(h)
            elif len(dis[d])!=1 and dis[d][1]!=h:
                f=1
        
        dis=[dis[e] for e in range(205) if len(dis[e])!=1]
        m=len(dis)
        if m==1 and f==0:
            print(i,j,dis[0][0]+dis[0][1])
            sys.exit()
            
        else:
            if all(dis[e][0]+dis[e][1]==dis[e+1][0]+dis[e+1][1] for e in range(m-1)) and f==0:
                print(i,j,dis[0][0]+dis[0][1])
                sys.exit()
if all(xyz[i][2]==0 for i in range(n)):
    print(a)

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
xyh=[[] for i in range(n)]
for i in range(n):
    x,y,h=map(int,input().split())
    xyh[i].append(x)
    xyh[i].append(y)
    xyh[i].append(h)
for i in range(101):
    for j in range(101):
        f=0
        dis=[[i] for i in range(205)]
        for q in range(n):
            x=xyh[q][0]
            y=xyh[q][1]
            h=xyh[q][2]
            d=abs(x-i)+abs(y-j)
            
            if len(dis[d])==1 and h!=0:
                dis[d].append(h)
            elif len(dis[d])!=1 and dis[d][1]!=h:
                f=1
        
        dis=[dis[e] for e in range(205) if len(dis[e])!=1]
        m=len(dis)
        if m==1 and f==0:
            print(i,j,dis[0][0]+dis[0][1])
            sys.exit()
            
        else:
            if all(dis[e][0]+dis[e][1]==dis[e+1][0]+dis[e+1][1] for e in range(m-1)) and f==0:
                print(i,j,dis[0][0]+dis[0][1])
                sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
p=0
n=int(input())
xyh=[[] for i in range(n)]
for i in range(n):
    x,y,h=map(int,input().split())
    xyh[i].append(x)
    xyh[i].append(y)
    xyh[i].append(h)
for i in range(101):
    for j in range(101):
        f=0
        dis=[[i] for i in range(205)]
        for q in range(n):
            x=xyh[q][0]
            y=xyh[q][1]
            h=xyh[q][2]
            d=abs(x-i)+abs(y-j)
            if len(dis[d])==1:
                dis[d].append(h)
            elif dis[d][1]!=h:
                f=1
        
        dis=[dis[e] for e in range(205) if len(dis[e])!=1]
        m=len(dis)
        if m==1 and f==0:
            print(i,j,dis[0][0]+dis[0][1])
            p+=1
        else:
            if all(dis[e][0]+dis[e][1]==dis[e+1][0]+dis[e+1][1] for e in range(m-1)) and f==0:
                print(i,j,dis[0][0]+dis[0][1])
                p+=1
if p>=2:
    print(l)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
xyh=[[] for i in range(n)]
for i in range(n):
    x,y,h=map(int,input().split())
    xyh[i].append(x)
    xyh[i].append(y)
    xyh[i].append(h)
for i in range(101):
    for j in range(101):
        f=0
        dis=[[i] for i in range(205)]
        for q in range(n):
            x=xyh[q][0]
            y=xyh[q][1]
            h=xyh[q][2]
            d=abs(x-i)+abs(y-j)
            if len(dis[d])==1:
                dis[d].append(h)
            elif dis[d][1]!=h:
                f=1
        
        dis=[dis[i] for i in range(205) if len(dis[i])!=1]
        m=len(dis)
        if m==1 and f==0:
            print(i,j,dis[0][0]+dis[0][1])
        else:
            if all(dis[i][0]+dis[i][1]==dis[i+1][0]+dis[i+1][1] for i in range(m-1)) and f==0:
                print(i,j,dis[0][0]+dis[0][1])

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def judge(id, sho, n):
    hito = [0]
    for i in range(n):
        if id % 2 == 1:
            hito.append(1)
        else:
            hito.append(0)
        id //= 2

    for i, h in enumerate(hito):
        if i == 0:
            continue
        if h == 1:
            for x, y in sho[i-1]:
                if hito[x] != y:
                    return -1

    return sum(hito)


def solve():
    n = getN()
    q = []
    for i in range(n):
        q.append(getList())

    for i in range(0, 101):
        for j in range(0, 101):
            ch = -1
            ok = True
            fzero = False
            for x, y, h in q:
                ins = h + abs(x-i) + abs(y-j)
                if ch == -1:
                    ch = ins
                    if h == 0:
                        fzero = True
                else:
                    if ch != ins:
                        if fzero:
                            ch = ins
                            fzero = h == 0
                        elif h != 0:
                            ok = False
                            break
            if ok:
                print(i, j, ch)
                return



def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def judge(id, sho, n):
    hito = [0]
    for i in range(n):
        if id % 2 == 1:
            hito.append(1)
        else:
            hito.append(0)
        id //= 2

    for i, h in enumerate(hito):
        if i == 0:
            continue
        if h == 1:
            for x, y in sho[i-1]:
                if hito[x] != y:
                    return -1

    return sum(hito)


def solve():
    n = getN()
    q = []
    for i in range(n):
        q.append(getList())

    for i in range(0, 101):
        for j in range(0, 101):
            ch = -1
            ok = True
            for x, y, h in q:
                ins = h + abs(x-i) + abs(y-j)
                if ch == -1:
                    ch = ins
                else:
                    if ch != ins:
                        ok = False
                        break
            if ok:
                print(i, j, ch)
                return



def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

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

dp=[[-1 for i in range(101)] for j in range(101)]
for n in range(N):
    dp[xyh[n][0]][xyh[n][1]]=xyh[n][2]

def find_top(x,y,N,xyh):
    find=True
    prev=-1
    for n in range(N):
        if xyh[n][2]!=0:
            top=xyh[n][2]+abs(xyh[n][0]-x)+abs(xyh[n][1]-y)
            if prev==-1:
                prev=top
            else:
                if prev!=top:
                    find=False
                    break
    return find,top

fin=False
for x in range(101):
    if fin==True:
        break
    for y in range(101):
        find=find_top(x,y,N,xyh)[0]
        height=find_top(x,y,N,xyh)[1]
        if find and height>=1 and dp[x][y]!=0:
            print("{} {} {}".format(x,y,height))
            fin=True

Submission status: Wrong Answer

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

def find_top(x,y,N,xyh):
    find=True
    prev=-1
    for n in range(N):
        if xyh[n][2]!=0:
            top=xyh[n][2]+abs(xyh[n][0]-x)+abs(xyh[n][1]-y)
            if prev==-1:
                prev=top
            else:
                if prev!=top:
                    find=False
                    break
    return find,top

fin=False
for x in range(101):
    if fin==True:
        break
    for y in range(101):
        find=find_top(x,y,N,xyh)[0]
        height=find_top(x,y,N,xyh)[1]
        if find and height>=1:
            print("{} {} {}".format(x,y,height))
            fin=True