Collatz Sequence

Starting from n, repeatedly apply the Collatz rule (halve evens, 3n+1 for odds) and print every value from n down to 1 on one line.

Easy2SimulationImplementationMathInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

The Collatz conjecture is a conjecture in mathematics that Lothar Collatz first proposed in 1937, and it is still unproven. The numbers it produces are also called a hailstone sequence, because the values rise and fall many times like hailstones in a cloud. The conjecture says that whatever number you start from, repeating the process always reaches 1.

The rule is also known as the 3n+13n + 1 problem, and it works like this.

  1. Start with an integer nn.
  2. If nn is 1, stop.
  3. If nn is even, divide nn by 2. Then go back to step 2.
  4. If nn is odd, multiply nn by 3 and add 1. Then go back to step 2.

By the conjecture, starting from any positive integer and repeating the process reaches n=1n = 1. Listing the values you pass through in order gives a sequence from nn down to 1.

For example, starting from n=14n = 14 the process goes like this.

  • 14 is even, so the next value is 14/2=714 / 2 = 7.
  • 7 is odd, so the next value is 3×7+1=223 \times 7 + 1 = 22.
  • 22 is even, so the next value is 11.
  • 11 is odd, so the next value is 34.
  • 34 is even, so the next value is 17.

You continue until the value becomes 1.

Given the starting value nn, write a program that prints the whole Collatz sequence.

Input

The first line contains an integer nn. (1n1000001 \le n \le 100\,000)

Output

Print the Collatz sequence that starts at nn and ends at 1 on one line, with the elements separated by a single space. Do not put a space at the beginning or the end of the line.