Hailstone Sequences

No attempts yetTime limit1sMemory limit128 MB

Problem

Consider the sequence built by starting from a positive integer $h_0$ and repeatedly applying, for $n = 1, 2, \ldots$, the following rule until $h_n = 1$:

  • $h_n = h_{n-1} / 2$ if $h_{n-1}$ is even
  • $h_n = 3 \times h_{n-1} + 1$ if $h_{n-1}$ is odd

For example, starting from $h_0 = 5$ produces the sequence $5, 16, 8, 4, 2, 1$. Starting from $h_0 = 11$ produces $11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1$.

As these examples show, the values rise and fall, yet eventually settle at $1$ (at least for every starting value ever tried). Such sequences are called Hailstone sequences because they resemble the way hailstones are carried upward by the wind again and again before finally descending to the ground.

Given a positive integer, compute the largest value that appears in the Hailstone sequence starting from that integer.

Input

The input consists of several test cases. Each test case is a single line containing one integer $H$ ($1 \le H \le 500$), the starting value of the sequence.

The final test case is followed by a line containing a single $0$, which is not processed.

Output

For each test case, output a single line with the largest value that appears in the Hailstone sequence starting from $H$.