stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define N (int)2e5

int n,k,memo[N],c[N];



int dp(int curr) {

    if (curr == n) return 0;

    if (curr > n) return 1e9;

    int &sol = memo[curr];

    if (sol != -1) return sol;

    int keep = INT_MAX;

    for (int i = 1 ; i <= k ; i++) {

        keep = min(

            dp(curr + i) + abs(c[curr] - c[curr + i]) ,

            keep

        );

    }

    return sol = keep;

}



int main() {

    scanf("%d%d" , &n , &k);

    for (int i = 1 ; i <= n ; i++)

        scanf("%d" , &c[i]);

    memset (memo , -1 , sizeof memo);

    printf("%d\n" , dp(1));

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>



using namespace std;



int main(){

    int N, K;

    cin >> N >> K;



    int p1, px, mins[N], alturas[N];



    for(int i = 0; i <= N; i++){

        if(i < N){

            cin >> px;

            alturas[i] = px;

        }

        else {

            cout << mins[N-1];

        }

        if(i == 0){

            p1 = px; 

        }

        else if(i == 1){

            mins[1] = abs(p1 - px);

        }

        else {

            int saltos = min(K, min(N, i));

            mins[i] = 1000000000; 

            for(int j = 0; j < saltos; j++){

                if(j == i-1){

                    mins[i] = min(mins[i], abs(p1 - px));

                }

                else {

                    int ult_salto = abs(px - alturas[i-j-1]);

                    mins[i] = min(mins[i], ult_salto + mins[i-j-1]); 

                }

            }

        }

    }

    return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

     for(int i=0;i<n;++i){

          cin>>h[i];

     }

     LL dp[100001];



      for(int i=0;i<n;++i){

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







     for(int i=2;i<n;++i){

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



int n,s;

int mem[100][100][100];

int f(int deps,int cnt,int sum)

{

    if(mem[deps][cnt][sum])return mem[deps][cnt][sum];

    if(cnt == n && sum == s)return 1;

    if(deps == 10) return 0;

    return mem[deps][cnt][sum]=f(deps + 1,cnt + 1,sum + deps)+f(deps + 1,cnt,sum);

}



int main()

{

    while(1){

    memset(mem,0,sizeof(mem));

    cin >> n >> s;

    if(n == 0 && s == 0)break;

    printf("%d\n",f(0,0,0));

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>



using namespace std;



int n,s;



int F(int deps,int cnt,int sum){

    if(deps == 10){

        if(cnt == n && sum == s)return 1;

        return 0;

    }

    return F(deps + 1,cnt + 1,sum + deps) + F(deps + 1,cnt,sum);

}



int main()

{

    while(1){

        cin >> n >> s;

        if(n == 0 && s == 0)break;

        cout << F(0,0,0) << endl;

    }



}

// Fastest known solution for this problem:
#include<iostream>

#include<algorithm>

#include<cstdio>

#include<cstdlib>

#include<vector>

#include<string>

#include<sstream>

#include<cmath>

#include<numeric>

#include<map>

#include<stack>

#include<queue>

#include<cassert>

using namespace std;

int inf = 1000000000;

int n, s;



int cnt = 0;



int func(string m, vector<bool> b, int num){

  if( m.size() == n ){

    int tmp = 0;

    for(int i=0; i<n; i++) tmp += m[i]-'0';

    if( tmp == s ) cnt++;

    // if( tmp == s ) cerr << m << endl;

    return 0;

  }



  for(int i=num+1; i<10; i++){

    if( b[i] ) continue;

    b[i] = true;

    func( m + to_string(i), b, i);

    b[i] = false;

  }

  return 0;

}



int main(void) {





  while(cin >> n >> s){

    if( n == 0 && s == 0 ) break;



    vector<bool> b(10, false);

    for(int i=0; i<10; i++){

      b[i] = true;

      func(to_string(i), b, i);

      b[i] = false;

    }

    cout << cnt << endl;

    cnt = 0;

  }



  return 0;

}





// EOF
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#define F first

#define S second

#define PB push_back

#define REP(i,a,b) for (int i = a ; i <= b ; i++)

#define REPI(i,a,b) for (int i = a ; i >= b ; i--)

using namespace __gnu_pbds;

using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pi;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;



const int OO = 1e9+7;

const int MOD = 1e9+7;

const int N = 1e5+7;



int mem[N];

int n,k;

int h[N];

int dp(int i)

{

    int &ret = mem[i];

    if (ret != -1) return ret;

    if (i == n-1) return 0;

    ret = OO;

    REP(j,1,k)

    {

        if (i+j >= n) break;

        ret = min(ret,dp(i+j)+abs(h[i]-h[i+j]));

    }

    cerr << i << ' ' << ret << endl;

    return ret;

}



int main()

{

    //ios::sync_with_stdio(0);

    //cin.tie(0);cout.tie(0);

    //freopen("teleport.in","r",stdin);

    //freopen("teleport.out","w",stdout);

    memset(mem,-1,sizeof mem);

    scanf("%d %d",&n,&k);

    REP(i,0,n-1) scanf("%d",&h[i]);

    printf("%d\n",dp(0));



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#define F first

#define S second

#define PB push_back

#define REP(i,a,b) for (int i = a ; i <= b ; i++)

#define REPI(i,a,b) for (int i = a ; i >= b ; i--)

using namespace __gnu_pbds;

using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pi;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;



const ll OO = 1e18+7;

const int MOD = 1e9+7;

const int N = 1e5+7;



ll dp[N];

int n,k;

ll h[N];



int main()

{

    //ios::sync_with_stdio(0);

    //cin.tie(0);cout.tie(0);

    //freopen("teleport.in","r",stdin);

    //freopen("teleport.out","w",stdout);



    scanf("%d %d",&n,&k);

    REP(i,0,n-1) scanf("%lld",&h[i]);



    REP(i,1,n-1)

    {

        dp[i] = OO;

        REPI(j,i-1,i-k)

        {

            if (j < 0) break;

            dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));

        }

    }

    printf("%lld\n",dp[n-1]);

    return 0;

}


// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

     for(int i=0;i<n;++i){

          cin>>h[i];

     }

     LL dp[100001];



      for(int i=0;i<n;++i){

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







     for(int i=2;i<n;++i){

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



int dp[100000],v[100000];



int calcdp(int k,int id){

	if(dp[id]==INT_MAX){

		int aux;

		for(int i=0;i<k;i++){

			if(id-k+i>=0){

				aux=calcdp(k,id-k+i);

				if(abs(v[id]-v[id-k+i])+aux<dp[id]){

					dp[id]=abs(v[id]-v[id-k+i])+aux;

				}

			}

		}

	}

	return dp[id];

}



int main(){

	int n,k;

	cin>>n>>k;

	for(int i=0;i<n;i++){

		cin>>v[i];

		dp[i]=INT_MAX;

	}

	dp[0]=0;

	dp[n-1]=calcdp(k,n-1);

	cout<<dp[n-1]<<endl;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

using namespace std;

int n,k,a[100005],f[100005];

int main()

{

	scanf("%d%d",&n,&k);

	for(int i=1;i<=n;++i)

		scanf("%d",a+i);

	memset(f,0x3f,sizeof(f));

	f[1]=0;

	for(int i=2;i<=n;++i)

		for(int j=max(i-k,1);j<i;++j)

			f[i]=min(f[i],f[j]+abs(a[i]-a[j]));

	printf("%d\n",f[n]);

	return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

     for(int i=0;i<n;++i){

          cin>>h[i];

     }

     LL dp[100001];



      for(int i=0;i<n;++i){

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







     for(int i=2;i<n;++i){

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

 

 

int main() {

int n, k; 

	scanf("%d %d", &n, &k );

	vector<int> arr(n), dp(n, INT_MAX);

	for(int i=0; i<n; ++i) scanf("%d", &arr[i]);

	

	dp[0]=0;

	

	for(int i=1; i<n; ++i){

		for(int j= max(0,i-k ); j<i; ++j ){

			dp[i] = min(dp[i], dp[j] + abs(arr[j]- arr[i]));

			

		}

	}

	printf("%d\n", dp[n-1]);



	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>



int main(){

  int s,k;

  long long st[100001],p[100001];

  scanf("%d%d",&s,&k);

  for(int i=1;i<=s;i++){

    scanf("%lld",&st[i]);

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = 1000000001;

  }

  for(int i=3;i<=s;i++){

    for(int j=1;j<=k;j++){

      if(i-j>=1){

	long long tmp;

	tmp = (st[i]-st[i-j] < 0) ? st[i-j]-st[i] : st[i]-st[i-j];

	if(p[i] > p[i-j]+tmp){

	  p[i] = p[i-j]+tmp;

	}

	if(tmp == 0) break;

      }else{

	break;

      }

    }

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

     for(int i=0;i<n;++i){

          cin>>h[i];

     }

     LL dp[100001];



      for(int i=0;i<n;++i){

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







     for(int i=2;i<n;++i){

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include <bits/stdc++.h>

 

#define ll long long

#define X first

#define Y second

#define MP make_pair

#define ld long double

 

using namespace std;

 

const int N = 5e5 + 123;

const ll mod = 1e9 + 7;



ll a[N], dp[N];

int n, k;



int main (){

	ios::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);



	cin >> n >> k;

	for(int i = 1;i <= n;i++)

		cin >> a[i];

	for(int i = 2;i <= n;i++){

		dp[i] = N * 1ll * N;

		for(int j = i;j >= max(1, i - k);j--){

			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));

		}

	}

	cout << dp[n];

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#define inf 2000000000

int n,k;

int h[100002]={100000},f[100002]={};

int min(int a,int b)

{

	return a<b? a:b;

}

int max(int a,int b)

{

	return a>b? a:b;

}

int abs(int x)

{

	return x<0? -x:x;

}

int main()

{

	scanf("%d%d",&n,&k);

	for(int i=1;i<=n;i++)

		scanf("%d",&h[i]);

	for(int i=2;i<=n;i++)

	{

		f[i]=inf;

		for(int j=max(i-k,1);j<i;j++)

			f[i]=min(f[i],f[j]+abs(h[i]-h[j]));

	}

	printf("%d",f[n]);

	return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

     for(int i=0;i<n;++i){

          cin>>h[i];

     }

     LL dp[100001];



      for(int i=0;i<n;++i){

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







     for(int i=2;i<n;++i){

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



#define ll long long

#define PI acos(-1.0)



ll dp[100105];

int n, k,arr[100005];



ll func(int indx)

{

	if(indx == n) return 0;

	if(dp[indx] != -1) return dp[indx];

	int len = min(indx+k, n);

	ll total = INT_MAX;

	for(int i = indx+1; i <= len;i++)

	{

		ll ans = abs(arr[indx]-arr[i]) + func(i);

		total = min(total,ans);

	}

	return dp[indx] = total;

}



int main()

{   

    scanf("%d %d", &n, &k);

    for(int i = 1;i <= n; i++)

    {

		scanf("%d", &arr[i]);

	}

	memset(dp,-1,sizeof(dp));

	ll ans = func(1);

	printf("%lld\n",ans);

	    	

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int arr[100100], dp[100100];



int main() {

  int n, k;

  cin >> n >> k;

  for (int i = 0; i < n; ++i) cin >> arr[i];



  dp[0] = 0;

  for (int i = 1; i < n; ++i) dp[i] = 2e9;



  for (int pos = 1; pos < n; ++pos) {

    for (int step = 1; step <= k; ++step) {

      if ( pos - step < 0 ) break;

      dp[pos] = min( dp[pos], dp[pos - step] + abs(arr[pos] - arr[pos - step]) );

    }

  }

  

  cout << dp[n - 1] << endl;

  return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

     for(int i=0;i<n;++i){

          cin>>h[i];

     }

     LL dp[100001];



      for(int i=0;i<n;++i){

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







     for(int i=2;i<n;++i){

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

map<ll,ll>mp;



int main(){

    ll n;scanf("%lld",&n);

    ll sum=0;

    for(ll i=0;i<n;i++){

        ll num;

        scanf("%lld",&num);

        mp[num]++;

        sum+=num;

    }

    ll q;scanf("%lld",&q);

    for(ll i=0;i<q;i++){

        ll b,c;scanf("%lld%lld",&b,&c);

        mp[c]+=mp[b];

        sum+=mp[b]*(c-b);

        mp[b]=0;

        cout<<sum<<endl;

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std; 

typedef long long LL;

const int MAXN=1E5+10;

int f[MAXN],sum[MAXN],tong[MAXN],a[MAXN];

long long sumans;



int main() {

	int N,K;

	scanf("%d",&N);

	sumans=0;

	for(int i=1;i<=N;++i) {

		scanf("%d",&a[i]);

		sumans+=a[i];

		tong[a[i]]+=1;

	}

	scanf("%d",&K);

	for(int i=1;i<=K;++i) {

		int b,c;scanf("%d%d",&b,&c);

		sumans-=1ll*tong[b]*b;

		sumans+=1ll*tong[b]*c;

		

		tong[c]+=tong[b];

		tong[b]=0;

		

		printf("%lld\n",sumans);

	}

	

	return 0;

} 

// Fastest known solution for this problem:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#include <string>

const int mxN=1e5;

const int maxN=5e3;

#define ld long double

#define pb push_back

#define mp make_pair

#define ins insert

#define vi vector<int>



int main()

{

    int n;

    cin >> n;

    int cnt[100000]={};

    ll s=0;

    for(int i=0;i<n;i++)

    {

        int x;

        cin >> x;

        cnt[x-1]++;

        s+=x;

    }

    int q;

    cin >> q;

    while(q--)

    {

        int b,c;

        cin >> b >> c;

        s+=cnt[b-1]*(c-b);

        cnt[c-1]+=cnt[b-1];

        cnt[b-1]=0;

        cout << s << "\n";

    }

}
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main() {

    vector<int> predas;

    vector<int> cutsos;

    int n, k;

    cin >> n >> k;



    for (int i = 0 ; i < n ; i++) {

        int c;

        cin >> c;

        predas.push_back(c);

    }

    cutsos.push_back(0);



    for (int i = 1; i < n ; i++) {

        int min = cutsos[i - 1] + abs(predas[i-1] - predas[i]);

        for (int j = i - 2; j >= i - k && j >= 0 ; j--) {

            if (cutsos[j] + abs(predas[j] - predas[i]) < min) min = cutsos[j] + abs(predas[j] - predas[i]);

        }

        cutsos.push_back(min);

    }



    cout << cutsos.back() << "\n";

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;



#define ll long long 



#define file_io 0



ll i,t,j;

ll n,k,h[100005],dp[100005];



int main(){

	if (file_io){

		freopen(".in","r",stdin);

		freopen(".out","w",stdout);

	}

	

	scanf("%lld%lld",&n,&k);

	

	for (i=1; i<=n; ++i){

		scanf("%lld",&h[i]);

	}

	

	dp[1]=0;

	for (i=2; i<=n; ++i){

		dp[i]=2e9;

		for (t=max(1ll,i-k); t<i; ++t){

			dp[i]=min(dp[t]+abs(h[i]-h[t]),dp[i]);

		}

	}

	

	printf("%lld\n",dp[n]);

	

	return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

     for(int i=0;i<n;++i){

          cin>>h[i];

     }

     LL dp[100001];



      for(int i=0;i<n;++i){

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







     for(int i=2;i<n;++i){

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}
// Original C++ solution (slower):
#include <iostream>



using namespace std;

int main(){

	long long int n,a;

	cin >> n;

	a=1;

	for (int i=1;i<=n;i++){



		a*=i;

			a=a%(10*10*10*10*10*10*10*10*10+7);

		//cout<<a<<endl;

	}

	cout<<a;

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

 

long long int n,a,b,c,i;



 

 

int main(void){

scanf("%d",&n);

b = 1;

for(i = 1;i <= n ;i++){



b = b * i;

b=b % (10*10*10*10*10*10*10*10*10 + 7);

}

c = b;

//b=b % (10*10*10*10*10*10*10*10*10 + 7);

printf("%lld",c);

return 0;

}

// Fastest known solution for this problem:
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;

using P = pair<ll, ll>;

const string ln = "\n";

constexpr int INF = 1001001001;

constexpr int MOD = 1000000007;



int main() {

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  int n;

  cin >> n;



  ll ans = 1;



  for (int i = 1; i <= n; i++) {

    ans *= i % MOD;

    ans %= MOD;

  }



  cout << ans << ln;



  return 0;

}
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <algorithm>

using namespace std;



int f(int n) {

    if(n % 2 == 0) {

        return n/2;

    }

    else {

        return 3*n + 1;

    }

}



int main() {

    int s;

    cin >> s;

    const int k = 1000000;

    int a[k];



    a[0] = s;

    for(int i = 1; i < k; i++) {

        a[i] = f(a[i-1]);

    }



    int ans;

    if(s == 1 || s == 2) { ans = 4; }

    else {

        for(int i = 0; i < k; i++) {

            if(a[i] == 4) {

                ans = i + 4;

                break;

            }

        }

    }



    cout << ans;



    cout << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <functional>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

typedef vector<vector<pair<ll, ll>>> vvpll;

#define rep(i, n) for(ll i = 0; i < n; i++)

#define exrep(i, a, b) for(ll i = a; i <= b; i++)

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

#define all(a) a.begin(), a.end()

#define rall(a) a.rbegin(), a.rend()

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_N = 100010;



ll f(ll n) {

    if(n%2 == 0) {

        return n/2;

    }

    else {

        return 3*n + 1;

    }

}



int main() {

    ll s;

    cin >> s;



    set<ll> st;

    ll a = s;

    st.insert(a);

    for(ll i = 2; ; i++) {

        a = f(a);

        st.insert(a);

        if(st.size() < i) {

            out(i);

            re0;

        }

    }



    re0;

}

// Fastest known solution for this problem:
#include <iostream> 



int main()

{

    int s;

    std::cin >> s;

    int list[1000000];

    int index = 0;

    int a_i;

    int a_pre = s;

    list[0] = s;

    index = index + 1;

    bool search_flag = false;

    while( true){

        if ( a_pre % 2 == 0){

            a_i = a_pre / 2;

        } else {

            a_i = 3 * a_pre + 1;

        }

        list[index] = a_i;

        index = index + 1;

        for ( int i = 0; i< index-1; ++ i ){

            if ( list[i] == a_i) {

                search_flag = true;

                break;

            }

        }

        if (search_flag==true){

            break;

        } 

        a_pre = a_i;



    }

    std::cout << index << std::endl;

    return 0;

}