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: Accepted

Solution code:
N = int(input())
x = [None] * N
y = [None] * N
h = [None] * N

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

def height(i, j, xn, yn, hn):
    return abs(j - xn) + abs(i - yn) + hn

def check(i, j, x, y, h, H):
    N = len(x)
    for n in range(N):
        if h[n] > 0:
            if height(i, j, x[n], y[n], h[n]) != H:
                return False
        else:
            if H - abs(j - x[n]) - abs(i - y[n]) > 0:
                return False
    return True


ok = False
for i in range(101):
    for j in range(101):
        for n in range(N):
            if h[n] > 0:
                H = height(i, j, x[n], y[n], h[n])
                ok = check(i, j, x, y, h, H)
                break
            if ok:
                break
        if ok:
            break
    if ok:
        break

print(j, i, H)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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


xyh.sort(key=lambda x: x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        H = xyh[0][2] + abs(xyh[0][0] - cx) + abs(xyh[0][1] - cy)
        flag = True
        for i in range(1, N):
            x, y, h = xyh[i]
            if h > 0:
                if H != h + abs(x - cx) + abs(y - cy):
                    flag = False
                    break
            else:
                if H > abs(x - cx) + abs(y - cy):
                    flag = False
                    break
        if flag:
            ans = [cx, cy, H]
            print(*ans)
            exit()

Submission status: Accepted

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

for cx in range(100+1):
  for cy in range(100+1):
    isans=True
    preH=0
    late=[]
    for i in range(N):
      x,y,h=S[i]
      if h==0:
        late.append((x,y,h))
      else:
        H=h+abs(x-cx)+abs(y-cy)
        #print(H)
        if preH==0:
          preH=H
        elif preH!=H:
          isans=False
        preH=H
    for i in range(len(late)):
      x,y,h=late[i]
      if preH!=0 and preH>abs(x-cx)+abs(y-cy):
          isans=False
    if isans:
      print(cx, cy, H)

Submission status: Accepted

Solution code:
n = int(input())
data = []
for i in range(n):
    xi,yi,hi = map(int,input().split())
    data.append((xi,yi,hi))
lst = [[] for _ in range(n)]
data.sort(key = lambda x:x[2],reverse = True)
x,y,h = data[0]
for i in range(101):
    for j in range(101):
        lst[0].append((i,j,h+abs(i-x)+abs(j-y)))
for i in range(1,n):
    xi,yi,hi = data[i]
    if hi > 0:
        for x,y,h in lst[i-1]:
            if abs(x-xi)+abs(y-yi)+hi == h:
                lst[i].append((x,y,h))
    else:
        for x,y,h in lst[i-1]:
            if abs(x-xi)+abs(y-yi) >= h:
                lst[i].append((x,y,h))
print(*lst[n-1][0])

Submission status: Accepted

Solution code:
n = int(input())

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


for c_x in range(101):
  for c_y in range(101):
    sign = 0
    judge = base[0][2] + abs(base[0][0] - c_x) + abs(base[0][1] - c_y)
    for i in range(1,n):
      x = base[i][0]
      y = base[i][1]
      h = base[i][2]
      
      if h > 0:
        learge_h = h + abs(x - c_x) + abs(y - c_y)
        if learge_h != judge:
          sign = 1
          break
      elif h == 0:
        if judge > abs(x - c_x) + abs(y - c_y):
          sign = 1
          break
          
    if sign == 0:
      break
      
  if sign == 0:
    break
    
print(c_x,c_y,judge)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

    for cx in range(101):
        for cy in range(101):
            for higth in range(a, a+300):
                for i in range(n):
                    if h[i] > 0:
                        if h[i] != (higth-abs(x[i]-cx)-abs(y[i]-cy)):
                            break
                    else:
                        if 0 < (higth-abs(x[i]-cx)-abs(y[i]-cy)):
                            break
                else:
                    print(cx, cy, higth)
                    exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
'''
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
'''
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n = int(readline())
  xyh = list(list(map(int, readline().split()))for _ in range(n))
  xyh.sort(key=lambda x:x[2], reverse=True)
  for cx in range(101):
    for cy in range(101):
      H = abs(xyh[0][0]-cx) + abs(xyh[0][1]-cy) + xyh[0][2]
      for i in range(n):
        if xyh[i][2] > 0:
          if abs(xyh[i][0]-cx) + abs(xyh[i][1]-cy) + xyh[i][2] != H:
            break
        else:
          if abs(xyh[i][0]-cx) + abs(xyh[i][1]-cy) < H:
            break
      else:
        print(cx, cy, H)
        sys.exit()
  
  
  
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N=int(input())

#h=max(H-|X-Cx|-|Y-Cy|,0)
#h=H-|X-Cx|-|Y-Cy|    h=0
#H=h+|X-Cx|+|Y-Cy|
S=[]
for i in range(N):
  x,y,h=map(int, input().split())
  S.append((x,y,h))

for cx in range(100+1):
  for cy in range(100+1):
    isans=True
    preH=0
    late=[]
    for i in range(N):
      x,y,h=S[i]
      if h==0:
        late.append((x,y,h))
      else:
        H=h+abs(x-cx)+abs(y-cy)
        #print(H)
        if preH==0:
          preH=H
        elif preH!=H:
          isans=False
        preH=H
    for i in range(len(late)):
      x,y,h=late[i]
      if preH!=0 and preH>abs(x-cx)+abs(y-cy):
          isans=False
    if isans:
      print(cx, cy, H)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input().strip())
xyh = [[int(str) for str in input().strip().split()] for _ in range(N)]

def f(x, y, cx, cy, H):
    return max(H - abs(x - cx) - abs(y - cy), 0)

def check(cx, cy, H):
    return all([f(x, y, cx, cy, H) == h for x, y, h in xyh])

for cx in range(101):
    for cy in range(101):
        hs = [h + abs(x - cx) + abs(y - cy) for x, y, h in xyh if h != 0]
        if len(set(hs)) == 1 and check(cx, cy, hs[0]):
            print(cx, cy, hs[0])

Submission status: Accepted

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

"""
方針：0<=cx,cy<=100なのでcx,cyの特定は全数探索で間に合う
(cx,cy)があっていればh+(abs(cx-x)+abs(cy-y))=const
"""

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

for cx in range(101):
	for cy in range(101):
		H = xyh[0][2] + (abs(cx-xyh[0][0]) + abs(cy-xyh[0][1]))
		correct_center = True
		for i in range(N):
			if max(H-(abs(cx-xyh[i][0]) + abs(cy-xyh[i][1])),0) != xyh[i][2]:
				correct_center = False
				break
		if correct_center:
			break
	if correct_center:
		break

print(cx,cy,H)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    x = [0]*N
    y = [0]*N
    h = [0]*N
    for i in range(N):
        x[i], y[i], h[i] = map(int, input().split())
    
    for Cx in range(101):
        for Cy in range(101):
            H = INF
            for i in range(N):
                if h[i] > 0:
                    H = h[i] + abs(x[i]-Cx) + abs(y[i]-Cy)

            flg = True
            for i in range(N):
                if max(H - abs(x[i]-Cx) - abs(y[i]-Cy), 0) != h[i]:
                    flg = False
                    break
            if flg:
                print(" ".join([str(Cx), str(Cy), str(H)]))
                return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import product

    n, *xyh = map(int, open(0).read().split())
    a = range(101)

    if n - xyh[2::3].count(0) == 1:
        i = xyh[2::3].index(1)
        print(xyh[3*i], xyh[3*i+1], xyh[3*i+2])
        return
    a = range(101)
    for x, y in product(a, a):
        l = None
        for i, j, h in zip(*[iter(xyh)] * 3):
            if h == 0:
                continue
            ll = h + abs(x - i) + abs(y - j)
            if l:
                if ll != l:
                    break
            else:
                l = ll
        else:
            print(x, y, l)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
xyh = [LI() for _ in range(n)]
lst = []
for cx in range(101):
    for cy in range(101):
        for x,y,h in xyh:
            X,Y = abs(cx-x), abs(cy-y)
            if h == 0:
                lst.append([X+Y,cx,cy,1])
            else:
                lst.append([X+Y+h,cx,cy,0])

max_h = 0
for a,b,c,d in lst:
    if d:
        max_h = max(max_h, a)
    else:
        for x,y,h in xyh:
            if max(a - abs(x-b) - abs(y-c),0) != h:
                break
        else:
            print(b,c,a)
            quit()
for cx in range(101):
    for cy in range(101):
        for H in range(1,max_h+1):
            for x,y,h in xyh:
                if max(H - abs(x-cx) - abs(y-cy),0) != h:
                    break
            else:
                print(cx,cy,H)
                quit()

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
t = []
for i in range(n):
    t.append(inl())
for i in range(n):
    if t[i][2]>0:
        k = i
        break
for cx in range(101):
    for cy in range(101):
        h = t[k][2]+abs(t[k][0]-cx)+abs(t[k][1]-cy)
        ok = True
        for i in range(n):
            if t[i][2] != max(0,h-abs(t[i][0]-cx)-abs(t[i][1]-cy)):
                ok = False
                break
        if ok:
            print("{} {} {}".format(cx,cy,h))
            exit()

Submission status: Accepted

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

for i in range(101):
  for j in range(101):
    H=xyh[0][2]+abs(i-xyh[0][0])+abs(j-xyh[0][1])
    cnt=1
    for k in range(1,N):
      if max(H-(abs(i-xyh[k][0])+abs(j-xyh[k][1])),0)==xyh[k][2]:
        cnt+=1
      else:
        break
    if cnt==N:
      print(i,j,H)
      exit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def readlines(n):
    for _ in range(n):
        x, y, h = map(int, input().split())
        yield x, y, h

def h_check(lines, cx, cy):
    for x, y, h in lines:
        if h > 0:
            yield h + abs(x - cx) + abs(y - cy)

def match(cx, cy, H, lines):
    for x, y, h in lines:
        yield max(H - abs(x - cx) - abs(y - cy), 0) == h

def main():
    n = int(input())
    lines = list(readlines(n))
    for cx in range(101):
        for cy in range(101):
            res = set(h_check(lines, cx, cy))
            if len(res) == 1:
                H = res.pop()
                if all(match(cx, cy, H, lines)):
                    print(cx, cy, H)
                    return

main()

Submission status: Accepted

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

def func():
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H=[el[2]+abs(el[0]-Cx)+abs(el[1]-Cy) for el in xyh if el[2]!=0]
            if H[0]>=1 and len(set(H))==1:
                temp=[H[0]-abs(el[0]-Cx)-abs(el[1]-Cy) for el in xyh if el[2]==0]
                for el in temp:
                    if el>0:
                        break
                else:
                    print(Cx, Cy, H[0])
                    return None
func()

Submission status: Accepted

Solution code:
n = int(input())
query = []
query0 = []
for i in range(n):
    x, y, h = map(int, input().split())
    if h > 0:
        query.append([x, y, h])
    else:
        query0.append([x, y, h])

for cx in range(101):
    for cy in range(101):
        res = []
        for i in range(len(query)):
            x, y, h = query[i]
            p = abs(x - cx) + abs(y - cy)
            H = h + p
            if h != 0:
                res.append(H)

        if len(set(res)) == 1:
            H = res[0]
            for j in range(len(query0)):
                x0, y0, _ = query0[j]
                if 0 < H - abs(x0 - cx) - abs(y0 - cy):
                    break
            else:
                print(cx, cy, H)
                exit()

Submission status: Accepted

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

cnt = 0
for x, y, h in query:
    if h == 0:
        cnt += 1
    else:
        res = [x, y, 1]

if n - cnt == 1:
    print(*res)
else:
    for cx in range(101):
        for cy in range(101):
            res = []
            for i in range(n):
                x, y, h = query[i]
                p = abs(x - cx) + abs(y - cy)
                H = h + p
                if h != 0:
                    res.append(H)

            if len(set(res)) == 1:
                print(cx, cy, res[0])
                exit()

Submission status: Accepted

Solution code:
import math
import collections
from operator import mul
from functools import reduce
import bisect

b=[]
def test(a):
    if len(a)>=8:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
    else:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
        test(a+"3")
        test(a+"5")
        test(a+"7")

#n,m=map(int,input().split())

n=int(input())
m=[(0,0,0)]*n
for i in range(n):
    m[i]=tuple(map(int,input().split()))

for x in range(101):
    for y in range(101):
        h=-1
        flag=0
        err=0
        for mi in m:
            hh=abs(mi[0]-x)+abs(mi[1]-y)
            if  mi[2]==0:
                if flag==0:
                    h=-hh
                    flag=1
                elif flag==1:
                    h=-min(abs(h),hh)
                else:
                    if h>hh:
                        err=1
                        break
            else:
                if flag==0:
                    h=mi[2]+hh
                    flag=2
                elif flag==1:
                    if abs(h)>=mi[2]+hh:
                        flag=2
                        h=mi[2]+hh
                    else:
                        err=1
                        break
                else:
                    if mi[2]+hh!=h:
                        err=1
                        break
        if err==0:
            print (x,y,h)
            exit()

Submission status: Accepted

Solution code:
n=int(input())
xyh = [list(map(int,input().split())) for _ in range(n)]
def dis(a,b):
  return abs(a[0]-b[0])+abs(a[1]-b[1])
for i in range(101):
  for j in range(101):
    for k in range(n):
      if xyh[k][2]!=0:
        kari=dis(xyh[k],(i,j))+xyh[k][2]
        break
    f=1
    for k in range(n):
      if xyh[k][2]!=max(kari-dis(xyh[k],(i,j)),0):
        f=0
        break
    if f:
      print(i,j,kari)
      exit()

Submission status: Accepted

Solution code:
N=int(input())
d=[]
d0=[]
d1=[]
for i in range(N):
  d.append(list(map(int,input().split())))
for i in range(N):
  if d[i][2]==0:
    d0.append(d[i])
  else:
    d1.append(d[i])
cx=0
cy=0
for x in range(101):
  for y in range(101):
    H=d1[0][2]+abs(x-d1[0][0])+abs(y-d1[0][1])
    c=0
    for i in range(len(d1)):
      if max((H-abs(x-d1[i][0])-abs(y-d1[i][1])),0)==d1[i][2]:
        c+=1
    if c==len(d1):
      cx=x
      cy=y
      cnt=0
      for j in range(len(d0)):
        if max((H-abs(x-d0[j][0])-abs(y-d0[j][1])),0)==0:
          cnt+=1
      if cnt==len(d0):
        ans=[cx,cy,H]
  else:
    continue
  break
for i in range(len(ans)):
  print(ans[i],end=' ')

Submission status: Accepted

Solution code:
n=int(input())
x=[]
y=[]
h=[]
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh.sort(reverse=True ,key=lambda na:(na[2]))
#print(xyh)
for i in range(n):
    x.append(xyh[i][0])
    y.append(xyh[i][1])
    h.append(xyh[i][2])

#print(h)
#中心座標を列挙
for i in range(101):#x
    for j in range(101):#y
        ha=abs(i-x[0])+abs(j-y[0])+h[0]
        for z in range(1,n):#違うかの確かめ作業
            if h[z] != max(ha-abs(i-x[z])-abs(j-y[z]),0):
                break
        else:
            print(i,j,ha)
            exit()
#print("DFGH")

Submission status: Accepted

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

A=[]
cnt,add=0,[0,0]
for i in range(101):
    for j in range(101):
        for x,y,h in XYH:
            H=h+abs(x-i)+abs(y-j)
            A.append([H,i,j])

for H,cx,cy in A:
    flag=1
    for x,y,h in XYH:
        if max(H-abs(x-cx)-abs(y-cy),0)!=h:flag=0
        if not flag:break
    if flag:print(cx,cy,H);exit()

Submission status: Accepted

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

A=[]
cnt,add=0,[0,0]
for i in range(101):
    for j in range(101):
        for x,y,h in XYH:
            H=h+abs(x-i)+abs(y-j)
            A.append([H,i,j])

for H,cx,cy in A:
    flag=1
    for x,y,h in XYH:
        if max(H-abs(x-cx)-abs(y-cy),0)!=h:flag=0
        if not flag:break
    if flag:
        print(cx,cy,H);exit()

Submission status: Accepted

Solution code:
N=int(input())
xyh=[list(map(int,input().split(' '))) for i in range(N)]
for i in range(101):
    for j in range(101):
        H_0=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh])
        H_1=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh if h!=0])
        if len(H_0)==1:
            print(i,j,max(H_0))
            exit()
        if len(H_1)==1:
            cx,cy,H=i,j,max(H_1)
print(cx,cy,H)

Submission status: Accepted

Solution code:
import sys

# import bisect
from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
from operator import attrgetter, itemgetter

# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    xyh = [list(map(int, readline().split())) for _ in range(n)]

    hbase = 0
    idx = 0

    while hbase == 0:
        xbase = xyh[idx][0]
        ybase = xyh[idx][1]
        hbase = xyh[idx][2]
        idx += 1

    for x in range(101):
        for y in range(101):
            h = hbase + (abs(xbase - x) + abs(ybase - y))
            for i in range(n):
                htemp = max((h - (abs(xyh[i][0] - x) + abs(xyh[i][1] - y)), 0))
                if htemp != xyh[i][2]:
                    break
            else:
                print(x, y, h)
                sys.exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for a,b,c in points:
  if c>0:
    a,b,c
    break

f = lambda x, y: abs(a-x) + abs(b-y)

for i in range(101):
  for j in range(101):
    height = f(i, j) + c
    flg = True
    for x, y, h in points:
      if h != max(height - abs(x-i) - abs(y-j) , 0):
        flg = False
        break
    if flg:
      print(i, j, height)
      sys.exit()

Submission status: Accepted

Solution code:
n=int(input())
inf=[list(map(int,input().split())) for i in range(n)]
for a,b,c in inf:
    if c>0:
        x,y,h=a,b,c
        break
def hei(a,b):
    return h+abs(a-x)+abs(b-y)
for i in range(101):
    for j in range(101):
        flag=True
        H=hei(i,j)
        # if i==2 and j==2:
        #     print(H)
        for k in range(n):
            # if i==2 and j==2:
            #     print(max(H-abs(inf[k][0]-i)-abs(inf[k][1]-j),0),inf[k][2])
            if max(H-abs(inf[k][0]-i)-abs(inf[k][1]-j),0)!=inf[k][2]:
                flag=False
                break
        if flag:
            print(i,j,H)
            exit()

Submission status: Accepted

Solution code:
N=int(input())
xyh=[list(map(int,input().split(' '))) for i in range(N)]
for i in range(101):
    for j in range(101):
        H_0=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh])
        H_1=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh if h!=0])
        if len(H_0)==1:
            print(i,j,max(H_0))
            exit()
        if len(H_1)==1:
            cx,cy,H=i,j,max(H_1)
print(cx,cy,H)

Submission status: Accepted

Solution code:
n = int(input())
arr = []
for i in range(n):
  x,y,h = map(int,input().split())
  if h >= 1:
    X,Y,H = x,y,h
  arr.append([x,y,h])

def d(a,b,c,d):
  return abs(c-a)+abs(d-b)


for i in range(101):
  for j in range(101):
    H0 = d(i,j,X,Y)+H
    flag = 1
    for l in arr:
      if l[2] != max(0,H0-d(i,j,l[0],l[1])):
        flag = 0
        break
    if flag == 1:
      print(i,j,H0)
      quit()

Submission status: Accepted

Solution code:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
for i in range(101):
    for j in range(101):
        H = []
        MIN = float('inf')
        for k in range(n):
            if a[k][2] == 0:
                MIN = min(MIN, abs(a[k][0] - i) + abs(a[k][1] - j))
            else:
                H.append(a[k][2] + abs(a[k][0] - i) + abs(a[k][1] - j))
        if len(set(H)) == 1 and H[0] <= MIN:
            print(i, j, H[0])
            exit()

Submission status: Accepted

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

    for px in range(101):
        for py in range(101):
            H = hint[2] + abs(px-hint[0]) + abs(py-hint[1])
            clearflag = True
            for point in points:
                x, y, h = point
                val = max([H - abs(px-x) - abs(py-y), 0])
                if val != h:
                    clearflag = False

            if clearflag:
                print(px, py, H)
                return
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
xyh=[]
for i in range(n):
	x,y,h=map(int,input().split())
	xyh.append((x,y,h))
def dis(a,b):
	return abs(a[0]-b[0])+abs(a[1]-b[1])
for i in range(101):
	for j in range(101):
		for k in range(n):
			if xyh[k][2]!=0:
				kari=dis(xyh[k],(i,j))+xyh[k][2]
				break
		f=1
		for k in range(n):
			if xyh[k][2]!=max(kari-dis(xyh[k],(i,j)),0):
				f=0
				break
		if f:
			print(i,j,kari)
			exit()

Submission status: Accepted

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

import sys

for cx in range(0,101):
    for cy in range(0,101):
        H = [0]*N
        for i in range(N):
            H[i] = h[i] + abs(x[i]-cx) + abs(y[i]-cy)
        for i in range(N):
            if h[i] == 0:
                H[i] = min(H)
        if max(H) == min(H):
            print(cx,cy,max(H))
            sys.exit()

Submission status: Accepted

Solution code:
N = int(input())
x = [0]*N
y = [0]*N
h = [0]*N

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

for i in range(101):
    for j in range(101):
        
        for k in range(N):
            if h[k] == 0:
                continue
            H = abs(i-x[k]) + abs(j-y[k]) + h[k]
            break

        for k in range(N):
            if h[k] == 0:
                continue
            if H != abs(i-x[k]) + abs(j-y[k]) + h[k]:
                break
        else:
            for k in range(N):
                if h[k] != max( H - abs(i-x[k]) - abs(j-y[k]) ,  0):
                    break
            else:
                print(i,j,H)

Submission status: Accepted

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

for x,y,h in lst:
    if h != 0:
        break

for cx in range(101):
    for cy in range(101):
        H = abs(cx-x) + abs(cy-y) + h
        if all(hi == max(H-abs(cx-xi)-abs(cy-yi),0) for xi,yi,hi in lst):
            print(cx,cy,H)
            exit()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    x = [0]*N
    y = [0]*N
    h = [0]*N
    k = N
    
    for i in range(N):
        x[i], y[i], h[i] = map(int, input().split())
        if(h[i] > 0):
            k = min(k, i)
    
    for Cx in range(101):
        for Cy in range(101):
            tmp = abs(x[k]-Cx)+abs(y[k]-Cy)+h[k]
            for i in range(N):
                if(h[i] != max(tmp-abs(x[i]-Cx)-abs(y[i]-Cy), 0)):
                    break
                if(i == N-1 and tmp > 0):
                    print(Cx, Cy, tmp)
                    quit()               
main()

Submission status: Accepted

Solution code:
import sys

N=int(input())
hxylist=[]
for i in range(N):
  x,y,h=map(int,input().split())
  hxylist.append((h,x,y))
hxylist.sort(reverse=True)
#print(hxylist)

for cx in range(101):
  for cy in range(101):
    ch=-1
    for h,x,y in hxylist:
      if h==0:
        max_ch=h+abs(x-cx)+abs(y-cy)
        if max_ch<ch:
          break
      elif ch==-1:
        ch=h+abs(x-cx)+abs(y-cy)
        #print(cx,cy,ch)
      else:
        ch2=h+abs(x-cx)+abs(y-cy)
        if ch!=ch2:
          break
    else:
      print(cx,cy,ch)
      sys.exit(0)

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    data=[list(map(int,input().split())) for i in range(N)]
    data=sorted(data,key=lambda x: x[2], reverse=True)

    def height(X,Y,Cx,Cy,H):
        return max(H-abs(X-Cx)-abs(Y-Cy),0)
    def main():
        for i in range(101):
            for j in range(101):
                H = data[0][2] + abs(data[0][0] - i) + abs(data[0][1] - j)
                for k in range(1,N):
                    if height(data[k][0],data[k][1],i,j,H)!=data[k][2]:
                        break
                    elif k==N-1:
                        print(i,j,H)
                        return None

    main()

resolve()

Submission status: Accepted

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

XYH.sort(key = lambda x:-x[2])#ソートしておくと早く見つかる

X0,Y0,H0 = XYH[0]#コーナーケース、入力が１個の場合
if N == 1:
    print(X0,Y0,H0)
    exit()

for Cx in range(101):#XとYで全探索
    for Cy in range(101):
        H = H0 + abs(X0 - Cx) + abs(Y0 - Cy)
        flag = True#フラグ管理、上手く行ったとき
        for X,Y,h in XYH[1:]:
            if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                continue
            flag = False
        if flag:#上手く行ったときだけ出力
            print(Cx,Cy,H)
            exit()#答は１個だけ

Submission status: Accepted

Solution code:
import sys
import copy

N = int(input())

def calcH(x, y, h, cx, cy):
    return (h+abs(cx-x)+abs(cy-y))

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

for cx in range(101):
    for cy in range(101):
        beforeH = ""
        roop = 0
        minH = float('inf')
        for i in range(len(XYH)):
            if XYH[i][2] == 0:
                minH = min(minH, abs(cx-XYH[i][0])+abs(cy-XYH[i][1]))
                roop += 1
            else:
                calced_H = calcH(XYH[i][0], XYH[i][1], XYH[i][2], cx, cy)
                if beforeH == "":
                    beforeH = calced_H
                elif calced_H > minH:
                    break
                elif beforeH != calced_H:
                    break
                roop += 1
        if roop == N and calced_H <= minH:
            print(str(cx)+" "+str(cy)+" "+str(beforeH))
            sys.exit()