This page is still under construction.

Parts of this page are still being built. What you see may change.

Two-Colored Towers of Hanoi

Time limit1sMemory limit128 MB

Summary
The task is to compute the minimum moves to gather odd disks on peg B and even disks on peg C under Hanoi rules.
Level

Medium7 of 10

Topics
Dynamic programming, Recursion, Math
Solved
No attempts yet

Problem

The Towers of Hanoi is a classic puzzle in which disks are threaded onto pegs. You are given nn disks with diameters 1,2,…,n1, 2, \dots, n and three pegs called AA, BB, and CC. Each disk has a hole in its center so it can be slipped onto a peg. Initially every disk is on peg AA, stacked from the largest at the bottom to the smallest at the top.

In the original puzzle you move all disks onto one of the free pegs (say BB) under these rules:

  • in a single move you may take the top disk of one peg and place it on top of another peg;
  • on every peg the order must always be preserved: larger disks below, smaller disks above.

The disks stacked on one peg form a tower. In summary:

  • you cannot pull a disk out of the middle of a tower, nor insert a disk into the middle of a tower;
  • you may not move more than one disk at a time;
  • you may not place a larger disk on top of a smaller one.

The goal of the original puzzle is to move the whole tower from one peg to another in the fewest possible moves.

The two-colored Towers of Hanoi is a slightly modified version. As before there are three pegs and nn disks with diameters 1,2,…,n1, 2, \dots, n. This time, however, disks with odd diameters (1,3,5,…1, 3, 5, \dots) are white and disks with even diameters (2,4,6,…2, 4, 6, \dots) are black. The goal is to move, following the rules above, all white disks onto peg BB and all black disks onto peg CC.

Write a program that computes the minimum number of moves needed to gather the white disks on peg BB and the black disks on peg CC.

Input

The first line of standard input contains a single integer nn (0≤n≤10000 \le n \le 1000), the number of disks.

Output

Print to standard output a single integer: the minimum number of moves needed to separate the white and black disks.

Examples4

  1. Example 1

    Input
    6
    
    Expected output
    45
    
  2. Example 2

    Input
    1
    
    Expected output
    1
    
  3. Example 3

    Input
    2
    
    Expected output
    2
    
  4. Example 4

    Input
    3
    
    Expected output
    5