Necklace of Beads#2227

Necklace of Beads

0.1 seconds
16 megabytes
Hard

Beads of red, blue, and green colors are connected together to form a circular necklace of beads (0 < n < 40). Ignoring repetitions resulting from rotation around the center and reflection across axes of symmetry, how many different necklaces can be formed?

Input

Each line represents a test case and contains a value of (0 < n < 40). n = -1 denotes the end of the input.

Output

For each test case, output the number of different necklaces on a separate line.

Examples

Example 1

Loading
Loading