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

#define INF INT_MAX

#define MINF INT_MIN

#define ll long long

#define PB push_back 

#define PF push_front

#define P_F pop_front

#define P_B pop_back

#define F front

#define B back

#define MP make_pair

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

#define forit(i, s) for(__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)

#define foritr(i, s) for(__typeof ((s).rend ()) i = (s).rbegin (); i != (s).rend (); ++i)

 

using namespace std;



int datos = 100000;

vector<int> all(datos+1);



int main() {

  int n, k, aux, peNe;

  cin >> n>> k; 

  vector<int> peso;

  vector< map<int, int> > grafo(n);

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

    cin>>aux;

    peso.PB(aux);

  }



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

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

      peNe = abs(peso[i]-peso[j]);

      grafo[i][j] = peNe;

    }

  }



  int nodo;

  deque<int> dq;

  vector<int> seen(n, INF);

  dq.PB(0);

  seen[0] = 0;



  while(!dq.empty()){

    nodo = dq.F();

    dq.P_F();

    

    if(nodo != n-1){

      forit(x, grafo[nodo]){

        if(seen[x->first] == INF){

          seen[x->first] = x->second + seen[nodo];

          dq.PB(x->first);

        }else

          seen[x->first]= min(seen[x->first], seen[nodo] + x->second);

      }

    }

  }

  

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



  return 0;

}

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

using namespace std;

#define MAXN 100000

#define INF 2000000000



int h[MAXN];

int dp[MAXN];

int n,k;



int main() {

	int i,j;

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

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

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

	}

	dp[n-1]=0;

	dp[n-2]=abs(h[n-1]-h[n-2]);

	for (i=n-3; i>=0; i--) {

		dp[i]=INF;

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

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

		}

	}

	

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

	return 0;

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

#define ll long long

#define vl vector<ll int>

#define vs vector<string>

#define v vector<int>

#define vd vector<double>

#define mi map<int,int>

#define mc map<char,int>

//ios_base::sync_with_stdio(false);cin.tie(NULL);



using namespace std;



int main(){

	ios_base::sync_with_stdio(false);cin.tie(NULL);

	int k,x;

	cin>>k >>x;

	v A;

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

		A.push_back(x-i);

		}

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

			A.push_back(x+i);

			}

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

			for(auto e:A)cout<<e <<" ";

			cout<<"\n";

			

}


// Faster C++ solution for the same problem (measured speedup: 5.346726234446721x):
////sfef

#include<stdio.h>

int main(){



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

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

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

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

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

if(k==1)

{

    printf("%d",x);

}

else{

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

    {

        printf("%d ",i);

    }

    printf("%d",r);

}



return 0;

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

using namespace std;

typedef long long ll;



const int mxN = 17;

int N, a[mxN][mxN];

ll scores[1 << mxN], dp[1 << mxN];

vector<int> v;



void rec(int idx, int mask, int grp, ll score_now)

{

	if (idx == (int)v.size())

	{

		dp[mask] = max(dp[mask], score_now + scores[grp]);

		return;

	}

	rec(idx + 1, mask, grp, score_now);

	rec(idx + 1, mask ^ (1 << v[idx]), grp ^ (1 << v[idx]), score_now);

}



int main()

{

	ios_base::sync_with_stdio(false);



	cin >> N;

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

	{

		for (int j = 0; j < N; j++)

			cin >> a[i][j];

	}

	for (int mask = 0; mask < (1 << N); mask++)

	{

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

		{

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

			{

				if ((mask & (1 << i)) && (mask & (1 << j)))

					scores[mask] += a[i][j];

			}

		}

	}

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

	dp[0] = 0;

	for (int mask = 0; mask < (1 << N); mask++)

	{

		v.clear();

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

		{

			if (!(mask & (1 << i)))

				v.push_back(i);

		}

		rec(0, mask, 0, dp[mask]);

	}

	cout << dp[(1 << N) - 1];



	return 0;

}

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

using namespace std;

typedef long long ll;



const int mxN = 17;

int N, a[mxN][mxN];

ll dp[1 << mxN], scores[1 << mxN];

vector<int> rem;



void rec(int idx, int mask, ll score, int grp) {

	if (idx == (int) rem.size()) {

		dp[mask] = max(dp[mask], score + scores[grp]);

		return;

	}

	rec(idx + 1, mask, score, grp);

	rec(idx + 1, mask ^ (1 << rem[idx]), score, grp ^ (1 << rem[idx]));

}



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	

	cin >> N;

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

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

			cin >> a[i][j];

		}

	}

	for (int mask = 0; mask < (1 << N); mask++) {

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

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

				if ((mask & (1 << i)) && (mask & (1 << j))) {

					scores[mask] += a[i][j];

				}

			}

		}

	}

	for (int mask = 0; mask < (1 << N); mask++) {

		rem.clear();

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

			if (!(mask & (1 << i))) {

				rem.push_back(i);

			}

		}

		rec(0, mask, dp[mask], 0);

	}

	cout << dp[(1 << N) - 1];

	

	return 0;

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

using namespace std;



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



using ll = long long;



constexpr int MAX_N = 1e5;

constexpr int MAX_K = 1e2;

constexpr ll INF = 1LL << 60;



int h[MAX_N];

ll dp[MAX_N+MAX_K];



int main() {

  int N, K;

  cin >> N >> K;

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

    cin >> h[i];



  fill_n(dp, MAX_N+MAX_K, INF);

  dp[0] = 0;

  for (int i{}; i < N-1; ++i) {

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

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

    }

  }



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

}


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

using namespace std;



template<typename T>

inline bool chmin(T &a, T b) {

  if (a > b) {

    a = b;

    return true;

  }

  return false;

}

template<typename T>

inline bool chmax(T &a, T b) {

  if (a < b) {

    a = b;

    return true;

  }

  return false;

}



constexpr int MAX_N = 1e5 + 9;

constexpr int MAX_K = 1e2;

constexpr int INF = 1e9 + 9;



int N, K;

int h[MAX_N];

int dp[MAX_N + MAX_K];



int main() {

  fill_n(dp, MAX_N + MAX_K, INF);

  cin >> N >> K;

  for (int i{}; i < N; ++i) cin >> h[i];



  dp[0] = 0;

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

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

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

    }

  }



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

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

using namespace std;



const int N=1e5+30;

typedef long long ll;

int n,k,arr[N];

int dp[N];

ll solve(int i){

    if(i>=n)return 1e15;

    if(i==n-1){

        return 0;

    }



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

    ll mn=1e18;

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

        ll path1=abs(arr[i]-arr[i+j])+solve(i+j);

        mn=min(path1,mn);

    }

    return dp[i]= mn;

}

int main()

{

    memset(dp,-1,sizeof dp);

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

    for(int i=0;i<n;i++)scanf("%d",arr+i);

    cout<<solve(0)<<endl;

}




// Faster C++ solution for the same problem (measured speedup: 1.376364224044151x):
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>

#include<functional>

#include <bitset>

#include<algorithm>

#include<fstream>

#include<string>

#include <cstring>

#include<stdio.h>

#include<iomanip>

#include<sstream>

#include<cmath>

#include<vector>

#include<assert.h>

#include<queue>

#include<deque>

#include<stack>

#include<set>

#include<map>

// never lose hope ..

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

#define eps 1e-8

using namespace std;

double const  PI = 3.141592653;

const int OO = 1000000000 + 9;



void fast() {

	ios_base::sync_with_stdio(0);

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

}





int main()

{

	fast();



	int n, k;

	cin >> n >> k;

	vector<int>v(n + 1, 0), dp(n + 1, OO);

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

		cin >> v[i];

	}

	dp[1] = 0;

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

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

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

		}

	}

	cout << dp[n];





	return 0;

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

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

#define ii          pair<int,int>

#define F           first

#define S           second

#define pb          push_back

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

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

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

#define forr(i,a)   for(int i = a; i >= 0; i--)

#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 

#define w(t)        while(t--)

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

#define cls(a,car)  memset(a,car,sizeof (a))

#define db(x)       cerr << #x << " is " << x << '\n'

#define FL          freopen("in", "r", stdin),freopen("out", "w", stdout);

#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

#define angle(x)    double(x * acos(-1) / 180.0)

using namespace std;

typedef long long   ll;

typedef vector<int> vi;

typedef vector<ii>  vii;

const int N = 1 * 1e5 + 5;

const ll mod = 1e9 + 7;

const double E = 1e-9;

//int dx[] = {1, 0}, dy[] = {0, 1};

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

//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};

// fflush(stdout)

// cout << flush

// a + b = a ^ b + 2 * (a & b)

int n, k;

int v[N];

int dp[N];

int f(int i){

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

    int &ans = dp[i];

    if(ans != -1)return ans;

    ans = 1e9;

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

        if(i + j < n)

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

    }

    return ans;

}

int main(){

    //FL;

    FIN;

    cin >> n >> k;

    fore(i, 0, n)cin >> v[i];

    cls(dp, -1);

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

    EjecuteTime;

    return 0;

}       

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

#define si(a) scanf("%d", &a)

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

#define N_MAX 100005

using namespace std;

typedef long long ll;

typedef pair<int,int> pi;

typedef vector<int> vi;

int n,k;

vi v;

vi dp;

void leer(){

    si(n); 

    si(k);//B

    //k=2; //A

    v.assign(n+1,0);

    dp.assign(n+1,INT_MAX);

    fore(i,1,n+1)

        si(v[i]);

    int x;

    x = v[1];

    if(k>n)

        k = n;

    fore(i,1,k+1)

        dp[i] = abs(x-v[i]);

    fore(i,k+1,n+1){

        fore(j,1,k+1){

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

        }

    }

}

void solve(){

	leer();

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

}

int main(){

	solve();

	return 0;

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

#include <cmath>

#include <cstring>



using namespace std;



int pedras[100100];  ///Inicializo o vetor das pedras;

long long dp[100100]; ///Guardo os valores da funcao frog nesse vetor dp;



int n,k;



///Aqui comeca a funcão do frog2 top-down recursiva



int frog2(int i,int j){



    if(dp[i] != -1){

        return dp[i];

    }



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

    

    int menor = 1000000000;



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

        if(i+x <= j){  

            long long cost = (frog2(i+x,j)+ abs(pedras[i]-pedras[i+x]));

  

            if(cost < menor){ ///Acho o menor custo dentre as tentativas k;

                menor = cost;

            }



        }

    }



    return dp[i] = menor;

}

////////////////////////////////////////////////////////



int main(){



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



    cin >>n>>k;



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

        cin >> pedras[i];

    }



    cout<<frog2(0,n-1)<<endl;

}

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

using namespace std;



typedef long long ll;

typedef pair<int, int> ii;

typedef vector<int> vi;

typedef vector<ii> vii;

typedef vector<vi> vvi;



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

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

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

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

#define len(x) (x).size()

#define pb push_back

#define eb emplace_back

#define f first

#define s second



const double eps = 1e-9;

const double pi = acos(-1.0);

const int inf = 1e9 + 7;

const int maxn = 1e5+5;



int n, k;

int h[maxn];

bool seen[maxn];

int dp[maxn];



int solve(int idx) {

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

    if (seen[idx]) return dp[idx];

    seen[idx] = true;

    int ans = inf;

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

        if (idx + i >= n) break;

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

    }

    return dp[idx] = ans;

}



int main() {

    fastIO();

    cin >> n >> k;

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

    

    for (int idx = n-2; idx >= 0; --idx) {

        int &ans = dp[idx];

        ans = inf;

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

            if (i + idx >= n) break;

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

        }

    }



    cout << dp[0] << "\n";

    return 0;

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

using namespace std;



int a[100001];



int minCost(int arr[], int& n, int k, int i, int sum){

    if(i==n-1){

        return sum;

    }

    int x = INT_MAX, temp = sum;

    sum = 0;

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

        sum += abs(arr[i+j]-arr[i]);

        if(a[i+j]!=-1) x = min(x, sum + a[i+j]);

        else x = min(x, minCost(arr, n, k, i+j, sum));

        sum -= abs(arr[i+j]-arr[i]);

    }

    // if(i+k>n-1) x = min(x, minCost(arr, n, k, n, sum));

    a[i] = x;

    return temp + a[i];

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    int n, k;

    cin >> n >> k;

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

    int m = 0;

    int arr[n];

    

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

        cin >> arr[i] ;

    }

    

    m = minCost(arr, n, k, 0, m);

    

    cout << m;

    

    return 0;

}

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

#define si(a) scanf("%d", &a)

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

#define N_MAX 100005

using namespace std;

typedef long long ll;

typedef pair<int,int> pi;

typedef vector<int> vi;

int n,k;

vi v;

vi dp;

void leer(){

    si(n); 

    si(k);//B

    //k=2; //A

    v.assign(n+1,0);

    dp.assign(n+1,INT_MAX);

    fore(i,1,n+1)

        si(v[i]);

    int x;

    x = v[1];

    if(k>n)

        k = n;

    fore(i,1,k+1)

        dp[i] = abs(x-v[i]);

    fore(i,k+1,n+1){

        fore(j,1,k+1){

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

        }

    }

}

void solve(){

	leer();

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

}

int main(){

	solve();

	return 0;

}
// Slower C++ solution:
/*

  Vivek Rathi

  CSE 2nd Year

  MNNIT

*/

#include<bits/stdc++.h>

using namespace std;

#define M 1000000007

#define ll long long int

#define pb push_back

#define pf push_front

#define pob pop_back

#define pof pop_front

#define debug1(x) cout<<#x<<" "<<x<<endl;

#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;

#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;

#define present(c,x) ((c).find(x) != (c).end())

#define null NULL

#define mp make_pair

#define fi first

#define se second

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

#define inf 1e17

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

ll n,h[100001],k;

ll dp[100001];

ll solve(ll i)

{

	if(i==n-1)

	{

		return 0;

	}

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

	vector<ll> v;

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

	{

		v.pb(abs(h[j]-h[i])+solve(j));

	}

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

	return dp[i]=v[0];

}

int main()

{

	boost

	cin>>n>>k;

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

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

	cout<<solve(0)<<endl;

	return 0;

}

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

  Vivek Rathi

  CSE 2nd Year

  MNNIT

*/

#include<bits/stdc++.h>

using namespace std;

#define M 1000000007

#define ll long long int

#define pb push_back

#define pf push_front

#define pob pop_back

#define pof pop_front

#define debug1(x) cout<<#x<<" "<<x<<endl;

#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;

#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;

#define present(c,x) ((c).find(x) != (c).end())

#define null NULL

#define mp make_pair

#define fi first

#define se second

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

#define inf 1e17

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

int main()

{

	boost

	ll n,k;

	cin>>n>>k;

	ll h[n];

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

	ll dp[n];

	for(ll i=0;i<n;i++) dp[i]=inf;

	dp[n-1]=0;

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

	{

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

		{

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

		}

	}

	cout<<dp[0]<<endl;

	return 0;

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



#define ok printf("ok\n");









long min(long a, long b){

    if(a>b)

        return b;

    else

        return a;

}



long abs(long a){

    if(a>=0)

        return a;

    else

        return 0-a;

}

long h[110000];

long dp[110000];



int main(){

    long a , b;

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



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

        scanf("%ld", h+i);

    }



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

        dp[i]=2147483647;

    }

    dp[0]=0;



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

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

            if(i+j<a)

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

        }

    }



    printf("%ld\n", dp[a-1]);



    return 0;





}


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

#include <cstring>



using namespace std;



const int maxn = 1e5+5;

int n,K;

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

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

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

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

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

	}

	f[0] = f[1] = 0;

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

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

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

		}

	}

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

	return 0;

}
// Slower C++ solution:
/**

 *  Author1: low-equipped w_udixixi

 *  Author2: Sher丶lock

 *  Date :2019-08-20

 **/

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<iostream>

#include<string>

#include<vector>

#include<stack>

#include<bitset>

#include<cstdlib>

#include<cmath>

#include<set>

#include<list>

#include<deque>

#include<queue>

#include<map>

#define ll long long

#define pb push_back

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

#define repp(x,a,b) for (int x=a;x<b;x++)

#define pi 3.14159265358979323846

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

#define lson rt<<1,l,mid

#define rson rt<<1|1,mid+1,r

using namespace std;

const int maxn=2e6+7;

const int INF=1e9;

const ll INFF=1e18;

int a[maxn];

int dp[maxn];

int n,k;

int main()

{

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

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

    rep(i,1,n)

        dp[i]=i==1?0:dp[i]=INF;

    rep(i,1,n)

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

            if (i+j<=n)

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

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

    cout<<dp[n]<<endl;

}


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

#include <algorithm>

#include <cmath>

using namespace std;



int h[(int)1e5], dp[(int)1e5], K, N;





int main()

{

	K = N = 0;

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

	{

		dp[j] = 1e9;

	}

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

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

	{

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

	}

	dp[1] = 0;

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

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

	{

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

		{

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

		}

	}

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

	return 0;	

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

using namespace std;

int main()

{

    int n;

    string s;

    cin>>n;

    cin>>s;

    int a=s.length();

    if(a>n)

    {

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

        {

            cout<<s[i];

        }

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

    }

    else

        cout<<s<<endl;

}

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

#include<cstdio>

#include<cstdlib>

#include<cctype>

#include<cmath>

#include<queue>

#include<cstring>

#include<map>

#include<stack>

#include<set>

#include<vector>

#include<algorithm>

#include<string>

typedef long long ll;

typedef unsigned long long LL;

using namespace std;

int n,h;

int main()

{

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

	int ans=0;

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

	{

		int x;

		scanf("%d",&x);

		if(x>=h)

			ans++;

	}

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

	//system("pause");

	return 0;

}


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



int main()

{

    int n,k,ans=0;

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

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

    {

        int x;

        scanf("%d",&x);

        if(x>=k)ans++;

    }

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

    return 0;

}