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: Runtime Error

Solution code:
n=int(input())
xymap=[[-1 for j in range(101)] for i in range(101)]
inp=[]
for i in range(n):
    xi,yi,hi=map(int,input().split())
    if hi==0:
        inp.append(xi,yi,hi)
        pass
    else:
            
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]==a or xymap[x][y]==-1 :
                    xymap[x][y]=a
                else:
                    xymap[x][y]=-2
flag=0
for x in range(101):
    for y in range(101):
        if xymap[x][y]!=-2:
            print(x,y,xymap[x][y])
            flag=1
if flag==0:
    xymap=[[-1 for j in range(101)] for i in range(101)]
    for i in range(len(inp)):
        for x in range(101):
            for y in range(101):
                if xymap[x][y]==1 or xymap[x][y]==-1 :
                    xymap[x][y]=1
                else:
                    xymap[x][y]=-2
    for x in range(101):
        for y in range(101):
            if xymap[x][y]!=-2:
                print(x,y,xymap[x][y])

Submission status: Runtime Error

Solution code:
n=int(input())
xymap=[[-1 for j in range(101)] for i in range(101)]
inp=[]
for i in range(n):
    xi,yi,hi=map(int,input().split())
    if hi==0:
        inp.append(xi,yi,hi)
        pass
    else:
            
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]==a or xymap[x][y]==-1 :
                    xymap[x][y]=a
                else:
                    xymap[x][y]=-2
flag=0
for x in range(101):
    for y in range(101):
        if xymap[x][y]!=-2:
            print(x,y,xymap[x][y])
        else:
            flag=1
if flag==1:
    xymap=[[-1 for j in range(101)] for i in range(101)]
    for i in range(len(inp)):
        for x in range(101):
            for y in range(101):
                if xymap[x][y]==1 or xymap[x][y]==-1 :
                    xymap[x][y]=1
                else:
                    xymap[x][y]=-2
    for x in range(101):
        for y in range(101):
            if xymap[x][y]!=-2:
                print(x,y,xymap[x][y])

Submission status: Runtime Error

Solution code:
n=int(input())
xymap=[[-1 for j in range(101)] for i in range(101)]
inp=[]
for i in range(n):
    xi,yi,hi=map(int,input().split())
    if hi==0:
        inp.append(xi,yi,hi)
        pass
    else:
            
        for x in range(101):
            for y in range(101):
                a=abs(xi-x)+abs(yi-y)+hi
                if xymap[x][y]==a or xymap[x][y]==-1 :
                    xymap[x][y]=a
                else:
                    xymap[x][y]=-2
flag=0
for x in range(101):
    for y in range(101):
        if xymap[x][y]!=-2:
            print(x,y,xymap[x][y])
            flag=1
if flag==1:
    xymap=[[-1 for j in range(101)] for i in range(101)]
    for i in range(len(inp)):
        for x in range(101):
            for y in range(101):
                if xymap[x][y]==1 or xymap[x][y]==-1 :
                    xymap[x][y]=1
                else:
                    xymap[x][y]=-2
    for x in range(101):
        for y in range(101):
            if xymap[x][y]!=-2:
                print(x,y,xymap[x][y])

Submission status: Runtime Error

Solution code:


def calculation(x,y,h):
    info = []
    for i in range(100+1): #X
        for j in range(100+1): #Y
            abss = abs(i-x) + abs(j-y)
            tmpH = h + abss
            if (tmpH - abss) > 0: 
                tmp = [i,j,tmpH]
                info.append(tmp)
            else:
                tmp = [i,j,tmpH]
                info.append(tmp)
    return info

def pointscal(info,x,y,h):
    choice = []
    for i in range(len(info)):
        height = info[i][2] - abs(info[i][0] - x) - abs(info[i][1] - y)
        if h == height or h == 0:
            choice.append([info[i][0],info[i][1],info[i][2]])
    return choice
        

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

for i in range(N):
    if i == 0:
        choices = calculation(x[0],y[0],h[0])
    else:
        choices = pointscal(choices,x[i],y[i],h[i])
    #print(i,choices)


print(choices[0][0],choices[0][1],choices[0][2])

Submission status: Runtime Error

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 = []
    for arrays in grid:
      if arrays[2]>=1:
        lis.append(arrays[2]+abs(x-arrays[0])+abs(y-arrays[1]))
    if min(lis)==max(lis):
      if print(x,y,max(0,arrays[2]+abs(x-arrays[0])+abs(y-arrays[1])))
      sys.exit()
    x += 1
  y += 1

Submission status: Runtime Error

Solution code:
import numpy as np
def kouho(x, y, h):
    if h:
        return np.abs(np.arange(101) - x)[:, np.newaxis]  + np.abs(np.arange(101) - y) [np.newaxis] + h

n = int(input())
arrs = []
for _ in range(n):
    arrs.append(kouho(*(map(int, input().split()))))
arrs = np.array(arrs)
for i in range(101):
  for j in range(101):
    if np.all(arrs[:,i,j]==arrs[0,i,j]):
      print(i, j, arrs[0, i, j])
      break

Submission status: Runtime Error

Solution code:
N = int(input())

points = []
for i in range(0, N):
    xi, yi, hi = map(int, input().split())
    points.append((xi, yi, hi))

cand = {}
for CX in range(101):
    for CY in range(101):
        Hs = set()
        for x, y, h in points:
            H = h + abs(x - CX) + abs(y - CY)
            Hs.add(H)
        if len(Hs) == 1:
            cand[H] = (CX, CY, H)

CX, CY, H = cand[max(cand)]
print('{} {} {}'.format(CX, CY, H))

Submission status: Runtime Error

Solution code:
n = int(input())

positions = [[list(map(int, input().split(" ")))] for i in range(n)]

print(max(list(map(lambda x: x[2], positions))))

Submission status: Runtime Error

Solution code:
a = int(input())

b = []

c = []

p = 0
pp = 0
ppp = 0
for i in range(a):
    b.append(list(map(int,input().split())))

for i in range(0,101):
    for j in range(0,101):
        for h in range()
        for k in range(a):
            if k == 0:
                p = abs(b[k][0] - i) + abs(b[k][1]-j)+b[k][2]
                if b[k][2] == 0:
                    pp == 1
                    break
            else:
                if max(0,p - abs(b[k][0]-i)- abs(b[k][1]-j)) != b[k][2]:
                    pp = 1
        if pp == 0:
            ppp = 1
            break
        else:
            pp = 0
    if ppp == 1:
        print(i,j,p)
        break

Submission status: Runtime Error

Solution code:
n = int(input())
info = [[int(i) for i in input().split()] for j in range(n)]
if n == 1:
    print(info[0][0], info[0][1], info[0][2])
else:
    for x in range(101):
        for y in range(101):
            for i in range(n):
                if i == 0:
                    cx = x
                    cy = y
                    h = info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1])
                elif 0 < i < n-1:
                    if h != info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                        break
                elif i == n-1:
                    if h == info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                        kakutei_cx = cx
                        kakutei_cy = cy
                        kakutei_h = h
    print(kakutei_cx, kakutei_cy, kakutei_h)

Submission status: Runtime Error

Solution code:
import numpy as np
def kouho(x, y, h):
    if h:
        return np.abs(np.arange(101) - x)[:, np.newaxis]  + np.abs(np.arange(101) - y) [np.newaxis] + h

n = int(input())
arrs = []
for _ in range(n):
    arrs.append(kouho(*(map(int, input().split()))))
arrs = np.array(arrs)
v = arrs.var(0)
m = arrs.mean(0)
for i in range(101):
  for j in range(101):
    if v[i, j]==0:
      print(i, j, int(m[i, j]))
      break

Submission status: Runtime Error

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[0]-i)+abs(y[0]-j)+h[0]
            calch = abs(x[k]-i)+abs(y[k]-j)+h[k]
            if tmph != calch:
                flag = False
                break
        if flag == False:
            continue
        else:
            ansx=i
            ansy=j
            ansh=tmph

print(ansx,ansy,ansh)

Submission status: Runtime Error

Solution code:
N = int(input())

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

H = []
xy = []

for i, xyh in enumerate(in_list):
    x, y, h = xyh[0], xyh[1], xyh[2]

    if i == 0:
        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])
    else:
        tmpH = []
        tmpxy = []
        for xy0, h0 in zip(xy, H):
            tm = h0-abs(x-xy0[0])-abs(y-xy0[1])
            if h == max(0, tm):
                tmpH.append(h0)
                tmpxy.append([xy0[0], xy0[1]])
        H = tmpH
        xy = tmpxy

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

Submission status: Runtime Error

Solution code:
n = int(input())
can = [[0] * 101 for _ in range(101)]


def solve(n, can):
    for k in range(n):
        x, y, h = map(int, input().split())
        if k == 0:
            for i in range(101):
                for j in range(101):
                    can[i][j] = h + abs(x - i) + abs(y - j)
        else:
            for i in range(101):
                for j in range(101):
                    if can[i][j] is None:
                        continue
                    if h + abs(x - i) + abs(y - j) != can[i][j]:
                        can[i][j] = None
    for i in range(101):
        for j in range(101):
            if can[i][j] is None:
                continue
            return i, j, can[i][j]


print(*solve(n, can))

Submission status: Runtime Error

Solution code:
from itertools import product
n = int(input())
l, lz = [], []
for _ in range(n):
    p = list(map(int, input().split()))
    if p[-1] == 0: lz.append(p)
    else: l.append(p)
res = [-1, -1, -1]
if len(l) == 0:
    print(0, 0, 0)
else:
    for cx, cy in product(range(101), repeat=2):
        h = set([hi + abs(x - cx) + abs(y - cy) for x, y, hi in l])
        if len(h) > 1: continue
        h = h.pop()

        if all(h - abs(x - cx) + abs(y - cy) == 0 for x, y, hi in lz):
            res = [str(cx), str(cy), str(h)]
            break
    print(' '.join(res))

Submission status: Runtime Error

Solution code:
n = int(input())
info = [[int(i) for i in input().split()] for j in range(n)]
for x in range(101):
    for y in range(101):
        for i in range(n):
            if n == 1:
                kakutei_cx = x
                kakutei_cy = y
                kakutei_h = info[i][2] + abs(x - info[i][0]) + abs(y - info[i][1])
            else:
                if i == 0:
                    cx = x
                    cy = y
                    h = info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1])
                elif 0 < i < n-1:
                    if h != info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                        break
                elif i == n-1:
                    if h == info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                        kakutei_cx = cx
                        kakutei_cy = cy
                        kakutei_h = h
print(kakutei_cx, kakutei_cy, kakutei_h)

Submission status: Runtime Error

Solution code:
n = int(input())
can = [[[0, 0]] * 101 for _ in range(101)]


def solve(n, can):
    for k in range(n):
        x, y, h = map(int, input().split())
        if k == 0:
            for i in range(101):
                for j in range(101):
                    can[i][j] = h + abs(x - i) + abs(y - j)
        else:
            for i in range(101):
                for j in range(101):
                    if can[i][j] is None:
                        continue
                    gg = h + abs(x - i) + abs(y - j)
                    gh = can[i][j]
                    if gg != gh:
                        can[i][j] = None
    for i in range(101):
        for j in range(101):
            if can[i][j] is None:
                continue
            return i, j, can[i][j]


print(*solve(n, can))

Submission status: Runtime Error

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=abs(x[0]-i)+abs(y[0]-j)+h[0]
        flag = True
        for k in range(0,n):
            calch = abs(x[k]-i)+abs(y[k]-j)+h[k]
            if tmph != calch:
                flag = False
                break
        if flag == False:
            continue
        else:
            ansx=i
            ansy=j
            ansh=tmph

print(ansx,ansy,ansh)

Submission status: Runtime Error

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

def CalcHigh(cx, cy, px, py, ph):
    ch = ph + abs(cx-px) + abs(cy-py)
    return ch

for i in range(101):
    for j in range(101):
        ch = CalcHigh(i, j, x[0], y[0], h[0])
        flag = True
        for k in range(N):
            if CalcHigh(i, j, x[k], y[k], h[k]) != ch:
                flag = False
                break
        if flag == True:
            ans = (i, j, ch)
            break
    else:
        continue
    break

print(ans[0], ans[1], ans[2])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

N = d_in()

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

info = []
for _ in range(N):
    info.append(ds_in())

for i in range(len(cand)):
    x, y, h = info[0]
    cand[i][2] = h + abs(x-cand[i][0]) + abs(y-cand[i][1])

if N > 1:
    idx = 1
    while len(cand) > 1:
        temp = []
        x, y, h = info[idx]
        for c in cand:
            if h == max(0, c[2] - abs(x-c[0]) - abs(y-c[1])):
                temp.append(c)
        cand = temp.copy()
        idx += 1

print(cand[0][0], cand[0][1], cand[0][2])

Submission status: Runtime Error

Solution code:
from itertools import product
n = int(input())
l, lz = [], []
for _ in range(n):
    p = list(map(int, input().split()))
    if p[-1] == 0: lz.append(p)
    else: l.append(p)
res = [-1, -1, -1]
for cx, cy in product(range(101), repeat=2):
    h = set([hi + abs(x - cx) + abs(y - cy) for x, y, hi in l])
    if len(h) > 1: continue
    h = h.pop()
    if all(h - abs(x - cx) + abs(y - cy) == 0 for x, y, hi in lz):
        res = [str(cx), str(cy), str(h)]
        break
print(' '.join(res))

Submission status: Runtime Error

Solution code:
N = int(input())
ans = set()
for i in range(N):
    tmp = set()
    x, y, h = map(int, input().split())
    for cx in range(0,101):
        for cy in range(0, 101):
            ch = abs(x-cx) + abs(y-cy) + h
            if ch < 1:
                continue
            tmp.add((cx, cy, ch))
    if ans == set():
        ans = tmp
        continue
    elif tmp == set():
        continue
    ans = ans & tmp
ans = list(ans)[0]
print(ans[0], ans[1], ans[2])

Submission status: Runtime Error

Solution code:
N = int(input())
ans = set()
for i in range(N):
    tmp = set()
    x, y, h = map(int, input().split())
    for cx in range(0,101):
        for cy in range(0, 101):
            ch = abs(x-cx) + abs(y-cy) + h
            if ch < 1:
                continue
            tmp.add((cx, cy, ch))
    if i == 0:
        ans = tmp
        continue
    elif tmp == set():
        continue
    ans = ans & tmp
ans = list(ans)[0]
print(ans[0], ans[1], ans[2])

Submission status: Runtime Error

Solution code:
N = int(input())
ans = set()
for i in range(N):
    tmp = set()
    x, y, h = map(int, input().split())
    for cx in range(0,101):
        for cy in range(0, 101):
            ch = abs(x-cx) + abs(y-cy) + h
            if ch < 1:
                continue
            tmp.add((cx, cy, ch))
    if i == 0:
        ans = tmp
        continue
    # elif tmp == set():
    #     continue
    ans = ans & tmp
ans = list(ans)[0]
print(ans[0], ans[1], ans[2])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

N = d_in()

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

info = []
for _ in range(N):
    info.append(ds_in())

for i in range(len(cand)):
    x, y, h = info[0]
    cand[i][2] = h + abs(x-cand[i][0]) + abs(y-cand[i][1])

if N > 1:
    idx = 1
    while len(cand) > 1:
        temp = []
        x, y, h = info[idx]
        for c in cand:
            if c[2] == h + abs(x-c[0]) + abs(y-c[1]):
                temp.append(c)
        cand = temp.copy()
        idx += 1
print(cand[0][0], cand[0][1], cand[0][2])

Submission status: Runtime Error

Solution code:
n = int(input())
info = [[int(i) for i in input().split()] for j in range(n)]
for x in range(101):
    for y in range(101):
        for i in range(n):
            if i == 0:
                cx = x
                cy = y
                h = info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1])
            elif 0 < i < n-1:
                if h != info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                    break
            elif i == n-1:
                if h == info[i][2] + abs(cx - info[i][0]) + abs(cy - info[i][1]):
                    kakutei_cx = cx
                    kakutei_cy = cy
                    kakutei_h = h
print(kakutei_cx, kakutei_cy, kakutei_h)

Submission status: Runtime Error

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

for cxi in range(101):
    for cyi in range(101):
        flag = True
        for i in range(n):
            if i == 0:
                height = h[i] + abs(x[i]-cxi) + abs(y[i]-cyi)
            else:
                if height != h[i] + abs(x[i]-cxi) + abs(y[i]-cyi):
                    flag = False
                    continue
        if flag:
            print(cxi, cyi, height)

Submission status: Runtime Error

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
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 and tmp_H<=0:
                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:
            return key,d[key]
(X,Y),H = find(Cxy)
print(X,Y,H)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

N = d_in()

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

x, y, h = ds_in()
for i in range(len(cand)):
    cand[i][2] = h + abs(x-cand[i][0]) + abs(y-cand[i][1])


info = []
for _ in range(N-1):
    info.append(ds_in())

idx = 0
while len(cand) > 1:
    temp = []
    x, y, h = info[idx]
    for c in cand:
        if c[2] == h + abs(x-c[0]) + abs(y-c[1]):
            temp.append(c)
    cand = temp.copy()
    idx += 1
print(cand[0][0], cand[0][1], cand[0][2])

Submission status: Runtime Error

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
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 and tmp_H<0:
                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:
            return key,d[key]
(X,Y),H = find(Cxy)
print(X,Y,H)

Submission status: Runtime Error

Solution code:
N = int(input())

def get_cands(x, y, h):
    for xc in range(100 + 1):
        for yc in range(100 + 1):
            yield (xc, yc, h + abs(xc - x) + abs(yc - y))

x1, y1, h1 = map(int, input().split())
cand = set(get_cands(x1, y1, h1))

for _ in range(N - 1):
    new_cand = set()
    x, y, h = map(int, input().split())
    for c in get_cands(x, y, h):
        if c in cand:
            new_cand.add(c)
    cand = new_cand
    if len(cand) == 1:
        break
print(*next(iter(cand)))