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

#include <vector>

using namespace std;

int n;

int k;

vector<int> h(100000);

vector<int> cost(100000);



int ans(int n, int k)

{

    if (cost.at(n) != -1)

        return cost.at(n);

    cost.at(n) = ans(n - 1, k) + abs(h.at(n) - h.at(n - 1));



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

    {

        cost.at(n) = min(cost.at(n), ans(n - i, k) + abs(h.at(n) - h.at(n - i)));

    }



    return cost.at(n);

}



void init(int k)

{

    cost.at(0) = 0;

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

    {

        cost.at(i) = cost.at(i - 1) + abs(h.at(i) - h.at(i - 1));

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

        {

            cost.at(i) = min(cost.at(i), cost.at(i - j) + abs(h.at(i) - h.at(i - j)));

        }

    }

}



int main()

{

    cin >> n;

    cin >> k;

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

    {

        cin >> h.at(i);

        cost.at(i) = -1;

    }

    init(k);

    cout << ans(n - 1, k) << endl;

}

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

using namespace std;

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

typedef long long int ll;

int main()

{

    int n, k;

    cin >> n >> k;

    vector<int> h(n);

    vector<ll> dp(n + 200, 1e15);

    rep(i, n)

    {

        cin >> h[i];

    }

    dp[0] = 0;

    rep(i, n)

    {

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

        {

            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[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 <iostream>

#include<vector>

using namespace std;

int main() {

  int n, k,soma=0;

  cin>>n>>k;

  int V[n];

  vector<int>custo;

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

    cin>>V[i];

  }

custo.push_back(0);

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

  int min = custo[i-1] + abs(V[i-1]-V[i]);

  //cout<<"Esse e o minimo: "<<min<<endl;

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

    if(custo[j]+abs(V[j]-V[i])<min){

        min=custo[j]+abs(V[j]-V[i]);

        //cout<<"Esse e o novo minimo: "<<min<<endl;

      }

    }

    custo.push_back(min);

  }

  //for(int i=0;i<custo.size();i++)cout<<custo[i]<<" ";

  //cout<<endl;

  cout<<custo[custo.size()-1]<<endl;

}

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

#include <cstring>

#include <algorithm>

#include <cmath>

using namespace std;

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

int main()

{

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

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

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

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

	f[1]=0;

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

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

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

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

	return 0;

}

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

using namespace std;

#define _GLIBCXX_DEBUG

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

#define ll long long

#define P pair<ll,ll>

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



const ll mod = 1e9+7;

const ll INF = 1e18;

const double pi = acos(-1.0);



int main(void)

{

    ll n, m, cnt=0;

    cin >> n >> m;

    vector<ll> a(200000,0);

    rep(i,m){

        ll l, r;

        cin >> l >> r;

        a[--l]++;

        a[r]--;

    }

    rep(i,200000) a[i+1] += a[i];

    rep(i,200000) if(a[i]>=m) cnt++;

    cout << cnt << endl;

    return 0;

}

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

using namespace std;

#define _GLIBCXX_DEBUG

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

#define ll long long

#define P pair<ll,ll>

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



const ll mod = 1e9+7;

const ll INF = 1e18;

const double pi = acos(-1.0);



int main(void)

{

    ll n, m, l=0, r=INF;

    cin >> n >> m;

    vector<ll> a(200000,0);

    rep(i,m){

        ll a, b;

        cin >> a >> b;

        l = max(l, a);

        r = min(r, b);

    }

    cout << max(0LL, r-l+1) << endl;

    return 0;

}

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

using namespace std;



int main()

{

    int N, M;

    cin >> N >> M;

    int LMax = 1;

    int RMin = N;

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

    {

        int L;

        int R;

        cin >> L >> R;

        LMax = max(LMax, L);

        RMin = min(RMin, R);

    }

    if(RMin + 1 >= LMax)

        cout << RMin - LMax + 1 << endl;

    else

        cout << "0" << endl;

    return 0;

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

#include <vector>

#include <cmath>

#include <algorithm>

#include <iomanip>

#include <cstring>

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

using namespace std;

typedef long long ll;

const ll INF = 9223372036854775807/2;

const int MOD = 1000000007;

const int N_MAX = pow(10,5);



int main() {

  int N, K; cin >> N >> K;

  int h[N]; rep(i, N) cin >> h[i];

  ll dp[N_MAX]; fill_n(dp, N_MAX, INF); dp[0] = 0;

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

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

  }

  // rep(i, N) cout << dp[i] << endl;

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

  return 0;

}

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



using namespace std;

typedef long long ll;

typedef pair<ll, ll> p_ll;



template<class T>

void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }

#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)

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

#define rep(i,N) repr(i,0,N)

#define per(i,N) for (int i=(int)N-1; i>=0; i--)



const ll MOD = pow(10,9)+7;

const ll LLINF = pow(2,61)-1;

const int INF = pow(2,30)-1;



vector<ll> fac;

void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }

ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }

ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }

ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }





int main() {

  int N, K; cin >> N >> K;

  int h[N]; rep(i,N) cin >> h[i];

  int result[N] = {};

  repr(i,1,N) {

    result[i] = INF;

    repr(j,1,min(i+1,K+1)) result[i] = min(result[i], result[i-j]+abs(h[i]-h[i-j]));

  }

  // debug(result,result+N);

  cout << result[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 <stdio.h>

#include <math.h>

#include <string.h>

#include <algorithm>

#include <iostream>

#include <string>

#include <time.h>

#include <queue>

#include <string.h>

#define sf scanf

#define pf printf

#define lf double

#define ll long long

#define p123 printf("123\n");

#define pn printf("\n");

#define pk printf(" ");

#define p(n) printf("%d",n);

#define pln(n) printf("%d\n",n);

#define s(n) scanf("%d",&n);

#define ss(n) scanf("%s",n);

#define ps(n) printf("%s",n);

#define sld(n) scanf("%lld",&n);

#define pld(n) printf("%lld",n);

#define slf(n) scanf("%lf",&n);

#define plf(n) printf("%lf",n);

#define sc(n) scanf("%c",&n);

#define pc(n) printf("%c",n);

#define gc getchar();

#define re(n,a) memset(n,a,sizeof(n));

#define len(a) strlen(a)

#define LL long long

#define eps 1e-6

using namespace std;





int main(){

	char a[1000];

	char b[1000];

	ss(a);

	int count0 = 0;

	int lena = len(a);

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

		if(a[i] == '1' || a[i] == '0'){

			b[count0++] = a[i];

		}else if(a[i] == 'B'){

			if(count0 != 0){

				count0 --;

			} 

		}

		 

	}

	b[count0] = '\0';

	ps(b) pn

    return 0;

}

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

#include<string.h>



int main(){

	char str[15];

	scanf("%s",&str);

	char temp[15];

	int index=0,len=strlen(str);

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

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

			temp[index] = '0';

			//printf("index[%d] : %s\n",index,temp);

			index++;

		} 

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

			temp[index] = '1';

			//printf("index[%d] : %s\n",index,temp);

			index++;

		} 				//01B0 temp =     --0

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

			//printf("index[%d] : %s\n",index,temp);

			if(index != 0) index--;

		}

	}

	//printf("%d\n",index);

	temp[index]='\0';

	printf("%s\n",&temp);

	

	

	

	return 0;

}

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

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

#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

#define pb push_back



using ll = long long;

using namespace std;

using pint = pair<int,int>;

using pll = pair<ll,ll>;

const int INFint = 1e9;

const ll INFll = 1e18;

ll MOD=1e9+7;



ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数

ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数



// aのn乗をMODで割りながら計算する

ll modpow(ll a, ll n) {

  long long res = 1;

  while (n > 0) {

    if (n & 1) res = res * a % MOD;

    a = a * a % MOD;

    n >>= 1; // right shift

  }

  return res;

}



// MODを法としたaの逆元を計算する

ll modinv(ll a) {

  return modpow(a, MOD - 2);

}



int main(){

  string s;

  cin>>s;

  int N = int(s.size());

  string ans;

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

    //cout << ans << endl;

    if (s[i] == 'B'){

      if (int(ans.size()) != 0){

        ans = ans.substr(0,int(ans.size())-1);

      }

    }else{

      ans += s[i];

    }

  }

  cout << ans << endl;

  return 0;

}
// Original C++ solution (slower):
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

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

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

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

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

#define clr(v, d) memset(v, d, sizeof(v))

#define fi first

#define se second

#define pp push_back

#define pb pop_back

#define pi 3.141592654

#define MOD 1000000007 

#define cons1 1e12

#define cons2 1e6

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int, int> pa;

typedef unsigned long long int ull;

typedef double long dl;

const int N = 1e5+9,oo=1e9;

int n,k;

int v[N], ans[N];

int sol(int i) {

	if (ans[i] == -1) {

		if (i == n - 1)

			ans[i] = 0;

		else {

			int x =1+ min(k, n - i - 1);

			int mx = oo;

			while (--x)

				mx = min(mx, abs(v[i] - v[i + x])+sol(i + x));

			

			ans[i] = mx;

		}



	}

	return ans[i];



}

void solve() {

	clr(ans, -1);

	cin >> n >> k;

	rep(i, 0, n)

		cin >> v[i];

	cout << sol(0) << endl;

	

}

int main() {

	ios::sync_with_stdio(0);

	cin.tie(NULL);

	cout.tie(NULL);

	int t = 1;

	//cin >> t;

	while (t--)

		solve();



#ifndef ONLINE_JUDGE

	- system("pause");

#endif



}

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

 

using namespace std;

 

#define mp make_pair

#define fi first

#define se second

#define pb push_back

typedef long long ll ;

typedef long double ld ;

typedef pair<ll, ll> pairs;

 

 

ll h[100009] ;

ll v[100009] ;

 

int main()

{

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);

    cout.tie(NULL);

 

    ll n , k ; cin >> n >> k ;

    for ( ll i = 0 ; i < n ; i++ ) cin >> h[i] ;

    for ( ll i = 1 ; i < min( n , k ) ; i++ ) v[i] = abs( h[i] - h[0] ) ;

    for ( ll i = k ; i < n  ; i++ ){ v[i] = 1000000009 ;

        for ( ll j = i - k; j < i ; j++ ){

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

            //cout << x << " " << y << " " << v[x] <<  "\n\n" ;

        }

    }  cout << v[n-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 <bits/stdc++.h>

# define ll long long

# define fi first

# define se second



using namespace std ;



ll n, x, k;

ll ans[200001], vc[200001];



int main() {

    cin >> n >> k;

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

        cin >> vc[i] ;

    }

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

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

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

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

        }

    }

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

}


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

}








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

#include <cstdio>

#include <cmath>

#include <cstring>

#include <iostream>

#include <vector>

#include <map>

#include <set>

#include <queue>

#include <string>

#include <stack>

#include <fstream>

#include <iomanip>

#include <algorithm>

#include <functional>

//#include <unordered_set>

#define INF 2147483647

#define MAXN  1000100

#define PII pair<int, int>

#define mp(a,b) make_pair(a,b)

typedef long long ll;

typedef unsigned long long ull;

using namespace std;

const int maxn = 35;

ll a[MAXN];



int main()

{

	//ios::sync_with_stdio(false);

	cin.tie(0);

#ifdef local_debug

	ifstream inputs("input.txt");

	cin.rdbuf(inputs.rdbuf());

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

#endif

	int n, k;

	while (cin >> n >> k) {

		ll ans = 0;

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

			int sz = n / i;

			ans += sz * (i - k);

			int j = n % i;

			if (j - k + 1 > 0)

				ans += j - k + 1;

		}

		if (k == 0)

			ans -= n;

		cout << ans << endl;

	}

	return 0;

}

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

#include<iostream>

#include<cmath>

using namespace std;

const int MAXN = 100010;

const int INF = 0x3f3f3f3f;

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

int main()

{

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

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

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

	f[1] = 0;

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

	{

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

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

	}

		

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

	return 0;

}

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

}








// 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 arr[100005], memo[100005],k;



int dp(int n){

    if(n==0) return 0;

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

    int cost=1e9;

    for(int i=1; i<=k&&i<=n; ++i) cost=min(dp(n-i)+abs(arr[n]-arr[n-i]),cost);

    return memo[n]=cost;

}



int main(){

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(0);

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

    int n;

    cin>>n>>k;

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

    cout<<dp(n-1)<<"\n";

    //for(int i=0; i<n; ++i) cout<<memo[i]<<"\n";

    return 0;

}


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

using namespace std;



int arr[100100], dp[100100];



int main() {

  int n, k;

  cin >> n >> k;

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



  dp[0] = 0;

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



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

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

      if ( pos - step < 0 ) break;

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

    }

  }

  

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

  return 0;

}

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





}