D. Collatz conjecture

Memory limit: 256 MiB Time limit: 1000 ms Input file: stdin Output file: stdout
Problem type: traditional Judging mode: text compare

Description

考拉兹猜想(也被稱為 3n + 1 猜想)指出:給定一個開始的正整數 N ,我們反覆進行以下操作之後最終會得到 N = 1

N \leftarrow \begin{cases} N/2 &\text{if } N \equiv 0 \pmod{2}\\ 3N+1 & \text{if } N\equiv 1 \pmod{2} .\end{cases}

我們定義 f(N) N 變成 1 需要的操作數。

例如,如果我們從 N = 13 開始,序列應該是: 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 。因此, f(N) = 9

你需要寫一個程式,在給定正整數 N 時找出 f(1) + f(2) + \cdots + f(N) 的值。


The Collatz conjecture, also called the 3n + 1 conjecture, states that: Given a starting positive integer N , we can eventually obtain N = 1 after carrying out the following operation repeatedly:

N \leftarrow \begin{cases} N/2 &\text{if } N \equiv 0 \pmod{2}\\ 3N+1 & \text{if } N\equiv 1 \pmod{2} .\end{cases}

We define f(N) as the number of operations needed before N becomes 1 .

For example, if we start from N = 13 , the sequence would be: 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 . Therefore, f(N) = 9 .

You are asked to write a program to find f(1) + f(2) + \cdots + f(N) given a positive integer N .

Input

輸入只有一個正整數, N


The input consists of only one integer N .

Output

輸出一個正整數, f(1) + f(2) + \cdots + f(N) 的值。


Output exactly one positive integer, the sum f(1) + f(2) + \cdots + f(N) .

Sample

Sample input

3

Sample output

8

Constraint and hint

對於全部測試數據,滿足 1 \leq N \leq 10^9

子任務 分數 附加限制
1 21 N \leq 10^5
2 6 N \leq 5 \times 10^5
3 25 N \leq 10^7
4 6 N \leq 3 \times 10^7
5 N \leq 6 \times 10^7
6 13 N \leq 10^8
7 10 N \leq 3 \times 10^8
8 5 N \leq 6 \times 10^8
9 8 無附加限制

For all test data, 1 \leq N \leq 10^9 .

Subtask Score Additional Constraints
1 21 N \leq 10^5
2 6 N \leq 5 \times 10^5
3 25 N \leq 10^7
4 6 N \leq 3 \times 10^7
5 N \leq 6 \times 10^7
6 13 N \leq 10^8
7 10 N \leq 3 \times 10^8
8 5 N \leq 6 \times 10^8
9 8 No additional constraints