Lexicographically smallest ternary
Medium
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
Numbers from A to B, inclusive, are expressed in the ternary numeral system without leading zeros. Each number is written on a separate line. These lines are then sorted in lexicographical order. Your task is to determine which number appears first in this order.
The numbers A and B are provided in the decimal numeral system, and your answer should also be given in the decimal numeral system.
For instance, if A=2 and B=12, the sequence would be:
In this example, the first number in lexicographical order is 3 (which is represented as 10 in the ternary numeral system).
Input
You are given natural numbers A and B (1 ≤ A ≤ B ≤ 10^15).
Output
Provide the answer to the problem.
Examples
Input #1
Answer #1
Submissions 200
Acceptance rate 13%