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:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(input = sys.stdin.readline):
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    N = II()
    
    MAXL = 101
    b = [[0] * MAXL for _ in range(MAXL)]

    def vtop(x1,x2,y1,y2,h1):
        return h1 + abs(x1-x2) + abs(y1-y2)
    h = 0
    while h == 0:
        x,y,h = LMIIS()
        if h == 0:
            continue
        for i in range(MAXL):
            for j in range(MAXL):
                b[i][j] = vtop(x,j,y,i,h)

    for _ in range(N-1):
        x,y,h = LMIIS()
        if h == 0:
            continue
        for i in range(MAXL):
            for j in range(MAXL):
                if b[i][j] != -1 and b[i][j] != vtop(x,j,y,i,h):
                    b[i][j] = -1
    for i in range(MAXL):
        for j in range(MAXL):
            if b[i][j] != -1 and b[i][j] < 10**9:
                print(j,i,b[i][j])
                return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
xy = [[i, j] for i in range(101) for j in range(101)]

def md(x1, x2):
  return abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])
        
infos = []
for i in range(n):
  info = list(map(int, input().split()))
  infos.append(info)
  
  if infos[i][2] == 0:
    xy.remove(infos[i][0], infos[i][1])
  
  if i != 0:
    for j in range(i):
      if infos[j][0] != 0:
        dh = infos[i][2] - infos[j][2]
        xy = list(filter(lambda x: md(x, infos[j][:2]) - md(x, infos[i][:2]) == dh, xy))
      
  if len(xy) == 1:    
    break

    
x = xy[0][0]
y = xy[0][1]
k = 0
for i in range(n):
  if infos[i][2] > 0:
    k = i
    break
h = md(infos[k][:2], [x, y]) + infos[k][2]
print('{} {} {}'.format(x, y, h))

Submission status: Runtime Error

Solution code:
n = int(input())
xy = [[i, j] for i in range(101) for j in range(101)]

def md(x1, x2):
  return abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])
        
infos = []
for i in range(n):
  info = list(map(int, input().split()))
  infos.append(info)
  
  if i != 0:
    for j in range(i):
      if infos[j][0] != 0:
        dh = infos[i][2] - infos[j][2]
        xy = list(filter(lambda x: md(x, infos[j][:2]) - md(x, infos[i][:2]) == dh, xy))
      
  if len(xy) == 1:    
    break

    
x = xy[0][0]
y = xy[0][1]
k = 0
for i in range(n):
  if infos[i][2] > 0:
    k = i
    break
h = md(infos[k][:2], [x, y]) + infos[k][2]
print('{} {} {}'.format(x, y, h))

Submission status: Runtime Error

Solution code:
n = int(input())
xy = [[i, j] for i in range(101) for j in range(101)]

def md(x1, x2):
  return abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])
        
infos = []
for i in range(n):
  info = list(map(int, input().split()))
  infos.append(info)
  if i != 0:
    for j in range(i):
      dh = infos[i][2] - infos[j][2]
      xy = list(filter(lambda x: md(x, infos[j][:2]) - md(x, infos[i][:2]) == dh, xy))    
  if len(xy) == 1:    
    break

x = xy[0][0]
y = xy[0][1]
k = 0
for i in range(n):
  if infos[i][2] > 0:
    k = i
    break
h = md(infos[k][:2], [x, y]) + infos[k][2]
print('{} {} {}'.format(x, y, h))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
pira = [[] for i in range(N)]
ans = [0,0,0]
a = False
for i in range(N):
	pira[i] = list(map(int, input().split()))
tmp = 0

for i in range(len(pira)):
	if pira[i][2] == 0:
		continue
	else:
		tmp = pira[i][2] + abs(pira[i][0]-x) + abs(pira[i][1]-y)

for x in range(101):
	for y in range(101):
		for i in range(1,len(pira)):
			if pira[i][2] == 0:
				continue
			if tmp != pira[i][2] + abs(pira[i][0]-x) + abs(pira[i][1]-y):
				a = False
				# ans = [0,0,0]
				break
			else:
				a = True
				ans = [x,y,tmp]
		if a:
			break
	if a:
		break

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

Submission status: Runtime Error

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

H=0
cx, cy=0,0
judge=False
for i in range(101):
    for j in range(101):
        H=0
        for k in xyh:
            if H==0:
                H=abs(i-k[0])+abs(j-k[1])+k[2]
            else:
                if H!=abs(i-k[0])+abs(j-k[1])+k[2] and 0<abs(i-k[0])+abs(j-k[1])+k[2]:
                    break
            if k==xyh[n-1]:
                judge=True
                cx,xy=i,j
        if judge:
            break
    if judge:
        break

print(cx, end=" ")
print(xy, end=" ")
print(H, end=" ")

Submission status: Runtime Error

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

H=0
cx, cy=0,0
judge=False
for i in range(101):
    for j in range(101):
        H=0
        for k in xyh:
            if H==0:
                H=abs(i-k[0])+abs(j-k[1])+k[2]
            else:
                if H!=abs(i-k[0])+abs(j-k[1])+k[2] and 0<abs(i-k[0])+abs(j-k[1])+k[2]:
                    break
            if k==xyh[n-1]:
                judge=True
                cx,xy=i,j
        if judge:
            break
    if judge:
        break

print(cx, end=" ")
print(xy, end=" ")
print(h, end=" ")

Submission status: Runtime Error

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

H=0
cx, cy=0,0
judge=False
for i in range(101):
    for j in range(101):
        H=0
        for k in xyh:
            if k[2]==0:
                continue
            if H==0:
                h=abs(i-k[0])+abs(j-k[1])+k[2]
                H+=h
            else:
                h=abs(i-k[0])+abs(j-k[1])+k[2]
            if h!=H:
                break
            if k==xyh[n-1]:
                judge=True
                cx,xy=i,j
        if judge:
            break
    if judge:
        break

print(cx, end=" ")
print(xy, end=" ")
print(h, end=" ")

Submission status: Runtime Error

Solution code:
N = int(input())
XYHs = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        XYHs.append((x, y, h))


def height(i):
    return abs(XYHs[i][0] - cx) + abs(XYHs[i][1] - cy) + XYHs[i][2]


for cx in range(101):
    for cy in range(101):
        H = height(0)
        for i in range(1, N):
            if height(i) != H:
                break
        else:
            print("%d %d %d" % (cx, cy, H))
            break
    else:
        continue
    break

Submission status: Runtime Error

Solution code:
N = int(input())
XYHs = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        XYHs.append((x, y, h))


def height(i):
    return abs(XYHs[i][0] - cx) + abs(XYHs[i][1] - cy) + XYHs[i][2]


for cx in range(101):
    for cy in range(101):
        H = height(0)
        for i in range(1, N):
            if height(i) != H:
                sw = False
                break
        else:
            print("%d %d %d" % (cx, cy, H))
            break
    else:
        continue
    break

Submission status: Runtime Error

Solution code:
N = int(input())
XYHs = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        XYHs.append((x, y, h))


def height(i):
    return abs(XYHs[i][0] - cx) + abs(XYHs[i][1] - cy) + XYHs[i][2]


for cx in range(101):
    for cy in range(101):
        H = height(0)
        for i in range(1, N):
            if height(i) != H:
                sw = False
                break
        else:
            print("%d %d %d" % (cx, cy, H))
            s = True
            exit(1)

Submission status: Runtime Error

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


def height(i):
    return abs(XYHs[i][0] - cx) + abs(XYHs[i][1] - cy) + XYHs[i][2]


for cx in range(101):
    for cy in range(101):
        H = height(0)
        for i in range(1, N):
            if height(i) != H:
                sw = False
                break
        else:
            print("%d %d %d" % (cx, cy, H))
            s = True
            exit(1)

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
lst=[]
for i in range(n):
  x,y,h=map(int,input().split())
  lst.append([x,y,h])
  
for j in range(101):
  for k in range(101):
    for i in range(n):
      H=abs(j-lst[i][0])-abs(k-lst[i][1])+lst[i][2]
      if H>0:
        if all(max(H-abs(j-lst[l][0])-abs(k-lst[l][1]),0)==h[l] for l in range(n)):
          print([j,k,H])
          sys.exit()

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
lst=[]
for i in range(n):
  x,y,h=map(int,input().split())
  lst.append([x,y,h])
def pita(a,b,c,d):
  return abs(a-b)+abs(c-d)
hm=float'inf'
for l in range(n):
  for j in range(101):
    for k in range(101):
      if lst[l][2]-pita(lst[l][0],j,lst[l][1],k)<=0:
        hm=min(hm,pita(lst[l][0],j,lst[l][1],k))
for l in range(hm+1):
  for j in range(101):
    for k in range(101):
      if lst[l][2]-pita(lst[l][0],j,lst[l][1],k)==0:
        print(j,k,lst[l][2])
        sys.exit()

Submission status: Runtime Error

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

H=0
cx, cy=0,0
judge=False
for i in range(101):
    for j in range(101):
        H=0
        for k in xyh:
            if k[2]==0:
                break
            if H==0:
                h=abs(i-k[0])+abs(j-k[1])+k[2]
                H+=h
            else:
                h=abs(i-k[0])+abs(j-k[1])+k[2]
            if h!=H:
                break
            if k==xyh[n-1]:
                judge=True
                cx,xy=i,j
        if judge:
            break
    if judge:
        break

print(cx, end=" ")
print(xy, end=" ")
print(h, end=" ")

Submission status: Runtime Error

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

H=0
cx, cy=0,0
judge=False
for i in range(101):
    for j in range(101):
        H=0
        for k in xyh:
            if H==0:
                h=abs(i-k[0])+abs(j-k[1])+k[2]
                H+=h
            else:
                h=abs(i-k[0])+abs(j-k[1])+k[2]
            if h!=H:
                break
            if k==xyh[n-1]:
                judge=True
                cx,xy=i,j
        if judge:
            break
    if judge:
        break

print(cx, end=" ")
print(xy, end=" ")
print(h, end=" ")

Submission status: Runtime Error

Solution code:
def calc_h(cx,cy,xyh_item):
  return(abs(cx-xyh_item[0])+abs(cy-xyh_item[1])+xyh_item[2])

n=int(input())
xyh=[[int(x) for x in input().split()] for _ in range(n)]
xyh=[item for item in xyh if item[2]!=0]

anslist=[]

for x in range(101):
  for y in range(101):
    c=0
    tmp=calc_h(x,y,xyh[0])
    for i in range(1,n):
      if tmp!=calc_h(x,y,xyh[i]):
        break
      else:
        c+=1
    anslist.append([c,x,y,tmp])

anslist.sort(key=lambda x:x[0])
print(*anslist[-1][1:])

Submission status: Runtime Error

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

List = []
for Cx in range(101):
    for Cy in range(101):
        tmp_h = Height[-1]+abs((Cx-X[-1]))+abs((Cy-Y[-1]))
        if tmp_h >= 1:
            List.append([Cx,Cy,tmp_h])
    
#1個目のx,y,hからCx,Cy,Hの候補を作り(List)，他のx,y,hは候補と照らし合わせながら答えを探す．
#制約が小さいからできる全探索

for i in range(1,N-1):
    for j in List[:]:
        if Height[i] == max(j[2]-abs(X[i]-j[0])-abs(Y[i]-j[1]),0):
            continue
        else:
            List.remove(j)

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

Submission status: Runtime Error

Solution code:
N = int(input())
X = []
Y = []
Height =[] 
for i in range(N):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    Height.append(h)
List = []
for Cx in range(101):
    for Cy in range(101):
        tmp_h = Height[0]+abs((X[0]-Cx))+abs((Y[0]-Cy))
        if tmp_h >= 1:
            List.append([Cx,Cy,tmp_h])

#1個目のx,y,hからCx,Cy,Hの候補を作り(List)，他のx,y,hは候補と照らし合わせながら答えを探す．
#制約が小さいからできる全探索

for i in range(1,N):
    for j in List[:]:
        if Height[i] == max(j[2]-abs((X[i]-j[0]))-abs((Y[i]-j[1])),0):
            continue
        else:
            List.remove(j)
print(List[0][0],List[0][1],List[0][2])

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
  n = int(input())
  x,y,z = [0]*n,[0]*n,[0]*n
  # ３点h>=に点があれば一意に求まる
  count = 0
  xyh = [[],[],[]]
  #print(xyh)
  for i in range(n):
    x[i],y[i],z[i] = map(int,input().split())
    #if z[i] != 0 and count < 3:
    if z[i] != 0:
      xyh[count].append(x[i])
      xyh[count].append(y[i])
      xyh[count].append(z[i])
      #print(xyh)
      count += 1
  #print(xyh)
  x,y,h = 0,0,0
  pass_ = 0
  #print(count)
  for i in range(101):
    for j in range(101): # x,y の座標を定める
      h = abs(i-xyh[0][0])+abs(j-xyh[0][1]) + xyh[0][2]
      for k in range(count):
        if h - abs(i-xyh[k][0])-abs(j-xyh[k][1]) - xyh[k][2] == 0:
          if k == count -1:
            print(i,j,h)
            exit(0)
        else:
          break

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
  n = int(input())
  x,y,z = [0]*n,[0]*n,[0]*n
  # ３点h>=に点があれば一意に求まる
  count = 0
  xyh = [[],[],[]]
  #print(xyh)
  for i in range(n):
    x[i],y[i],z[i] = map(int,input().split())
    #if z[i] != 0 and count < 3:
    if z[i] != 0:
      xyh[count].append(x[i])
      xyh[count].append(y[i])
      xyh[count].append(z[i])
      #print(xyh)
      count += 1
  #print(xyh)
  x,y,h = 0,0,0
  pass_ = 0
  #print(count)
  for i in range(101):
    for j in range(101): # x,y の座標を定める
      h = abs(i-xyh[0][0])+abs(j-xyh[0][1]) + xyh[0][2]
      for k in range(count):
        if h - abs(i-xyh[k][0])-abs(j-xyh[k][1]) - xyh[k][2] == 0:
          if k == count -1:
            print(i,j,h)
            exit(0)
        else:
          break
      
      
      '''if count == 3:
        if h - abs(i-xyh[1][0])-abs(j-xyh[1][1]) - xyh[1][2] == 0 and h - abs(i-xyh[2][0])-abs(j-xyh[2][1]) - xyh[2][2] == 0:
          pass_ = 1
          x,y = i,j
          break
      
      if count == 2:
        if h - abs(i-xyh[1][0])-abs(j-xyh[1][1]) - xyh[1][2] == 0 :
          pass_ = 1
          x,y = i,j
          break
      if count == 1:
        pass_ == 1
    if pass_ == 1:
      break''' 
  #print(x,y,h)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
  n = int(input())
  x,y,z = [0]*n,[0]*n,[0]*n
  # ３点h>=に点があれば一意に求まる
  count = 0
  xyh = [[],[],[]]
  #print(xyh)
  for i in range(n):
    x[i],y[i],z[i] = map(int,input().split())
    if z[i] != 0 and count < 3:
      xyh[count].append(x[i])
      xyh[count].append(y[i])
      xyh[count].append(z[i])
      #print(xyh)
      count += 1
  #print(xyh)
  x,y,h = 0,0,0
  pass_ = 0
  for i in range(101):
    for j in range(101): # x,y の座標を定める
      h = abs(i-xyh[0][0])+abs(j-xyh[0][1]) + xyh[0][2]
      if count == 3:
        if h - abs(i-xyh[1][0])-abs(j-xyh[1][1]) - xyh[1][2] == 0 and h - abs(i-xyh[2][0])-abs(j-xyh[2][1]) - xyh[2][2] == 0:
          pass_ = 1
          x,y = i,j
          break
      
      if count == 2:
        if h - abs(i-xyh[1][0])-abs(j-xyh[1][1]) - xyh[1][2] == 0 :
          pass_ = 1
          x,y = i,j
          break
	  if count == 1:
        pass_ = 1
    if pass_ == 1:
      break 
  print(x,y,h)

Submission status: Runtime Error

Solution code:
N = int(input())
ls = []
for i in range(N):
  x,y,h = map(int, input().split())
  ls += [(x,y,h)]
ls.sort(key=lambda x:x[2])
px, py, ph = ls[-1]

ans = []
for i in range(101):
  for j in range(101):
    H = ph+abs(px-i)+abs(py-j)
    for l in ls:
      x, y, h = l
      u = max(H - abs(x-i) - abs(y-j), 0)
      if not u==h:
        break
    else:
      ans = (i,j,H)
      flag = True
      break
  if flag:
    break
print(*ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ls = []
for i in range(N):
  x,y,h = map(int, input().split())
  ls += [(h,x,y)]
ls.sort(key=lambda x:x[2])
px, py, ph = ls[-1]

ans = []
for i in range(101):
  for j in range(101):
    pH = ph+abs(px-i)+abs(py-j)
    for l in ls:
      h, x, y = l
      u = max(pH - abs(x-i) - abs(y-j), 0)
      if not u==h:
        break
    else:
      ans = (i,j,pH)
      flag = True
      break
  if flag:
    break
print(*ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ls = []
for i in range(N):
  x,y,h = map(int, input().split())
  ls += [(h,x,y)]
ls.sort(key=lambda x:x[2])
px, py, ph = ls[-1]

ans = []
for i in range(101):
  for j in range(101):
    pH = ph+abs(px-i)+abs(py-j)
    for l in ls:
      h, x, y = l
      u = pmax(H - abs(x-i) - abs(y-j), 0)
      if not u==h:
        break
    else:
      ans = (i,j,pH)
      break
  if ans:
    break
print(*ans)

Submission status: Runtime Error

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


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

H = 0
pH = -1
ansh = 0
log = []
na = []
for a in ans:
  i, j = a
  pH = -1
  for l in ls:
    h, x, y = l
    if h>0:
      H = h+abs(x-i)+abs(y-j)
      if pH==-1:
        pH = H
      elif not H==pH:
        break
    else:
      log += [a]
  else:
    na += [(a,H)]
ans = 0
for a in na:
  i,j = a[0]
  H = a[1]
  for l in log:
    h,x,y = l
    h = H-abs(x-i)-abs(y-j)
    if max(h,0)>0:
      break
  else:
    ans = a
    break
x, y = ans
print(x, y, H)

Submission status: Runtime Error

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


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

H = 0
pH = -1
ansh = 0
log = []
na = []
for a in ans:
  i, j = a
  pH = -1
  for l in ls:
    h, x, y = l
    if h>0:
      H = h+abs(x-i)+abs(y-j)
      if pH==-1:
        pH = H
      elif not H==pH:
        break
    else:
      log += [a]
  else:
    na += [a]
ans = 0
for a in na:
  i,j = a
  for l in log:
    h,x,y = l
    h = H-abs(x-i)-abs(y-j)
    if max(h,0)>0:
      break
  else:
    break
x, y = a
print(x, y, H)

Submission status: Runtime Error

Solution code:
N = int(input())
ls = []
for i in range(N):
  x,y,h = map(int, input().split())
  ls += [(h,x,y)]
  
L = sorted(ls, key=lambda x:x[0], reverse=True)

Cx1 = 101
Cy1 = 101
Cx2 = -1
Cy2 = -1
Chx1 = 0
Chy1 = 0
Chx2 = 0
Chy2 = 0
for l in L:
  h, x, y = l
  if Chx1<=h and Cx1>x:
    Cx1 = x
    Chx1 = h
  if Chx2<=h and Cx2<x:
    Cx2 = x
    Chx2 = h
  if Chy1<=h and Cy1>y:
    Cy1 = y
    Chy1 = h
  if Chy2<=h and Cy2<y:
    Cy2 = y
    Chy2 = h
  #print(Cx1, Cx2, Cy1, Cy2)

ans = []
for i in range(Cx1, Cx2+1):
  for j in range(Cy1, Cy2+1):
    ans += [(i,j)]

H = 0
pH = -1
ansh = 0
while len(ans)>1:
  na = []
  for a in ans:
    i, j = a
    pH = -1
    for l in L:
      h, x, y = l
      #print(l, a)
      if h>0:
        H = h+abs(x-i)+abs(y-j)
#        print(pH, H, l)
        if pH==-1:
          pH = H
        elif not H==pH:
          break
    else:
      na += [a]
      ansh = H
  ans = na
if pH == -1:
  for l in L:
    h, x, y =l
    if h>0:
      break
  ansh = h + abs(x-ans[0][0]) + abs(y-ans[0][1])
print(*ans[0], ansh)

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    points = reversed(
        [[int(i) for i in input().split()] for _ in range(n)],
        key=lambda x: x[2],
        reverse=True,
    )
    print(points)
    hoge = 101
    for cx in range(hoge):
        for cy in range(hoge):
            x, y, z = points[0]
            h = max(z + abs(x - cx) + abs(y - cy), 0)
            # print(h, [max(z + abs(x - cx) + abs(y - cy), 0) for x, y, z in points])
            if h == 0:
                continue
            if all(
                [h == max(z + abs(x - cx) + abs(y - cy), 0) for x, y, z in points[1:]]
            ):
                print(cx, cy, h)
                break


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
hxy = []
for _ in range(N):
        x,y,h = map(int,input().split())
        hxy.append([h,x,y])
hxy.sort(reverse=True)
xy = [[x,y] for x in range(101) for y in range(101)]
for i in range(len(hxy) - 1):
        h1,x1,y1 = hxy[i]
        for j in range(i + 1,len(hxy)):
                h2,x2,y2 = hxy[j]
                xy_copy = xy.copy()
                if h1 == 0 and h2 == 0:
                        xy.remove([x1,y1])
                        xy.remove([x2,y2])
                        continue
                elif h1 == 0:
                        for x,y in xy_copy:
                                if abs(x - x2) + abs(y - y2) - abs(x - x1) - abs(y - y1) + h2 > 0:
                                        xy.remove([x,y])
                                        if len(xy) == 1:
                                                x,y = xy[0]
                                                print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                                                exit()
                                        continue
                elif h2 == 0:
                        for x,y in xy_copy:
                                if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2)  + h1 > 0:
                                        xy.remove[x,y]
                                        if len(xy) == 1:
                                                x,y = xy[0]
                                                print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                                                exit()
                                        continue
                

                for x,y in xy_copy:
                        if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2) != h2 - h1:
                                xy.remove([x,y])
                if len(xy) == 1:
                        x,y = xy[0]
                        print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                        exit()

Submission status: Runtime Error

Solution code:
N = int(input())
hxy = []
for _ in range(N):
        x,y,h = map(int,input().split())
        hxy.append([h,x,y])
hxy.sort(reverse=True)
xy = [[x,y] for x in range(101) for y in range(101)]
for i in range(len(hxy) - 1):
        h1,x1,y1 = hxy[i]
        for j in range(i + 1,len(hxy)):
                h2,x2,y2 = hxy[j]
                xy_copy = xy.copy()
                if h1 == 0 and h2 == 0:
                        xy.remove([x1,y1])
                        xy.remove([x2,y2])
                        continue
                elif h1 == 0:
                        for x,y in xy_copy:
                                if abs(x - x2) + abs(y - y2) - abs(x - x1) - abs(y - y1) + h2 > 0:
                                        xy.remove([x,y])
                                        continue
                elif h2 == 0:
                        for x,y in xy_copy:
                                if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2)  + h1 > 0:
                                        xy.remove[x,y]
                                        continue
                

                for x,y in xy_copy:
                        if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2) != h2 - h1:
                                xy.remove([x,y])
                if len(xy) == 1:
                        x,y = xy[0]
                        print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                        exit()

Submission status: Runtime Error

Solution code:
N = int(input())
hxy = []
for _ in range(N):
        x,y,h = map(int,input().split())
        hxy.append([h,x,y])
hxy.sort(reverse=True)
xy = [[x,y] for x in range(101) for y in range(101)]
for i in range(len(hxy) - 1):
        h1,x1,y1 = hxy[i]
        for j in range(i + 1,len(hxy)):
                h2,x2,y2 = hxy[j]
                xy_copy = xy.copy()
                if h1 == 0 or h2 == 0:
                        if h1 == 0:
                                for x,y in xy_copy:
                                        if h1 + abs(x - x1) + abs(y - y1) > 0:
                                                xy.remove[x,y]
                        xy_copy = xy.copy()
                        if h2 == 0:
                                for x,y in xy_copy:
                                        if h2 + abs(x - x2) + abs(y - y2) > 0:
                                                xy.remove[x,y]
                        if len(xy) == 1:
                                x,y = xy[0]
                                print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                                exit()
                        continue

                for x,y in xy_copy:
                        if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2) != h2 - h1:
                                xy.remove([x,y])
                if len(xy) == 1:
                        x,y = xy[0]
                        print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                        exit()

Submission status: Runtime Error

Solution code:
N = int(input())
hxy = []
for _ in range(N):
        x,y,h = map(int,input().split())
        hxy.append([h,x,y])
hxy.sort(reverse=True)
xy = [[x,y] for x in range(101) for y in range(101)]
for i in range(len(hxy) - 1):
        h1,x1,y1 = hxy[i]
        for j in range(i + 1,len(hxy)):
                h2,x2,y2 = hxy[j]
                xy_copy = xy.copy()
                if h1 == 0 or h2 == 0:
                        if h1 == 0:
                                for x,y in xy_copy:
                                        if h1 + abs(x - x1) + abs(y - y1) > 0:
                                                xy.remove[x,y]
                        xy_copy = xy.copy()
                        if h2 == 0:
                                for x,y in xy_copy:
                                        if h2 + abs(x - x2) + abs(y - y2) > 0:
                                                xy.remove[x,y]
                        continue

                for x,y in xy_copy:
                        if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2) != h2 - h1:
                                xy.remove([x,y])
                if len(xy) == 1:
                        x,y = xy[0]
                        print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                        exit()

Submission status: Runtime Error

Solution code:
N = int(input())

info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        info.append([h, x, y])

info.sort(reverse=True)

for c_x in range(101):
    for c_y in range(101):
        H = info[0][0] + abs(info[0][1] - c_x) + abs(info[0][2] - c_y)
        flag = True
        for i in range(1, N):
            if info[i][0] != H - abs(info[i][1] - c_x) - abs(info[i][2] - c_y):
                flag = False
                break

        if flag:
            print(*[c_x, c_y, H])
            exit()

Submission status: Runtime Error

Solution code:
N = int(input())
hxy = []
hxy2 = []
for _ in range(N):
	x,y,h = map(int,input().split())
	if h == 0:
		hxy2.append([h,x,y])
		continue
	hxy.append([h,x,y])
hxy.sort(reverse=True)
xy = [[x,y] for x in range(101) for y in range(101)]
for i in range(len(hxy) - 1):
	h1,x1,y1 = hxy[i]
	for j in range(i + 1,len(hxy)):
		h2,x2,y2 = hxy[j]
		xy_copy = xy.copy()
		for x,y in xy_copy:
			if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2) != h2 - h1:
				xy.remove([x,y])
		if len(xy) == 1:
			x,y = xy[0]
			print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
			exit()
for x,y in xy:
	for h1,x1,y1 in hxy2:
		if h1 + abs(x - x1) + abs(y - y1) - abs(x - x1) - abs(y - y1) >= 0:
			xy.remove([x,y])
	if len(xy) == 1:
			x,y = xy[0]
			print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
			exit()

Submission status: Runtime Error

Solution code:
# 解答ちらっと見た
# 問題のキモは Cx,Cy,Hがそれぞれ100通り、
# 全探索をCx,Cy,Hに対して試みると 入力された情報のcheckを入れて101*101*100*100でTLEする。
# でもよく考えてみると、Cx,CyがわかればHはそのあとで出せるので Cx,Cyに対して全探索をする(101*101*100+100の計算量で済む)


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


def checks(x, y, eh, cx, cy, h):
    cah = max(h - abs(x - cx) - abs(y - cy), 0)
    return cah == eh


N = int(input())
H = {}

checkers = [(list(map(int, input().split()))) for _ in range(N)]
for x,y,h in checkers:
    if h>0:
        lockx=x
        locky=y
        lockh=h

for icx in range(101):
    for icy in range(101):
        H = set({})
        for checker in checkers:
            H.add(lockh + abs(lockx - icx) + abs(locky - icy))

        if len(H) == 1:
            # print('{} {} {}'.format(icx, icy, H[0]))
            ok = True
            for c in checkers:
                if not checks(c[0], c[1], c[2], icx, icy, H[0]):
                    # print('failedin {} {} {} {} {} {}'.format(c[0], c[1], c[2], icx, icy, H[0]))
                    ok = False
                    break
            if ok:
                print('{} {} {}'.format(icx, icy, H[0]))
                exit(0)

Submission status: Runtime Error

Solution code:
N = int(input())

L = []
for i in range(N):
    x, y, h = map(int, input().split())
    L.append([x, y, h])
    if h != 0:
        idx = i


for i in range(101):
    for j in range(101):
        H = L[idx][2] + abs(L[idx][0]-i) + abs(L[idx][1]-j)
        for k in range(N):
            if L[k][2] == H - abs(L[k][0]-i) - abs(L[k][1]-j):
                pass
            else:
                break
            if k == N-1:
                ansx = i
                ansy = j
                ansh = H

print(ansx, ansy, ansh)