When is your turn? turn.X
Farmer John is in luck! His cow herd has finally reached his goal size of "infinitely large," and he is now testing how he would like to arrange them in his new infinitely-large barn, due to be delivered tomorrow.
Because he, Farmer Jane, and Bessie will occupy the 0th, 1st, and 2nd stalls in the barn, Farmer John has set aside those assignments. For all of the rest of his cows, he has given them positive integer labels starting at 3. However, FJ does not necessarily want to simply place the cows labeled 3, 4, 5, 6, 7, ... into the barn in their labels' order, because Bessie is picky about which cows she'll be near.
As a result, Farmer John is testing rearrangements according to the following rule: he looks at the label of the cow in the front (left-hand-side) of the sequence -- suppose that cow is labeled x. Then, FJ moves that cow to the x-th position in the sequence. For example, these are the first four moves:
3, 4, 5, 6, 7, 8, ...
-> 4, 5, 3, 6, 7, 8, ...
-> 5, 3, 6, 4, 7, 8, ...
-> 3, 6, 4, 7, 5, 8, ...
-> 6, 4, 3, 7, 5, 8, ...
and so on.
The challenge is to find which step of the process (starting at 1) that a cow with a given label n will come to the front (left-hand-side) of the sequence for the first time.
For example, using the rearrangements above, we see that
if n is 3 the answer is 1.
if n is 4 the answer is 2.
if n is 5 the answer is 3.
if n is 6 the answer is 5.
PROBLEM NAME: turn
INPUT FORMAT:
* Line 1: The integer N mentioned in the problem statement.
SAMPLE INPUT:
6
INPUT DETAILS:
We wish to calculate the first step in which N=6 appears in the front of
the sequence, starting our counting at 1.
OUTPUT FORMAT:
* Line 1: A single integer k, which will fit into a signed 3 2bit integer, and
which is the number of the step that N comes appears in the
front of the sequence for the first time.
SAMPLE OUTPUT:
5