No Petya
Time limit2sMemory limit1024 MB
Given n and k, find two numbers on Yatep's sheet whose difference is exactly k, or report that no such pair exists.
- Level
Medium6 of 10
- Topics
- Recursion, Divide and conquer, Math
- Solved
- No attempts yet
Statement
On the third planet of one star, people are very fond of the number three. For this reason, everything on this planet is divided into three parts.
Yatep is an ordinary resident of the third planet. Naturally, he lives in a triangular house, not a square one. Recently Yatep got bored, so to entertain himself he took all integers from to and split them into three parts: from to , from to , and from to . That seemed too little, so he applied the same operation to the first and third parts (after all, and are powers of three!). He did not stop there. He applied his split to the new first and third parts, and kept splitting the first and third parts until he got sets of two numbers (those are hard to split into three parts). More precisely, if Yatep splits a set of numbers from to , he gets three sets: from to , from to , and from to .
Consider Yatep's work for . At the start, all numbers from to are present. After the first split we get the parts , , . After the next split we get , , , , and .
Yatep did not split the numbers at random. Each time before splitting a set of numbers from to into three parts, he wrote the numbers and on a special sheet of paper with triangular cells instead of square ones. If a number was already on the sheet, he did not write it again. In the example above, the sheet ends up with the numbers , , , , , , , .
When Yatep finished his work, his friend Yasav, from the -th planet, came to visit. Yasav wants to know whether Yatep's sheet contains two numbers whose difference is exactly . Help Yasav and Yatep find these numbers.
Input
The first line contains two integers and (, ).
Output
Print the numbers and such that both are on Yatep's sheet and . If there are several such pairs, print any of them. If no such numbers exist, print the single word <<Impossible>>.