P2696 Charitable Josephus

Description

You have probably heard of the Josephus problem, which finds the unique survivor among $N$ people. Now Old Josephus is organizing a new game that makes everyone happy. Suppose $N$ people stand in a circle. Starting from person 1, players are removed alternately (i.e., every other player), but only temporarily, until only one survivor remains. After the survivor is selected, every person whose number is greater than the survivor's number receives 1 gold coin and leaves permanently. The remaining people then repeat the above process; after selecting a survivor, everyone with a number larger than that survivor's number receives 1 gold coin and leaves. After several such rounds, once the number of people no longer decreases, the remaining people each receive 2 gold coins. Please compute the total amount of money Old Josephus has to pay.

Input Format

A single line containing a positive integer $N$ representing the number of people.

Output Format

A single line containing a positive integer representing the total amount of money to be paid.

Explanation/Hint

Constraints: $1\le N \le 10^5$. Translated by ChatGPT 5