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



using namespace std;



const int nax = 1e5+103;

int n, k;

int dp[nax];

int a[nax];

int f(int i){

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

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

	int ans = abs(a[i]-a[i+1])+f(i+1);

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

		if(i+j<n) ans = min(ans, abs(a[i]-a[i+j])+f(i+j));

	}

	return dp[i]=ans;

}

int main(){

	cin>>n>>k;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}

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

using namespace std;

const int nax = 1e5+103;

int n, k;

int dp[nax];

int a[nax];

int frog2(int i){

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

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

	int ans = abs(a[i]-a[i+1])+frog2(i+1);

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

		if(i+j<n) ans = min(ans, abs(a[i]-a[i+j])+frog2(i+j));

	}

	return dp[i]=ans;

}

int main(){

	cin>>n>>k;

	for(int i=0; i<n; i++) {cin>>a[i]; dp[i]=-1;}



	cout<<frog2(0)<<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 <iostream>

#include <algorithm>

using namespace std;

static const int LEFT = -1000000;

static const int RIGHT = 1000000;

int main() {

    int K, X;

    cin >> K >> X;

    for (int i = max(LEFT, X - K + 1); i <= min(RIGHT, X + K - 1); i++)

        cout << i << " ";

}

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

static const int left = -1000000;

static const int right = 1000000;

inline int max(int a, int b) {

    return a > b ? a : b;

}

inline int min(int a, int b) {

    return a < b ? a : b;

}

int main() {

    int K, X;

    scanf("%d %d", &K, &X);

    const int limit = min(right, X + K - 1);

    for (int i = max(left, X - K + 1); i <= limit; i++) printf("%d ", i);

}

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

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

using namespace std;



int main(void) {

	int k, x;

	cin >> k >> x;

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

		if (i == x+k) cout << i << endl;

		else cout << i << " ";

	}

	return 0;

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

#include <algorithm>

using std::min;

 

int m_abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}

 

int main(void)

{

    int *a,*dp,N,i,j,K;

    scanf("%d%d",&N,&K);

    a=new int [N];

    dp=new int [N];

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

    {

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

    }

    dp[N-1]=0;

    if(K>N)

        K=N;

    for(i=0;i<K;i++)

        dp[N-1-i]=abs(a[N-1]-a[N-1-i]);

 

    for(i=N-1-K;i>=0;i--)

    {

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

        for(j=2;j<=K;j++)

        {

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

        }

        //printf("dp[%d]= %d\n",i,dp[i]);

 

    }

 

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

    delete [] dp;

    delete [] a;

 

    return 0;

}

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

using namespace std;

#define MAX(a,b) (a>b?a:b)

#define MOD(a) (a>0?a:-(a))

#define custoate(i)

int main(){

  int npedras, maxpulo;

  scanf("%d %d",&npedras,&maxpulo);

  int hpedra[npedras],custoate[npedras];

  for (size_t i = 0; i < npedras; i++)

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

  custoate[0] = 0;

  int tempcost = 2147483647,k,tempcost2;

  for (size_t i = 1; i < npedras; i++,tempcost = 2147483647) {

    // printf("i = %d, tempcost = %d\n", i,tempcost);

    for (k= (maxpulo>i ? i : maxpulo); k > 0; k--) {

      // printf("k = %d ",k);

      tempcost2 = custoate[i-k] + MOD(hpedra[i-k]-hpedra[i]);

      if (tempcost > tempcost2)

        tempcost = tempcost2;

    }

    // printf("custo[%d] = %d",i,tempcost);

    custoate[i] = tempcost;

    // printf("\n\n");

  }

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



}

// 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>

#include<cstdio>

#include<cmath>

using namespace std;

int main()

{

	int n,i,x=0;

	double k,a;

	cin>>n>>k;

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

	{

		cin>>a;

		if(a>=k)

		x++;

	}

	cout<<x;

	return 0;

}

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

int main()

{

	int a,n,k,h[100000],cnt=0;

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

	for(a=0;a<n;a++){

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

		if(h[a]>=k){

			cnt++;

		}

	}

	printf("%d",cnt);

}

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

using namespace std ;

 

int main()

{

  int n , k , a , answer ;

  cin >> n >> k ;

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

  {

    cin >> a ;

    if(a >= k)

      answer++ ;

  }

  cout << answer << endl ;

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

#include <cstring>

using namespace std;

int dp[100000];

int n,a[100000],k;



int topdown()

{

	dp[n-1]=0;



	for(int i=n-2;i>=0;i--)

	{

		dp[i]=1e9;

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

		{

          	if(i+j<n)

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

		}

	}

	return dp[0];

}



int main()

{

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

	cin>>n>>k;

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

		cin>>a[i];



	cout<<topdown();



	return 0;

}


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

#include <cstring>

using namespace std;

int dp[100000];

int n,a[100000],k;



int topdown()

{

	dp[n-1]=0;



	for(int i=n-2;i>=0;i--)

	{

		dp[i]=1e9;

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

		{

          	if(i+j<n)

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

		}

	}

	return dp[0];

}



int main()

{

  	ios_base::sync_with_stdio(0);            //fast input and output

	cin.tie(NULL);

	cout.tie(NULL);

	cin>>n>>k;

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

		cin>>a[i];



	cout<<topdown();



	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, k;

int a[100000];

int dp[100000];



int solve(int i)

{

	if (i == n - 1)

		return dp[i] = 0;

	if (dp[i] != -1)

		return dp[i];

	int ans = INT_MAX;

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

	{

		if (j + i < n)

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

		else

			break;

	}

	return dp[i] = ans;

}



int main()

{

	cin >> n >> k;

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

		cin >> a[i];

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

	cout << solve(0) << endl;

	return 0;

}


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



using namespace std;



int n, k;

int a[100000];

int dp[100000];



int main()

{

	cin >> n >> k;

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

		cin >> a[i];

	dp[0] = 0;

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

	{

		dp[i] = INT_MAX;

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

		{

			if (i - j >= 0)

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

		}

	}

	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;

typedef unsigned long long ull;



const int mod  = 100003;

const int maxn = 1e5+10;



int a[maxn];

int dp[maxn];

int f(int a)

{

	if (a<0)

		a=-a;

	return a;

}

int k;

int solve(int n)

{

	if (dp[n]!=-1)

		return dp[n];

	int ans=1e9;

	for (int i=1;n-i>=1&&i<=k;i++)

	{

		int tem=solve(n-i)+f(a[n]-a[n-i]);

		ans=min(tem,ans);

	}

	dp[n]=ans;

	return dp[n];

}

int main()

{

	int n;

	cin>>n>>k;

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

		dp[i]=-1;

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

		cin>>a[i];

	dp[1]=0;

	dp[2]=f(a[1]-a[2]);

	cout<<solve(n);

	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 <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <stack>

#include <queue>

#include <algorithm>

using namespace std;

typedef long long ll;

int main(void)

{

	ll i,ans,n,k,count,num;

	while(scanf("%lld%lld",&n,&k)!=EOF)

	{

		ans=0;

		count=1;

		if(k==0)

		{

			ans=n*n;

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

			continue;

		}

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

		{

			num=n%i;

			if((num-k+1)>0)

			ans+=(num-k+1);

			ans+=(count++)*((n-num)/i);

		}

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

	}

 } 

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

#include<algorithm>

using namespace std;

int N,K;

long long ans=0;

int main() {

	#ifdef LOACL

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

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

	#endif

	scanf("%d %d",&N,&K);

	if(K==0)ans=1ll*N*N;

	else {

		for(int b=K+1;b<=N;b++) {

			int x1=b-K;

			int x2=N/b;

			int k=N-x2*b;

			if(k>=K)ans+=k-K+1;

			ans+=x1*x2;

		}

	}

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

	return 0;

}


// Fastest known solution for this problem:


#include <iostream>

#include <cstdio>



using namespace std;



int main()

{

    long long n,k;

    long long i,j;

    long long ans;

    while (scanf("%lld%lld",&n,&k)!=EOF)

    {

        ans=0;

        for (i=1;i<=n-k;i++)

        {

            j=i+k;

            ans+=(n/j)*i;

            if(n%j-k>=0)

                ans+=n%j-k+1;

        }

        if (k==0)

            ans=n*n;

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

    }

    return 0;

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

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f3f3f3f

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define pb push_back

#define ms(a, x) memset(a, x, sizeof(a))

#define forn(i, n) for(int i = 0; i < n; ++i)

#define for1(i, n) for(int i = 1; i <= n; ++i) 

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

using namespace std;

const int mod = 1e9;

const int N = 1e5+10;

/*=======================================================================*/



int n, h[N], sum, k;

int f[N];



int main() {

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

   for1(i, n) {

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

   }

   ms(f, inf);

   f[n] = 0;

   for(int i = n; i > 1; i--) {

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

         if(i - j < 1) break;

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

      }

   }

   cout << f[1] << endl;

   return 0;

}

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

using namespace std;

const int N=100005;

int a[N],dp[N];

int main()

{

	int n,k;

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

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

		dp[i]=INT_MAX;

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

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

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

		for(int j=1;j<=k&&j<i;j++)

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

	printf("%d\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>

#include <algorithm>

#include <string>

#include <vector>

#include <cstdio>

#include <cmath>

#include <cstring>

#include <cstdlib>

#define endl '\n'

#define ll long long

#define pb push_back

#define pi 3.14159265358979323846264338327950288419716939937510

#define RUN_FAST ios::sync_with_stdio(false);

#define sz 100

using namespace std;



int main()

{

    RUN_FAST;

    ll n, x, tmp, i, j, cnt;

    ll sum=0;

    vector <ll> v;

    scanf("%lld", &n);

    tmp=n;

    while (tmp--) {

        scanf("%lld", &x);

        sum+=x;

        v.push_back(x);

    }

    ll arr[100110]={0};

    sort(v.begin(), v.end());

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

        cnt=1;

        tmp=v[i];

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

            if (v[j]!=tmp) {

                break;

            }

            cnt++;

        }

        arr[tmp]=cnt;

        i=j-1;

    }

    ll q, a, b;

    scanf("%lld", &q);

    while (q--) {

        scanf("%lld %lld", &a, &b);

        tmp=arr[a];

        sum-=tmp*a;

        sum+=tmp*b;

        arr[b]=arr[b]+tmp;

        arr[a]=0;

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

    }

    return 0;

}


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

#include <algorithm>

#include <string>

#include <vector>

#include <cstdio>

#include <cmath>

#include <cstring>

#include <cstdlib>

#define endl '\n'

#define ll long long

#define pb push_back

#define pi 3.14159265358979323846264338327950288419716939937510

#define RUN_FAST ios::sync_with_stdio(false);

#define sz 100

using namespace std;



ll arr[100110];



int main()

{

    RUN_FAST;

    ll n, x, tmp, i, j, cnt;

    ll sum=0;

    scanf("%lld", &n);

    tmp=n;

    while (tmp--) {

        scanf("%lld", &x);

        arr[x]++;

        sum+=x;

    }

    ll q, a, b;

    scanf("%lld", &q);

    while (q--) {

        scanf("%lld %lld", &a, &b);

        tmp=arr[a];

        sum-=tmp*a;

        sum+=tmp*b;

        arr[b]=arr[b]+tmp;

        arr[a]=0;

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

    }

    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 <iostream>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include<queue>

#include<algorithm>

using namespace std;

const int maxn = 1e6+5;

int n;

int pre[maxn];

int main() {

    cin>>n;

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

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

	}

	int ans=0;

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

    	int s1=pre[0],s2=0;

    	for(int j=i;j!=0;j=(j-1)&i){

    	    if (pre[j]>s1) {

				s2=s1;

				s1=pre[j];

			}

    	    else if(pre[j]>s2) s2=pre[j]; 

    	}

    	ans=max(ans,s1+s2);

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

    } 

    return 0;

}


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

#include<algorithm>

#define rep(i,l,r) for (int i=(l); i<=(r); i++)

using namespace std;



const int N=300010;

int n,m,a[N],r[N],mx[N];



int main(){

    scanf("%d",&m); int n=1<<m;

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

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

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

            r[j]=max(r[j],a[i]+mx[j]),mx[j]=max(mx[j],a[i]);

    for (int i=1; i<n; i++) printf("%d\n",r[i]=max(r[i],r[i-1]));

    return 0;

}

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

	#define mx 300005

	using namespace std;



	int a[mx], n;

	vector<vector<bool> > vis(mx, vector<bool> (20, false));

	vector<vector<pair<int,int> > > memo(mx, vector<pair<int, int> > (20, {0, 0}));



	void dp(int num, int pos) {

		if(pos == 0) {

			memo[num][0].first = a[num];

			vis[num][0] = true;

			return;

		}

		if(vis[num][pos]) return;

 		vector<int> cons;

		dp(num, pos-1);

		cons.push_back(memo[num][pos-1].first);

		cons.push_back(memo[num][pos-1].second);

		if(num & (1<<(pos-1))) {

			dp(num ^ (1<<(pos-1)), pos-1);

			cons.push_back(memo[num ^ (1<<(pos-1))][pos-1].first);

			cons.push_back(memo[num ^ (1<<(pos-1))][pos-1].second);

		}

		sort(cons.begin(), cons.end(), greater<int>());

		memo[num][pos].first = cons[0];

		memo[num][pos].second = cons[1];

		vis[num][pos] = true;

	}



	int main() {

		ios_base::sync_with_stdio(false);

	    cin.tie(NULL);

	    cout.tie(NULL);



		cin >> n;

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

			cin >> a[i];

			

		}

		for(int i = (1<<n) - 1; i >= 0; --i) {

			if(!vis[i][n]) {

				dp(i, n);

			}

		}

		int mxv = 0;

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

			mxv = max(memo[i][n].first + memo[i][n].second, mxv);

			cout << mxv << "\n";	

		}

		return 0;

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

#include<vector>

using namespace std;



int main(){

    int s;

    vector<int> a(1000000);

    cin >> s;

    a.at(0) = s;



    int i = 0;

    while(1){

        if(a.at(i)%2 == 0){

            a.at(i+1) = a.at(i) / 2;

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

                if(a.at(i+1) == a.at(j)){

                    cout << i+2 << endl;

                    return 0;

                }

            }

            i++;

        }else{

            a.at(i+1) = 3*a.at(i) + 1;

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

                if(a.at(i+1) == a.at(j)){

                    cout << i+2 << endl;

                    return 0;

                }

            }

            i++;

        }

    }



}

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

#include<vector>

#include<map>

using namespace std;



const int mod = 1000000007;

const int MAX_N = 1000000;



int func(int n){

    if(n%2){

        return 3*n+ 1;

    }else{

        return n/2;

    }

}



int main(){

    int s;

    cin >> s;

    map<int,int> mp;

    

    //mp[s]の初期値は０だった。

    //一度登場するとインクリメントが行われる。

    mp[s]++;

    //最短で一致するとa2となるので。

    int count = 2;



    while(1){

        //この時点でｓは別物のｓとなる。

        s = func(s);



        //なるほど、同じ数字が出てくると同じ配列？の通し番号

        //にアクセスすることを利用しているのか。

        if(mp[s]){

            cout << count << endl;

            return 0;

        }

        //一度登場するとインクリメントが行われる。

        mp[s]++;

        count++;

        

    }

    





    



}


// 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;

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



using namespace std;



int main()

{

int x,y;

cin>>x>>y;

for(int i=y-x+1;i<y+x;i++){

    cout<<i<<" ";

}

return 0;

}


// Optimized solution to the same problem (faster):
////sfef

#include<stdio.h>

int main(){



int k,x,i,p,q,r;

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

p=(x-(k-1));

q=(x+(k-2));

r=(x+(k-1));

if(k==1)

{

    printf("%d",x);

}

else{

    for(i=p;i<=q;i++)    

    {

        printf("%d ",i);

    }

    printf("%d",r);

}



return 0;

}


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

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

using namespace std;



int main(void) {

	int k, x;

	cin >> k >> x;

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

		if (i == x+k) cout << i << endl;

		else cout << i << " ";

	}

	return 0;

}