Tower of Hanoi move sequence

Print the minimal sequence of moves that transfers N disks from rod 1 to rod 3 under the smaller-on-larger rule.

Easy3RecursionImplementationInterviewNo attempts yetTime limit1sMemory limit256 MB

Problem

There are three rods. The first rod holds NN disks of pairwise different radii, stacked from the largest at the bottom to the smallest at the top. Monks want to move every disk to the third rod under these two rules.

  1. Only one disk may be moved to another rod at a time.
  2. In every stack, an upper disk must always be smaller than the disk below it.

Write a program that prints the sequence of moves for this task. The number of moves must be the smallest possible.

The picture below is an example with 5 disks.

Tower of Hanoi with 5 disks

Input

The first line contains NN, the number of disks stacked on the first rod. (1N201 \le N \le 20)

Output

Print the number of moves KK on the first line.

On each of the next KK lines, print the moves in order. Each line holds two integers AA and BB separated by one space, meaning that the topmost disk of rod AA moves onto the top of rod BB.

The move sequence with the smallest number of moves is unique, so the correct output is unique as well.