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?
Each line represents a test case and contains a value of (0 < n < 40). n = -1 denotes the end of the input.
For each test case, output the number of different necklaces on a separate line.
Example 1