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())
coords = [tuple(map(int, input().split())) for i in range(n)]
left, right, top, down = 0, 100, 0, 100
iplusj = -1
H = -1
for i in range(n):
    x1, y1, h1 = coords[i]
    for j in range(i+1, n):
        x2, y2, h2 = coords[j]
        if h2-h1< 0:
            h2, x2, y2, h1, x1, y1 = h1, x1, y1, h2, x2, y2
        if h1 == 0 or h2 == 0:
            continue
        dx = x2 - x1
        dy = y2 - y1
        dh = h2 - h1
        print (left, right, x1, x2)
        if abs(dh) < abs(dx) + abs(dy):
            d = (abs(dx) + abs(dy) - abs(dh))//2 
            if H < max(h1, h2) + d:
                #print (x1, y1, h1, x2, y2, h2, d)
                H = max(h1, h2) + d
                if dx > 0 or dy > 0:
                    iplusj = x2-d+y2
                elif dx < 0 or dy < 0:
                    iplusj = x2+d+y2
            """
            if dx > 0:
                left = max(x1, left)
                right = min(x2, right)
            elif dx < 0:
                left = max(x2, left)
                right = min(x1, right)
            if dy > 0:
                top = max(y1, top)
                down = min(y2, down)
            elif dy < 0:
                top = max(y2, top)
                down = min(y1, down)
            """
        else:
            #print (h1, x1, y1, h2, x2, y2)
            if dx > 0:
                left = max(x1, left)
                right = min(x2, right)
            elif dx < 0:
                left = max(x2, left)
                right = min(x1, right)
            if dy > 0:
                top = max(y1, top)
                down = min(y2, down)
            elif dy < 0:
                top = max(y2, top)
                down = min(y1, down)
print ("iplusj", left, right, top, down, iplusj, H)
if iplusj == -1:
    no1 = max(coords, key=lambda x: x[2])
    x, y, H = no1
    print (x, y, H)
else:
    for y in range(101):
        x = iplusj - y
        if x < 0:
            continue
        success = True
        for i in range(n):
            x1, y1, h1 = coords[i]
            if h1 == 0:
                continue
            dx, dy = x-x1, y-y1
            #print (x, y, h1, abs(dx), abs(dy), H)
            if (h1 + abs(dx)+abs(dy) != H):
                success = False
                break
        if success:
            print (x, y, H)
            break

Submission status: Wrong Answer

Solution code:
N = int(input())

high_sets = [list(map(int, input().split())) for _ in range(N)]

# このセットから中心座標と高さは絞り込める


def compute_diff_from_top(x, y, cx, cy):
    # -4 + -77
    return ((-1 * abs(x - cx)) + (-1 * abs(y - cy)))


ans = 0
ans_x = None
ans_y = None
for i in range(101):
    for j in range(101):
        nums = set([])
        for high_set in high_sets:
            # i == 55 j == 80
            # high_set_x = 59 high_set_y = 3
            # high_set[2] == 0の時は、区別が必要。
            num = high_set[2] + (-1 * compute_diff_from_top(i, j, high_set[0], high_set[1]))
            if high_set[2] == 0:
                pass
            else:
                nums.add(num)
        # if i == 55:
        #     print(i, j, nums)
        if len(nums) == 1:
            ans_x, ans_y = i, j
            ans = nums.pop()

print(ans_x, ans_y, ans)
# 55 80 79

Submission status: Wrong Answer

Solution code:
N = int(input())

high_sets = [list(map(int, input().split())) for _ in range(N)]

# このセットから中心座標と高さは絞り込める


def compute_diff_from_top(x, y, cx, cy):
    return (-1 * abs(x - cx)) + (-1 * abs(y - cy))


ans = 0
ans_x = None
ans_y = None
for i in range(101):
    for j in range(101):
        nums = set([])
        for high_set in high_sets:
            num = high_set[2] + (-1 * compute_diff_from_top(i, j, high_set[0], high_set[1]))
            nums.add(num)
        # if i == 2:
            # print(i, j, nums)
        if len(nums) == 1:
            ans_x, ans_y = i, j
            ans = nums.pop()

print(ans_x, ans_y, ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
coords = [tuple(map(int, input().split())) for i in range(n)]
left, right, top, down = 0, 100, 0, 100
iplusj = -1
H = -1
for i in range(n):
    x1, y1, h1 = coords[i]
    for j in range(i+1, n):
        x2, y2, h2 = coords[j]
        if h1-h1< 0:
            h2, x2, y2, h1, x1, y1 = h1, x1, y1, h2, x2, y2
        dx = x2 - x1
        dy = y2 - y1
        dh = h2 - h1
        if abs(dh) < abs(dx) + abs(dy):
            d = (abs(dx) + abs(dy) - abs(dh))//2
            #print (h1, x1, y1, h2, x2, y2, d)
            H = max(h2, h1) + d
            if dx >= 0:
                left = max(x1, left)
                right = min(x2, right)
                iplusj = x2-d+y2
            else:
                left = max(x2, left)
                right = min(x1, right)
                iplusj = x2+d+y2
            if dy > 0:
                top = max(y1, top)
                down = min(y2, down)
            else:
                top = max(y2, top)
                down = min(y1, down)
        else:
            #print (h1, x1, y1, h2, x2, y2)
            if dx > 0:
                left = max(x1, left)
                right = min(x2, right)
            elif dx < 0:
                left = max(x2, left)
                right = min(x1, right)
            if dy > 0:
                top = max(y1, top)
                down = min(y2, down)
            elif dy < 0:
                top = max(y2, top)
                down = min(y1, down)
#print (left, right, top, down, iplusj)
if iplusj == -1:
    no1 = max(coords, key=lambda x: x[2])
    x, y, H = no1
else:
    for y in range(101):
        x = iplusj - y
        success = True
        for i in range(n):
            x1, y1, h1 = coords[i]
            dx, dy = x-x1, y-y1
            if (h1 + abs(dx)+abs(dy) != H):
                success = False
                continue
        if success:
            break
print (x, y, H)

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
h_list =[0]*N

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

from bisect import bisect_right
xyh.sort(key =lambda x:x[2])
h_list.sort()
ind =bisect_right(h_list,0)
from collections import defaultdict
H =defaultdict(set)

for x,y,h in xyh[ind:]:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                H[(cx,cy)].add( (h -xx -yy) )
            
#print(xyh)
#H.sort(key =lambda x:x[1])
for k,v in H.items():
   
    if len(v)==1:
        vv =v.pop()
        if 0 <= vv :
            print(*k,vv)
        elif vv <0:
            print(*k,0)

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
h_list =[0]*N

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

from bisect import bisect_right
xyh.sort(key =lambda x:x[2])
h_list.sort()
ind =bisect_right(h_list,0)
from collections import defaultdict
H =defaultdict(set)

for x,y,h in xyh[ind:]:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                H[(cx,cy)].add( (h -xx -yy) )
            
#print(xyh)
#H.sort(key =lambda x:x[1])
for k,v in H.items():
   
    if len(v)==1:
        vv =v.pop()
        if 0 <= vv <=10**9:
            print(*k,vv)
        elif vv <0:
            print(*k,0)
        elif 10**9 <vv:
            print(*k,10**9)
        break

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
h_list =[0]*N

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

from bisect import bisect_left
xyh.sort(key =lambda x:x[2])
h_list.sort()
ind =bisect_left(h_list,0)
from collections import defaultdict
H =defaultdict(set)

for x,y,h in xyh[ind:]:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                 H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                 H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                 H[(cx,cy)].add( (h -xx -yy) )
            
#print(xyh)
#H.sort(key =lambda x:x[1])
for k,v in H.items():
   
    if len(v)==1:
        vv =v.pop()
        if 0 <= vv <=10**9:
            print(*k,vv)
        elif vv <0:
            print(*k,0)
        elif 10**9 <vv:
            print(*k,10**9)

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
for i in range(N):
    xyh[i] = tuple(int(i) for i in input().split())

from collections import defaultdict
H =defaultdict(set)
for x,y,h in xyh:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                 H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                 H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                 H[(cx,cy)].add( (h -xx -yy) )
            
#print(xyh)
#H.sort(key =lambda x:x[1])
for k,v in H.items():
   
    if len(v)==1:
        vv =v.pop()
        if 0 <= vv <=10**9:
            print(*k,vv)
        elif vv <0:
            print(*k,0)
        elif 10**9 <vv:
            print(*k,10**9)

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
for i in range(N):
    xyh[i] = tuple(int(i) for i in input().split())

from collections import defaultdict
H =defaultdict(set)
for x,y,h in xyh:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                 H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                 H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                 H[(cx,cy)].add( (h -xx -yy) )
            
#print(xyh)
#H.sort(key =lambda x:x[1])
for k,v in H.items():
    if len(v)==1:
        print(*k,*v)

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
for i in range(N):
    xyh[i] = tuple(int(i) for i in input().split())

from collections import defaultdict
H =defaultdict(set)
for x,y,h in xyh:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                 H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                 H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                 H[(cx,cy)].add( (h -xx -yy) )
            
print(xyh)
#H.sort(key =lambda x:x[1])
for k,v in H.items():
    if len(v)==1:
        print(*k,*v)

Submission status: Wrong Answer

Solution code:
#c
N=int(input())
XYH = [None]*N
for i in range(N):
    XYH[i] = list(map(int,input().split()))

for cx in range(101):
    for cy in range(101):
        found=False
        for i in range(N):
            d = abs(XYH[i][0]-cx)+abs(XYH[i][1]-cy)
            
            if XYH[i][2]>0 and not found:
                h = XYH[i][2]+d
                found=True
#                 print(cx,cy,h)
            if found and XYH[i][2]!= max(0,h-d):
                break
        else:
            print(cx,cy,h)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2], reverse=True)

# print(xyh)
ans = (0,0,0)
for c_x in range(101):
    for c_y in range(101):
        H = 0
        flag = True
        for i, (x, y, h) in enumerate(xyh):
            if i == 0:
                H = h + abs(x - c_x) + abs(y - c_y)
            if H != max(h + abs(x - c_x) + abs(y - c_y), 0):
                flag = False
        if flag:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2], reverse=True)

# print(xyh)
ans = (0,0,0)
for c_x in range(101):
    for c_y in range(101):
        H = -1
        flag = True
        for i, (x, y, h) in enumerate(xyh):
            if i == 0:
                H = h + abs(x - c_x) + abs(y - c_y)
            if H != h + abs(x - c_x) + abs(y - c_y):
                flag = False
        if flag:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2], reverse=True)

# print(xyh)
ans = (0,0,0)
for c_x in range(101):
    for c_y in range(101):
        H = -1
        flag = True
        for i, (x, y, h) in enumerate(xyh):
            if H == -1:
                H = h + abs(x - c_x) + abs(y - c_y)
            if H != h + abs(x - c_x) + abs(y - c_y):
                flag = False
        if flag:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2], reverse=True)

# print(xyh)
ans = (0,0,0)
for c_x in range(101):
    for c_y in range(101):
        H = -1
        for i, (x, y, h) in enumerate(xyh):
            if H == -1:
                H = h + abs(x - c_x) + abs(y - c_y)
            if H != h + abs(x - c_x) + abs(y - c_y):
                break
        else:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

Submission status: Wrong Answer

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

ans = False
for cy in range(101):
    for cx in range(101):
        x0, y0, h0 = xyh[0]
        H = abs(x0-cx) + abs(y0-cy) + h0
        # 全てのクエリについて高さを計算する
        for x, y, h in xyh[1:]:
            hh = max(H-abs(x-cx)-abs(y-cy), 0)
            if h > 0 and h != hh:
                break
        else:
            # 回り切ったら答え
            ans = True
            print(cx, cy, H)
            break
        if ans:
            break
    if ans:
        break

Submission status: Wrong Answer

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

ans = False
for cy in range(101):
    for cx in range(101):
        x0, y0, h0 = xyh[0]
        H = abs(x0-cx) + abs(y0-cy) + h0
        # 全てのクエリについて高さを計算する
        for x, y, h in xyh[1:]:
            hh = max(H-abs(x-cx)-abs(y-cy), 0)
            if h != hh:
                break
        else:
            # 回り切ったら答え
            ans = True
            print(cx, cy, H)
            break
        if ans:
            break
    if ans:
        break

Submission status: Wrong Answer

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

ans = False
for cy in range(101):
    for cx in range(101):
        x0, y0, h0 = xyh[0]
        H = abs(x0-cx) + abs(y0-cy) + h0
        # 全てのクエリについて試す
        for x, y, h in xyh[1:]:
            HH = abs(x-cx) + abs(y-cy) + h
            if H != HH:
                break
        else:
            # 回り切ったら答え
            ans = True
            print(cx, cy, H)
            break
        if ans:
            break
    if ans:
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
xyh = [tuple(map(int, input().split())) for _ in range(n)]
for cy in range(101):
    for cx in range(101):
        x0, y0, h0 = xyh[0]
        H = abs(x0-cx) + abs(y0-cy) + h0
        # 全てのクエリについて試す
        for x, y, h in xyh[1:]:
            HH = abs(x-cx) + abs(y-cy) + h
            if H != HH:
                break
        else:
            # 回り切ったら答え
            print(cx, cy, H)
            break

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[]
for i in range(n):
  x,y,h=nii()
  l.append([x,y,h])
  if h!=0:
    ini_x=x
    ini_y=y
    ini_h=h

for tx in range(101):
  for ty in range(101):
    n_h=abs(tx-ini_x)+abs(ty-ini_y)+ini_h

    check=1
    for x,y,h in l:
      t_h=max(abs(tx-x)+abs(ty-y)+h,0)
      if n_h!=t_h:
        check=0
    if check==1:
        print(tx,ty,n_h)
        exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[]
for i in range(n):
  x,y,h=nii()
  l.append([x,y,h])
  if h!=0:
    ini_x=x
    ini_y=y
    ini_h=h

for tx in range(101):
  for ty in range(101):
    n_h=abs(tx-ini_x)+abs(ty-ini_y)+ini_h
    for x,y,h in l:
      t_h=max(abs(tx-x)+abs(ty-y)+h,0)
      if n_h!=t_h:
        break
    else:
        print(tx,ty,n_h)
        exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[]
for i in range(n):
  x,y,h=nii()
  l.append([x,y,h])
  if h!=0:
    ini_x=x
    ini_y=y
    ini_h=h

if n==1:
  print(ini_x,ini_y,ini_h)
  exit()

ans_x=[]
ans_y=[]
ans_h=[]

for tx in range(101):
  for ty in range(101):
    n_h=abs(tx-ini_x)+abs(ty-ini_y)+ini_h
    for x,y,h in l:
      t_h=abs(tx-x)+abs(ty-y)+h
      if h!=0 and n_h!=t_h:
        break
      if h==0 and n_h>t_h:
        break
    else:
      ans_x.append(tx)
      ans_y.append(ty)
      if [tx,ty,0] in l:
        ans_h.append(0)
      else:
        ans_h.append(t_h)

inx=ans_h.index(max(ans_h))
print(ans_x[inx],ans_y[inx],ans_h[inx])

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[]
for i in range(n):
  x,y,h=nii()
  l.append([x,y,h])
  if h!=0:
    ini_x=x
    ini_y=y
    ini_h=h

ans_x=[]
ans_y=[]
ans_h=[]

for tx in range(101):
  for ty in range(101):
    n_h=abs(tx-ini_x)+abs(ty-ini_y)+ini_h
    for x,y,h in l:
      t_h=abs(tx-x)+abs(ty-y)+h
      if h!=0 and n_h!=t_h:
        break
      if h==0 and n_h>t_h:
        break
    else:
      ans_x.append(tx)
      ans_y.append(ty)
      if [tx,ty,0] in l:
        ans_h.append(0)
      else:
        ans_h.append(t_h)

inx=ans_h.index(max(ans_h))
print(ans_x[inx],ans_y[inx],ans_h[inx])

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[]
for i in range(n):
  x,y,h=nii()
  l.append([x,y,h])
  if h!=0:
    ini_x=x
    ini_y=y
    ini_h=h

ans_x=[]
ans_y=[]
ans_h=[]

for tx in range(101):
  for ty in range(101):
    n_h=abs(tx-ini_x)+abs(ty-ini_y)+ini_h
    for x,y,h in l:
      if h==0:
        continue

      t_h=abs(tx-x)+abs(ty-y)+h
      if n_h!=t_h:
        break
    else:
      ans_x.append(tx)
      ans_y.append(ty)
      if [tx,ty,0] in l:
        ans_h.append(0)
      else:
        ans_h.append(t_h)

inx=ans_h.index(max(ans_h))
print(ans_x[inx],ans_y[inx],ans_h[inx])

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[lnii() for i in range(n)]

ans_x=[]
ans_y=[]
ans_h=[]

for tx in range(101):
  for ty in range(101):
    t_h=0
    for x,y,h in l:
      if h==0:
        continue

      dist=abs(tx-x)+abs(ty-y)
      if t_h==0:
        t_h=h+dist
      else:
        if t_h!=h+dist:
          break
    else:
      ans_x.append(tx)
      ans_y.append(ty)
      if [tx,ty,0] in l:
        ans_h.append(0)
      else:
        ans_h.append(t_h)

inx=ans_h.index(max(ans_h))
print(ans_x[inx],ans_y[inx],ans_h[inx])

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[lnii() for i in range(n)]

ans_x=[]
ans_y=[]
ans_h=[]

for tx in range(101):
  for ty in range(101):
    t_h=-1
    for x,y,h in l:
      if h==0:
        continue

      dist=abs(tx-x)+abs(ty-y)
      if t_h==-1:
        t_h=h+dist
      else:
        if t_h!=h+dist:
          break
    else:
      ans_x.append(tx)
      ans_y.append(ty)
      ans_h.append(t_h)

inx=ans_h.index(max(ans_h))
print(ans_x[inx],ans_y[inx],ans_h[inx])

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[lnii() for i in range(n)]

if n==1:
  print(*l[0])
  exit()

ans_x=[]
ans_y=[]
ans_h=[]

for tx in range(101):
  for ty in range(101):
    t_h=-1
    for x,y,h in l:
      dist=abs(tx-x)+abs(ty-y)
      if t_h==-1:
        t_h=h+dist
      else:
        if t_h!=h+dist:
          break
    else:
      ans_x.append(tx)
      ans_y.append(ty)
      ans_h.append(t_h)
      print(tx,ty,t_h)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[lnii() for i in range(n)]

if n==1:
  print(*l[0])
  exit()

for tx in range(101):
  for ty in range(101):
    t_h=0
    for x,y,h in l:
      dist=abs(tx-x)+abs(ty-y)
      if t_h==0:
        t_h=h+dist
      else:
        if t_h!=h+dist:
          break
    else:
      ans_x=tx
      ans_y=ty
      ans_h=t_h
      print(ans_x,ans_y,ans_h)
      exit()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    X, Y, H = [], [], []
    for i in range(n):
        x, y, h = map(int, input().split())
        X.append(x), Y.append(y), H.append(h)

    for cx in range(101):
        for cy in range(101):
            res = []
            for x, y, h in zip(X, Y, H):
                if h == 0:
                    continue
                hh = h + abs(x - cx) + abs(y - cy)
                res.append(hh)
            if len(set(res)) == 1:
                print(cx, cy, res[0])


solve()

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh=sorted(xyh,key=lambda x:x[2])
for cx in range(101):
    for cy in range(101):
        h_a=h_b=10**10
        minh=10**10
        for i in range(n):
            x,y,h=xyh[i]
            if h!=0:
                h_a=h+abs(cx-x)+abs(cy-y)
                if h_b!=10**10 and (h_a!=h_b or h_a>minh):
                    break
                else:
                    h_b=h_a
            else:
                minh=min(minh,abs(cx-x)+abs(cy-y))
                if minh==0:
                  break
        else:
            if minh==1 and h_a==10**10:
              print(cx,cy,1)
              exit()
            else:
                print(cx,cy,h_a)
                exit()

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh=sorted(xyh,key=lambda x:x[2])
for cx in range(101):
    for cy in range(101):
        h_a=h_b=10**10
        minh=10**9+2
        for i in range(n):
            x,y,h=xyh[i]
            if h!=0:
                h_a=h+abs(cx-x)+abs(cy-y)
                if h_b!=10**10 and (h_a!=h_b or h_a>minh):
                    break
                else:
                    h_b=h_a
            else:
                minh=min(minh,abs(cx-x)+abs(cy-y))
                if minh==0:
                  break
        else:
            if minh==1 and h_a==10**10:
              print(cx,cy,1)
              exit()
            else:
                print(cx,cy,h_a)
                exit()

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh=sorted(xyh,key=lambda x:x[2])
for cx in range(101):
    for cy in range(101):
        h_a=h_b=10**10
        minh=10**9+2
        for i in range(n):
            x,y,h=xyh[i]
            if h!=0:
                h_a=h+abs(cx-x)+abs(cy-y)
                if h_b!=10**9+1 and (h_a!=h_b or h_a>minh):
                    break
                else:
                    h_b=h_a
            else:
                minh=min(minh,abs(cx-x)+abs(cy-y))
                if minh==0:
                  break
        else:
            if minh==1 and h_a==10**10:
              print(cx,cy,1)
              exit()
            else:
                print(cx,cy,h_a)
                exit()

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh=sorted(xyh,key=lambda x:x[2])
for cx in range(101):
    for cy in range(101):
        h_a=h_b=10**10
        minh=10**9+2
        for i in range(n):
            x,y,h=xyh[i]
            if h!=0:
                h_a=h+abs(cx-x)+abs(cy-y)
                if h_b!=10**10 and (h_a!=h_b or h_a>minh):
                    break
                else:
                    h_b=h_a
            else:
                minh=min(minh,abs(cx-x)+abs(cy-y))
                if minh==0:
                  break
        else:
            if h_a>=1:
              print(cx,cy,h_a)
              exit()

Submission status: Wrong Answer

Solution code:
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)
  if c!=0:q=[a,b,c]
for i in range(101):
  for j in range(101):
    H=q[2]+abs(q[0]-i)+abs(q[1]-j)
    for a,b,c in zip(x,y,h):
      if c!=max(H-abs(a-i)-abs(b-j),0):break
    else:
      print(i,j,h[0]+abs(x[0]-i)+abs(y[0]-j))
      exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]
y=[]
h=[]
for i in range(n):
  a,b,c=map(int,input().split())
  if c==0:continue
  x.append(a)
  y.append(b)
  h.append(c)
for i in range(101):
  for j in range(101):
    H=h[0]+abs(x[0]-i)+abs(y[0]-j)
    for a,b,c in zip(x,y,h):
      if c!=H-abs(a-i)-abs(b-j):break
    else:
      print(i,j,h[0]+abs(x[0]-i)+abs(y[0]-j))
      exit()