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:
N = int(input())
X = []
Y = []
H = []

N_MAX = 100
X_MAX = 101
H_MAX = 1000000000

for i in range(N):
    t = list(map(int,input().split()))
    X.append(t[0])
    Y.append(t[1])
    H.append(t[2])

coord = []
[[coord.append([i,j]) for j in range(X_MAX)] for i in range(X_MAX)]
check = [1 for i in range(len(coord))]

for i in range(N):
    if H[i] != 0:
        table = [[H[0]+abs(i-X[0])+abs(j-Y[0]) for j in range(X_MAX)] for i in range(X_MAX)]
        table_num = i
        break

for k in range(N):
    if k != table_num:
        if H[k] != 0:
            tmp = [[H[k]+abs(i-X[k])+abs(j-Y[k]) for j in range(X_MAX)] for i in range(X_MAX)]
            for i,c in enumerate(coord):
                if tmp[c[0]][c[1]] != table[c[0]][c[1]]:
                    check[i] = 0
flag = 0
if sum(check) == 1:
    top_coord = coord[check.index(1)]
    print(top_coord[0], top_coord[1], H[table_num]+abs(top_coord[0]-X[table_num])+abs(top_coord[1]-Y[table_num]))
elif sum(check) == len(check):
    print(X[table_num], Y[table_num], H[table_num])

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
H = []

N_MAX = 100
X_MAX = 101
H_MAX = 1000000000

for i in range(N):
    t = list(map(int,input().split()))
    X.append(t[0])
    Y.append(t[1])
    H.append(t[2])

coord = []
[[coord.append([i,j]) for j in range(X_MAX)] for i in range(X_MAX)]
check = [1 for i in range(len(coord))]

for i in range(N):
    if H[i] != 0:
        table = [[H[0]+abs(i-X[0])+abs(j-Y[0]) for j in range(X_MAX)] for i in range(X_MAX)]
        table_num = i
        break

for k in range(N):
    if k != table_num:
        if H[k] != 0:
            tmp = [[H[k]+abs(i-X[k])+abs(j-Y[k]) for j in range(X_MAX)] for i in range(X_MAX)]
            for i,c in enumerate(coord):
                if tmp[c[0]][c[1]] != table[c[0]][c[1]]:
                    check[i] = 0
flag = 0
if sum(check) == 1:
    top_coord = coord[check.index(1)]
    print(top_coord[0], top_coord[1], H[table_num]+abs(top_coord[0]-X[table_num])+abs(top_coord[1]-Y[table_num]))
elif sum(check) == len(check):
    print(X[table_num], Y[table_num], H[table_num])
else: # sum(check) > 1
    for i in range(len(check)):
        if check[i] == 1:
            for x,y,h in zip(X, Y, H):
                tmp_top_coord = coord[i]
                tmp_top_H = H[table_num]+abs(tmp_top_coord[0]-X[table_num])+abs(tmp_top_coord[1]-Y[table_num])
                if abs(tmp_top_coord[0]-x)+abs(tmp_top_coord[1]-y)+h != tmp_top_H:
                    break
                flag == 1
            if flag == 1:
                print(tmp_top_coord[0], tmp_top_coord[1], tmp_top_H)
                break

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
xyhs = []
for _ in range(n):
    xyh = list(map(int, input().split()))
    xyhs.append(xyh)

for x in range(101):
    for y in range(101):
        h = -1
        is_vertex = True
        for xyh in xyhs:
            temp_h = abs(xyh[0]-x)+abs(xyh[1]-y)+xyh[2]
            if h == -1:
                h = temp_h
            if temp_h != h:
                is_vertex = False
                break
        if is_vertex:
            print("{x} {y} {h}".format(x=x, y=y, h=max(h,0)))
            sys.exit()

Submission status: Wrong Answer

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

for x in range(101):
    for y in range(101):
        h = -1
        is_vertex = True
        for xyh in xyhs:
            temp_h = abs(xyh[0]-x)+abs(xyh[1]-y)+xyh[2]
            if h == -1:
                h = temp_h
            if temp_h != h:
                is_vertex = False
                break
        if is_vertex:
            print("{x} {y} {h}".format(x=x, y=y, h=max(h,0)))

Submission status: Wrong Answer

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

for x in range(101):
    for y in range(101):
        h = -1
        is_vertex = True
        for xyh in xyhs:
            temp_h = abs(xyh[0]-x)+abs(xyh[1]-y)+xyh[2]
            if h == -1:
                h = temp_h
            if temp_h != h:
                is_vertex = False
                break
        if is_vertex:
            print("{x} {y} {h}".format(x=x, y=y, h=h))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
H = []

N_MAX = 100
X_MAX = 101
H_MAX = 1000000000

for i in range(N):
    t = list(map(int,input().split()))
    X.append(t[0])
    Y.append(t[1])
    H.append(t[2])

coord = []
[[coord.append([i,j]) for j in range(X_MAX)] for i in range(X_MAX)]
check = [1 for i in range(len(coord))]

for i in range(N):
    if H[i] != 0:
        table = [[H[0]+abs(i-X[0])+abs(j-Y[0]) for j in range(X_MAX)] for i in range(X_MAX)]
        table_num = i
        break

for k in range(N):
    if k != table_num:
        if H[k] != 0:
            tmp = [[H[k]+abs(i-X[k])+abs(j-Y[k]) for j in range(X_MAX)] for i in range(X_MAX)]
            for i,c in enumerate(coord):
                if tmp[c[0]][c[1]] != table[c[0]][c[1]]:
                    check[i] = 0

if sum(check) == 1:
    top_coord = coord[check.index(1)]
    print(top_coord[0], top_coord[1], H[table_num]+abs(top_coord[0]-X[table_num])+abs(top_coord[1]-Y[table_num]))
elif sum(check) == len(check):
    print(X[table_num], Y[table_num], H[table_num])
else: # sum(check) > 1
    for i in range(len(check)):
        if check[i] == 1:
            for x,y,h in zip(X, Y, H):
                tmp_top_coord = coord[i]
                tmp_top_H = H[table_num]+abs(tmp_top_coord[0]-X[table_num])+abs(tmp_top_coord[1]-Y[table_num])
                if abs(tmp_top_coord[0]-x)+abs(tmp_top_coord[1]-y)+h != tmp_top_H:
                    break
            print(tmp_top_coord[0], tmp_top_coord[1], tmp_top_H)
            break

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
H = []

N_MAX = 100
X_MAX = 101
H_MAX = 1000000000

for i in range(N):
    t = list(map(int,input().split()))
    X.append(t[0])
    Y.append(t[1])
    H.append(t[2])

coord = []
[[coord.append([i,j]) for j in range(X_MAX)] for i in range(X_MAX)]
check = [1 for i in range(len(coord))]

for i in range(N):
    if H[i] != 0:
        table = [[H[0]+abs(i-X[0])+abs(j-Y[0]) for j in range(X_MAX)] for i in range(X_MAX)]
        table_num = i
        break

for k in range(0,N):
    if k != table_num:
        if H[k] != 0:
            tmp = [[H[k]+abs(i-X[k])+abs(j-Y[k]) for j in range(X_MAX)] for i in range(X_MAX)]
            for i,c in enumerate(coord):
                if tmp[c[0]][c[1]] != table[c[0]][c[1]]:
                    check[i] = 0

if sum(check) == 1:
    top_coord = coord[check.index(1)]
    print(top_coord[0], top_coord[1], H[table_num]+abs(top_coord[0]-X[table_num])+abs(top_coord[1]-Y[table_num]))
elif sum(check) == 0:
    print(X[table_num], Y[table_num], H[table_num])
else: # sum(check) > 1
    for i in range(len(check)):
        if check[i] == 1:
            for x,y,h in zip(X, Y, H):
                tmp_top_coord = coord[i]
                tmp_top_H = H[table_num]+abs(tmp_top_coord[0]-X[table_num])+abs(tmp_top_coord[1]-Y[table_num])
                if abs(tmp_top_coord[0]-x)+abs(tmp_top_coord[1]-y)+h != tmp_top_H:
                    break
            print(tmp_top_coord[0], tmp_top_coord[1], tmp_top_H)
            break

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
H = []
 
N_MAX = 100
X_MAX = 101
H_MAX = 1000000000
 
for i in range(N):
    t = list(map(int,input().split()))
    X.append(t[0])
    Y.append(t[1])
    H.append(t[2])
 
coord = []
[[coord.append([i,j]) for j in range(X_MAX)] for i in range(X_MAX)]
check = [1 for i in range(len(coord))]
 
for i in range(N):
    if H[i] != 0:
        table = [[H[0]+abs(i-X[0])+abs(j-Y[0]) for j in range(X_MAX)] for i in range(X_MAX)]
        table_num = i
        break
 
for k in range(0,N):
    if k != table_num:
        if H[k] != 0:
            tmp = [[H[k]+abs(i-X[k])+abs(j-Y[k]) for j in range(X_MAX)] for i in range(X_MAX)]
            for i,c in enumerate(coord):
                if tmp[c[0]][c[1]] != table[c[0]][c[1]]:
                    check[i] = 0
 
if sum(check) == 1:
    top_coord = coord[check.index(1)]
    print(top_coord[0], top_coord[1], H[table_num]+abs(top_coord[0]-X[table_num])+abs(top_coord[1]-Y[table_num]))
elif sum(check) == 0:
    print(X[table_num], Y[table_num], H[table_num])
else: # sum(check) > 1
    pass

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
H = []

N_MAX = 100
X_MAX = 101
H_MAX = 1000000000

for i in range(N):
    t = list(map(int,input().split()))
    X.append(t[0])
    Y.append(t[1])
    H.append(t[2])

coord = []
[[coord.append([i,j]) for j in range(X_MAX)] for i in range(X_MAX)]
check = [1 for i in range(len(coord))]

for i in range(N):
    if H[i] != 0:
        table = [[H[0]+abs(i-X[0])+abs(j-Y[0]) for j in range(X_MAX)] for i in range(X_MAX)]
        table_num = i
        break

for k in range(0,N):
    if k != table_num:
        if H[k] != 0:
            tmp = [[H[k]+abs(i-X[k])+abs(j-Y[k]) for j in range(X_MAX)] for i in range(X_MAX)]
            for i,c in enumerate(coord):
                if tmp[c[0]][c[1]] != table[c[0]][c[1]]:
                    check[i] = 0

if sum(check) == 1:
    top_coord = coord[check.index(1)]
    print(top_coord[0], top_coord[1], H[table_num]+abs(top_coord[table_num]-X[table_num])+abs(top_coord[1]-Y[table_num]))
elif sum(check) == 0:
    print(X[table_num], Y[table_num], H[table_num])
else: # sum(check) > 1
    pass

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
H = []

N_MAX = 100
X_MAX = 101
H_MAX = 1000000000

for i in range(N):
    t = list(map(int,input().split()))
    X.append(t[0])
    Y.append(t[1])
    H.append(t[2])

coord = []
[[coord.append([i,j]) for j in range(X_MAX)] for i in range(X_MAX)]
check = [1 for i in range(len(coord))]

for i in range(N):
    if H[i] != 0:
        table = [[H[0]+abs(i-X[0])+abs(j-Y[0]) for j in range(X_MAX)] for i in range(X_MAX)]
        table_num = i
        break

for k in range(0,N):
    if k != table_num:
        if H[k] != 0:
            tmp = [[H[k]+abs(i-X[k])+abs(j-Y[k]) for j in range(X_MAX)] for i in range(X_MAX)]
            for i,c in enumerate(coord):
                if tmp[c[0]][c[1]] != table[c[0]][c[1]]:
                    check[i] = 0

if sum(check) == 0:
    top_coord = coord[table_num]
else:
    top_coord = coord[check.index(1)]

print(top_coord[0], top_coord[1], H[0]+abs(top_coord[0]-X[0])+abs(top_coord[1]-Y[0]))

Submission status: Wrong Answer

Solution code:
def abc(n:int,lst:list):
    l0=list(filter(lambda x:x[2]==0,lst))
    l=list(filter(lambda x:x[2]!=0,lst))
    if len(l0):
        x0 =l[0][0]
        y0=l[0][1]
        h0 =l[0][2]
        ans=[]
        for x in range(101):
            for y in range(101):
                for i in range(len(l)):
                    if abs(x0-x)+abs(y0-y)-abs(l[i][0]-x)-abs(l[i][1]-y) == l[i][2]-h0:
                        if i ==len(l)-1:
                            ans.append([x,y])
                    else:
                        break
        for xy in ans:
            for h in range(1,201):
                for i in range(len(l0)):
                    if abs(l0[i][0]-xy[0])+abs(l0[i][1]-xy[1])>=h:
                        if i == len(l0)-1:
                            return xy[0],xy[1],h
                    else:
                        break
    else:
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)

Submission status: Wrong Answer

Solution code:
def abc(n:int,lst:list):
    l=list(map(lambda x:x[2],lst))
    if min(l)==0:
        M=max(map(lambda x:x[0],lst))+max(map(lambda x:x[1],lst))
        for x in range(101):
            for y in range(101):
                for h in range(M):
                    for i in range(n):
                        if max(0,h-abs(lst[i][0]-x)-abs(lst[i][1]-y)) ==lst[i][2]:
                            if i ==n-1:
                                return x,y,h
                        else:
                            break
    else:
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)
print("a")

Submission status: Wrong Answer

Solution code:
def abc(n:int,lst:list):
    l=list(map(lambda x:x[2],lst))
    if min(l)==0 and max(l)<201:
        print("a")
        for x in range(101):
            for y in range(101):
                for h in range(201):
                    for i in range(n):
                        if max(0,h-abs(lst[i][0]-x)-abs(lst[i][1]-y)) ==lst[i][2]:
                            if i ==n-1:
                                return [x,y,h]
                        else:
                            h=0
                            break
    else:
        print("b")
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)

Submission status: Wrong Answer

Solution code:
n = int(input())
pyramid = [[int(x) for x in input().split()] for y in range(n)]
tmp_pyramid = [[{} for x in range(101)] for y in range(101)]

for x, y, h in pyramid:
    tmp_pyramid[x][y].setdefault(h, 0)
    tmp_pyramid[x][y][h] += 1
    for j in range(101):
        for k in range(101):
            tmp_h = max(h - abs(x - j) - abs(y - k), 0)
            tmp_pyramid[j][k].setdefault(tmp_h, 0)
            tmp_pyramid[j][k][tmp_h] += 1
            tmp_h = max(h + abs(x - j) + abs(y - k), 0)
            tmp_pyramid[j][k].setdefault(tmp_h, 0)
            tmp_pyramid[j][k][tmp_h] += 1

res = 0
four_array = []
three_array = []
for j in range(101):
    for k in range(101):
        four_array += [[j, k, key] for key, value in tmp_pyramid[j][k].items() if value == 4]
        three_array += [[j, k, key] for key, value in tmp_pyramid[j][k].items() if value == 3]
        if (j == 100 and k == 100) or (j == 0 and k == 0) or (j == 100 and k == 0) or (j == 0 and k == 100):
            four_array += [[j, k, key] for key, value in tmp_pyramid[j][k].items() if value == 3]

if not four_array:
    ans = sorted(three_array, key=lambda x:x[2])[-1]
    print(ans[0], ans[1], ans[2])
else:
    ans = sorted(four_array, key=lambda x: x[2])[-1]
    print(ans[0], ans[1], ans[2])

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list()
Y = list()
H = list()
for n in range(0,N):
    S = list(map(int,input().split()))
    X.append(S[0])
    Y.append(S[1])
    H.append(S[2])
for x in range(0,101):
    for y in range(0,101):
        sub = abs(x - X[0]) + abs(y - Y[0]) + H[0]
        for n in range(1,N):
            Sub = abs(x-X[n]) + abs(y-Y[n]) + H[n]
            if not sub == Sub:
                break
            else:
                if n == N-1:
                    print(x, y, Sub)

Submission status: Wrong Answer

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

for cx in range(101):
    for cy in range(101):
        h=[]
        for i in range(N):
            if data[i][2]>0:
                h.append(data[i][2]+abs(cx-data[i][0]) + abs(cy-data[i][1]))
        if len(set(h))==1:
            ans = [cx,cy,h[0]]
            
print('{0[0]} {0[1]} {0[2]}'.format(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
data = [[0 for i in range(3)] for j in range(N)]
for i in range(N):
    data[i][0],data[i][1],data[i][2] = [int(s) for s in input().split()]


for p in data:
    if p[2] != 0:
        base_x = p[0]
        base_y = p[1]
        base_height = p[2]



fl = 0
for Cx in range(0,101):
    for Cy in range(0,101):
        s1 = abs(base_x-Cx)+abs(base_y-Cy)+base_height
        for i in range(1,N):
            if data[i][2] != 0:
                s2 = abs(data[i][0]-Cx)+abs(data[i][1]-Cy)+data[i][2]
            else:
                continue
            if s1 != s2:
                break
        else:
            H = s1
            cx = Cx
            cy = Cy
            fl = 1
        if fl:
            break
    if fl:
        break

print(cx,cy,H)

Submission status: Wrong Answer

Solution code:
dataset = []
for _ in range(int(input())):
	dataset.append(list(map(int, input().split())))
 
lastH = None
for cx, cy in [[x, y] for x in range(0, 101) for y in range(0, 101)]:
	flag = True
	for x, y, h in dataset:
		H = h + abs(x - cx) + abs(y - cy)
		if lastH:
			if h > 0:
				if lastH == H: continue
				else:
					flag = False
					lastH = None
					break
			else:
				if lastH - abs(x - cx) - abs(y - cy) <= 0: continue
				else:
					flag = False
					lastH = None
					break
		else:
			lastH = H
	if flag:
		print(cx, cy, lastH)

Submission status: Wrong Answer

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

lastH = None
for cx, cy in [[x, y] for x in range(101) for y in range(101)]:
	flag = True
	for x, y, h in dataset:
		H = h + abs(x - cx) + abs(y - cy)
		if lastH:
			if h > 0:
				if lastH == H: continue
				else:
					flag = False
					lastH = None
					break
			else:
				if lastH - abs(x - cx) - abs(y - cy) <= 0: continue
				else:
					flag = False
					lastH = None
					break
		else:
			lastH = H
	if flag:
		print(cx, cy, lastH)

Submission status: Wrong Answer

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

lastH = None
for cx, cy in [[x, y] for x in range(101) for y in range(101)]:
	flag = True
	for x, y, h in dataset:
		H = h + abs(x - cx) + abs(y - cy)
		if lastH:
			if lastH == H: continue
			else:
				flag = False
				lastH = None
				break
		else:
			lastH = H
	if flag:
		print(cx, cy, lastH)

Submission status: Wrong Answer

Solution code:
W = 101

def solve(xyh):
    for yy in range(W):
        for xx in range(W):
            H = set()
            for x, y, h in xyh:
                d = abs(xx - x) + abs(yy - y)
                if h > 0:
                    H.add(d + h)
            if len(H) == 1:
                h = H.pop()
                if 0 < h:
                    return (xx, yy, h)

N = int(input())
xyh = [tuple(map(int, input().split())) for i in range(N)]
print(*solve(xyh))

Submission status: Wrong Answer

Solution code:
N = int(input())
W = 101
INF = W ** 2
H = [[INF] * W for i in range(W)]
L = [[0] * W for i in range(W)]
for i in range(N):
    x, y, h = map(int, input().split())
    for yy in range(W):
        for xx in range(W):
            c = h + abs(xx - x) + abs(yy - y)
            H[yy][xx] = min(H[yy][xx], c)
            if h > 0:
                L[yy][xx] = max(L[yy][xx], c)
for yy in range(W):
    for xx in range(W):
        if H[yy][xx] == L[yy][xx]:
            print(xx, yy, H[yy][xx])

Submission status: Wrong Answer

Solution code:
N = int(input())
W = 101
EMPTY, INVALID = -1, -2
m = [[EMPTY] * W for i in range(W)]
for i in range(N):
    x, y, h = map(int, input().split())
    for yy in range(W):
        for xx in range(W):
            c = h + abs(xx - x) + abs(yy - y)
            if m[yy][xx] in (EMPTY, c):
                m[yy][xx] = c
            else:
                m[yy][xx] = INVALID
for yy in range(W):
    for xx in range(W):
        if m[yy][xx] != INVALID:
            print(xx, yy, m[yy][xx])

Submission status: Wrong Answer

Solution code:
N=input()

Data=[]
for i in range(N):
    Data.append(map(int,raw_input().split()))
    
Data.sort(key=lambda x:x[2], reverse=True)
for i in range(0,101):
    for j in range(0,101):
        H=Data[0][2]+abs(Data[0][0]-i)+abs(Data[0][1]-j)
        k=1
        while k<N:
            if H==Data[k][2]+abs(Data[k][0]-i)+abs(Data[k][1]-j):
                k+=1
            else:
                break
        if k==N:
            print i,j,H
            exit()

Submission status: Wrong Answer

Solution code:
N = int(input())

xyh = []

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

print("xyh",xyh)

xyh.sort(reverse=True, key=lambda x: x[2])

print("xyh",xyh)

for i in range(101):
    for j in range(101):
        px, py, ph = xyh[0]
        H = ph + abs(px-i) + abs(py-j)
        if all(h == max(H-abs(x - i) - abs(y - j),0) for x, y, h in xyh):
            print(i,j,H)
            break

Submission status: Wrong Answer

Solution code:
import sys
import itertools

cols = []
for line in sys.stdin:
  col = line.strip().split(' ')
  col = [int(c) for c in col]
  cols.append(col)

cols = cols[1:]
for cx,cy in itertools.product(list(range(101)), list(range(101))):
  H, H_max, flag = None, None, True
  for x,y,h in cols:
    if h <= 0:
      tmp_H_max = abs(x-cx) + abs(y-cy)
      if tmp_H_max < 1:
        flag = False
        break
      else:
        H_max = tmp_H_max if not H_max else min(H_max, tmp_H_max)
    else:
      tmp_H = h + abs(x-cx) + abs(y-cy)
      if not H:
        H = tmp_H
      if H and H != tmp_H:
        flag = False
        break
      if H_max and H_max < tmp_H:
        flag = False
        break
  if flag:
    print(cx,cy,H)

Submission status: Wrong Answer

Solution code:
import sys
import itertools

cols = []
for line in sys.stdin:
  col = line.strip().split(' ')
  col = [int(c) for c in col]
  cols.append(col)

cols = cols[1:]
for cx,cy in itertools.product(list(range(101)), list(range(101))):
  H, H_max, flag = None, None, True
  for x,y,h in cols:
    if h < 0:
      tmp_H_max = abs(x-cs) + abs(y-cy)
      if tmp_H_max < 1:
        flag = False
        break
      else:
        H_max = tmp_H_max if H_max is None else min(H_max, tmp_H_max)
    else:
      tmp_H = h + abs(x-cx) + abs(y-cy)
      if not H:
        H = tmp_H
      if H and H != tmp_H:
        flag = False
        break
      if H_max and H_max < tmp_H:
        flag = False
        break
  if flag:
    print(cx,cy,H)

Submission status: Wrong Answer

Solution code:
n = int(input())

xyh = []

for i in range(n):
    x, y, h = map(int, input().split())
    xyh.append([x, y, h])
    

for i in range(101):
    for j in range(101):
        px, py, ph = xyh[0]
        H = ph + abs(px - i) + abs(py - j)
        if all(h == max(H - abs(x - i) - abs(y -j), 0) for x, y, h in xyh):
            print(i, j, H)
            break

Submission status: Wrong Answer

Solution code:
#coding:utf-8

def validate(N, points, c_x, c_y):
    #estimate height
    x = points[0][0]
    y = points[0][1]
    h = points[0][2]
    estimated_height = h + abs(c_x - x) + abs(c_y - y)

    #validate height
    for n in range(1, N):
        x = points[n][0]
        y = points[n][1]
        h = points[n][2]
        height = max(estimated_height - abs(c_x - x) - abs(c_y - y), 0)

        if h != height:
            return -1
    return estimated_height

if __name__ == "__main__":
    N = int(input())
    points = [None] * N
    for n in range(N):
        x, y, h = map(int, input().split())
        points[n] = [x, y, h]

    candidates = [i for i in range(101)]
    for c_x in candidates:
        for c_y in candidates:
            height = validate(N, points, c_x, c_y)
            if height != -1:
                print(c_x, c_y, height)
                break

Submission status: Wrong Answer

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

for i in range(101):
  for j in range(101):
    for k in range(N):
      if xyh[k] != 0:
        H = xyh[k][2] + abs(i-xyh[k][0]) + abs(j-xyh[k][1])
        break
    is_h = True
    for k in range(N):
      if max(0, H-abs(i-xyh[k][0])-abs(j-xyh[k][1])) != xyh[k][2]:
        is_h = False
        break
    if is_h:
      print(i, j, H)

Submission status: Wrong Answer

Solution code:
N = int(input())

arr = []

for i in range(N):
    arr.append(list(map(int, input().split())))
    
for x in range(101):
    for y in range(101):
        for i in range(N):
            if arr[i][0] != 0 and arr[i][1] != 0:
                H = arr[i][2] + abs(x-arr[i][0]) + abs(y-arr[i][1])
                break
        ok = True
        for i in range(N):
            if max(H-abs(x-arr[i][0])-abs(y-arr[i][1]),0) != arr[i][2]:
                ok = False
        if ok :
            print(x,y,H)

Submission status: Wrong Answer

Solution code:
N = int(input())

arr = []

for i in range(N):
    arr.append(list(map(int, input().split())))
    
for x in range(101):
    for y in range(101):
        ok = True
        H = arr[0][2] + abs(x-arr[0][0]) + abs(y-arr[0][1])
        for i in range(N):
            if max(H-abs(x-arr[i][0])-abs(y-arr[i][1]),0) != arr[i][2]:
                ok = False
                continue
        if ok :
            print(x,y,H)
            break

Submission status: Wrong Answer

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

    if N == 1:
        print(x,y,h)
        exit()

    if h == 0:
        continue
    XYHA.append([x,y,h])

for i in range(101):
    for j in range(101):
        HC = max(XYHA[0][2] + abs(XYHA[0][0] - i) + abs(XYHA[0][1] - j), 0)
        for k in range(1, len(XYHA)):

            H = max(XYHA[k][2] + abs(XYHA[k][0] - i) + abs(XYHA[k][1] - j), 0)

            if HC != H:
                break
            elif k == len(XYHA) - 1:
                print(i,j,HC)
                exit()

Submission status: Wrong Answer

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

for i in range(101):
    for j in range(101):
        HC = max(XYHA[0][2] + abs(XYHA[0][0] - i) + abs(XYHA[0][1] - j), 0)
        for k in range(1, len(XYHA)):

            H = max(XYHA[k][2] + abs(XYHA[k][0] - i) + abs(XYHA[k][1] - j), 0)

            if HC != H:
                break
            elif k == len(XYHA) - 1:
                print(i,j,HC)
                exit()

Submission status: Wrong Answer

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

for i in range(101):
    for j in range(101):
        HC = XYHA[0][2] + abs(XYHA[0][0] - i) + abs(XYHA[0][1] - j)
        for k in range(1, len(XYHA)):

            H = XYHA[k][2] + abs(XYHA[k][0] - i) + abs(XYHA[k][1] - j)

            if HC != H:
                break
            elif k == len(XYHA) - 1:
                print(i,j,HC)
                exit()

print(1,1,1)

Submission status: Wrong Answer

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

for i in range(101):
    for j in range(101):
        HC = XYHA[0][2] + abs(XYHA[0][0] - i) + abs(XYHA[0][1] - j)
        for k in range(1, len(XYHA)):

            H = XYHA[k][2] + abs(XYHA[k][0] - i) + abs(XYHA[k][1] - j)

            if HC != H:
                break
            elif k == len(XYHA)-1:
                print(i,j,HC)
                exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
 
XYHA = []
 
for i in range(N):

    BBBB = input().split(" ")

    if BBBB[2] == '0':
        continue

    XYHA.append(BBBB)

for i in range(101):
    for j in range(101):
        HC = int(XYHA[0][2]) + abs(int(XYHA[0][0]) - i) + abs(int(XYHA[0][1]) - j)
        for k in range(1, len(XYHA)):

            H = int(XYHA[k][2]) + abs(int(XYHA[k][0]) - i) + abs(int(XYHA[k][1]) - j)

            if HC != H:
                break
            elif k == len(XYHA)-1:
                print(i,j,HC)
                exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
 
XYHA = []
 
for i in range(N):

    BBBB = input().split(" ")

    if BBBB[2] == '0':
        continue

    XYHA.append(BBBB)

for i in range(101):
    for j in range(101):
        OKFLG = True
        HC = int(XYHA[0][2]) + abs(int(XYHA[0][0]) - i) + abs(int(XYHA[0][1]) - j)
        for k in range(1, len(XYHA)):

            H = int(XYHA[k][2]) + abs(int(XYHA[k][0]) - i) + abs(int(XYHA[k][1]) - j)

            if HC != H:
                OKFLG = False
                break
            elif k == N-1:
                print(i,j,HC)
                exit()