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

#define int long long

#define ll long long

#define ld long double

#define mod ((ll)1e9+7)

#define maxx ((ll)1e6+5)

#define pb push_back

#define ins insert

#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

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

#define test ll t; cin>>t; while(t--)

ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}

ll expo(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}

/*int sv[1000000]={0};

ll fact[1000007]={0};

void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}

void sve() {sv[0]=1;sv[1]=1;for(int i=2;i*i<=maxx;i++){if(!sv[i]){for(int j=2*i;j<=maxx;j+=i)sv[j]=1;}}}//0 hai to prime

ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],mod-2)))%mod; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}

ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}*/

int a[3][100003];

using namespace std;

signed main()

{

    int n,k,i,j;

    cin >> n >> k;

    int a[n],d[n] = {0};

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

    	cin >> a[i];

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

    {

    	int p = 1e17;

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

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

    	d[i] = p;

    }

    cout << d[n-1] <<"\n";

    return 0;

}

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

#include <algorithm>

#include <vector>

using namespace std;

 

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

int main(){

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

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

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

	}

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

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

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

			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[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 "bits/stdc++.h"

#define ll long long

#define PI 3.1415926535897932384626433832795l

#define MAX_NUM 1000000000

using namespace std;

template <typename T> inline T __lcm(T a,T b)

{

    return (a*b)/__gcd(a,b);

}



ll h[1000000];

ll dp[1000000];

ll n,k;

ll fun(ll i)

{

    if(i>=n)

    {

        return MAX_NUM;

    }

    if(i==n-1)

    {

        return 0;

    }

    if(dp[i]!=-1)

    {

        return dp[i];

    }

    //return dp[i]=min(fabs(h[i]-h[i+1])+fun(i+1),fabs(h[i]-h[i+2])+fun(i+2));

    ll minimum=MAX_NUM;

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

    {

        ll temp=fabs(h[i]-h[i+j])+fun(i+j);

        minimum=min(minimum,temp);

    }

    return dp[i]=minimum;

}



int main()

{

    cin>>n>>k;

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

    {

        cin>>h[i];

    }

    memset(dp,-1,sizeof(dp[0])*1000000);

    ll ans=fun(0);

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

}


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

using namespace std;







int main() {

    ios_base::sync_with_stdio(false);



    long long int a,b,c,d,i,j,k,n,m;

    cin>>n>>k;

    long long int ar[n+1],dp[n+1];

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

        cin>>ar[i];

     dp[0]=0;

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

        dp[i]=INT_MAX;

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

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

    {

        //a=INT_MAX;

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

        {

           c=i+j;

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

           //cout<<i<<" "<<c<<" "<<dp[0]<<" "<<dp[c]<<"\n";

        }





    }

    cout<<dp[n-1]<<"\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 pb push_back

#define mp make_pair

#define fi first

#define se second

#define si size()

#define bk back()

#define popb pop_back()

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

#define endl "\n"

#define lb lower_bound

#define ub upper_bound

#define emp empty()

#define beg begin()

#define en end()

#define ump unordered_map

#define forl(i,a,n) for(int i=a;i<n;i++)

#define rfor(i,n,a) for(int i=n;i>=a;i--)

#define fore(i,a,n) for(int i=a;i<=n;i++)

#define len length()

#define N 200000 

int dp[N];

int func(int arr[],int i,int n,int k)

{

	if(i>=n-1) return dp[i]=0;

	if(dp[i]>=0) return dp[i];

	int t=1;

	int min=INT_MAX;

	while(t<=k )

	{

		int x=abs(arr[i+t]-arr[i])+func(arr,i+t,n,k);

		if(x<min)min=x;

		t++;

	}

	return dp[i]=min;

}

int main()

{

	int n,k;

	cin>>n>>k;

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

	int arr[n+k];

	forl(i,0,n) cin>>arr[i];

	forl(i,n,n+k) arr[i]=INT_MAX;

	cout<<func(arr,0,n,k)<<endl;

	

	

}

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

using namespace std;

#define ll long long

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define si size()

#define bk back()

#define popb pop_back()

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

#define endl "\n"

#define lb lower_bound

#define ub upper_bound

#define emp empty()

#define beg begin()

#define en end()

#define ump unordered_map

#define forl(i,a,n) for(int i=a;i<n;i++)

#define rfor(i,n,a) for(int i=n;i>=a;i--)

#define fore(i,a,n) for(int i=a;i<=n;i++)

#define len length()

#define N 200000

int main()

{

	int n,k;

	cin>>n>>k;

	int arr[n];

	forl(i,0,n) cin>>arr[i];

	int dp[n];

	dp[0]=0;

	forl(i,1,n) dp[i]=INT_MAX;

	forl(i,1,n)

	{

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

		{

			if(j>=0)

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

		}

	}

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

	

	

}

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

	string a;cin>>a;

	if(a.length()<=k)cout<<a<<endl;

	else{

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

		cout<<a[i];

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

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#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");

	}

}

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

using namespace std;

typedef long long ll;

const int mod = 1000000007;

const double PI = acos(-1);



int main()

{

	int k;

	string s;

	cin >> k >> s;

	if (s.size() <= k) cout << s << endl;

	else cout << s.substr(0, k) + "..." << endl;

}
// Original C++ solution (slower):
// 14/06/19 // 8:03 PM //



#include <iostream>

#include <cmath>

#include <cstring>



using  namespace std;



#define  MAXN 100010

#define INF 2000000000



int n, k;

int h[MAXN];



int memo[MAXN];



int funcao(int i){

    if(memo[i]>=0) return memo[i];



    if(i>=n) return memo[i] = 0;



    memo[i] = INF;



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

        if( (i+j)<=n )

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

        else

            break;

    }



    return memo[i];

}



int main(){



    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



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



    cin >> n >> k;



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

        cin >> h[i];



    cout << funcao(1) << "\n";



    return 0;

}


// Optimized solution to the same problem (faster):
// 14/06/19 // 8:03 PM //



#include <iostream>

#include <cmath>



using  namespace std;



#define  MAXN 100010

#define INF 2000000000



int n, k;

int h[MAXN];



int memo[MAXN];



int funcao(){





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



        memo[i] = INF;



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

            if(j>=1)

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

            else

                break;

        }

    }



    return memo[n];

}



int main(){



    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    cin >> n >> k;



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

        cin >> h[i];



    cout << funcao() << "\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;

//-------------------------------------------MACROS---------------------------------------------

#define 	TIEMPO_CORRIDA		cerr << "tiempo: "<<1.0*clock()/CLOCKS_PER_SEC <<" seg.\n";

#define 	FILES				freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);

#define 	FORIT(it,e)			for(it = e.begin() ; it != e.end() ; it++)

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

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

#define 	FORSW(i,a,b,sw)		for(i = a ; i < b && sw ; i++)

#define 	RFORSW(i,a,b,sw)	for(i = a ; i >= b && sw ; i--)

#define 	fast 				ios::sync_with_stdio(false),cin.tie(),cout.tie();

#define 	to_int(x) 			atoi(x.data())

#define 	to_long(x) 			atoll(x.data())

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

#define 	RALL(x) 			x.rbegin(),x.rend()

typedef 	long long 			ll;

typedef 	pair<int,int> 		pi;

typedef 	pair<ll,ll> 		pl;

const		int 				modN = 1e9+7;

const		double 				PI = 3.1415926535897932384626433832795028841;

//---------------------------------------------------------------------------------------------

const int tam = 6e5;

const int oo=1e9;

int ar[tam],memo[tam];

int n,k;



int f(int x){

	if (memo[x]!=-1) return memo[x];

	if(x == n-1) return memo[x]=0;

	int ans=oo, i;

	FOR(i,1,k+1)

		if(x+i<n)

			ans = min(ans,f(x+i) + abs(ar[x+i]-ar[x]));

	return memo[x]=ans;

}



int main(){

	int i;

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

		memset(memo,-1,sizeof memo);

		FOR(i,0,n) scanf("%d",&ar[i]);

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

	}

	return 0;

}

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

#define ll long long int

ll n,k;

using namespace std;

int main() {			

cin>>n>>k;

int arr[n];

int memo[n];

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

cin>>arr[i];

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

memo[i]=INT_MAX;

memo[0]=0;

//memo[1]=abs(arr[0]-arr[1]);//Queda rebundante. Sigue siendo 10000

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

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

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

cout << memo[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;



#define min3(a, b, c)           min((a), min((b), (c)))

#define max3(a, b, c)           max((a), max((b), (c)))

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

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

#define dist(x1,y1,x2,y2)       sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))

#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))

#define sqr(a)                  ((a)*(a))

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

#define fRead(x)                freopen(x,"r",stdin)

#define fWrite(x)               freopen (x,"w",stdout)

#define pb                      push_back

#define mk                      make_pair

#define ff                      first

#define ss                      second

#define lb                      lower_bound

#define ub                      upper_bound

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

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



int main()

{

    FASTIO



    int  n, m;

    cin >> n >> m;



    bool AC[100050];

    memset(AC, false, sizeof AC);



    map<int, int> WA;



    FOR (0, m)

    {

        int submission;

        string verdict;



        cin >> submission;

        cin >> verdict;



        if (verdict == "AC")

            AC[submission] = true;

        if (verdict == "WA")

        {

            if (!AC[submission])

                WA[submission]++;

        }

    }



    int ACCOUNT=0, WACOUNT =0;



    for (auto it: WA)

    {

        if (AC[it.first])

        {

            ACCOUNT++;

            WACOUNT += it.second;

            AC[it.first] = false;

        }

    }



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

        if (AC[i])

            ACCOUNT++;

    cout << ACCOUNT << " " << WACOUNT;



}




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

using namespace std;

int main()

{

   int x=0 ,y=0,m,n,i,j,k;

   cin >> n >> m;

   string s;

   map<int,int>mp,mp1;

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

   {

       cin >> k >>s;

       if(s == "AC" && mp1[k]==0)

        {

            x++;y+=mp[k];

            mp1[k]=1;

        }

       else

        mp[k]++;

   }

   cout<<x<<" "<<y<<endl;

}






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

#include <vector>

using namespace std;

int main ()

{

	int n, m, acc=0, pen=0; cin>>n>>m;

	bool test[n+1]={false};

	int arr[n+1]={0};

	int p[m];

	string s[m];

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

	{

		cin>>p[i];

		cin>>s[i];

		if (test [p[i]]==false && s[i]=="AC")

		{

			test[p[i]]=true;

			acc++;

			pen+=arr[p[i]];

		}

		if (test[p[i]]==false && s[i]=="WA")

		{

			arr[p[i]]++;

		}

	}

	cout<<acc<<endl<<pen<<endl;

	return 0;

}
// Original C++ solution (slower):


#include <iostream>



using namespace std;



int dict[500];

int f[500][500];



int n, m;



void solve(int a, int depth)

{

    if (depth == 3) return;



    dict[a] = 1;



    for(int i = 0; i < n; ++i) if (f[a][i] == 1) solve(i, depth + 1);

}



int main(void)

{

    while (cin >> n >> m, n && m) {

        dict[0] = 1;



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

            int a, b; cin >> a >> b;

            a--; b--;

            f[a][b] = f[b][a] = 1;

        }



        solve(0, 0);



        int ans = 0;



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

            if (dict[i]) ans++;

        }



        cout << ans << endl;



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

            dict[i] = 0;

            for(int j = 0; j < 500; ++j) f[i][j] = 0;

        }

    }

}

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

#include <cstring>



using namespace std;



int n, m;

int fr[501][501];

int s[501];



void f(int from, int depth)

{

	s[from] = 1;

	if (depth == 3) return;

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

		if (fr[from][i]) f(i, depth + 1);

	}

}





int main()

{

	while (scanf("%d %d", &n, &m), n || m) {

		for (int i = 1; i <= n; ++i) memset(fr[i], 0, sizeof(fr[i]));

		memset(s, 0, sizeof(s));

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

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

			fr[a][b] = fr[b][a] = 1;

		}

		f(1, 1);

		int cnt = 0;

		for (int i = 1; i <= n; ++i) if (s[i]) cnt++;

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

	}

}

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

using namespace std;



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



int n, m;

vector< vector< int > > adj;

vector< int > vis;



void dfs(int v, int d) {

	if (d == 3) return;

	vis[v] = 1;

	for (int u : adj[v]) dfs(u, d + 1);

}



int main() {

	while (cin >> n >> m, n) {	

		adj.assign(n, vector< int >());

		

		for_(i,0,m) {

			int a, b;

			cin >> a >> b;

			--a; --b;

			adj[a].push_back(b);

			adj[b].push_back(a);

		}

		

		vis.assign(n, 0);		

		dfs(0, 0);

		cout << accumulate(vis.begin(), vis.end(), int()) - 1 << endl;

	}

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

using namespace std;

typedef long long int ll;

int main()

{

    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    string s;

    int k;

    cin>>k;

    cin>>s;

    if(s.size()<=k)

        cout<<s<<endl;

    else

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

        cout<<s[i];

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



    return 0;

}


// Optimized solution to the same problem (faster):
#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");

	}

}

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

using namespace std;

typedef long long ll;

const int mod = 1000000007;

const double PI = acos(-1);



int main()

{

	int k;

	string s;

	cin >> k >> s;

	if (s.size() <= k) cout << s << endl;

	else cout << s.substr(0, k) + "..." << endl;

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

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <sstream>

#include <queue>

#include <deque>

#include <bitset>

#include <iterator>

#include <list>

#include <stack>

#include <map>

#include <set>

#include <functional>

#include <numeric>

#include <utility>



#include <cmath>

#include <iomanip>



using namespace std;



int main()

{

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n;

  cin >> n;

  int k;

  cin >> k;

  int h[n];

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

    int cur;

    cin >> cur;

    h[i] = cur;

  }

  int minCosts[n];

  minCosts[0] = 0;

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

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

    int cur = abs(h[i]-h[i-1])+minCosts[i-1];

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

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

    }

    minCosts[i] = cur;

  }

  cout << minCosts[n-1] << "\n";

  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;





}