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:
def resolve():
    N = int(input())
    conds = [list(map(int, input().split(" "))) for i in range(N)]
    
    # [[cx, cy, H]]
    candidates = []

    first = sorted(conds, reverse=True, key=lambda x:x[2])[0]
    for cx in range(101):
        for cy in range(101):
            H = abs(first[0]-cx)+abs(first[1]-cy)+first[2]
            for n in range(1, N):
                cond = conds[n]
                if cond[2] == 0:
                    if abs(cond[0]-cx)+abs(cond[1]-cy) < cond[2]: 
                        ansflg = False
                        break
                else:
                    if abs(cond[0]-cand[0])+abs(cond[1]-cand[1])+cond[2] != H:
                        ansflg = False
                        break
            else:
                print("{} {} {}".format(cx, cy, H))
                exit()


if '__main__' == __name__:
    resolve()

Submission status: Runtime Error

Solution code:
def resolve():
    N = int(input())
    conds = [list(map(int, input().split(" "))) for i in range(N)]
    
    # [[cx, cy, H]]
    candidates = []

    cond = conds[0]
    for cx in range(101):
        for cy in range(101):
            H = abs(cond[0]-cx)+abs(cond[1]-cy)+cond[2]
            if 1 <= H:
                candidates.append([cx, cy, H])
    
    ans = []
    for cand in candidates:
        ansflg = True
        for n in range(1, N):
            cond = conds[n]
            if cond[2] == 0:
                if abs(cond[0]-cand[0])+abs(cond[1]-cand[1]) < cond[2]: 
                    ansflg = False
                    break
            else:
                H = abs(cond[0]-cand[0])+abs(cond[1]-cand[1])+cond[2]
                if H != cand[2]:
                    ansflg = False
                    break
        if ansflg:
            ans = cand
            break
    
    print("{} {} {}".format(ans[0], ans[1], ans[2]))

    


if '__main__' == __name__:
    resolve()

Submission status: Runtime Error

Solution code:
def resolve():
    N = int(input())
    conds = [list(map(int, input().split(" "))) for i in range(N)]
    
    # [[cx, cy, H]]
    candidates = []

    cond = conds[0]
    for cx in range(101):
        for cy in range(101):
            H = abs(cond[0]-cx)+abs(cond[1]-cy)+cond[2]
            if 1 <= H:
                candidates.append([cx, cy, H])
    
    ans = []
    for cand in candidates:
        ansflg = True
        for n in range(1, N):
            cond = conds[n]
            if cond[2] == 0:
                ansflg = False
                break
            H = abs(cond[0]-cand[0])+abs(cond[1]-cand[1])+cond[2]
            if H != cand[2]:
                ansflg = False
                break
        if ansflg:
            ans = cand
            break
    
    print("{} {} {}".format(ans[0], ans[1], ans[2]))

    


if '__main__' == __name__:
    resolve()

Submission status: Runtime Error

Solution code:
def resolve():
    N = int(input())
    conds = [list(map(int, input().split(" "))) for i in range(N)]
    
    # [[cx, cy, H]]
    candidates = []

    cond = conds[0]
    for cx in range(101):
        for cy in range(101):
            H = abs(cond[0]-cx)+abs(cond[1]-cy)+cond[2]
            if 1 <= H:
                candidates.append([cx, cy, H])
    
    ans = []
    for cand in candidates:
        ansflg = True
        for n in range(1, N):
            cond = conds[n]
            H = abs(cond[0]-cand[0])+abs(cond[1]-cand[1])+cond[2]
            if H != cand[2]:
                ansflg = False
                break
        if ansflg:
            ans = cand
            break
    
    print("{} {} {}".format(ans[0], ans[1], ans[2]))

    


if '__main__' == __name__:
    resolve()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()

st=set()
prevset=set()
for i in range(N):
    x,y,h=LI()
    st = set()
    for i in range(101):
        for j in range(101):
            if not h == 0:
                st.add((i,j, h+abs(x-i)+abs(y-j)))

    prevset = st if not prevset else st.intersection(prevset)
    if len(prevset) == 1:
        break

print(*prevset.pop())

Submission status: Runtime Error

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

xyh_hNonzero = sorted(xyh, reverse=True, key=lambda x:x[2])[0]

for cx in range(101):
  for cy in range(101):
    h = abs(xyh_hNonzero[0] - cx) + abs(xyh_hNonzero[1] - cy) + xyh_hNonzero[2]
    for i in range(N):
      if xyh[i][2] == 0 and abs(xyh[i][0] - cx) + abs(xyh[i][1] - cy) < h:
        break
      if abs(xyh[i][0] - cx) + abs(xyh[i][1] - cy) + xyh[i][2] != h:
        break
    else:
      print(' '.join(map(str, [cx,cy,h])))
      exit()
else:
  raise Exception('aaa!!!')

Submission status: Runtime Error

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

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(1, N):
      if abs(xyh[i][0] - cx) + abs(xyh[i][1] - cy) + xyh[i][2] != h:
        break
    else:
      print(' '.join(map(str, [cx,cy,h])))
      exit()
else:
  raise Exception('aaa!!!')

Submission status: Runtime Error

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

for x in range(101):
    for y in range(101):
        flag = True
        h = d[0][2] + abs(d[0][0] - x) + abs(d[0][1] - y)
        for i in d:
            if i[2] != max(h - abs(i[0] - x) - abs(i[1] - y),0):
                flag = False
                break

        if flag:
            ansx = x
            ansy = y
            ansh = h

print(ansx,ansy,ansh)

Submission status: Runtime Error

Solution code:
def search():
    for i in range(0,101):
        for j in range(0,101):
            h=l[0][2]+abs(i-l[0][0])+abs(j-l[0][1])
            for a,b,c in l[1:]:
                hi=c+abs(i-a)+abs(j-b)
                if h!=hi:break
            else:
                return [i,j,hi]

l=[list(map(int,input().split())) for i in range(int(input()))]
a,b,c=search()
print(a,b,c)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[[]]*n
for i in range(n):
    l[i]=list(map(int,input().split()))
lst=sorted(l,key=lambda x:-x[2])
flag=False

for i in range(0,101):#i=X
    if flag:
        break
    for j in range(0,101):#j=Y
        if flag:
            break
        tmp=lst[0][2]+abs(lst[0][0]-i)+abs(lst[0][1]-j)
        for k in range(n):
            if lst[k][2]!=0:
            #print(k,'ループ目')
                sum=abs(lst[k][0]-i)+abs(lst[k][1]-j)
                H=lst[k][2]+sum
                if tmp!=H :
                    break
                a,b,c=i,j,H
                if k==n-1:
                    flag=True
                    print(i,j,H)
                    break
            else:
                if lst[0][2]!=max(c-abs(a-lst[k][1])-abs(b-lst[k][2])):
                    break
                if k==n-1:
                    flag=True
                    print(i,j,H)
                    break

Submission status: Runtime Error

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())

# C_xとC_yを10000通り全探索してH-hが全式で同じ値のものを出力
for C_x in range(101):
    for C_y in range(101):
        same_H_count = 0
        for i in range(N):
            if h[i] > 0:
                tmp_H = abs(x[i] - C_x) + abs(y[i] - C_y) + h[i]
                if i == 0:
                    H = tmp_H
                    same_H_count += 1
                else:
                    if H == tmp_H:
                        same_H_count += 1
                        if same_H_count == N:
                            print(C_x, C_y, H)
                        continue
                    else:
                        break

Submission status: Runtime Error

Solution code:
N = int(input())
x, y, h = map(int, input().split())
candidates = {(X, Y, h + abs(X - x) + abs(Y - y))
              for X in range(0, 101) for Y in range(0, 101)}
for _ in range(N - 1):
    x, y, h = map(int, input().split())
    bad = set()
    for p in candidates:
        X, Y, H = p
        if h + abs(X - x) + abs(Y - y) != H:
            bad.add(p)
    candidates -= bad
print("{} {} {}".format(*candidates.pop()))

Submission status: Runtime Error

Solution code:
N = int(input())
x = []
y = []
h = []
for _ in range(N):
    tmp = [int(i) for i in input().split()]
    if tmp[2] == 0:
        continue
    x.append(tmp[0])
    y.append(tmp[1])
    h.append(tmp[2])

for Cx in range(100 + 1):
    for Cy in range(100 + 1):
        correct_flag = True
        H = abs(x[0] - Cx) + abs(y[0] - Cy) + h[0]
        for i in range(1, N):
            if abs(x[i] - Cx) + abs(y[i] - Cy) + h[i] != H:
                correct_flag = False
                break
        if correct_flag:
            print(Cx, Cy, H)
            break

Submission status: Runtime Error

Solution code:
N = int(input())
x = []
y = []
h = []
for _ in range(N):
    tmp = [int(i) for i in input().split()]
    if tmp[2] == 0:
        continue
    x.append(tmp[0])
    y.append(tmp[1])
    h.append(tmp[2])

for Cx in range(100 + 1):
    for Cy in range(100 + 1):
        correct_flag = True
        H = abs(x[0] - Cx) + abs(y[0] - Cy) + h[0]
        for i in range(1, N):
            if abs(x[i] - Cx) + abs(y[i] - Cy) + h[i] != H:
                correct_flag = False
                break
        if correct_flag:
            print(Cx, Cy, H)
            break
    if correct_flag:
        break

Submission status: Runtime Error

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

def judge(Cx,Cy):
    x0,y0,h0 = info[0]
    pH = abs(x0-Cx) + abs(y0-Cy) + h0
    for x, y, h in info:
        H = abs(x-Cx) + abs(y-Cy) + h
        if h == 0:
            if not H <= 0:
                return
        elif H != pH:
            return
        pH = H
    global ans
    ans = [Cx,Cy,H]
    
for Cx in range(101):
    for Cy in range(101):
        judge(Cx,Cy)

print(*ans)

Submission status: Runtime Error

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

def judge(Cx,Cy):
    x0,y0,h0 = info[0]
    pH = abs(x0-Cx) + abs(y0-Cy) + h0
    for x, y, h in info:
        if h == 0: continue
        H = abs(x-Cx) + abs(y-Cy) + h
        if H != pH:
            return
        pH = H
    global ans
    ans = [Cx,Cy,H]
    
for Cx in range(101):
    for Cy in range(101):
        judge(Cx,Cy)

print(*ans)

Submission status: Runtime Error

Solution code:
N = int(input())
 
x = []
y = []
h = []
for i in range(N):
    x_, y_, h_ = map(int, input().split())
    x.append(x_)
    y.append(y_)
    h.append(h_)
"""
for i in range(0,101):
    for j in range(0,101):
        for n, hn in enumerate(h):
            if hn > 0:
                tmph = hn + abs(i-x[n]) + abs(j-y[n])
                break
        count = 0
        for n in range(N):
            count += 1
            if h[n] != max(tmph - abs(i-x[n]) - abs(j-y[n]), 0):
                break
            if count == N:
                print(str(i) + ' ' + str(j) + ' ' + str(tmph))

Submission status: Runtime Error

Solution code:
from sys import stdin
import sys
N=int(stdin.readline().rstrip())
data=[]
for i in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
 
cnt=1
for X in range(0,101):
    for Y in range(0,101):
        for data_ in data:
            if data_[2] == 0:
                cnt+=1
                continue
            H = data_[2] + abs(X-data_[0]) + abs(Y-data_[1])
            if H == h_log:
                cnt+=1
            h_log = H
            
        if cnt == N:
            break
        
        cnt=1
    else:
        continue
    break
    
print(X,Y,H)

Submission status: Runtime Error

Solution code:
N = int(input())

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

for i in range(0,101):
    for j in range(0,101):
        for hn in h:
            if hn > 0:
                tmph = hn + abs(i-x[n]) + abs(j-y[n])
                break
        count = 0
        for n in range(N):
            count += 1
            if h[n] != max(tmph - abs(i-x[n]) - abs(j-y[n]), 0):
                break
            if count == N:
                print(str(i) + ' ' + str(j) + ' ' + str(tmph))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
C - Pyramid
https://atcoder.jp/contests/abc112/tasks/abc112_c

"""
import sys


def solve(N, positions):
    if N == 1:
        return positions[0]
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[0]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[1:]:
                hh = max(ph - abs(cy-y) - abs(cx-x), 0)
                if hh != h:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)


def main(args):
    N = int(input())
    positions = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, positions)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
C - Pyramid
https://atcoder.jp/contests/abc112/tasks/abc112_c

"""
import sys


def solve(N, positions):
    if N == 1:
        return positions[0]
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[0]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[1:]:
                hh = h + abs(cy-y) + abs(cx-x)
                if hh != ph:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)

def main(args):
    N = int(input())
    positions = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, positions)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
C - Pyramid
https://atcoder.jp/contests/abc112/tasks/abc112_c

"""
import sys


def solve(N, positions):
    for cy in range(101):
        for cx in range(101):
            is_valid = True
            x, y, h = positions[0]
            ph = h + abs(cy-y) + abs(cx-x)
            for x, y, h in positions[1:]:
                hh = h + abs(cy-y) + abs(cx-x)
                if hh != ph:
                    is_valid = False
                    break
            if is_valid:
                return (cx, cy, ph)


def main(args):
    N = int(input())
    positions = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, positions)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

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

N = int(input())
A = [[0] * 3 for i in range(N)]
for a in A:
    a[0], a[1], a[2] = list(map(int, input().split()))


def calc(A):
    for x in range(101):
        for y in range(101):
            h_spots = [0] * N
            for i, a in enumerate(A):
                h_spots[i] = a[2] + abs(x - a[0]) + abs(y - a[1])

            if min(h_spots) == max(h_spots):
                return x, y, h_spots[0]


print(*calc(A))

Submission status: Runtime Error

Solution code:
n=int(input())
XYH=[]
for i in range(n):
  x,y,h=map(int,input().split())
  XYH.append([x,y,h])
XYH.sort(key=lambda x:x[2])
for i in range(101):
  for j in range(101):
    peak=abs(i-XYH[0][0])+abs(j-XYH[0][1])+XYH[0][2]
    flag=1
    for k in range(1,n):
      if max(0,peak-abs(i-XYH[k][0])-abs(j-XYH[k][1]))!=XYH[k][2]:
        flag=0
    if flag==1:
      Ans=[i,j,peak]
print(*Ans)

Submission status: Runtime Error

Solution code:
import itertools
N=int(input())
l=[]
#l:調査情報のリスト
M=max(item[2] for item in l)
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))
#s:中心座標の候補リスト
for A,B in itertools.combinations(range(N),2):
  #調査情報の全ての2つ組を用いて絞り込む
  if len(s)==1:
    break
  t=[]
  #t:新たな中心座標の候補リスト
  if l[A][2]<l[B][2]:
    A,B=B,A
  if l[A][2]>l[B][2]:
    #2地点の高さが異なる場合
    if l[B][2]==0:
      #B地点の高さが0ならB地点は中心から[Aの高さ]以上離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap<=abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
    else:
      #B地点の高さが0でなければA地点は中心から[Aの高さ-Bの高さ]だけ離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap==abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
  
  elif l[A][2]!=0:
    #2地点の高さが等しく0ではない場合
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  else:
    #2地点の高さが等しく0の場合
    #2地点が中心ではない
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>=M and abs(X-l[B][0])+abs(Y-l[B][1])>=M:
        t.append((X,Y))
  s=t[:]
#sの要素は唯一だと思いたい
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
for cx in range(101):
    for cy in range(101):
        ll=[]
        flag=True
        for i in range(n):
            H=l[i][2]+abs(l[i][0]-cx)+abs(l[i][1]-cy)
            ll.append(H)
            if i!=0 and all(ll[j]!=ll[j-1] for j in range(1,i):
                flag=False
                break
        if flag:
            print(cx,cy,H)
            break

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
for cx in range(101):
    for cy in range(101):
        ll=[]
        flag=True
        for i in range(n):
            H=l[i][2]+abs(l[i][0]-cx)+abs(l[i][1]-cy)
            ll.append(H)
            if i!=0 and all(ll[j]!=ll[j-1] for j in range(i):
                flag=False
                break
        if flag:
            print(cx,cy,H)
            break

Submission status: Runtime Error

Solution code:
N = int(input())
C = []
for i in range(N):
    x, y, h = map(int,input().split())
    for CX in range(101):
        for CY in range(101):
            for H in range(201):

                saX = abs(CX - x)
                saY = abs(CY - y)
                sa = saX + saY
                if h == H - sa:
                    C.append([CX, CY, H])
ans = [v for v in C if C.count(v) == N]
print(ans[0][0], ans[0][1], ans[0][2])

Submission status: Runtime Error

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

xyhs = sorted(xyhs, key=lambda v: v[2], reverse=True)

anss = []
for y in range(101):
    for x in range(101):
        x0, y0, h0 = xyhs[0]
        ht = h0 + abs(x0 - x) + abs(y0 - y)

        flag = True
        for xyh in xyhs[1:]:
            xi, yi, hi = xyh
            his = ht - abs(xi - x) - abs(yi - y)
            if his != hi:
                flag = False
                break

        if flag:
            anss.append((x, y, ht))

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

Submission status: Runtime Error

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

xyhs = sorted(xyhs, key=lambda v: v[2], reverse=True)

anss = []
for y in range(101):
    for x in range(101):
        x0, y0, h0 = xyhs[0]
        ht0 = h0 + abs(x0 - x) + abs(y0 - y)

        flag = True
        for xyh in xyhs[1:]:
            xi, yi, hi = xyh
            hti = hi + abs(xi - x) + abs(yi - y)
            if hti != ht0:
                flag = False
                break

        if flag:
            anss.append((x, y, ht0))

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

Submission status: Runtime Error

Solution code:
import collections
#入力
N = int(input())

dp = [[None]* 101 for _ in range(101)] #101×101の盤面
check = [[None]* 101 for _ in range(101)] #101×101の盤面　重ね合わせた結果に利用
#print (dp)
lst = []
for i in range(N):
    x, y, z = map(int, input().split())
    lst += [[x, y, z]]

#print (lst)
#print (dp)

move = [[-1,0], [1, 0], [0, -1],[0, 1]]
def bfs(x, y, h):
    if h == 0:
        return 0
    dp2 = [[-1]* 101 for _ in range(101)] #101×101の盤面　bfsするときに訪れたかどうかの判定に利用
    dp2[x][y] = h #bfsのスタート地点を記入
    if check[x][y] == None: #重ね合わせた結果が入っていない場合、記録する
        check[x][y] = h
    elif dp2[x][y] != check[x][y]:
        check[x][y] = -10
    #print ('check', check)
    q = collections.deque()
    q.append([x, y]) #スタート地点をqueueに記録
    #print (q)
    while True: #常にループ
        #print ('True') 
        if not q: #dequeが空になっていたら終わる
            #print (q)
            #print ('dp2', dp2)
            return 'B'
        else: #deque内に要素が入っているとき
            px, py = q.popleft() #要素を1組取り出す
            for dx, dy in move:
                nx = px + dx
                ny = py + dy
                if 0 <= nx and nx <101 and 0 <= ny and ny < 101: #範囲内の確認
                    if dp2[nx][ny] == -1: #初めて訪れる時
                        if check[nx][ny] == None: #checkが入っていないとき
                            check[nx][ny] = dp2[px][py] + 1 #移動前のマス+1が移動先の値
                            dp2[nx][ny] = dp2[px][py] + 1 #移動前のマス+1が移動先の値
                            q.append([nx, ny]) #移動先の地点を表す組をdequeに記録
                            #print (check)
                            #print ('C')
                        else: #checkが入っているとき
                            #print ('D')
                            dp2[nx][ny] = dp2[px][py] + 1
                            if dp2[nx][ny] == check[nx][ny]: #今回求めたdp2と記録されているcheckが等しい時
                                #print ('(nx, ny)', nx, ny)
                                pass
                            else: #一致しない時
                                check[nx][ny] = -10
                            q.append([nx, ny])
    return 'A'

def bfs2(x, y, h):
    dp2 = [[-1]* 101 for _ in range(101)] #101×101の盤面　bfsするときに訪れたかどうかの判定に利用
    dp2[x][y] = h #bfsのスタート地点を記入
    if check[x][y] == None: #重ね合わせた結果が入っていない場合、記録する
        check[x][y] = h
    elif dp2[x][y] != check[x][y]:
        check[x][y] = -10
    #print ('check', check)
    q = collections.deque()
    q.append([x, y]) #スタート地点をqueueに記録
    #print (q)
    while True: #常にループ
        #print ('True') 
        if not q: #dequeが空になっていたら終わる
            #print (q)
            #print ('dp2', dp2)
            return 'B'
        else: #deque内に要素が入っているとき
            px, py = q.popleft() #要素を1組取り出す
            for dx, dy in move:
                nx = px + dx
                ny = py + dy
                if 0 <= nx and nx <101 and 0 <= ny and ny < 101: #範囲内の確認
                    if dp2[nx][ny] == -1: #初めて訪れる時
                        if check[nx][ny] == None: #checkが入っていないとき
                            check[nx][ny] = dp2[px][py] + 1 #移動前のマス+1が移動先の値
                            dp2[nx][ny] = dp2[px][py] + 1 #移動前のマス+1が移動先の値
                            q.append([nx, ny]) #移動先の地点を表す組をdequeに記録
                            #print (check)
                            #print ('C')
                        else: #checkが入っているとき
                            #print ('D')
                            dp2[nx][ny] = dp2[px][py] + 1
                            if dp2[nx][ny] == check[nx][ny]: #今回求めたdp2と記録されているcheckが等しい時
                                #print ('(nx, ny)', nx, ny)
                                pass
                            else: #一致しない時
                                check[nx][ny] = -10
                            q.append([nx, ny])
    return 'A'

#print (bfs(59, 3, 0))
#print (bfs(64, 94, 56))
#print (bfs(5, 62, 11))
#print (bfs(3, 93, 14))

for h in range(N):
    a, b, c = lst[h]
    bfs2(a, b, c)
    #print (check)

ans = -1
ans_x = -1
ans_y = -1
for i in range(101):
    for j in range(101):
        if ans < check[i][j]:
            ans = max(ans, check[i][j])
            ans_x, ans_y = i, j

if ans_x != -1 and ans__y != -1:
    print (ans_x, ans_y, ans)
else:
    for h in range(N):
        a, b, c = lst[h]
        bfs(a, b, c)
        for i in range(101):
            for j in range(101):
                if ans < check[i][j]:
                    ans = max(ans, check[i][j])
                    ans_x, ans_y = i, j
    print (ans_x, ans_y, ans)
#print (check)

Submission status: Runtime Error

Solution code:
import collections
#入力
N = int(input())

dp = [[0]* 101 for _ in range(101)] #101×101の盤面
check = [[None]* 101 for _ in range(101)] #101×101の盤面　重ね合わせた結果に利用
#print (dp)
lst = []
for i in range(N):
    x, y, z = map(int, input().split())
    lst += [[x, y, z]]
    dp[x][y] = z

#print (lst)
#print (dp)

move = [[-1,0], [1, 0], [0, -1],[0, 1]]
def bfs(x, y, h):
    dp2 = [[-1]* 101 for _ in range(101)] #101×101の盤面　bfsするときに訪れたかどうかの判定に利用
    dp2[x][y] = h #bfsのスタート地点を記入
    if check[x][y] == None: #重ね合わせた結果が入っていない場合、記録する
        check[x][y] = h
    elif dp2[x][y] != check[x][y]:
        check[x][y] = -10
    #print ('check', check)
    q = collections.deque()
    q.append([x, y]) #スタート地点をqueueに記録
    #print (q)
    while True: #常にループ
        #print ('True') 
        if not q: #dequeが空になっていたら終わる
            #print (q)
            #print ('dp2', dp2)
            return 'B'
        else: #deque内に要素が入っているとき
            px, py = q.popleft() #要素を1組取り出す
            for dx, dy in move:
                nx = px + dx
                ny = py + dy
                if 0 <= nx and nx <101 and 0 <= ny and ny < 101: #範囲内の確認
                    if dp2[nx][ny] == -1: #初めて訪れる時
                        if check[nx][ny] == None: #checkが入っていないとき
                            check[nx][ny] = dp2[px][py] + 1 #移動前のマス+1が移動先の値
                            dp2[nx][ny] = dp2[px][py] + 1 #移動前のマス+1が移動先の値
                            q.append([nx, ny]) #移動先の地点を表す組をdequeに記録
                            #print (check)
                            #print ('C')
                        else: #checkが入っているとき
                            #print ('D')
                            dp2[nx][ny] = dp2[px][py] + 1
                            if dp2[nx][ny] == check[nx][ny]: #今回求めたdp2と記録されているcheckが等しい時
                                #print ('(nx, ny)', nx, ny)
                                pass
                            else: #一致しない時
                                check[nx][ny] = -10
                            q.append([nx, ny])
    return 'A'

#print (bfs(2, 3, 5))
#print (bfs(2, 1, 5))
#print (bfs(1, 2, 5))
#print (bfs(3, 2, 5))

for h in range(N):
    a, b, c = lst[h]
    bfs(a, b, c)

ans = 0
for i in range(101):
    for j in range(101):
        if ans < check[i][j]:
            ans = max(ans, check[i][j])
            ans_x, ans_y = i, j

print (ans_x, ans_y, ans)
#print (check)

Submission status: Runtime Error

Solution code:
n = int(input())
s_list = []
ans = 0
zero_list = []
for _ in range(n):
    x, y, s = map(int, input().split())
    if s > 0:
        s_list.append([x, y, s])
    else:
        zero_list.append([x, y, s])
for x in range(101):
    for y in range(101):
        t = []
        for i in range(len(s_list)):
            x_, y_, h = s_list[i]
            if h > 0:
                t.append(h + abs(x_ - x) + abs(y_ - y))
        if (len(set(t)) == 1):
            zero_p = max([list(t)[0] - abs(x - x_zero) - abs(y - y_zero) for (x_zero, y_zero, s_zero) in zero_list])
            if zero_p <= 0:
                ttt = h + abs(x_ - x) + abs(y_ - y)
                ans = str(x) + " " + str(y) + " " + str(ttt)
                break
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s_list = []
ans = 0
zero_list = []
for _ in range(n):
    x, y, s = map(int, input().split())
    if s > 0:
        s_list.append([x, y, s])
    else:
        zero_list.append([x, y, s])
for x in range(101):
    for y in range(101):
        t = []
        for i in range(n):
            x_, y_, h = s_list[i]
            if h > 0:
                t.append(h + abs(x_ - x) + abs(y_ - y))
        if (len(set(t)) == 1):
            zero_p = max([list(t)[0] - abs(x - x_zero) - abs(y - y_zero) for (x_zero, y_zero, s_zero) in zero_list])
            if zero_p <= 0:
                ttt = h + abs(x_ - x) + abs(y_ - y)
                ans = str(x) + " " + str(y) + " " + str(ttt)
                break
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

n = int(input())


def rec_dd():
    return defaultdict(rec_dd)


hd = rec_dd()
x0, y0, h0 = list(map(int, input().split()))
for xi in range(101):
    for yi in range(101):
        hd[xi][yi] = h0 + abs(x0 - xi) + abs(y0 - yi)

ans = 0
for _ in range(n - 1):
    x, y, h = list(map(int, input().split()))
    for xi in hd.keys():
        for yi in hd[xi].keys():
            if h == hd[xi][yi] - abs(x - xi) - abs(y - yi):
                ans = (xi, yi, hd[xi][yi])
            else:
                hd[xi][yi] = 0

for e in ans:
    print(e, end=" ")

Submission status: Runtime Error

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

li.sort(key=lambda x: x[2])
a, b, c = li[-1]

for x in range(101):
    for y in range(101):
        h=c+abs(a-x)+abs(b-y)
        if all(k==max(h-abs(i-x)-abs(j-y),0) for i,j,k in li):
        print(x,y,h)
        exit()