stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstring>

using namespace std;

int main()

{

	int k;

	string s;

	cin>>k>>s;

	if(s.length()>k)

	{

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

		cout<<s[i];

		cout<<"...";

	}

	else

	cout<<s;

} 

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

#include <string.h>

int main(){

	int k;

	scanf("%d",&k);

	char s[100];

	scanf("%s",&s);

	int lol = strlen(s);

	s[k] = '\0';

	for(int i=0;s[i]!='\0';i++){

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

	}

	if(k<lol){

		printf("...");

	}

return 0;

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

using namespace std;

#define ll long long

#define vi vector<int>

#define pb push_back

#define pii pair<int , int>

#define fast ios_base::sync_with_stdio(0)

#define mx 100005

#define inf 100000000000000000LL

ll arr[mx], dp[mx];

int n, k;

ll solve(int pos)

{

    if(pos==n) return 0;

    ll&ret = dp[pos];

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

    ret = inf;

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

        int nxt = pos+i;

        if(nxt>n) break;

        ret = min(ret, llabs(arr[pos] - arr[nxt]) + solve(nxt));

    }

    return ret;

}

int main()

{

    //fast;

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

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

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

        memset(dp, -1, sizeof dp);

        printf("%lld\n", solve(1));

        return 0;

    }

}




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

using namespace std;

#define ll long long

#define vi vector<int>

#define pb push_back

#define pii pair<int , int>

#define fast ios_base::sync_with_stdio(0)

#define mx 100005

#define inf 100000000000000000LL

ll arr[mx], dp[mx];

int main()

{

    int n,k;

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

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

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

        dp[n] = 0;

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

            dp[i] = inf;

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

                int nxt = i+j;

                if(nxt>n) break;

                dp[i] = min(dp[i], llabs(arr[i] - arr[nxt]) + dp[nxt]);

            }

        }

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

        return 0;

    }

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

using namespace std;

int main(){

	int k;

	string s;

	cin >> k >> s;

	if(s.length() > k){

		for(int i = 0;i < k;i++) cout << s[i];

		cout << "...";

	}else {

		cout << s;

	}

	return 0;

}

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

#include<string.h>

int main(){

	int k;

	char s[105];

	scanf("%d",&k);

	getchar();

	scanf("%s",&s);

	if(strlen(s)>k){

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

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

		}

		printf("...");

		printf("\n");

	}

	else{

		int l = strlen(s);

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

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

		printf("\n");

	}

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

using namespace std;



int main() {

	// your code goes here

	cin.tie(NULL);

	cout.tie(NULL);

	

	long long n,k;

	

	while(cin>>n && cin>>k)

	{

		vector<long long>cost(n);

		

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

		

		vector<long long>dp(n,INT_MAX);

		

		dp[0] = 0;

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

		

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

		{

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

			{

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

			}

		}

		

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

	}

	return 0;

}

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

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



using namespace std;



const int MAXN = 1000000;

int A[MAXN + 1];



int f(int n) {

	if (n % 2 == 0) {

		return n / 2;

	} else {

		return 3 * n + 1;

	}

}



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int s, count = 1;

  cin >> s;



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

  	A[i] = 0;

  }



  A[s] += 1;

  while (true) {

  	s = f(s);

  	count++;

  	if (A[s] != 0) {

  		cout << count << '\n';

  		break;

  	}

  	A[s]++;

  }

  return 0;

}


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



using namespace std;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int s;

  cin >> s;



  set<int> c;

  while (c.count(s) == 0) {

    c.insert(s);

    if (s % 2 == 0)

      s /= 2;

    else

      s = 3 * s + 1;

  }

  cout << c.size() + 1 << '\n';

  return 0;

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

using namespace std;

typedef long long ll;

const ll inf = 1e9;

#define sz              300005

#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);



string s;



int main(){

    Fast;

    int a,b,c, i,j, n,m,t, cs=1;

    cin>>n>>s;



    if(s.size()<=n){

        cout<<s<<endl;

        return 0;

    }

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

        cout<<s[i];

    }

    cout<<"..."<<endl;





    return 0;

}




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

	# include <string.h>

	int main () {

		int a = 0;

		int c =0;

	char name [100];

		scanf ("%d",&a);

		scanf("%s%[^\n]",&name);

		c = strlen (name);

		if (c<=a) {

			printf ("%s",name);

		} else if (c>a) {

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

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

			}

			printf("...");

		}

		return 0;

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

  using namespace std;



typedef long long int int64;

typedef unsigned long long int uint64;

typedef vector<int64> vi;

typedef vector<bool> vb;

typedef vector<char> vc;

typedef pair<int64,int64> pi; 

bool doubleSame(double a, double b)

{ const double eps = 1e-15; return ( abs(a-b)<= eps*abs(a) ); }

 

int main()

{

	int64 n,k;

	cin>>n>>k;

 

	vector<int64> h(n);

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

		cin>>h[i];

 

	vector<int64> ans(n);

	ans[0] = 0;

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

 

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

	{

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

		for(int64 j = 2 ; j<=i && j<=k ; j++)

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

	}

	cout<<ans[n-1];

}

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

#include<stdlib.h>

#include<math.h>





typedef long long ll;





ll *mem, *inp, dist, min_dist, N;

int k;



int main()

{

    ll i, j;

    scanf("%lld%d", &N, &k);



    mem =(ll*) malloc(N * sizeof(ll));

    inp =(ll*) malloc(N * sizeof(ll));



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

        scanf("%lld", inp+i);

    }



    *(mem+N-2) = llabs(*(inp+N-2) - *(inp+N-1));



    for(i = 3; i<=k+1 && i<=N; ++i)

        *(mem+N-i) = llabs(*(inp+N-i) - *(inp+N-1));



    for(i = N-(k+2); i>=0; --i){



        min_dist = llabs(*(inp+i) - *(inp+i+1)) + *(mem+i+1);

        for(j = 2; j<=k && i+j<N; ++j){

            dist = llabs(*(inp+i) - *(inp+i+j)) + *(mem+i+j);

            if (dist < min_dist) min_dist = dist;

        }



        *(mem+i) = min_dist;

    }



    printf("%lld\n", *mem);



    return 0;

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

using namespace std;



long long n,a,m,b,qq,k;

string ss;

int main() {

    cin>>n>>k;

    long long l[n],l1[n];

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

        l[i]=0;

        l1[i]=0;

    }

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

        cin>>l[i];

    }

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

        l1[i]=l1[i-1]+abs(l[i-1]-l[i]);

        for (int j=1; j<=min(i*1ll,k); j++){

            l1[i]=min(l1[i], l1[i-j]+abs(l[i-j]-l[i]));

        }

    }

    cout<<max(0*1ll,l1[n-1])<<endl;

}


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

#include<stdlib.h>

#include<math.h>





typedef long long ll;





ll *mem, *inp, dist, min_dist, N;

int k;



int main()

{

    ll i, j;

    scanf("%lld%d", &N, &k);



    mem =(ll*) malloc(N * sizeof(ll));

    inp =(ll*) malloc(N * sizeof(ll));



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

        scanf("%lld", inp+i);

    }



    *(mem+N-2) = llabs(*(inp+N-2) - *(inp+N-1));



    for(i = 3; i<=k+1 && i<=N; ++i)

        *(mem+N-i) = llabs(*(inp+N-i) - *(inp+N-1));



    for(i = N-(k+2); i>=0; --i){



        min_dist = llabs(*(inp+i) - *(inp+i+1)) + *(mem+i+1);

        for(j = 2; j<=k && i+j<N; ++j){

            dist = llabs(*(inp+i) - *(inp+i+j)) + *(mem+i+j);

            if (dist < min_dist) min_dist = dist;

        }



        *(mem+i) = min_dist;

    }



    printf("%lld\n", *mem);



    return 0;

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

using namespace std;

#define ll long long



const ll INF= 1LL << 60;



//入力

ll N;

ll K;

ll h[100010];

//dp

ll dp[100010];





void chmin(ll& a, ll b){

  if(a>b){

    a=b;

  }

}



int main(){

  cin >> N >> K;

  for(int i=0;i<N;i++) cin >>h[i];

  for(int i=0;i<100010;i++) dp[i]=INF;

  

  dp[0]=0;

  

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

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

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

      //cout<<i<<","<<j<<":"<<dp[j]<<endl;

    }

  }

  

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

}

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



using namespace std;



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

#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)

#define REP(i,n) rep(i,0,n)

#define REP2(i,n) rep2(i,0,n)

#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)

#define ll long long

#define ull unsigned long long

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

#define en '\n'

template <class T> using vec = vector<T>;

template <class T> using vvec = vector<vec<T>>;

typedef pair<ll, ll> P;

constexpr long long INF = 1LL << 60;

constexpr int INF_INT = 1 << 25;

constexpr long long MOD = (ll) 1e9 + 7;

typedef vector<ll> Array;

typedef vector<Array> Matrix;

constexpr int loose = 0;

constexpr int tight = 1;





template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}

template<class T> inline bool chmax(T& a, T b) {

    if (a < b) {

        a = b;

        return true;

    }

    return false;

}



struct Edge {

	ll to, cap, rev;

	Edge(ll _to, ll _cap, ll _rev) {

	to = _to; cap = _cap; rev = _rev;

	}

};

typedef vector<Edge> Edges;

typedef vector<Edges> Graph;



void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {

	G[from].push_back(Edge(to, cap, (ll)G[to].size()));

	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));

}



void solve(){

	ll n, k;

	cin>>n>>k;

	Array h(n);

	REP(i,n) cin>>h[i];

	

	Array dp(n,INF);

	dp[0]=0;

	REP(i,n){

		rep(j,1,k+1){

			if(i+j>=n) break;

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

		}

	}

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

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    solve();

    return 0;

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

#include<cstdio>

#include<cstdlib>

#include<string>

#include<cstring>

#include<cmath>

#include<ctime>

#include<algorithm>

#include<utility>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<map>

#include<bitset>

#define EPS 1e-9

#define PI acos(-1.0)

#define INF 0x3f3f3f3f

#define LL long long

const int MOD = 1E9+7;

const int N = 1000+5;

const int dx[] = {-1,1,0,0,-1,-1,1,1};

const int dy[] = {0,0,-1,1,-1,1,-1,1};

using namespace std;

LL a[10000];

int main()

{

    int n;

    scanf("%d",&n);

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

    {

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

    }

    LL ans=0;

    while(true)

    {

        LL maxn=a[1];

        int id=1;

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

        {

            if(maxn<a[i])

            {

                maxn=a[i];

                id=i;//---

            }

        }

        if(maxn<=n-1)

            break;////////------

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

        {

            if(i==id)

            {

                a[i]=maxn%n;



            }

            else

            {

                a[i]+=maxn/n;

            }

        }

        ans+=maxn/n;//

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 4.724101566438609x):
/*

    数据量很小,直接模拟

    对最大的数-n,其他数+1,直到最大数都小于n

    问操作次数.

    数据量大时,二分也应该可以.

*/

#include<cstdio>

using namespace std;

typedef long long LL;

LL a[55];

int main(){

    LL n, ans = 0;

    scanf("%lld", &n);

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

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

    }

    while(true){

        LL ma = a[0], pos = 0;

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

            if(a[i]>ma){

                ma = a[i];

                pos = i;

            }

        }

        if(ma<n){

            break;

        }

        LL tmp = ma / n;

        a[pos] %= n;

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

            a[i] += tmp;

        }

        a[pos] -= tmp;

        ans += tmp;

    }

    printf("%lld", ans);

    return 0;

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

using namespace std;

typedef		long long       ll;

typedef		vector<ll>      vll;

#define     fi              first

#define     se              second

#define		pb              push_back

#define		nn              "\n"

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

#define		zz(v)           (ll)v.size()

#define 	S(a)            scanf("%lld",&a)

#define 	SS(a,b)         scanf("%lld %lld",&a,&b)

#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)

#define		ss              ' '

#define     pii             pair<ll,ll>

const double eps = 1e-8;



ll ar[100010];

ll dp[100010];

ll n,k;

ll solve(ll i)

{

    if(i==n)

        return 0;

    if(i>n)

        return INT_MAX;



    if(dp[i]!=-1)

        return dp[i];

    ll arr[k+10],sz=0;

    for(ll step = 1; step<=k; ++step)

    {

        if(i+step<=n)

        {

            arr[sz++]=abs(ar[i]-ar[i+step])+solve(i+step);

        }

        else

            break;

    }

    ll mn=INT_MAX;

    for(ll x=0; x<sz; x++)

        mn=min(mn,arr[x]);

    return dp[i]=mn;



}



int main()

{

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

    cin>>n>>k;

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

        cin>>ar[i];

    cout<<solve(1);



}














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

using namespace std;

typedef		 long long int    ll;

typedef		vector<ll>      vll;

#define     fi              first

#define     print(v)        for(ll i:v) cout<<i<<ss

#define     se              second

#define		pb              push_back

#define		nn              "\n"

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

#define		zz(v)           (ll)v.size()

#define 	S(a)            scanf("%lld",&a)

#define 	SS(a,b)         scanf("%lld %lld",&a,&b)

#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)

#define		ss              ' '

#define     pii             pair<ll,ll>

#define		gcd(a,b)        __gcd(a,b)

#define		lcm(a,b)        (a*b)/gcd(a,b)

const double eps = 1e-8;







int main()

{



    ll n,k;

    cin>>n>>k;

    ll ar[n+10];

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

    {

        cin>>ar[i];

    }



    ll dp[n+10];



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

    {

        dp[i]=1e18;

    }

    dp[1]=0;

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

    {

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

        {

            if(i+j>n)

                continue;



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

        }

   



    }



    



     cout<<dp[n]<<nn;









}





/* Final check before submit :



1. array size or integer overflow,like uninitialised 0 index.



2. Think twice,code once.check all possible counter test case.



3. Be careful about corner case! n=1?k=1? something about 0?



4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?



5. if got WA than remember that you are missing something common.

   *** Be confident!!! who knows? may be your one step back to AC ***

4. minus mod ans=(ans-k+mod)%mod;



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

#include <cmath>



using namespace std;



int main(){

  long long int n;

  cin >> n;

  long long int ans = 1;

  

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

    ans = (ans * i) % (int)(pow(10,9) + 7);

  }

  

  cout << ans << endl;

  return 0;

}

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

#include <math.h>



int main(void){

  int n;

  scanf("%d", &n);

  long int ans = 1;

  

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

    ans = (ans * i) % (int)(pow(10, 9) + 7);

  }

  

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

  return 0;

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

using namespace std;



int main()

{

    int k,x;

    cin >>  k >> x;

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

        cout << i<<" ";

    }

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

        cout << i<<" ";

    }

    cout <<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.225934219411619x):
///d. one clue

#include <stdio.h>

#include <math.h>



int main()

{

    int k,x;

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



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

        printf("%d ",i);

    }

    return 0;

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

using namespace std;

typedef long long ll;



ll read(){

    ll x=0,f=1;char c=getchar();

    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}

    while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}

    return x*f;

}



int n;

int a[1000100];

pair<int,int> b[1000100];



void upd(int x,int y){

    int num1=b[x].first,num2=b[x].second,num3=b[y].first,num4=b[y].second;

    b[x].first=max(num1,num3);

    if(num1>num3) b[x].second=max(num2,num3);

    else b[x].second=max(num1,num4);

}



int main(){

    #ifdef LZT

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

    #endif

    n=read();

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

        a[i]=read();

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

        b[i].first=a[i],b[i].second=-1e9;

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

        //cout<<k<<endl;

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

            if((i&(1<<k))!=0) continue;

            upd(i|(1<<k),i);

            //cout<<(i|(1<<k))<<' '<<i<<endl;

        }

    }/*

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

        upd(i+1,i);

    }*/

    int lastans=0;

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

        lastans=max(lastans,b[i].first+b[i].second);

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

    }

    return 0;

}



/*

2

1 2 3 1

*/

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

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<vector>

#include<ctime>

#include<map>

#include<bitset>

#include<set>

#define LL long long

#define mp(x,y) make_pair(x,y)

#define pll pair<long long,long long>

#define pii pair<int,int>

using namespace std;

inline int read()

{

	int f=1,x=0;char ch=getchar();

	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}

	return x*f;

}

int stack[20];

inline void write(LL x)

{

	if(x<0){putchar('-');x=-x;}

    if(!x){putchar('0');return;}

    int top=0;

    while(x)stack[++top]=x%10,x/=10;

    while(top)putchar(stack[top--]+'0');

}

inline void pr1(int x){write(x);putchar(' ');}

inline void pr2(LL x){write(x);putchar('\n');}



const int MAX_N=20;

int bin[MAX_N];

#define pr pair<int,int>

#define FR first

#define SE second

#define MP make_pair

int a[1<<MAX_N];pr b[1<<MAX_N];

int gmax(int x,int y){return a[x]>a[y]?x:y;}

pr merge(pr x,pr y)

{

	if(a[x.FR]>a[y.FR]) return MP(x.FR,gmax(x.SE,y.FR));

	else return MP(y.FR,gmax(x.FR,y.SE));

}

void fwt(int n)

{

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

		for(int j=bin[n]-1;j>=0;j--) if(j&bin[i])

				b[j]=merge(b[j],b[j^bin[i]]);

}

int main()

{

	bin[0]=1;for(int i=1;i<MAX_N;i++) bin[i]=bin[i-1]<<1;

	

	int n;scanf("%d",&n);a[bin[n]]=0;

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

	fwt(n);

	int lst=0;

	for(int i=1;i<bin[n];i++)

	{

		lst=max(a[b[i].FR]+a[b[i].SE],lst);

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

	}

}

/*

4

75 26 45 72 81 47 97 97 2 2 25 82 84 17 56 32

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

using namespace std;

typedef long long ll;

typedef pair<int,int> pii;

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

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

#define read(x) scanf("%d",&x)

#define read2(x,y) scanf("%d%d",&x,&y)

#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define readll(x) scanf("%lld",&x)

#define mst(a,b) memset(a,b,sizeof(a))

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

#define pb push_back

#define lowbit(x) x&-x

#define lc rt<<1

#define rc rt<<1|1

#define ls lc,l,m

#define rs rc,m+1,r

#define dbg(x) cout<<' '<<#x<<" = "<<x<<endl;

#define dbg2(x,y) cout<<' '<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<endl;

#define dbg3(x,y,z) cout<<' '<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<endl;

const int INF =0x3f3f3f3f;

const int mod = 1e9+7;

const double eps=1e-8;

const int N = 2e5+5;

int dir[4][2]={0,1,0,-1,1,0,-1,0};

int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

ll dp[N];

int h[N];

int main(){

//	freopen("BZW.txt","r",stdin);

	//freopen("BZW.txt","r",stdin);

	//freopen("BZW.txt","r",stdin);

	//freopen("BZW.txt","r",stdin);

	int n,k;

	read2(n,k);

	fe(i,1,n)read(h[i]);

	mst(dp,0x3f);

    dp[1] = 0;

    fe(i,1,n){

		fe(j,1,k){

			if(i-j<1)break;

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

		}

    }

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









	return 0;

}


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

using namespace std;

typedef long long int ll;

const int MAX=1e5+10;

int N,k,A[MAX],dp[MAX];

int solve(int idx)

{

    if(idx==N)return 0;

    if(idx>N)return 1e9;

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

    int res=1e9;

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

        res = min(res,solve(idx+i)+abs(A[idx+i]-A[idx]));

    }

    return dp[idx]=res;

}

int  main ()

{

    memset(dp,-1,sizeof dp);

    cin >> N >> k;

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

        cin >> A[i];

    }

    cout<<solve(1)<<endl;

    return 0;

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

using namespace std;

const int N = 1e5 + 1;

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

int calc(int i){

    if(i == n - 1)

        return 0;

    if(i >= n)

        return 1e9 + 10;

    int &ret = dp[i];

    if(ret != -1)return ret;

    ret = 1e9 + 10;

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

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

    return ret;

}

int main(){

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

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

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

    }

    memset(dp , -1 , sizeof dp);

    cout<<calc(0);

    return 0;

}

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

using namespace std;

const int N = 1e5 + 1;

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

int main(){

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

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

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

    }

    dp[0] = 0;

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

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

        dp[i] = 1e9 + 10;

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

            if(i >= j)

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

    }

    cout<<dp[n - 1];

    return 0;

}