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 sys
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
x = 0
y = 0
while y <= 100:
  x = 0
  while x <= 100:
    lis = []
    lis2 = []
    for arrays in grid:
      if arrays[2]>=1:
        lis.append(arrays[2]+abs(x-arrays[0])+abs(y-arrays[1]))
        lis2.append(arrays)
    if len(lis)>=2 and min(lis)==max(lis):
      print(x,y,max(0,arrays[2]+abs(x-arrays[0])+abs(y-arrays[1])))
      sys.exit()
    elif len(lis)==1:
      print(lis2[0][0],lis2[0][1],lis[0])
      sys.exit()
    x += 1
  y += 1

Submission status: Wrong Answer

Solution code:
n = int(input())
X = [[int(i) for i in input().split()] for j in range(n)]

x_s = 0
x_e = 100
y_s = 0
y_e = 100

for x, y, z in X:
    for x2, y2, z2 in X:
        if (x, y) == (x2, y2):
            continue
        d = abs(x-x2) + abs(y-y2)
        if d == z - z2:
            if x <= x2:
                x_e = min(x_e, x) #左側
            else:
                x_s = max(x_s, x) #右側
            if y <= y2:
                y_e = min(y_e, y) #上川
            else:
                y_s = max(y_e, y) #下側
        else:
            if x <= x2:
                x_s = max(x_s, x) #左側
            else:
                x_e = min(x_e, x) #右側
            if y <= y2:
                y_s = max(y_e, y) #上川
            else:
                y_e = min(y_e, y) #下側

x, y, z = X[0]
print(x_s, y_s, z + abs(x_s - x) + abs(y_s - y))

Submission status: Wrong Answer

Solution code:
n = int(input())
X_list = []
Y_list = []
H_list = []
for i in range(n):
    tmp1, tmp2, tmp3 = map(int, input().split())
    X_list.append(tmp1)
    Y_list.append(tmp2)
    H_list.append(tmp3)

X_max = max(X_list)
X_min = min(X_list)
Y_max = max(Y_list)
Y_min = min(Y_list)
flag = False
res  = []
for x in range(X_min, X_max+1):
    for y in range(Y_min, Y_max+1):
        tmp = []
        tmp2 = []
        for i in range(n):
            if H_list[i] != 0:
                tmp.append(abs(X_list[i]-x) + abs(Y_list[i]-y)+H_list[i])
            else:
                tmp2.append(abs(X_list[i]-x) + abs(Y_list[i]-y)+H_list[i])
                
        if max(tmp) == min(tmp):
            res.append([x, y, max(tmp)])
        if max(tmp+tmp2) == min(tmp+tmp2):
            res.append([x, y, max(tmp)])
#         if flag:
#             break
#     if flag:
#         break
a = 0
res = res[-1]
print(res[0], res[1], res[2])

Submission status: Wrong Answer

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

for x in range(101):
    for y in range(101):
        h = [0]*n
        ans = 0
        for i in range(n):
            if xyh[i][2]!=0:
                h[i] = abs(xyh[i][0] - x) + abs(xyh[i][1] - y) + xyh[i][2]
                if ans == h[i] or ans ==0:
                    ans =h[i]
                else:
                    break
            if i ==n-1:
                a = 0
                for j in range(n):
                    if xyh[j][2]!= max(h[i]- abs(xyh[j][0] - x) - abs(xyh[j][1] - y),0):
                        a=1
                        break
                if a==0:
                    print(x, y, h[i])

Submission status: Wrong Answer

Solution code:
import sys
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
x = 0
y = 0
while y <= 100:
  x = 0
  while x <= 100:
    lis = []
    lis2 = []
    for arrays in grid:
      if arrays[2]>=1:
        lis.append(arrays[2]+abs(x-arrays[0])+abs(y-arrays[1]))
        lis2.append(arrays)
    if len(lis)>=2 and min(lis)==max(lis):
      print(x,y,max(0,arrays[2]+abs(x-arrays[0])+abs(y-arrays[1])))
      sys.exit()
    elif len(lis)==1:
      print(lis2[0][0],lis2[0][1],1)
      sys.exit()
    x += 1
  y += 1

Submission status: Wrong Answer

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

halt = False
for i in range(100+1):
    for j in range(100+1):
        H_cand = set([])
        for d in data:
            if d[2] != 0:
                H_cand.add(abs(d[0] - i) + abs(d[1] - j) + d[2])
        if len(H_cand) == 1 and list(H_cand)[0] >= 1:
            print(i, j, list(H_cand)[0])
            halt = True
            break
    if halt:
        break

Submission status: Wrong Answer

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

for x in range(101):
    for y in range(101):
        h_must = 0
        h_min = 1
        for k in range(N):
            h_tmp = xyh[k][2]+abs(x-xyh[k][0])+abs(y-xyh[k][1])
            if h_must == 0:
                if xyh[k][2] != 0:
                    h_must = h_tmp
                else:
                    h_min = max(h_min,h_tmp)
            else:
                if xyh[k][2] != 0:
                    if h_must != h_tmp:
                        break
                else:
                    h_min = max(h_min,h_tmp)
                    if h_must < h_min:
                        break
        else:
            if h_must == 0:
                h_must = h_min
            print("{} {} {}".format(x,y,h_must))
            break
    else:
        continue
    break

Submission status: Wrong Answer

Solution code:
N = int(input())
x = N*[0]
y = N*[0]
h = N*[0]

board = [101*[0] for i in range(101)]

for i in range(N):
    x[i], y[i], h[i] = list(map(int, input().split(" ")))
    board[x[i]][y[i]] = h[i]


for i in range(101):
    for j in range(101):
        H = h[0] + abs(x[0] - i) + abs(y[0] - j)
        flag = 0
        for k in range(N):
            if(h[k] == 0):
                if(i != 0):
                    if(board[i-1][j] == 1): flag = 1
                if(i != 100):
                    if(board[i+1][j] == 1): flag = 1
                if(j != 0):
                    if(board[i][j-1] == 1): flag = 1
                if(j != 100):
                    if(board[i][j+1] == 1): flag = 1
                if(flag == 0): continue
            else: flag = 1
            if(H != (h[k] + abs(x[k] - i) + abs(y[k] - j))):
                flag = 0
                break
        if(flag == 1):
            print("%d %d %d" %(i, j, H))
            exit()

Submission status: Wrong Answer

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

for x in range(101):
    for y in range(101):
        h = [0]*n
        ans = 0
        for i in range(n):
            if xyh[i][2]!=0:
                h[i] = abs(xyh[i][0] - x) + abs(xyh[i][1] - y) + xyh[i][2]
                if ans == h[i] or ans ==0:
                    ans =h[i]
                else:
                    break
                if i ==n-1:
                    a = 0
                    for j in range(n):
                        if xyh[j][2]!= max(h[i]- abs(xyh[j][0] - x) - abs(xyh[j][1] - y),0):
                            a=1
                            break
                    if a==0:
                        print(x, y, h[i])

Submission status: Wrong Answer

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

judge = 0
ans = [0, 0, 0]
for x in range(101):
    for y in range(101):
        judge = 0
        h = data[0][2] + abs(x-data[0][0]) + abs(y-data[0][1])
        for d in range(1, N):
            h_ = h - abs(x-data[d][0]) - abs(y-data[d][1])
            if data[d][2] != h_:
                judge = 1
                break
        if judge == 0:
            break
    if judge == 0 and h > 0:
        ans = [x, y, h]
        break


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

Submission status: Wrong Answer

Solution code:
N = int(input())
x = []
y = []
h = []
for _ in range(N):
    xx,yy,hh = map(int,input().split())
    x.append(xx)
    y.append(yy)
    h.append(hh)
cm = 100
def height(cx,x,cy,y,h):
    return(max(0,h-abs(cx-x)-abs(cy-y)))
def judge(cx,cy,hc):
    for i in range(N):
        hcand = height(cx,x[i],cy,y[i],hc) 
        if hcand < h[i]:
            return(-1)
        if hcand > h[i]:
            return(1)
    return(0)
        
    
for cx in range(cm+1):
    for cy in range(cm+1):
        left = -1
        right = 1000000001
        while right > left + 1:
            mid = (right+left)//2
            j = judge(cx,cy,mid) 
            if j == 0:
                print(cx,cy,mid)
                exit()
            elif j == 1:
                right = mid
            else:
                left = mid

Submission status: Wrong Answer

Solution code:
N = int(input())
x, y, h = [], [], []
x2, y2, h2 = [], [], []
for i in range(N):
    xi, yi, hi = map(int, input().split())
    if hi == 0:
        x2.append(xi)
        y2.append(yi)
        h2.append(hi)
    else:
        x.append(xi)
        y.append(yi)
        h.append(hi)


def fn(H, X, Y, Cx, Cy):
    return H + abs(Cx - X) + abs(Cy - Y)

heights = []
for Cx in range(101):
    for Cy in range(101):
        height = fn(h[0], x[0], y[0], Cx, Cy)
        heights.append([height, Cx, Cy])
        if len(h) == 1:
            continue
        flag = True
        for i in range(1, len(h)):
            if height != fn(h[i], x[i], y[i], Cx, Cy):
                flag = False
                break
        if flag:
            print(Cx, Cy, height)
            exit()

def fn2(H, X, Y, Cx, Cy):
    return max(H - abs(Cx - X) + abs(Cy - Y), 0)

for H, Cx, Cy in heights:
    flag = True
    for i in range(len(h2)):
        if h2[i] != fn2(H, x2[i], y2[i], Cx, Cy):
            flag = False
            break
    if flag:
        print(Cx, Cy, height)

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

n = int(input())
vh = {}
for i in range(n):
    x, y, h = list(map(int, input().split()))
    if i == 0:
        for j in range(101):
            for k in range(101):
                vh[j, k] = h + abs(j - x) + abs(k - y)
    else:
        for j in range(101):
            for k in range(101):
                if vh[j, k] > -1:
                    hi = h + abs(j - x) + abs(k - y)
                    if vh[j, k] != hi:
                        vh[j, k] = -1

for j in range(101):
    for k in range(101):
        if vh[j, k] > -1:
            print(j, k, vh[j, k])

Submission status: Wrong Answer

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

if N == 1:
    print(G[0][0],G[0][1],G[0][2])
    exit(0)

for Cx in range(101):
    for Cy in range(101):
        f = 1
        H = G[0][2] + abs(Cx-G[0][0]) + abs(Cy-G[0][1])
        for k in range(1,N):
            if max(0,H-abs(G[k][0]-Cx)-abs(G[k][1]-Cy)) != G[k][2]:
                f = 0
        if f:
            print(Cx,Cy,H)
            exit(0)

Submission status: Wrong Answer

Solution code:
import sys
Input = sys.stdin.readline

N = int(Input())
x_y_h = [list(map(int, Input().split())) for _ in range(N)]
Cx = None
Cy = None
H = None

x_y_h = [xyh for xyh in x_y_h if xyh[2] > 0]
if N == 1:
    print("{0} {1} {2}".format(x_y_h[0][0], x_y_h[0][1], x_y_h[0][2]))
else:
    for c_x in range(0, 100+1):
        for c_y in range(0, 100+1):
            for i, (x, y, h) in enumerate(x_y_h):
                if i == 0:
                    H = abs(c_x - x) + abs(c_y - y) + h
                elif H != abs(c_x - x) + abs(c_y - y) + h:
                    break
            else:
                Cx = c_x
                Cy = c_y
                print("{0} {1} {2}".format(Cx, Cy, H))
                sys.exit()

Submission status: Wrong Answer

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] = list(map(int, input().split()))
min_min_h = 10**9+1
for i in range(101):
    for j in range(101):
        tmp = []
        for k in range(N):
            if h[k] !=0:
                tmp.append(abs(i-x[k])+abs(j-y[k])+h[k])
        if len(set(tmp)) == 1:
            print(i,j,tmp[0])

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
a = []
for i in range(N):
    a.append(map(int, raw_input().split()))

for i in range(101):
    for j in range(101):
        count = 0
        H = []
        for k in range(N):
            H.append(a[k][2]+abs(a[k][0]-i)+abs(a[k][1]-j))
            #print(a[k][2]+abs(a[k][0]-i)+abs(a[k][1]-j))

            if k > 0 and H[k-1] != H[k]:
                break
            else:
                count = k
        if count == N-1:
            print i, j, H[0]

Submission status: Wrong Answer

Solution code:

def main():
    buf = input()
    N = int(buf)
    x = []
    y = []
    h = []
    for i in range(N):
        buf = input()
        buflist = buf.split()
        x.append(int(buflist[0]))
        y.append(int(buflist[1]))
        h.append(int(buflist[2]))
    for cx in range(101):
        for cy in range(101):
            H = h[0] + dist(cx, cy, x[0], y[0])
            correct = True
            for i in range(1, N):
                if h[i] + dist(cx, cy, x[i], y[i]) != H and dist(cx, cy, x[i], y[i]) <= H:
                    correct = False
                    break
            if correct == True:
                print(cx, cy, H)
                return


def dist(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def H(h,cx,cy,x,y):
    return h+abs(cx-x)+abs(cy-y)

n = int(input())
arr=[]
for i in range(n):
    arr.append(list(map(int, input().split())))
isSame = True
for cx in range(0,101):
    for cy in range(0,101):
        isSame = True
        h_prev=-1
        for a in arr:
            h= H(a[2],cx,cy,a[0],a[1])
            if a[2]>0 or a[2]==h==0:
                if h_prev==-1:
                    h_prev=h
                if h!=h_prev:
                    isSame=False
                    break
                else:
                    h_prev=h
        if isSame==True:
            print("{} {} {}".format(cx,cy,h))
            exit

Submission status: Wrong Answer

Solution code:
n = int(input())
x=[]
y=[]
h=[]
for i in range(0,n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    h.append(c)



for i in range(0,101):
    for j in range(0,101):
        tmph=0
        flag = True
        for k in range(0,n):
            if tmph == 0 and h[k] != 0:
                tmph=abs(x[k]-i)+abs(y[k]-j)+h[k]
            calch = abs(x[k]-i)+abs(y[k]-j)+h[k]
            if tmph != calch and h[k] != 0:
                flag = False
                break
        if flag == False:
            continue
        elif tmph == 0:
            flag2 = True
            for c in range(0,101):
                if i == x[c] and j == y[c]:
                    flag2 = False
                    break
            if flag2:
                ansx = i
                ansy = j
                ansh = 1
        else:
            ansx=i
            ansy=j
            ansh=tmph

print(ansx,ansy,ansh)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
x = 0
y = 0
while y <= 100:
  x = 0
  while x <= 100:
    lis = []
    lis2 = []
    for arrays in grid:
      if arrays[2]>=1:
        lis.append(arrays[2]+abs(x-arrays[0])+abs(y-arrays[1]))
        lis2.append(arrays)
    if len(lis)>=2 and min(lis)==max(lis):
      print(x,y,max(0,arrays[2]+abs(x-arrays[0])+abs(y-arrays[1])))
      sys.exit()
    elif len(lis)==1:
      if lis2[0][0]<50:
        p = 0
      else:
        p = 100
      if lis2[0][1]<50:
        q = 0
      else:
        q = 100
      print(p,q,2)
      sys.exit()
    x += 1
  y += 1

Submission status: Wrong Answer

Solution code:
n = int(input())
tmp = [int(i) for _ in range(n) for i in input().split()]

xs = tmp[0::3]
ys = tmp[1::3]
hs = tmp[2::3]
stopflag = False

for H in range(max(hs), 10**9+1):
    for cx in range(101):
        for cy in range(101):
            for x,y,h in zip(xs,ys,hs):
                if h != max(H-abs(x-cx)-abs(y-cy),0):
                    break
            else:
                print('{} {} {}'.format(cx,cy,H))
                stopflag = True
                break
        if stopflag:
            break
    if stopflag:
        break

Submission status: Wrong Answer

Solution code:
def get_coord(C):
    for xi in range(0, 101):
        for yi in range(0, 101):
            H = 10 ** 9 + 1
            success = True
            for i in range(0, len(C)):
                if i == 0:
                    d = abs(xi - C[i][0]) + abs(yi - C[i][1])
                    th = H - d
                    H -= th - C[i][2]
                else:
                    nh = H - abs(xi - C[i][0]) - abs(yi - C[i][1])
                    if C[i][2] == nh:
                        continue
                    else:
                        success = False
                        break
            if success:
                return (xi, yi)
    return (-1, -1)


def solve(C):
    C.sort(key=lambda x: x[2])
    x, y = get_coord(C)
    for c in C:
        if c[2] != 0:
            h = abs(x - c[0]) + abs(y - c[1]) + c[2]
            return [str(x), str(y), str(h)]


if __name__ == "__main__":
    N = int(input())
    C = []
    for n in range(N):
        d = input().split(" ")
        C.append((int(d[0]), int(d[1]), int(d[2])))
    print(" ".join(solve(C)))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

H = []
xy = []
first = True
for xyh in in_list:
    x, y, h = xyh[0], xyh[1], xyh[2]
    if first:
        for x1 in range(0, 101):
            for y1 in range(0, 101):
                H1 = h + abs(x-x1) + abs(y-y1)
                H.append(H1)
                xy.append([x1, y1])
        first = False
    else:
        tmpH = []
        tmpxy = []
        for xy0, h0 in zip(xy, H):
            if h == max(h0-abs(x-xy0[0])-abs(y-xy0[1]), 0):
                tmpH.append(h0)
                tmpxy.append([xy0[0], xy0[1]])
        if len(tmpH) != 0:
            xy = tmpxy
            H = tmpH


print(xy[0][0], end=" ")
print(xy[0][1], end=" ")
print(H[0], end=" ")

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
if n>=4:
  L=[l[0]]
  for v in range(n):
    if l[v][0]!=l[0][0]:
      k=(l[v][1]-l[0][1])/(l[v][0]-l[0][0])
      L.append(l[v])
      break
  for w in range(n):
    if l[w][0]-l[0][0]==0 and l[w] not in L:L.append(l[w])
    if l[w][0]-l[0][0]!=0 and (l[w][1]-l[0][1])/(l[w][0]-l[0][0])!=k and l[w] not in L:L.append(l[w])
    if len(L)==4:
      break
  for x in range(101):
    for y in range(101):
      if abs(L[0][0]-x)+abs(L[0][1]-y)+L[0][2]==abs(L[1][0]-x)+abs(L[1][1]-y)+L[1][2]==abs(L[2][0]-x)+abs(L[2][1]-y)+L[2][2]==abs(L[3][0]-x)+abs(L[3][1]-y)+L[3][2]:
        print(x,y,abs(L[0][0]-x)+abs(L[0][1]-y)+L[0][2])
elif n>=3:
  for x in range(101):
   for y in range(101):
     if abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2]==abs(l[1][0]-x)+abs(l[1][1]-y)+l[1][2]==abs(l[2][0]-x)+abs(l[2][1]-y)+l[2][2]:
       print(x,y,abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2])
else:
  for x in range(101):
   for y in range(101):
     if abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2]==abs(l[1][0]-x)+abs(l[1][1]-y)+l[1][2]:
       print(x,y,abs(l[0][0]-x)+abs(l[0][1]-y)+l[0][2])

Submission status: Wrong Answer

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

N = int(input())

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


for xi in range(101):
    for yi in range(101):
        H_list = []
        for x,y,h in xyhn:
            if h > 0:
                H = h + abs(x - xi) + abs(y - yi)
                H_list.append(H)

        if min(H_list) == max(H_list):
            print("%d %d %d"%(xi,yi,H_list[0]))
            exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
x = N*[0]
y = N*[0]
h = N*[0]

board = [101*[0] for i in range(101)]

for i in range(N):
    x[i], y[i], h[i] = list(map(int, input().split(" ")))
    board[x[i]][y[i]] = h[i]


for i in range(101):
    for j in range(101):
        H = h[0] + abs(x[0] - i) + abs(y[0] - j)
        for k in range(N):
            if(h[k] == 0):
                if(i != 0):
                    if(board[i-1][j] == 1): flag = 1
                if(i != 100):
                    if(board[i+1][j] == 1): flag = 1
                if(j != 0):
                    if(board[i][j-1] == 1): flag = 1
                if(j != 100):
                    if(board[i][j+1] == 1): flag = 1
            else: flag = 1
            if(H != (h[k] + abs(x[k] - i) + abs(y[k] - j))):
                flag = 0
                break
        if(flag == 1):
            print("%d %d %d" %(i, j, H))
            exit()

Submission status: Wrong Answer

Solution code:
import sys
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
x = 0
y = 0
while y <= 100:
  x = 0
  while x <= 100:
    lis = []
    lis2 = []
    for arrays in grid:
      if arrays[2]>=1:
        lis.append(arrays[2]+abs(x-arrays[0])+abs(y-arrays[1]))
        lis2.append(arrays)
    if len(lis)>=2 and min(lis)==max(lis):
      print(x,y,max(0,arrays[2]+abs(x-arrays[0])+abs(y-arrays[1])))
      sys.exit()
    elif len(lis)==1:
      if lis2[0][0]<50:
        p = 0
      else:
        p = 100
      if lis2[0][1]<50:
        q = 0
      else:
        q = 100
      print(p,q,1)
      sys.exit()
    x += 1
  y += 1

Submission status: Wrong Answer

Solution code:
n = int(input())
#x = []
#y = []
#h = []
l = []
for i in range(n):
    ex,ey,eh = map(int,input().split())
    #x.append(ex)
    #y.append(ey)
    #h.append(eh)
    if eh != 0:
        l.append([ex,ey,eh])

def func(cx,cy,l1,l2):
    ans1 = -abs(l1[0]-cx)+abs(l2[0]-cx)-abs(l1[1]-cy)+abs(l2[1]-cy)
    ans2 = l1[2]-l2[2]
    if ans1 == ans2:
        return True
    else:
        return False

def func2(cx,cy,l):
    ans = l[2] + abs(l[0]-cx) +  abs(l[1]-cy)
    return ans

cx = -1
cy = -1
flag = False
for i in range(101):
    for j in range(101):
        for k in range(len(l)-1):
            if func(i,j,l[k],l[k+1]):
                if k == n-2:
                    cx = i
                    cy = j
                    flag = True
                    break
            else:
                break
        if flag:
            break
    if flag:
        break
h = func2(cx,cy,l[0])

print(cx, cy, h)

Submission status: Wrong Answer

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

for x in range(101):
    for y in range(101):
        h_must = 0
        h_min = 1
        for k in range(N):
            h_tmp = xyh[k][2]+abs(x-xyh[k][0])+abs(y-xyh[k][1])
            if h_must == 0:
                if xyh[k][2] != 0:
                    h_must = h_tmp
                else:
                    h_min = max(h_min,h_tmp)
            else:
                if xyh[k][2] != 0:
                    if h_must != h_tmp:
                        break
                else:
                    if h_must < h_tmp:
                        break
        else:
            if h_must == 0:
                h_must = h_min
            print("{} {} {}".format(x,y,h_must))
            break
    else:
        continue
    break

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
y = []
h = []
for i in range(n):
    xi,yi,hi = map(int, input().split())
    x.append(xi)
    y.append(yi)
    h.append(hi)


cxyl = []
for i in range(101):
    for j in range(101):
        cxyl.append((i,j))
cxy = set(cxyl)
hd = {}
for i in range(n):
    for c in list(cxy):
        if h[i] == 0:
            if 1 > abs(x[i]-c[0]) + abs(y[i]-c[1]):
                cxy.remove(c)
                continue
        else:
            H = abs(x[i]-c[0]) + abs(y[i]-c[1]) + h[i]
            if c in hd:
                if hd[c] != H:
                    cxy.remove(c)
                    continue
            else:
                hd[c] = H
ret = cxy.pop()
print(str(ret[0]) + ' ' + str(ret[1]) + ' ' + str(hd[ret]))

Submission status: Wrong Answer

Solution code:
import sys
Input = sys.stdin.readline

N = int(Input())
x_y_h = [list(map(int, Input().split())) for _ in range(N)]
Cx = None
Cy = None
H = None

if N == 1:
    print("{0} {1} {2}".format(x_y_h[0][0], x_y_h[0][1], x_y_h[0][2]))
else:
    x_y_h = [xyh for xyh in x_y_h if xyh[2] > 0]
    for c_x in range(0, 100+1):
        for c_y in range(0, 100+1):
            for i, (x, y, h) in enumerate(x_y_h):
                if i == 0:
                    H = abs(c_x - x) + abs(c_y - y) + h
                elif H != abs(c_x - x) + abs(c_y - y) + h:
                    break
            else:
                
                Cx = c_x
                Cy = c_y
                print("{0} {1} {2}".format(Cx, Cy, H))
                sys.exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
x, y, h = [], [], []
x2, y2, h2 = [], [], []
for i in range(N):
    xi, yi, hi = map(int, input().split())
    if hi == 0:
        x2.append(xi)
        y2.append(yi)
        h2.append(hi)
    else:
        x.append(xi)
        y.append(yi)
        h.append(hi)


def fn(H, X, Y, Cx, Cy):
    return H + abs(Cx - X) + abs(Cy - Y)

heights = []
for Cx in range(101):
    for Cy in range(101):
        height = fn(h[0], x[0], y[0], Cx, Cy)
        heights.append([height, Cx, Cy])
        flag = True
        for i in range(1, len(h)):
            if height != fn(h[i], x[i], y[i], Cx, Cy):
                flag = False
                break
        if flag:
            print(Cx, Cy, height)
            exit()

def fn2(H, X, Y, Cx, Cy):
    return max(H - abs(Cx - X) + abs(Cy - Y), 0)

for H, Cx, Cy in heights:
    flag = True
    for i in range(len(h2)):
        if h2[i] != fn2(H, x2[i], y2[i], Cx, Cy):
            flag = False
            break
    if flag:
        print(Cx, Cy, height)

Submission status: Wrong Answer

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

Cxy = defaultdict(int)

#-1 NG
# 0 default
#1+ ok
verify =[]
for x,y,h in XYH:
    for cx in range(101):
        for cy in range(101):
            val = Cxy[(cx,cy)]
            if val<0:
                continue
            tmp_H = abs(x-cx)+abs(y-cy)+h
            if h==0:
                verify.append((x,y,h))
                continue #????

            if val==0:
                Cxy[(cx,cy)] = tmp_H
            elif val != tmp_H:
                Cxy[(cx, cy)] =-1

def find(d):
    for key in d.keys():
        if d[key] >0:
            for x,y,h in verify:
                if (d[key]-abs(key[0]-x) - abs(key[1]-y))>0:
                    continue
            return key,d[key]

(X,Y),H = find(Cxy)
print(X,Y,H)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
data = []
for i in range(N):
    v = map(int, raw_input().split())
    data.append(v)

cond = []
for x in range(100+1):
    for y in range(100+1):
        h = []
        for d in data:
            if d[2] != 0:
                h.append(d[2] + abs(d[0]-x) + abs(d[1]-y))
        if len(set(h)) == 1:
            cond.append((x, y, h[0]))

if len(cond) == 1:
    print cond[0][0], cond[0][1], cond[0][2]
else:
    for c in cond:
        for d in data:
            if d[2] == 0:
                if c[2] - (abs(d[0]-c[0]) + abs(d[1]-c[1])) <= 0:
                    print c[0], c[1], c[2]
                    exit(0)

Submission status: Wrong Answer

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

Cxy = defaultdict(int)

#-1 NG
# 0 default
#1+ ok
verify =[(1000,1000,0)]
for x,y,h in XYH:
    for cx in range(101):
        for cy in range(101):
            val = Cxy[(cx,cy)]
            if val<0:
                continue
            tmp_H = abs(x-cx)+abs(y-cy)+h
            if h==0:
                verify.append((x,y,h))
                continue #????

            if val==0:
                Cxy[(cx,cy)] = tmp_H
            elif val != tmp_H:
                Cxy[(cx, cy)] =-1

def find(d):
    for key in d.keys():
        if d[key] >0:
            for x,y,h in verify:
                if (d[key]-abs(key[0]-x) - abs(key[1]-y))>0:
                    continue
            return key,d[key]

(X,Y),H = find(Cxy)
print(X,Y,H)

Submission status: Wrong Answer

Solution code:
n = input()
l = []
isz = 0
for i in xrange(n):
    x, y, h = map(int, raw_input().strip().split())
    if h == 0: isz += 1
    l.append([x, y, h])

assert isz != n

for cx in xrange(101):
    for cy in xrange(101):
        H = 0
        poss = True
        for xyh in l:
            x, y, h = xyh
            tx = abs(cx - x) + abs(cy - y)
            if h != 0:
                nH = tx + h
                if H != 0 and nH != H:
                    poss = False
                    break
                elif H == 0: H = nH
                
        if poss:
            print cx, cy, H
            break
        
    if poss: break
    
assert poss == True

Submission status: Wrong Answer

Solution code:
def H(h,cx,cy,x,y):
    return h+abs(cx-x)+abs(cy-y)

n = int(input())
arr=[]
for i in range(n):
    arr.append(list(map(int, input().split())))
isSame = True
for cx in range(0,101):
    for cy in range(0,101):
        isSame = True
        h_prev=-1
        for a in arr:
            if a[2]>0:
                h= H(a[2],cx,cy,a[0],a[1])
                if h_prev==-1:
                    h_prev=h
                if h!=h_prev:
                    isSame=False
                    break
                else:
                    h_prev=h
        if isSame==True:
            print("{} {} {}".format(cx,cy,h))
            exit