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:

from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]

    kari = [[0 for i in range(101)]for j in range(101)]

    x, y, h = data[0]
    for i in range(101):
        for j in range(101):
            kyori = abs(i - x) + abs(j - y)
            kari[i][j] = h + kyori


    for k in range(num):
        x, y, h = data[k]

        for i in range(101):
            for j in range(101):
                kyori = abs(i - x) + abs(j - y)
                if h + kyori == kari[i][j]:
                    # if k == 3:
                    #     print(x, y, h, kari[i][j], i, j)
                    pass
                else:
                    kari[i][j] = -1

    for i in range(101):
        for j in range(101):
            if kari[i][j] >= 0:
                print(i, j, kari[i][j])




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():

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

    for cx in range(101):
        for cy in range(101):
            H = -1
            b = True
            for i in I:
                h = abs(i[0]-cx) + abs(i[1]-cy) + i[2]
                if H == -1:
                    H = h
                if H != h:
                    b = False
                    break
            if b:
                print(cx, cy, H)
                return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
x, y, h = [], [], []
for _ in range(n):
    xi, yi, hi = map(int, input().split())
    if hi != 0:
        x.append(xi)
        y.append(yi)
        h.append(hi)
candidate_cx = list(range(min(x), max(x) + 1))
candidate_cy = list(range(min(y), max(y) + 1))

for cx, cy in list(itertools.product(candidate_cx, candidate_cy)):
    adapted = True
    ch = 0
    for xi, yi, hi in zip(x, y, h):
        ch = max(ch, hi + abs(xi - cx) - abs(yi - cy))
    for xi, yi, hi in zip(x, y, h):
        if hi != ch - abs(xi - cx) - abs(yi - cy):
            adapted = False
            break
    if adapted == False:
        continue
    print(cx, cy, ch, sep = ' ')
    exit(0)

Submission status: Wrong Answer

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

def main():

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

    for cx in range(101):
        for cy in range(101):
            H = 0
            b = True
            for i in I:
                h = abs(i[0]-cx) + abs(i[1]-cy) + i[2]
                if H == 0:
                    H = h
                elif H != h:
                    b = False
                    break
            if b:
                print(cx, cy, H)
                return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
n,a=int(input()),[]
for i in range(n):
    a.append(list(map(int,input().split())))
for x in range(101):
    for y in range(101):
        b=a[0][2]+abs(x-a[0][0])+abs(y-a[0][1])
        c=0
        for i in range(n-1):
            if b-a[i+1][2]!=abs(x-a[i+1][0])+abs(y-a[i+1][1]):
                c=1
        if c==0:
            print(x,y,b)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import math;

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def main():
    n = int(input())
    x = []
    y = []
    h = []
    for i in range(n):
        a,b,c = map(int,input().split())
        x.append(a)
        y.append(b)
        h.append(c)
    for i in range(n):
        if h[i]!=0:
            setH = i
            break
    for i in range(101):
        for j in range(101):
            H = h[setH] + abs(x[setH]-i) + abs(y[setH]-j)
            ac = 0
            for k in range(n):
                if h[k]+abs(x[k]-i)+abs(y[k]-j)!=H:
                    if h[k]+abs(x[k]-i)+abs(y[k]-j)>0:
                        ac = -1
                        break
                    else:
                        ac = 1
                else:
                    ac = 1
            if ac>0:
                print("{} {} {}".format(i,j,H))
                return
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math;

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def main():
    n = int(input())
    x = []
    y = []
    h = []
    for i in range(n):
        a,b,c = map(int,input().split())
        x.append(a)
        y.append(b)
        h.append(c)
    for i in range(n):
        if h[i]!=0:
            setH = i
            break
    for i in range(101):
        for j in range(101):
            H = h[setH] + abs(x[setH]-i) + abs(y[setH]-j)
            ac = 0
            h0 = []
            for k in range(n):
                if h[k]+abs(x[k]-i)+abs(y[k]-j)!=H:
                    if h[k]+abs(x[k]-i)+abs(y[k]-j)>0:
                        ac = -1
                        break
                else:
                    ac = 1
            if ac>0:
                print("{} {} {}".format(i,j,H))
                return
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

            if all(
                [
                    h == max(z + abs(x - cx) + abs(y - cy), 0)
                    for x, y, z in points
                    if z != 0
                ]
            ):
                print(cx, cy, h)
                return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

xyh.sort(key=lambda x: -x[2])

for x in range(101):
  for y in range(101):
    flg = True
    for i in range(N):
      if i == 0:
        ansh = xyh[i][2] + (abs(xyh[i][0] - x) + abs(xyh[i][1] - y))
      else:
        kouhoh = xyh[i][2] + (abs(xyh[i][0] - x) + abs(xyh[i][1] - y))
        if ansh != kouhoh:
          flg = False
          break
    if flg:
      print(x, y, ansh)
      exit()

Submission status: Wrong Answer

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

xyh.sort(key=lambda x: -x[2])

for x in range(101):
  for y in range(101):
    for i in range(N):
      if i == 0:
        ansh = xyh[i][2] + (abs(xyh[i][0] - x) + abs(xyh[i][1] - y))
        ansx = x
        ansy = y
      else:
        kouhoh = xyh[i][2] + (abs(xyh[i][0] - x) + abs(xyh[i][1] - y))
        if ansh != kouhoh:
          break
      if i == N - 1:
        print(ansx, ansy, ansh)
        exit()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

info.sort(reverse=True)

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

info.sort(reverse=True)

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

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

Submission status: Wrong Answer

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

def main():
    for cx in range(101):
        for cy in range(101):
            h = -1
            success = True
            for xi, yi, hi in info:
                if hi == 0:
                    continue

                if h == -1:
                    h = abs(xi - cx) + abs(yi - cy) + hi
                elif h != abs(xi - cx) + abs(yi - cy) + hi:
                    success = False
                    break

            if success:
                print(cx, cy, h)
                return

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = [[l[i][2], l[i][0], l[i][1]] for i in range(n)]
l.sort()

for x in range(101):
    for y in range(101):
        h = l[0][0] + abs(x-l[0][1]) + abs(y-l[0][2])
        for i in range(1, n):
            if l[i][0] != max(h-abs(x-l[i][1])-abs(y-l[i][2]), 0):
                break
        else:
            print(str(x) + " " + str(y) + " " + str(h))
            exit()

Submission status: Wrong Answer

Solution code:
#ABC112C
n = int(input())
x,y,h = [0]*n,[0]*n,[0]*n
for i in range(n):
    x[i],y[i],h[i]=list(map(int,input().split()))

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

c_x,c_y,H = -1,-1,-1
for i in range(101):
    for j in range(101):
        h_ = -1
        for k in range(n):
            d = dist(i,j,x[k],y[k])
            if h_ == -1:
                h_ = d + h[k]
            elif h[k]!=max(h_-d,0):
                break
            if k==n-1:
                c_x,c_y,H =i,j,d+h[k]

print(c_x,c_y,H)

Submission status: Wrong Answer

Solution code:
#ABC112C
n = int(input())
x,y,h = [0]*n,[0]*n,[0]*n
for i in range(n):
    x[i],y[i],h[i]=list(map(int,input().split()))

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

c_x,c_y,H = 0,0,0
for i in range(101):
    for j in range(101):
        h_ = -1
        for k in range(n):
            if h[k]>0:
                d = dist(i,j,x[k],y[k])
                if h_ == -1:
                    h_ = d + h[k]
                elif h_!=d+h[k]:
                    break
            if k==n-1:
                c_x,c_y,H =i,j,d+h[k]

print(c_x,c_y,H)

Submission status: Wrong Answer

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

xx, yy, hh = next(l for l in L if l[2] >= 1)
for Cx in range(101):
    for Cy in range(101):
        H = hh + abs(xx - Cx) + abs(yy - Cy)
        for x, y, h in L:
            if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
                break
        else:
            print(Cx, Cy, H)
            quit()

Submission status: Wrong Answer

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

ans_x = 0
ans_y = 0
before = 0
cnt = 0

for cx in range(101):
    for cy in range(101):
        for x,y,h in xyh:
            if cnt ==0:
                before = max(abs(cx-x)+abs(cy-y)+h, 0)
            height = max(abs(cx-x)+abs(cy-y)+h, 0)
            if height != before:
                cnt = 0
                break
            before = height
            cnt += 1
            if cnt == n:
                print(' '.join(map(str,[cx,cy,height])))
                exit()