Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!
ALGOR Contest: Round #3 (Weekly Sprint)
Problem E · 250 points · ICPC rules

~/algor $ cat contests/round-3/E

E. Tower of Hanoi

1000 ms 64 MB

There are three rods numbered $1$, $2$ and $3$. Rod $1$ holds $n$ disks: the largest at the bottom, each next one smaller. All disks must be moved to rod $3$ in the fewest moves. One move takes only one disk, the top one; a larger disk may not be placed on a smaller one.

The shortest sequence of moves is unique and has $2^{n} - 1$ moves. Find from which rod to which rod the $k$-th move of this sequence goes. For example, for $n = 2$ the moves are $1 \to 2$, $1 \to 3$, $2 \to 3$.

Three rods with the disks on the first one; an arrow shows from which rod to which the disk goes in the given move

Input

One line with two positive integers: $n$ and $k$.

Output

One line with two positive integers: the rod ($1$, $2$ or $3$) the disk is taken from and the rod it is put on in the $k$-th move.

Note

$1 \le n \le 60$
$1 \le k \le 2^{n} - 1 \lt 2^{60}$

Examples

Input #1
2 1
Output #1
1 2
Input #2
2 3
Output #2
2 3

Sign in to submit a solution

Signing up is free and takes a minute.