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: Runtime Error

Solution code:
N=int(input())
x=[list(map(int,input().split())) for _ in range(N)]
Cx=0
Cy=0
H=0
dp=[[0]*101 for i in range(101)]
ans=10**10
for i in range(N):
  for j in range(101):
    for k in range(101):
      count=abs(x[i][0]-j)+abs(x[i][1]-k)+x[i][2]
      if dp[j][k]!=i*count:
        dp[j][k]=0
      else:
        dp[j][k]+=count
      ans=min(ans,x[i][2])
p=10**19
a=0
b=0
for i in range(101):
  for j in range(101):
    if dp[i][j]%N==0 dp[i][j]!=0:
      if p!=min(p,dp[i][j]//N):
        a=i
        b=j
        p=min(p,dp[i][j]//N)
print(a,b,p)

Submission status: Runtime Error

Solution code:
import sys

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

for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        tmp_h = abs(cy - y) + abs(cx - x) + h
        H = np.zeros(n, dtype=np.bool)
        for i, a in enumerate(xyh):
            H[i] = a[2] == max(tmp_h - abs(cx - a[0]) - abs(cy - a[1]), 0)
        if np.all(H):
            print(cx, cy, tmp_h)
            sys.exit()

Submission status: Runtime Error

Solution code:
from itertools import product
def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(list(map(int, input().split())))
    for a in A:
        if a[2] != 0:
            t = a
            break
    for x, y in product(range(0, 101), repeat = 2):
        H = t[2] + abs(t[0] - x) + abs(t[1] - y)
        for a in A:
            if a[2] == 0 and H < abs(a[0] - x) + abs(a[1] - y):
                break
            elif a[2] == 0:
                continue
            elif a[2] != 0 and a[2] == H - abs(a[0] - x) - abs(a[1] - y):
                continue
            elif a[2] != H - abs(a[0] - x) - abs(a[1] - y):
                break
        else:
            ansx, ansy = x, y
            break
    H = t[2] + abs(t[0] - ansx) + abs(t[1] - ansy)
    print('{} {} {}'.format(ansx, ansy, H))



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
lis = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h != 0:
        lis.append([x, y, h])
        sx, sy, sh = x, y, h

for i in range(101):
    for j in range(101):
        
        cx, cy = i, j
        for K in range(len(lis)):
            x, y, h = lis[K]
            
            if h > 0 and sh + abs(sx - cx) + abs(sy - cy) != h + abs(cx - x) + abs(cy -y):
                break
            elif sh +  abs(sx - cx) + abs(sy - cy) > abs(cx - x) + abs(cx + y):
                break
            if K == len(lis) - 1:
                print(cx, cy, hight)
                exit()

Submission status: Runtime Error

Solution code:
N = int(input())

d = {}
l = []
p = 0

for i in range(N):
  l.append(list(map(int, input().split())))

while True:
  if(l[0][2] == 0):
    l.append(l[0])
    l.remove[0]
  else:
    x, y, h= l[0]
    for i in range(101):
      for j in range(101):
        d[(i, j)] = abs(i- x)+ abs(j- y)+ h
    break

for k in range(N- 1):
  x, y, h = l[k+ 1]
  if(h == 0):
    for i in range(101):
      for j in range(101):
        if(d[(i, j)]- abs(i- x)- abs(j- y)> 0):
          del d[(i, j)]
  else:
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)] != abs(i- x)+ abs(j- y)+ h):
            del d[(i, j)]


zahyou, height = list(d.items())[0]
  
print("{0[0]} {0[1]} {1}".format(zahyou, height))

Submission status: Runtime Error

Solution code:
N = int(input())

d = {}

x, y, h = map(int, input().split())
count = 0

while True:
  if(h == 0):
    x, y, h = map(int, input().split())
    count+= 1
    continue
  else:
    for i in range(101):
      for j in range(101):
        d[(i, j)] = abs(i- x)+ abs(j- y)+ h
    count+= 1
    break

for k in range(N- count):
  x, y, h = map(int, input().split())
  if(h == 0):
    for i in range(101):
      for j in range(101):
        if(d[(i, j)]- abs(i- x)- abs(j- y)> 0):
          del d[(i, j)]
  else:
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)] != abs(i- x)+ abs(j- y)+ h):
            del d[(i, j)]

if(len(d) == 1):            
  zahyou, height = list(d.items())[0]
else:  
  zahyou, height = list(d.items())[10]
  
print("{0[0]} {0[1]} {1}".format(zahyou, height))

Submission status: Runtime Error

Solution code:
N = int(input())

d = {}
x, y, h = map(int, input().split())

for i in range(101):
  for j in range(101):
    d[(i, j)] = abs(i- x)+ abs(j- y)+ h

for k in range(N- 1):
  x, y, h = map(int, input().split())
  for i in range(101):
    for j in range(101):
      if((i, j) in d):
        if(d[(i, j)] != abs(i- x)+ abs(j- y)+ h):
          del d[(i, j)]
          
zahyou, height = list(d.items())[0]
print("{0[0]} {0[1]} {1}".format(zahyou, height))

Submission status: Runtime Error

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

takasa = [[-1] * (101) for _ in range(101)]
for i in range(n):
    x, y, h = XYH[i]
    if h == 0:
        continue
    for j in range(101):
        for k in range(101):
            if takasa[j][k] == -1:
                takasa[j][k] = abs(x - j) + abs(y - k) + h
            else:
                if takasa[j][k] == abs(x - j) + abs(y - k) + h:
                else:
                    takasa[j][k] = -2

for i in range(101):
    for j in range(101):
        if takasa[i][j] > 0:
            print(i, j, takasa[i][j])
            exit()

Submission status: Runtime Error

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

#print('xyh', xyh)


for Cx in range(101):
    for Cy in range(101):
        Hcands=[0]*100000
        for i in range(N):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            #print('xyh',x,y,h)
            if h>0:
                Hcand = h + abs(x-Cx) + abs(y-Cy)
                #print('H',H)
                if Hcand>=1:
                    Hcands[Hcand-1]+=1
                    if Hcands[Hcand-1]==N:
                        print(Cx,Cy,Hcand)
                        break

Submission status: Runtime Error

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

#print('xyh', xyh)


for Cx in range(101):
    for Cy in range(101):
        Hcands=[0]*1000
        for i in range(N):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            #print('xyh',x,y,h)
            if h>0:
                Hcand = h + abs(x-Cx) + abs(y-Cy)
                #print('H',H)
                if Hcand>=1:
                    Hcands[Hcand-1]+=1
                    if Hcands[Hcand-1]==N:
                        print(Cx,Cy,Hcand)

Submission status: Runtime Error

Solution code:
import sys

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

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

Submission status: Runtime Error

Solution code:
N=int(input())
x=[]
y=[]
h=[]
for i in range(N):
  a,b,c=map(int,input().split())
  x.append(a)
  y.append(b)
  h.append(c)
field=[[-1 for i in range(101)] for i in range(101)]
for i in range(N):
  for j in range(101):
    for k in range(101):
      if(field[j][k]==-1):
        field[j][k]=h[i]+abs(j-x[i])+abs(k-y[i])
      elif(field[j][k]!=h[i]+abs(j-x[i])+abs(k-y[i])):
        field[j][k]=-2
for i in range(101):
  for j in range(101):
    if(field[i][j]>=0):
      cx=i
      cy=j
      H=field[i][j]
print(cx,cy,H)

Submission status: Runtime Error

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

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


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

        for i in range(1, n):
            x, y, h = xyh[i]
            HH = abs(x - cx) + abs(y - cy) + h
            if HH != H:
                f = False
                break

        if f:
            ans = (cx, cy, H)

print(ans[0], ans[1], ans[2])

Submission status: Runtime Error

Solution code:
def check(X,Y):
    Hs = []
    for x,y,h in xyh:
        if h > 0:
            H = h + abs(X-x) + abs(Y-y)
            Hs.append(H)
        else:
            if abs(X-x) + abs(Y-y) < H:
                return False
    
    if len(set(Hs)) == 1:
        print(X,Y,Hs[0])
        return True
    else:
        return False

N = int(input())

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

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

Submission status: Runtime Error

Solution code:
def check(X,Y):
    Hs = []
    for x,y,h in xyh:
        if h > 0:
            H = h + abs(X-x) + abs(Y-y)
            Hs.append(H)
        else:
            if abs(X-x) + abs(Y-y) < H:
                return False

    if len(set(Hs)) == 1:
        print(X,Y,Hs[0])
        return True
    else:
        return False

N = int(input())

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

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

Submission status: Runtime Error

Solution code:
def check(X,Y):
    Hs = []
    for x,y,h in xyh:

        if h > 0:
            H = h + abs(X-x) + abs(Y-y)
            Hs.append(H)
        else:
            if abs(X-x) + abs(Y-y) < H:
                return False
    if len(set(Hs)) == 1:
        print(X,Y,Hs[0])
        return True

N = int(input())

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[2],reverse=True)
for x in range(101):
    for y in range(101):
        a,b,h = A[0]
        H = h+abs(x-a)+abs(y-b)
        flag = 1
        for i in range(1,N):
            a,b,h = A[i]
            if H==h+abs(x-a)+abs(y-b):continue
            else:
                flag = 0
                break
        if flag==1:
            cx = x
            cy = y
            break
    if flag==1:break
print(cx,cy,H)

Submission status: Runtime Error

Solution code:
A=abs
h,y,x=max([list(map(int,t.split()[::-1]))for t in open(0)][1:])
r=range(101)
for i in r:
 for j in r:H=h+A(x-j)+A(y-i);print(*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for u,t,s in p))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
x,y,h = IL()
import itertools
dic = {(i,j):h+(abs(i-x)+abs(j-y))  for i,j in itertools.product(range(101),repeat=2)}

while len(dic)>1:
  x,y,h = IL()
  for i,j in itertools.product(range(101),repeat=2):
    if (i,j) in dic:
      if h > 0:
        if dic[(i,j)] != h+(abs(i-x)+abs(j-y)):
          dic.pop((i,j))
      else:
        if dic[(i,j)] > h+(abs(i-x)+abs(j-y)):
          dic.pop((i,j))

ans = [k for k in dic][0]

print(ans[0],ans[1],dic[ans])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
x,y,h = IL()
import itertools
dic = {(i,j):h+(abs(i-x)+abs(j-y))  for i,j in itertools.product(range(101),repeat=2)}

while len(dic)>1:
  x,y,h = IL()
  for i,j in itertools.product(range(101),repeat=2):
    if (i,j) in dic:
      if dic[(i,j)] != h+(abs(i-x)+abs(j-y)):
        dic.pop((i,j))

ans = [k for k in dic][0]

print(ans[0],ans[1],dic[ans])

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh.sort()
p=xyh[-1]
q=xyh[-2]
for cx in range(0,101):
    for cy in range(0,101):
      if abs(p[0]-cx)+abs(p[1]-cy)==abs(q[0]-cx)+abs(q[1]-cy)+p[2]-q[2]:
        ax=cx
        ay=cy
H=p[2]+abs(p[0]-ax)+abs(p[1]-ay)
print(ax,ay,H)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = set()
for i in range(N):
    x,y,h = (int(x) for x in input().split())
    if h > 0:
        for j in range(101):
            for k in range(101):
                ans.add((j,k,h+abs(j-x)+abs(k-y)))
        break
for i in range(N):
    x,y,h = (int(x) for x in input().split())
    temp = set()
    for j in range(101):
        for k in range(101):
            temp.add((j,k,h+abs(j-x)+abs(k-y)))
    if len(ans&temp) > 0:
        ans = ans & temp
for x in ans:
    print(*x)

Submission status: Runtime Error

Solution code:
# C - Pyramid

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

for cx in range(101):
    for cy in range(101):
        pre_tmp_H = 0
        for (x, y, h) in XYH:
            tmp_H = h + abs(x - cx) + abs(y - cy)
            if pre_tmp_H != 0 and tmp_H != pre_tmp_H:
                break
            pre_tmp_H = tmp_H
        else:
            ans = (cx, cy, tmp_H)

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

Submission status: Runtime Error

Solution code:
# C - Pyramid

N = int(input())
XYH = [tuple(int(x) for x in input().split()) for _ in range(N)]

for cx in range(101):
    for cy in range(101):
        pre_tmp_H = 0
        for (x, y, h) in XYH:
            tmp_H = h + abs(x - cx) + abs(y - cy)
            if pre_tmp_H != 0 and tmp_H != pre_tmp_H:
                break
            pre_tmp_H = tmp_H
        else:
            ans = (cx, cy, tmp_H)

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

Submission status: Runtime Error

Solution code:
import sys

N = int(input())

if N == 1:
    print('aaa')
    sys.exit(0)
    

infos = []
first_info = []
second_info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0 and len(first_info) == 0:
        first_info = [x, y, h]
    elif h > 0 and len(second_info) == 0:
        second_info = [x, y, h]
    elif h > 0:
        infos.append([x, y, h])


# cxとcyを1つに絞り込む
x1, y1, h1 = first_info
x2, y2, h2 = second_info
kouhos = []
for cx in range(101):
    for cy in range(101):
        if h1-h2 == abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouhos.append([cx, cy])

#print(kouhos)
kouho_isvalid = [True for _ in range(len(kouhos))]

for info in infos:
    x2, y2, h2 = info
    for i in range(len(kouhos)):
        cx, cy = kouhos[i]
        if h1-h2 != abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouho_isvalid[i] = False


for i in range(len(kouhos)):
    if kouho_isvalid[i]:
        cx, cy = kouhos[i]

H = h1 + abs(x1-cx) + abs(y1-cy)
print(cx, cy, H)

Submission status: Runtime Error

Solution code:
N = int(input())

infos = []
first_info = []
second_info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0 and len(first_info) == 0:
        first_info = [x, y, h]
    elif h > 0 and len(second_info) == 0:
        second_info = [x, y, h]
    elif h > 0:
        infos.append([x, y, h])


# cxとcyを1つに絞り込む
x1, y1, h1 = first_info
x2, y2, h2 = second_info
kouhos = []
for cx in range(101):
    for cy in range(101):
        if h1-h2 == abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouhos.append([cx, cy])

#print(kouhos)
kouho_isvalid = [True for _ in range(len(kouhos))]

for info in infos:
    x2, y2, h2 = info
    for i in range(len(kouhos)):
        cx, cy = kouhos[i]
        if h1-h2 != abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouho_isvalid[i] = False

cx = 0
cy = 0
for i in range(len(kouhos)):
    if kouho_isvalid[i]:
        cx, cy = kouhos[i]

H = h1 + abs(x1-cx) + abs(y1-cy)
print(cx, cy, H)

Submission status: Runtime Error

Solution code:
N = int(input())

infos = []
first_info = []
second_info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0 and len(first_info) == 0:
        first_info = [x, y, h]
    elif h > 0 and len(second_info) == 0:
        second_info = [x, y, h]
    elif h > 0:
        infos.append([x, y, h])


# cxとcyを1つに絞り込む
x1, y1, h1 = first_info
x2, y2, h2 = second_info
kouhos = []
for cx in range(101):
    for cy in range(101):
        if h1-h2 == abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouhos.append([cx, cy])

#print(kouhos)
kouho_isvalid = [True for _ in  range(len(kouhos))]

for info in infos:
    x2, y2, h2 = info
    for i in range(len(kouhos)):
        cx, cy = kouhos[i]
        if h1-h2 != abs(x2-cx) + abs(y2-cy) - abs(x1-cx) - abs(y1-cy):
            kouho_isvalid[i] = False


for i in range(len(kouhos)):
    if kouho_isvalid[i]:
        #print(kouhos[i])
        cx, cy = kouhos[i]

H = h1 + abs(x1-cx) + abs(y1-cy)

print(cx, cy, H)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

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

N = getN()
info = []
for i in range(N):
    x, y, h = getNM()
    info.append([x, y, h])

ans = []
for i in range(101):
    for j in range(101):
        X = i
        Y = j
        height = []
        flag = True
        for k in range(N):
            minusx = abs(X - info[k][0])
            minusy = abs(Y - info[k][1])
            if info[k][2] != 0:
                h = info[k][2] + minusx + minusy
                if k != 0 and h != height[-1]:
                    flag = False
                    break
                height.append(h)
        if flag:
            ans = [i, j, height[0]]
print(*ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
a=[]
for x in range(101):
  for y in range(101):
    c=[]
    for t in l:
      if t[2]:
        c.append(t[2]+abs(x-t[0])+abs(y-t[1]))
    f=0
    if len(set(c))==1:
      f=1
      h=c[0]
      for t in l:
        if l[2]==0:
          if h-abs(x-t[0])-abs(y-t[1])>0:
            f=0
    if f:
      print(x,y,h)
      exit()

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
a=[]
for x in range(101):
  for y in range(101):
    c=[]
    for t in l:
      if l[2]:
        c.append(t[2]+abs(x-t[0])+abs(y-t[1]))
    f=0
    if len(set(c))==1:
      f=1
      h=c[0]
      for t in l:
        if l[2]==0:
          if h-abs(x-t[0])-abs(y-t[1])>0:
            f=0
    if f:
      print(x,y,h)
      exit()

Submission status: Runtime Error

Solution code:
def search_center(xyh_list):
    xyh_list.sort(key=lambda r: r[2], reverse=True)
    highest = xyh_list[0]
    for cx in range(101):
        for cy in range(101):
            h = highest[2] + abs(highest[0] - cx) + abs(highest[1] - cy)
            matched = True
            for xyh in xyh_list[1:]:
                if xyh[2] == 0:
                    if h - abs(highest[0] - cx) - abs(highest[1] - cy) > 0:
                        matched = False
                        break
                else:
                    hh = xyh[2] + abs(xyh[0] - cx) + abs(xyh[1] - cy)
                    if h != hh:
                        matched = False
                        break
            if matched:
                return cx, cy, h
    return None


def main():
    N = int(input())
    xyh_list = [list(map(int, input().split(' '))) for _ in range(N)]
    xyh_list.sort(key=lambda r: r[2], reverse=True)
    cx, cy, ph = search_center(xyh_list)
    print('{} {} {}'.format(cx, cy, ph))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
xyh = li2(N)

for c_x in range(101):
    for c_y in range(101):
        flag = 0
        left = 1
        right = float('inf')
        for i in range(N):
            tmp = xyh[i][2] + abs(c_x-xyh[i][0]) + abs(c_y-xyh[i][1])
            if tmp < 1 or not (left <= tmp <= right):
                    flag = 1
                    break
            if xyh[i][2] > 0:
                left = tmp
                right = tmp
            else:
                right = tmp
        if not flag:
            print(c_x, c_y, tmp)
            exit()
print(xyh[N+1])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
xyh = li2(N)

for c_x in range(101):
    for c_y in range(101):
        flag = 0
        left = 1
        right = float('inf')
        for i in range(N):
            tmp = xyh[i][2] + abs(c_x-xyh[i][0]) + abs(c_y-xyh[i][1])
            if tmp < 1 or not (left <= tmp <= right):
                    flag = 1
                    break
            if xyh[i][2] > 0:
                left = right = tmp
            else:
                right = tmp
        if not flag:
            print(c_x, c_y, tmp)
            exit()
print(xyh[N+1])

Submission status: Runtime Error

Solution code:
from sys import exit

n=int(input())
x=[0]*n
y=[0]*n
h=[0]*n

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

if n==1:
	print(xx,yy,hh)
	exit()
else:
	for cx in range(101):
		for cy in range(101):
			cnt=0
			h2=h[0]+abs(x[0]-cx)+abs(y[0]-cy)
			for i in range(1,n):
				h1=h[i]+abs(x[i]-cx)+abs(y[i]-cy)
				if h2!=h1:
					cnt=1
			if cnt==0 and h1>hres:
				hres=h1
				xres=cx
				yres=cy
				
print(xres,yres,hres)

Submission status: Runtime Error

Solution code:
n, *XYH = map(int, open(0).read().split())
for cx, cy in product(range(101), repeat=2):
    B, C = set(), set()
    for x, y, h in zip(XYH[::3], XYH[1::3], XYH[2::3]):
        s = h + abs(x-cx) + abs(y-cy)
        if h:
            C.add(s)
        else:
            B.add(s)
    if len(C) == 1:
        h = C.pop()
        if all(h <= b for b in B):
            print(cx, cy, h)
            exit()

Submission status: Runtime Error

Solution code:
n, *XYH = map(int, open(0).read().split())
X, Y, H = XYH[::3], XYH[1::3], XYH[2::3]
A = []
for cx, cy in product(range(101), repeat=2):
    B = set()
    C = set()
    for x, y, h in zip(X, Y, H):
        s = h + abs(x-cx) + abs(y-cy)
        if h == 0:
            B.add(s)
        else:
            C.add(s)
    if len(C) == 1:
        h = C.pop()
        if all(h <= b for b in B):
            A.append((cx, cy, h))
print(*A.pop())