stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122



int main() {

    int s;

    cin >> s;

    int a[2000000] = {};

    bool flag[10000] = {};

    a[0] = s;

    flag[a[0]] = true;

    int i = 1;

    while(1) {

        if (a[i - 1] % 2 == 0) a[i] = a[i - 1] / 2;

        else a[i] = a[i - 1] * 3 + 1;

        if (flag[a[i]]) {

            cout << i + 1 << endl;

            return 0;

        }

        flag[a[i]] = true;

        i++;

    }

}


// Faster C++ solution for the same problem (measured speedup: 9.429382222305126x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122



int main() {

    int s;

    cin >> s;

    set<int> used;

    int a = s;

    while(used.count(a) == 0) {

        used.insert(a);

        if (a % 2 == 0) a /= 2;

        else a = a * 3 + 1;

    }

    cout << used.size() + 1 << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int arr [100009];

int dp [100009];

int n,k;

int frog (int f_index)

{

if (f_index + 1 == n)return 0;

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

int s = INT_MAX;

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

{

if (f_index + i >= n)break;

s = min (s , frog (f_index + i) + abs (arr [f_index + i] - arr [f_index]));

}

return dp [f_index] = s ;

}

int main ()

{

cin >>n>>k;

for (int p = 0;p < 100009;p++)

{

dp [p] = -1;

}

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

{

cin >> arr [i];

}

cout <<frog (0)<<'\n';



}

// Faster C++ solution for the same problem (measured speedup: 1.3811773164505432x):
#include<bits/stdc++.h>



#define  ll         long long

#define  llu        unsigned long long

#define  mod        1000000007

#define  pi         ((2.0)*acos(0.0))

#define  pb         push_back

#define  pf         push_front

#define  eb         emplace_back

#define  mp         make_pair

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

#define  X          first

#define  Y          second



/*loop*/

#define  fr(i,m,n)   for(ll i=m;i<n;++i)



/*output shortcuts*/

#define  nl         "\n"

#define  Yes        cout<<"Yes\n"

#define  yes        cout<<"yes\n"

#define  YES        cout<<"YES\n"

#define  No         cout<<"No\n"

#define  no         cout<<"no\n"

#define  NO         cout<<"NO\n"



ll a[10000000];





using namespace std;

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll n,k;

    cin>>n>>k;



    ll a[n];

    fr(i,0,n)

    cin>>a[i];



    ll dp[n];

    dp[n-1]=0;



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

    {

        ll p=LONG_MAX;



        fr(j,1,k+1)

        {

            if(i+j >= n)

                break;

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

            dp[i]=p;

        }

    }



    cout<<dp[0]<<nl;



return 0;

}
// Slower C++ solution:
/*

 * VJUDGE B - Collatz Problem

 * author: roy4801

 * (C++)

 */

#include <bits/stdc++.h>



using namespace std;



#define PROB "B"

#define TESTC ""



#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)

typedef long long int LL;

typedef unsigned long long ULL;

typedef pair<int, int> P;

#define F first

#define S second

#define INF 0x3f3f3f3f

#define MP make_pair

#define MT make_tuple

#define PB push_back

#define N 1000000

bool arr[N+5];

int n, cnt; // s, times

int main()

{

	#ifdef DBG

	freopen("./testdata/" PROB TESTC ".in", "r", stdin);

	freopen("./testdata/" PROB ".out", "w", stdout);

	#endif

	while(cin >> n)

	{

		memset(arr, 0, sizeof(arr));

		cnt = 1;

		//

		while(true)

		{

			arr[n] = true;

			if(n & 1) // odd

			{

				n *= 3;

				n += 1;

			}

			else

			{

				n /= 2;

			}



			cnt++;

			if(arr[n])

				break;

		}



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

	}



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.9250447093920946x):
#include <bits/stdc++.h>



using namespace std;



#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)



int main(int argc, char const *argv[]){



	map<int, int> m;

	int input, ans, sta;

	while(cin >> input){

		sta = 0;

		ans = 1;

		m[input] = 1;

		while(1){

			if (input % 2 == 0){

				ans++;

				input /= 2;

				m[input] += 1;

			}

			else{

				ans++;

				input = (3*input + 1);

				m[input] +=1;

			}

			for (map<int,int>::iterator it=m.begin(); it != m.end(); ++it){

				if (it->second == 2){

					cout << ans << endl;

					sta = 1;

					break;

				}

			}

			if(sta == 1)	break;

		}

	}



	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

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

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

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

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}

inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}

//==================================================================================================================================================================//



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



int main() {

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

   for1(i, n) scanf("%d", h+i);

   ms(dp, inf); dp[n] = 0;

   for(int i = n; i; --i)

      for1(j, k) {

         if(i - j < 1) break;

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

      }

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

   return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3701016308328573x):
#include <bits/stdc++.h>

 

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

#define af(i,a,b) for( ll i = a; i >= b ; i--)

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

#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)

#define ones(x) (ll) __builtin_popcount(x)

#define fs first

#define sc second

#define pb push_back

#define po pop_back

#define mp make_pair  

#define sz(a) (ll) a.size()

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

#define sor(a) sort( a.begin(), a.end() )

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)

#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl

#define PI 3.1415926535

using namespace std;

typedef long long ll;

typedef long double ld; 

typedef pair<ll,ll> ii ;

typedef vector<ll>  vi ;

typedef vector<ii> vii ;

const ll mod = 1e9+7;

const ll MAX = 1e5+5;

const ll inf = 1e18+7;



ll n,k,h[MAX];

ll dp[MAX];



ll DP(ll caso){

  if(caso==1) return 0;

  ll &ans = dp[caso];

  if(ans!=inf) return ans;

  f(i,caso-k,caso){

    if(i<=0) continue;

    ans = min(ans,DP(i)+abs(h[caso]-h[i]));

  }

  return ans;

}





int main() {

  fastio;

  cin>>n>>k;

  f(i,0,n+5) dp[i]=inf;

  f(i,1,n+1) cin>>h[i];

  cout<<DP(n)<<"\n";

  return 0; 

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

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



    string s;

    cin >> s;

    stack<char> st;

    int n = s.size();

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

        if (s[i] == 'B' && !st.empty())

            st.pop();

        else if (s[i] != 'B')

            st.push(s[i]);



    s = "";

    while (!st.empty())

    {

        s += st.top();

        st.pop();

    }

    reverse(s.begin(), s.end());

    cout << s;

}

// Faster C++ solution for the same problem (measured speedup: 5.433653421343267x):
#include<stdio.h>

#include<string.h>

int main(){

	int pivot = 0;

	char str[15],monitor[15];

	scanf("%s" , &str);

	for(int i = 0 ; i < strlen(str) ; i++){

		if(str[i] == '0'){

			monitor[pivot] = '0';

			pivot++;

		}

		else if(str[i] == '1'){

			monitor[pivot] = '1';

			pivot++;

		}

		else if(str[i] == 'B'){

			if(pivot != 0){

				pivot--;

			}

		}

	}

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

		printf("%c" , monitor[i]);

	}

	

	

	

	return 0;

}
// Slower C++ solution:
#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;

    cin >> n;

    tmp=n;

    while (tmp--) {

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

    cin >> q;

    while (q--) {

        cin >> a >> b;

        tmp=arr[a];

        sum-=tmp*a;

        sum+=tmp*b;

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

        arr[a]=0;

        cout << sum << endl;

    }

    v.clear();

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8109593393115606x):
#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;

}
// Slower C++ solution:
#include <bits/stdc++.h>





using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;







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;

}

// Faster C++ solution for the same problem (measured speedup: 1.4089476145326971x):
#include <bits/stdc++.h>

using namespace std;

 

int h[100000], mCost[100000];

int Nstones, k;



int main() {



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

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

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

	}

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

        	mCost[i] = 10000000000;

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

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

        	}

	}

	printf("%d", mCost[Nstones - 1]);

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARINGS

#include <iostream>

#include <iomanip>

#include <map>

#include <cmath>

#include <algorithm>

#include <string>

#include <vector>

#include <queue>

#include <set>

#include <deque>

#include <stack>

#include <bitset>

#include <fstream>

#include <map>

#include <unordered_map>



using namespace std;

typedef int me;

typedef long long ll;

typedef unsigned long long ull;



#define andrew ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define endl '\n'

#define sz(v) (int)(v.size())

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

#define PI 3.1415926535

#define sin(i) (long double)sin(i *PI / 180.0)

#define cos(i) (long double)cos(i * PI/ 180.0)



ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }

ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }



int dy8[] = { 0, 0, 1, -1, 1, -1, -1, 1 };

int dx8[] = { 1, -1, 0, 0, 1, -1, 1, -1 };

int id8[] = { 0, 1, 2, 3, 4, 5, 6, 7 };



int main()

{

    andrew;

    int n, k;

    cin >> n >> k;

    vector<ll>v(n + 1);

    v[0] = 0;

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

        cin >> v[i];



    vector<ll>mem(100005, 1e9);

    

    mem[0] = 0;

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

    {

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

        {

            if (j < n)

                mem[j] = min(mem[j], mem[i] + abs(v[i] - v[j]));



        }

    }



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



    









}


// Faster C++ solution for the same problem (measured speedup: 1.2979533014959876x):
#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n,k;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];



    int step=INT_MAX;



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

    {

        if(index+jump<=n-1)

        {

            step=min(step,abs(arr[index]-arr[index+jump])+func(index+jump));

        }



    }



    return cost[index]=step;





}

int main()

{

    optimize();



    cin>>n>>k;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define Solved int main()

#define pb push_back

#define mp make_pair

#define F first

#define S second

#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

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

#define rep(i, x, y) for(int i = x; i <= y; i++)

#define sz(x) (int)x.size()

#define pii pair<int, int>

#define ll long long

#define ull unsigned long long

#define ld long double

#define mii map<int, int>

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

using namespace std;



inline ll bip(ll x,ll n,ll mod){ll res=1;while(n){if(n&1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}



const int maxn = 1e9;

const ll inf = 1e18;

const int mod = 998244353;

//const int mod = 1e9 + 7;

const int N = 1e5 + 10;



int n, k;

ll a[N];

ll dp[N];



void solve() {

    cin >> n >> k;



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

        cin >> a[i];



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

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

        dp[i] = inf;

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

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

        }

    }

    cout << dp[n];

}



Solved {

    SpeedForce;

	int tt = 1;

    //cin >> tt;

	while (tt--) {

		solve();

		cout << '\n';

	}



}


// Faster C++ solution for the same problem (measured speedup: 5.29587888336856x):
#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;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 1e5;

int a[N+5];

struct ft{

	int ft[2*N+10];

	void init(){

		memset(ft, 0, sizeof(ft));

	}

	void update(int i, int v){

		for(;i<=2*N+5;i+=(i&-i)){

			ft[i] += v;

		}

	}

	int query(int i){

		int res = 0;

		for(;i>0;i-=(i&-i)) res+=ft[i];

		return res;

	}

}ft;

int main(){

	int n;

	scanf("%d", &n);

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

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

	}

	LL tot = (LL)n*(n+1)/2;

	LL m = tot/2+1;



	int lo = 1, hi = 1e9, ans = 0;

	while(lo <= hi){

		int mid = (lo+hi)/2;



		int cnt = 100001;

		LL res = 0;

		ft.init();

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

			ft.update(cnt, 1);

			if(a[i] <= mid) cnt++;

			else cnt--;

			res += ft.query(cnt-1);

		}



		if(res >= m) ans = mid, hi = mid-1;

		else lo = mid+1;

	}

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

}

// Faster C++ solution for the same problem (measured speedup: 22.198808538912758x):
#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cassert>

const int MAXN = 1e5 + 10;

typedef int IntAr[MAXN];

typedef long long LL;



int N;

IntAr A, B, C, D;

LL tot;



namespace FastIO {

	template <typename T>

	void read(T & x) {

		x = 0; register char ch = getchar();

		for (; ch < '0' || ch > '9'; ch = getchar());

		for (; ch >= '0' && ch <= '9'; x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar());

	}

}

LL count(int);

void merge(int l, int r);



// #define DEBUG_MD_



int main() {

	using FastIO::read;

	read(N);

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

	memcpy(B, A, sizeof(int) * N);

	std::sort(B, B + N);

	int lb = -1, mid, ub = std::unique(B, B + N) - B - 1;

	LL pos = (LL(N) * (N + 1) >> 2) + 1;

#ifdef DEBUG_MD_

	printf("pos=%lld\n", pos);

#endif 

	for (; ub - lb > 1; ) { // (lb, ub]

		mid = lb + ub >> 1;

		assert(mid >= 0);

		if (count(B[mid]) >= pos) ub = mid;

		else lb = mid;

	}

	// return 0;

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

	return 0;

}



LL count(int key) {

	C[0] = 0;

	for (int i = 1; i <= N; i++) C[i] = C[i - 1] + (A[i - 1] > key ? -1 : 1);

	tot = 0;

	merge(0, N + 1);

#ifdef DEBUG_MD_

	printf("key=%d, tot=%lld\n", key, tot);

#endif 

	return tot;

}



void merge(int l, int r) {

	// merge sort interval [l, r)

	if (r - l <= 1) return;

	int mid = l + r >> 1;

	merge(l, mid);

	merge(mid, r);

#ifdef DEBUG_MD_

	printf("[%d, %d)\n", l, r);

#endif

	int i, j, k;

	for (i = l, j = mid, k = l; i < mid && j < r; )

		if (C[i] < C[j]) {

			D[k++] = C[i++];

			tot += r - j;

		}

		else D[k++] = C[j++];

	for (; i < mid; ) D[k++] = C[i++];

	for (; j < r; ) D[k++] = C[j++];

	memcpy(C + l, D + l, sizeof(int) * (r - l));

}
// Slower C++ solution:
#include <iostream>



using namespace std;

typedef long long ll;



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

int memo[100010];



int main(void)

{

    int s, i = 1;

    REP(ii, 100000) memo[ii] = 0;

    cin >> s;

    while(1) {

        if(memo[s] == 1) {



            cout << i << endl;

            return 0;

        }

        memo[s] ++;

        if(s%2==0) {

            s=s/2;

        } else {

            s = 3 * s + 1;

        }

        i++;

    }

}


// Faster C++ solution for the same problem (measured speedup: 1.3842858418301671x):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;



#define INF (long long)(1e9+7)

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

#define REP1(i,n) for(ll i = 1; i <= n; i++)



ll gcd(ll a, ll b)

{

  if(b == 0) return a;

  return gcd(b, a % b);

}







int main(void)

{

  ll s;

  cin >> s;

  set<ll> st;



  ll cnt = 1;

  ll a = s;

  do {

    st.insert(a);

    if(a % 2 == 0) {

      a = a / 2;

    } else {

      a = 3 * a + 1;

    }

    cnt++;

    //    cout << a << " " << endl;

  } while(st.find(a) == st.end());

  //  cout << endl;

  cout << cnt << endl;

}
// Slower C++ solution:
//Coded by not_surrender

#pragma GCC optimize ("O3")



#include <bits/stdc++.h>



#define MAXN 300003

#define MOD 1000000007

#define oo (1<<20)

#define mid ((a+b)/2)

#define pb push_back

#define sz size()

#define fastCpp() ios_base::sync_with_stdio( false ), cin.tie( NULL ), cout.tie( NULL )



using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef vector <int> vi;



struct Data{

	int n1, n2;

	Data(int n1 = 0, int n2 = 0):n1(n1),n2(n2){}

}dp[MAXN];



int N, M, ans;

 

int main(){



    #ifndef ONLINE_JUDGE

		//~ freopen( "a.txt", "r", stdin );

    #endif // ONLINE_JUDGE

    

    fastCpp();

    

    scanf( "%d", &N );

    

    M = (1<<N);

    

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

		scanf( "%d", &dp[i].n1 );

    

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

		for ( int j = M-1, nxt; j > 0; --j ){

			nxt = j-(j&(1<<i));

			if ( nxt < j ){

				if ( dp[nxt].n1 > dp[j].n1 )

					dp[j].n2 = dp[j].n1, dp[j].n1 = dp[nxt].n1;

				else

					dp[j].n2 = max( dp[j].n2, dp[nxt].n1 );

			}

		}

	}

	

	for ( int i = 1, ans = 0; i < M; ++i ){

		ans = max( ans, dp[i].n1+dp[i].n2 );

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

	}

	

return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.3642850411566534x):
#include <bits/stdc++.h>

using namespace std;



int b[1 << 21], *a;

int Max[1 << 20], __Max[1 << 20], ans[1 << 20];



int main() {

	

	ios::sync_with_stdio(0);

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

	

	a = b + 10;

	int n; cin >> n;

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

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

		Max[s] = s, __Max[s] = -1;

		for (int i = 0; i < n; i++) if (s >> i & 1) {

			auto t = s ^ (1 << i);

			if (a[Max[s]] == a[Max[t]]) {

				if (Max[s] == Max[t]) {

					if (a[__Max[s]] < a[__Max[t]]) __Max[s] = __Max[t];

				} else __Max[s] = Max[t];

			}

			if (a[Max[s]] > a[Max[t]]) {

				if (a[__Max[s]] < a[Max[t]]) __Max[s] = Max[t];

			}

			if (a[Max[s]] < a[Max[t]]) {

				if (a[Max[s]] < a[__Max[t]]) __Max[s] = __Max[t];

				else __Max[s] = Max[s];

				Max[s] = Max[t];

			}

		}

	}

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

		if (s == 0) ans[s] = a[Max[s]];

		else ans[s] = max(a[Max[s]] + a[__Max[s]], ans[s - 1]);

	}

	for (int s = 1; s < (1 << n); s++) cout << ans[s] << "\n";

	

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <cstdint>

#include <cinttypes>

#include <cstring>



using i32 = std::int_fast32_t;

using i64 = std::int_fast64_t;



inline i32 diff(i32 x, i32 y) {

	return x > y ? x - y : y - x;

}



const i32 MaxN = 100001;



i32 dp[MaxN], A[MaxN];



signed main(signed argc, char **argv) {

	i32 n, k;

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



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

		scanf("%" SCNdFAST32, A + i);

	}

	

	memset(dp, 0x3f, sizeof dp);

	

	dp[0] = 0;



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

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

			if (i - j < 0) {

				break;

			}

			dp[i] = std::min(dp[i], dp[i - j] + diff(A[i], A[i - j]));

		}

	}



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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.554355318407519x):
#include<cstdio>

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn=1e5 + 5;

int main()

{

	int dp[maxn];

	int h[maxn];

	int n,k;

	while(~scanf("%d %d",&n,&k)){

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

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

		dp[1] = 0;

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

	    	dp[i]=1e9;

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

				if(i==j) break;

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

				}

	}

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

	}

	return 0;

}