k = int(input())
ma = 1
mi = 1
while k != 0:
if k % 3 == 0 and ma % 3 != 0:
ma = k
if k % 3 == 0 and ma % 3 == 0 and k > ma:
if k % 3 == 0 and mi % 3 != 0:
mi = k
if k % 3 == 0 and mi % 3 == 0 and k < mi:
if ma % 3 == 0:
print(mi, ma)
else:
print("нет")
k = int(input())
ma = 1
mi = 1
while k != 0:
if k % 3 == 0 and ma % 3 != 0:
ma = k
if k % 3 == 0 and ma % 3 == 0 and k > ma:
ma = k
if k % 3 == 0 and mi % 3 != 0:
mi = k
if k % 3 == 0 and mi % 3 == 0 and k < mi:
mi = k
if ma % 3 == 0:
print(mi, ma)
else:
print("нет")