Problem: 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.

Submission attempts (in order):
import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    H=[]
    Z=[]
    for i in range(n):
      x,y,h=s[i]
      if h==0:
        H.append(abs(x-cx)+(y-cy)+h)
      else:
        Z.append(abs(x-cx)+(y-cy))
    if len(Z)==0:
      Z.append(10**18)
    if H.count(H[0])==len(H) and min(Z)>=H[0]:
      print(cx,cy,H)
      exit()

import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    Z=10**18
    flag=True
    for i in range(n):
      x,y,h=s[i]
      if h!=0:
        if flag:
          H=abs(x-cx)+abs(y-cy)+h
        else:
          if H!=abs(x-cx)+abs(y-cy)+h:
            H=10**18+1
            break
      else:
        Z=min(Z,abs(x-cx)+abs(y-cy))
    if H<=Z:
      print(cx,cy,H)
      exit()

import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    H=[]
    Z=[]
    for i in range(n):
      x,y,h=s[i]
      if h!=0:
        H.append(abs(x-cx)+(y-cy)+h)
      else:
        Z.append(abs(x-cx)+(y-cy))
    if len(Z)==0:
      Z.append(10**18)
    if H.count(H[0])==len(H) and min(Z)>=H[0]:
      print(cx,cy,H[0])
      exit()

import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    H=[]
    Z=[]
    for i in range(n):
      x,y,h=s[i]
      if h!=0:
        H.append(abs(x-cx)+abs(y-cy)+h)
      else:
        Z.append(abs(x-cx)+abs(y-cy))
    if H.count(H[0])==len(H) and min(Z)>=H[0]:
      print(cx,cy,H[0])
      exit()


import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    flag=True
    flag2=True
    stack2==10**18
    for i in range(n):
      if flag==False:
        break
      x,y,h=s[i]
      H=abs(x-cx)+abs(y-cy)+h
      if h!=0 and flag2:
        stack=H
        flag2=False
      if h==0:
        stack2=min(stack2,H)
      if h!=0 and flag2==False:
        if stack!=H:
          flag=False
          break
    if flag and stack<=stack2:
      print(cx,cy,H)
      exit()

import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    flag=True
    flag2=True
    for i in range(n):
      if flag==False:
        break
      x,y,h=s[i]
      H=abs(x-cx)+abs(y-cy)+h
      if i==0:
        if h==0:
          flag2=False
        stack=H
        continue
      if stack!=H:
        if h==0 and H>=stack:
          continue
        if flag2==False:
          if h==0 and stack>=H:
            stack=H
            continue
          elif h!=0 and H<=stack:
            stack=H
            flag2=True
            continue
          elif h!=0 and H>stack:
            flag=False
            continue
    if flag:
      print(cx,cy,H)
      exit()

import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    Z=10**18
    flag=True
    for i in range(n):
      x,y,h=s[i]
      if h!=0:
        if flag:
          H=abs(x-cx)+abs(y-cy)+h
        else:
          if H!=abs(x-cx)+abs(y-cy)+h:
            H=10**18+1
            break
      else:
        Z=min(Z,abs(x-cx)+abs(y-cy))
    if H<=Z:
      print(cx,cy,H[0])
      exit()

import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    flag=True
    flag2=True
    for i in range(n):
      x,y,h=s[i]
      if x>=cx and y>=cy:
        H=h+x+y-cx-cy
      elif x>=cx:
        H=h+x-y-cx+cy
      elif y>=cy:
        H=h-x+y+cx-cy
      else:
        H=h-x-y+cx+cy
      if i==0:
        if h==0:
          flag2=False
        stack=H
        continue
      if h==0:
        if flag2==False:
          if H<stack:
            stack=H
          continue
        elif stack>H:
          flag=False
          break
      if flag2=False:
        if H>stack:
          flag=False
          break
        else:
          stack=H
          flag2=True
      if stack!=H:
        flag=False
        break
    if flag:
      print(cx,cy,H)
      exit()

import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    H=[]
    Z=[]
    for i in range(n):
      x,y,h=s[i]
      if h==0:
        H.append(abs(x-cx)+(y-cy)+h)
      else:
        Z.append(abs(x-cx)+(y-cy))
    if H.count(H[0])==len(H) and min(Z)>=H[0]:
      print(cx,cy,H)
      exit()

import sys
n=int(input())
s=[[int(i) for i in l.split()] for l in sys.stdin]
for cx in range(101):
  for cy in range(101):
    flag=True
    Z=10**18
    for i in range(n):
      x,y,h=s[i]
      if h!=0 and flag:
        H=abs(x-cx)+abs(y-cy)+h
        flag=False
      elif h!=0 and flag==False:
        if H!=abs(x-cx)+abs(y-cy)+h:
          H=10**18+1
          break
      elif h==0:
        Z=min(Z,abs(x-cx)+abs(y-cy)+h)
    if H<=Z:
      print(cx,cy,H)
      exit()


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted