Problem:


Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).  

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:  

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.  

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."  

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.  

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:  

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.  

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.  

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.  



Sample input:
4
2 3 5
2 1 5
1 2 5
3 2 5


Sample output:
2 2 6

Submission status: Wrong Answer

Solution code:
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):
    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'

#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]
    bfs(a, b, c)
    #print (check)

ans = 0
ans_x = 0
ans_y = 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: Wrong Answer

Solution code:
import sys
 
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    #N=3
    #x=[99,100,99]
    #y=[1,1,0]
    #h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
    N = 2
    x = [0,0]
    y = [0,100]
    h = [0,0]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100
    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
  
  ans_h = 0
  ans_x = 0
  ans_y = 0
  max_h = max(h)
  for temp_x in range(101):
    for temp_y in range(101):
      temp_h = 0
      if max_h == 0:
        temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
      else:
        for i in range(N):
          if h[i] != 0:
            temp_h = abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]
            break
            
      for i in range(N):
        if max_h == 0:
          if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
            break
        elif h[i] != 0:
          if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
            break
        if i == N - 1:
          if ans_h == 0:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h            
          elif temp_h > ans_h:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h
 
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  sys.exit()
 
main()

Submission status: Wrong Answer

Solution code:
a=int(input())
if a==1:
    print(input())
else:
    b=[]
    k=l=0
    for i in range(a):
        x,y,h=map(int,input().split())
        b.append([x,y,h])

    for i in range(101):
        for j in range(101):
            l=b[k][2]+abs(b[k][0]-i)+abs(b[k][1]-j)
            for I in range(a):
                if b[I][2]!=max(0,l-abs(i-b[I][0])-abs(j-b[I][1])):
                    break
                elif I==a-1:
                    print(str(i)+" "+str(j)+" "+str(l))
                    exit()

Submission status: Wrong Answer

Solution code:
a=int(input())
if a==1:
    print(input())
else:
    b=[]
    k=l=0
    for i in range(a):
        x,y,h=map(int,input().split())
        b.append([x,y,h])
    for i in range(101):
        for j in range(101):
            l=b[k][2]+abs(b[k][0]-i)+abs(b[k][1]-j)
            for I in range(a):
                if l!=abs(i-b[I][0])+abs(j-b[I][1])+b[I][2]:
                    break
                elif I==a-1:
                    print(str(i)+" "+str(j)+" "+str(l))

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[]
k=l=0
for i in range(a):
    x,y,h=map(int,input().split())
    b.append([x,y,h])
for i in range(101):
    for j in range(101):
        l=b[k][2]+abs(b[k][0]-i)+abs(b[k][1]-j)
        for I in range(a):
            if l!=abs(i-b[I][0])+abs(j-b[I][1])+b[I][2]:
                break
            elif I==a-1:
                print(str(i)+" "+str(j)+" "+str(l))

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[]
l=0
H=[]
for i in range(a):
    x,y,h=map(int,input().split())
    b.append([x,y,h])
for k in range(a):
    if b[k][2]!=0:break
for i in range(101):
    for j in range(101):
        l=b[k][2]+abs(b[k][0]-i)+abs(b[k][1]-j)
        #if i==2:
            #print(l)
        for I in range(a):
            #if i==2:
                #print(str(i)+" "+str(j))
                #print(abs(i-b[I][0])+abs(j-b[I][1])+b[I][2])
            if l!=abs(i-b[I][0])+abs(j-b[I][1])+b[I][2]:
                break
            elif I==a-1:
                print(str(i)+" "+str(j)+" "+str(l))

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[]
l=0
H=[]
for i in range(a):
    x,y,h=map(int,input().split())
    b.append([x,y,h])
for k in range(a):
    if b[k][2]!=0:break
for i in range(101):
    for j in range(101):
        l=b[k][2]+abs(b[k][0]-i)+abs(b[k][1]-j)
        for I in range(a):
            if l!=abs(i-b[I][0])+abs(j-b[I][1])+b[I][2]:
                break
            elif I==a-1:
                print(str(i)+" "+str(j)+" "+str(l))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
ans = 0
for _ in range(n):
    s.append([int(i) for i in input().split()])
for x in range(101):
    for y in range(101):
        t = []
        for i in range(n):
            x_, y_, h = s[i]
            if h > 0:
                t.append(h + abs(x_ - x) + abs(y_ - y))
        if (len(set(t)) == 1):
            ttt = h + abs(x_ - x) + abs(y_ - y)
            ans = str(x) + " " + str(y) + " " + str(ttt)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
 
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    N = 4
    x = [2,2,1,3]
    y = [3,1,2,2]
    h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    #N=3
    #x=[99,100,99]
    #y=[1,1,0]
    #h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100
 
    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
  
  ans_h = 0
  ans_x = 0
  ans_y = 0
  for temp_x in range(101):
    for temp_y in range(101):
      temp_h = 0
      for i in range(N):
        if h[i] != 0:
          temp_h = abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]
          ans_x = temp_x
          ans_y = temp_y
          ans_h = temp_h
          break
      for i in range(N):
        if h[i] != 0:
          if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
            break
        if i == N - 1:
          if temp_h > ans_h:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h
 
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  sys.exit()
 
main()

Submission status: Wrong Answer

Solution code:
import sys
 
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    N = 4
    x = [2,2,1,3]
    y = [3,1,2,2]
    h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    #N=3
    #x=[99,100,99]
    #y=[1,1,0]
    #h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100
 
    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
  
  ans_h = 0
  ans_x = 0
  ans_y = 0
  for temp_x in range(101):
    for temp_y in range(101):
      temp_h = 0
      for i in range(N):
        if h[i] != 0:
           temp_h = abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]
           break
      for i in range(N):
        if h[i] != 0:
          if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
            break
        if i == N - 1:
          if ans_h == 0:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h            
          elif temp_h > ans_h:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h
 
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  sys.exit()
 
main()

Submission status: Wrong Answer

Solution code:
import sys
 
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    N = 4
    x = [2,2,1,3]
    y = [3,1,2,2]
    h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    #N=3
    #x=[99,100,99]
    #y=[1,1,0]
    #h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100
 
    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
  
  ans_h = 0
  ans_x = 0
  ans_y = 0
  for temp_x in range(101):
    for temp_y in range(101):
      temp_h = 0
      for i in range(N):
        if h[i] != 0:
          if temp_h == 0:
            temp_h = abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]
          if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
            break
        if i == N - 1:
          if ans_h == 0:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h            
          elif temp_h > ans_h:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h
 
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  sys.exit()
 
main()

Submission status: Wrong Answer

Solution code:
import sys
 
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    N = 4
    x = [2,2,1,3]
    y = [3,1,2,2]
    h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    #N=3
    #x=[99,100,99]
    #y=[1,1,0]
    #h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100
 
    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
  
  ans_h = 0
  ans_x = 0
  ans_y = 0
  for temp_x in range(101):
    for temp_y in range(101):
      temp_h = 0
      for i in range(N):
        if h[0] != 0:
          if temp_h == 0:
            temp_h = abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]
          if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
            break
        if i == N - 1:
          if ans_h == 0:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h            
          elif temp_h > ans_h:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h
 
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  sys.exit()
 
main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    N = 4
    x = [2,2,1,3]
    y = [3,1,2,2]
    h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    #N=3
    #x=[99,100,99]
    #y=[1,1,0]
    #h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100

    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
  
  ans_h = 0
  ans_x = 0
  ans_y = 0
  for temp_x in range(101):
    for temp_y in range(101):
      temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
      for i in range(N):
        if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
          break
        if i == N - 1:
          if ans_h == 0:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h            
          elif temp_h > ans_h:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h

  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  sys.exit()

main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    N = 4
    x = [2,2,1,3]
    y = [3,1,2,2]
    h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    #N=3
    #x=[99,100,99]
    #y=[1,1,0]
    #h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100

    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
  
  ans_h = 0
  ans_x = 0
  ans_y = 0
  for temp_x in range(101):
    for temp_y in range(101):
      for i in range(N):
        if i == 0:
          temp_h = abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]
        if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
          break
        if i == N - 1:
          if ans_h == 0:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h            
          elif temp_h > ans_h:
            ans_x = temp_x
            ans_y = temp_y
            ans_h = temp_h

  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  sys.exit()

main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    N=3
    x=[99,100,99]
    y=[1,1,0]
    h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  if N == 1:
    if x[0] > 50:
      temp_x = 0
    elif x[0] == 50:
      temp_x = 50
    else:
      temp_x = 100

    if y[0] > 50:
      temp_y = 0
    elif y[0] == 50:
      temp_y = 50
    else:
      temp_y = 100
    
    temp_h = abs(temp_x - x[0]) + abs(temp_y - y[0]) + h[0]
    print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
    sys.exit()    
      
  for temp_x in range(101):
    for temp_y in range(101):
      for i in range(N):
        if i == 0:
          temp_h = abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]
        if temp_h != abs(temp_x - x[i]) + abs(temp_y - y[i]) + h[i]:
          break
        if i == N -1:
          print("{} {} {}".format(int(temp_x), int(temp_y), int(temp_h)))
          sys.exit()
          
main()

Submission status: Wrong Answer

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    N=3
    x=[99,100,99]
    y=[1,1,0]
    h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  max_x = max(x)
  min_x = min(x)
  max_h = h[x.index(max_x)]
  min_h = h[x.index(min_x)]
  # 距離の差
  dist_x = abs(max_x - min_x)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_x > dist_h:
    if min_h > max_h:
      ans_x = min_x + (dist_x + dist_h) / 2
    else:
      ans_x = max_x - (dist_x + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_x = 100
    elif max_h == min_h:
      if max_x > 50:
        ans_x = 0
      elif max_x == 50:
        ans_x = 50
      else:
        ans_x = 100
    else:
      ans_x = 0
  
  max_y = max(y)
  min_y = min(y)
  max_h = h[y.index(max_y)]
  min_h = h[y.index(min_y)]
  # 距離の差
  dist_y = abs(max_y - min_y)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_y < dist_h:
    if min_h > max_h:
      ans_y = min_y + (dist_y + dist_h) / 2
    else:
      ans_y = max_y - (dist_y + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_y = 100
    elif max_h == min_h:
      if max_y > 50:
        ans_y = 0
      elif max_y == 50:
        ans_y = 50
      else:
        ans_y = 100
    else:
      ans_y = 0
        
  ans_h = abs(ans_x - x[0]) + abs(ans_y - y[0]) + h[0]
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  
main()

Submission status: Wrong Answer

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    N=3
    x=[99,100,99]
    y=[1,1,0]
    h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  max_x = max(x)
  min_x = min(x)
  max_h = h[x.index(max_x)]
  min_h = h[x.index(min_x)]
  # 距離の差
  dist_x = abs(max_x - min_x)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_x > dist_h:
    if min_h < max_h:
      ans_x = min_x + (dist_x + dist_h) / 2
    else:
      ans_x = max_x - (dist_x + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_x = 100
    elif max_h == min_h:
      if max_x > 50:
        ans_x = 0
      elif max_x == 50:
        ans_x = 50
      else:
        ans_x = 100
    else:
      ans_x = 0
  
  max_y = max(y)
  min_y = min(y)
  max_h = h[y.index(max_y)]
  min_h = h[y.index(min_y)]
  # 距離の差
  dist_y = abs(max_y - min_y)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_y < dist_h:
    if min_h < max_h:
      ans_y = min_y + (dist_y + dist_h) / 2
    else:
      ans_y = max_y - (dist_y + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_y = 100
    elif max_h == min_h:
      if max_y > 50:
        ans_y = 0
      elif max_y == 50:
        ans_y = 50
      else:
        ans_y = 100
    else:
      ans_y = 0
        
  ans_h = abs(ans_x - x[0]) + abs(ans_y - y[0]) + h[0]
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  
main()

Submission status: Wrong Answer

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    N=3
    x=[99,100,99]
    y=[1,1,0]
    h=[191,192,192]
    #N = 1
    #x = [0]
    #y = [40]
    #h = [100]
        
  # Processing
  max_x = max(x)
  min_x = min(x)
  max_h = h[x.index(max_x)]
  min_h = h[x.index(min_x)]
  # 距離の差
  dist_x = abs(max_x - min_x)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_x > dist_h:
    if min_h > max_h:
      ans_x = min_x + (dist_x + dist_h) / 2
    else:
      ans_x = max_x - (dist_x + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_x = 100
    elif max_h == min_h:
      if max_x > 50:
        ans_x = 0
      elif max_x == 50:
        ans_x = 50
      else:
        ans_x = 100
    else:
      ans_x = 0
  
  max_y = max(y)
  min_y = min(y)
  max_h = h[y.index(max_y)]
  min_h = h[y.index(min_y)]
  # 距離の差
  dist_y = abs(max_y - min_y)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_y > dist_h:
    if min_h > max_h:
      ans_y = min_y + (dist_y + dist_h) / 2
    else:
      ans_y = max_y - (dist_y + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_y = 100
    elif max_h == min_h:
      if max_y > 50:
        ans_y = 0
      elif max_y == 50:
        ans_y = 50
      else:
        ans_y = 100
    else:
      ans_y = 0
        
  ans_h = abs(ans_x - x[0]) + abs(ans_y - y[0]) + h[0]
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  
main()

Submission status: Wrong Answer

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    #N=3
    #x=[99,100,99]
    #y=[1,1,0]
    #h=[191,192,192]
    N = 1
    x = [0]
    y = [40]
    h = [100]
        
  # Processing
  max_x = max(x)
  min_x = min(x)
  max_h = h[x.index(max_x)]
  min_h = h[x.index(min_x)]
  # 距離の差
  dist_x = abs(max_x - min_x)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_x > dist_h:
    ans_x = min_x + (dist_x + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_x = 100
    elif max_h == min_h:
      if max_x > 50:
        ans_x = 0
      elif max_x == 50:
        ans_x = 50
      else:
        ans_x = 100
    else:
      ans_x = 0
  
  max_y = max(y)
  min_y = min(y)
  max_h = h[y.index(max_y)]
  min_h = h[y.index(min_y)]
  # 距離の差
  dist_y = abs(max_y - min_y)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_y > dist_h:
    ans_y = min_y + (dist_y + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_y = 100
    elif max_h == min_h:
      if max_y > 50:
        ans_y = 0
      elif max_y == 50:
        ans_y = 50
      else:
        ans_y = 100
    else:
      ans_y = 0
        
  ans_h = abs(ans_x - x[0]) + abs(ans_y - y[0]) + h[0]
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  
main()

Submission status: Wrong Answer

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    #N=3
    #x=[99,100,99]
    #y=[1,1,0]
    #h=[191,192,192]
    N = 1
    x = [0]
    y = [40]
    h = [100]
        
  # Processing
  if N > 1:
    max_x = max(x)
    min_x = min(x)
    max_h = h[x.index(max_x)]
    min_h = h[x.index(min_x)]
    # 距離の差
    dist_x = abs(max_x - min_x)
    # 高さの差
    dist_h = abs(max_h - min_h)
    # 高さの差より距離の差が小さければ中間に頂点がある
    if dist_x > dist_h:
      ans_x = min_x + (dist_x + dist_h) / 2
    # そうでなければ、0か100が頂点
    else:
      if max_h > min_h:
        ans_x = 100
      else:
        ans_x = 0
  
    max_y = max(y)
    min_y = min(y)
    max_h = h[y.index(max_y)]
    min_h = h[y.index(min_y)]
    # 距離の差
    dist_y = abs(max_y - min_y)
    # 高さの差
    dist_h = abs(max_h - min_h)
    # 高さの差より距離の差が小さければ中間に頂点がある
    if dist_y > dist_h:
      ans_y = min_y + (dist_y + dist_h) / 2
    # そうでなければ、0か100が頂点
    else:
      if max_h > min_h:
        ans_y = 100
      else:
        ans_y = 0
        
  else:
    if x[0]>50:
      ans_x = 0
    elif x[0]==50:
      ans_x = 50
    else:
      ans_x = 100
      
    if y[0]>50:
      ans_y = 0
    elif y[0]==50:
      ans_y = 50
    else:
      ans_y = 100
        
  ans_h = abs(ans_x - x[0]) + abs(ans_y - y[0]) + h[0]
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  
main()

Submission status: Wrong Answer

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    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())
  else:
    #N = 4
    #x = [2,2,1,3]
    #y = [3,1,2,2]
    #h = [5,5,5,5]
    #N = 2
    #x = [0,1]
    #y = [0,1]
    #h = [100,98]
    N=3
    x=[99,100,99]
    y=[1,1,0]
    h=[191,192,192]
        
  # Processing
  
  max_x = max(x)
  min_x = min(x)
  max_h = h[x.index(max(x))]
  min_h = h[x.index(min(x))]
  # 距離の差
  dist_x = abs(max_x - min_x)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_x > dist_h:
    ans_x = min_x + (dist_x + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_x = 100
    else:
      ans_x = 0
  
  max_y = max(y)
  min_y = min(y)
  max_h = h[y.index(max(y))]
  min_h = h[y.index(min(y))]
  # 距離の差
  dist_y = abs(max_y - min_y)
  # 高さの差
  dist_h = abs(max_h - min_h)
  # 高さの差より距離の差が小さければ中間に頂点がある
  if dist_y > dist_h:
    ans_y = min_y + (dist_y + dist_h) / 2
  # そうでなければ、0か100が頂点
  else:
    if max_h > min_h:
      ans_y = 100
    else:
      ans_y = 0
  
  ans_h = abs(ans_x - x[0]) + abs(ans_y - y[0]) + h[0]
  print("{} {} {}".format(int(ans_x), int(ans_y), int(ans_h)))
  
main()

Submission status: Wrong Answer

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

for i in range(len(XYH)):
    if not XYH[i][2] == 0:
        start = i
        break
for i in range(len(XYH)-1, -1, -1):
    if not XYH[i][2] == 0:
        end = i
        break

for x in range(101):
    for y in range(101):
        for i in range(len(XYH)):
            if XYH[i][2] == 0:
                continue
            if i == start:
                tmpH = XYH[i][2] + abs(XYH[i][0] - x) + abs(XYH[i][1] - y)
            H = XYH[i][2] + abs(XYH[i][0] - x) + abs(XYH[i][1] - y)
            if tmpH == H and i == end:
                print(x, y, H)
            elif tmpH == H:
                tmpH = H
            else:
                break