Problem:
Score : 200 points

Problem Statement

A sequence a=\{a_1,a_2,a_3,......\} is determined as follows:

The first term s is given as input.

Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.

a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.

Find the minimum integer m that satisfies the following condition:

There exists an integer n such that a_m = a_n (m > n).

Constraints

1 \leq s \leq 100

All values in input are integers.

It is guaranteed that all elements in a and the minimum m that satisfies the condition are at most 1000000.

Input

Input is given from Standard Input in the following format:

s

Output

Print the minimum integer m that satisfies the condition.

Sample Input 1

8

Sample Output 1

5

a=\{8,4,2,1,4,2,1,4,2,1,......\}. As a_5=a_2, the answer is 5.

Sample Input 2

7

Sample Output 2

18

a=\{7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......\}.

Sample Input 3

54

Sample Output 3

114

Solution in C (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
/* void swap(int* a, int* b) { */
/*   int tmp; */
/*   tmp = *a; */
/*   *a = b; */
/*   *b = tmp; */
/* } */
int compare_int(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;
}
int f(int n){
  switch(n%2) {
  case 0:
    return n/2;
    break;
  case 1:
    return 3*n+1;
    break;
  }
  
}
int main(){
  //long long int N, M,i,j,Q,k, A, B, T;
  long long int x[20] ={0};
  long long int v[20] ={0};
  long long int ans[20] ={0};
  long long int s = 0;
  //int flag = 0;
  //long long int K, S, cnt=0, cnt2=0;
  char str[120] = {0};
  long long int len[120];
  int lenstr;
  int L[1000000];
  long long int c[200000];
  long long int t[100000];
  int i, j;
  char S[300000] = {0};
  int SS[300000] = {0};
  //long long int A[100000];
  long long int cnt = 0;
  int max, min, min_cost=9999;
  scanf("%d", &s);

  long long a_i_1 = s;
  L[0] = s;
  for (i = 1; i < 1000000; i++) {
    /* long long int a_i = f() */
    L[i] = f(L[i-1]);
  }
  /* for (i = 0; i < 3; i++) { */
  /*   scanf("%d", &x[i]); */
  /* } */

  int kdkssd = 0;
  /* qsort(x, 3, sizeof(long long int), compare_int); */
  for (i = 0; i < 1000000; i++) {
    for (j = 0; j < 1000000; j++) {
      if (L[i] == L[j] && i != j) {
        printf("%d\n", j+1);
        return 0;
      }
    }
  }

  /* for (i = 0; i < 1000000;i++) { */
  /*   if (L[i] == 4) { */
  /*     kdkssd += 1; */
  /*   } */
  /*   if (kdkssd == 2) { */
  /*     printf("%d/n", i+1); */
  /*     return 0; */
  /*   } */
  /* } */
  /* double a = (float)x[0]; */
  /* double b = (float)x[1]; */
  /* printf("%d\n", x[0]*x[1]/2); */
  /* //printf("%d\n", cnt); */
  return 0;
}