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

#include <math.h>

using namespace std;



int a,b,c,d,gede;

int main(){

cin>>a>>b;

d=0;

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

	cin>>c;

	if(c>=b){

		d++;

	}

}

cout<<d;

}

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

int main()

{

	int a,n,k,h[100000],cnt=0;

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

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

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

		if(h[a]>=k){

			cnt++;

		}

	}

	printf("%d",cnt);

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

#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <vector>

#include <string>

#include <climits>

#include <map>

#include <set>

#include <stack>

#include <queue>

#include <deque>

#include <stdio.h>

//#define int long long

using namespace std;

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

#define endl '\n'

#define OnlineJudgec

#define F first

#define S second

#define  precision(n)  cout << fixed << setprecision(n)

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

typedef long long ll;

typedef vector<int> vi;

void init()

{

    cin.tie(0);

    cin.sync_with_stdio(0);

    cout.tie(0);

    #ifdef OnlineJudge

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

    freopen("output.txt","w",stdout);

    #endif

}

ll S(ll x){ll s = 0;while(x){s += x % 10;x /= 10;}return s;} /// sum of digits.

ll powe(ll a , ll n){if(n == 1)return a;return a * powe(a ,n-1);}

ll com(int n,int m){ll z = 1;for(int i = 0; i < m;i++){z = z * ( n - i) / (i + 1) ;}return z;}

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

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

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

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

/// <<------------------------------------------------------------------------------>>

const int mx = 100009;

int n , k;

int arr[mx];

int dp[mx];

int solve(int idx)

{

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

    int &rst = dp[idx];

    if(~rst) return rst;

    int choice = 1e9 , ans = 1e9;

    for(int i = idx + 1,cnt = 0 ;cnt < k && i < n;i++,cnt++)

    {

        choice  = solve(i) + abs(arr[idx] - arr[i]);

        ans     = min(choice , ans);

    }

    return rst = ans;

}

/// <<------------------------------------------------------------------------------>>

int main()

{

    init();

    cin >> n >> k;

    loop(n) cin >> arr[i];

    clr(dp,-1);

    cout<<solve(0);

}


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

#include<algorithm>

using namespace std;



#define ll long long 



#define file_io 0



ll i,t,j;

ll n,k,h[100005],dp[100005];



int main(){

	if (file_io){

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

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

	}

	

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

	

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

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

	}

	

	dp[1]=0;

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

		dp[i]=2e9;

		for (t=max(1ll,i-k); t<i; ++t){

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

		}

	}

	

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

	

	return 0;

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

#include<ext/pb_ds/assoc_container.hpp>



using namespace std;

using namespace __gnu_pbds;

//#define int          long long int

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

#define mod      1000000007

#define MOD      998244353

#define mp       make_pair

#define pb       push_back

#define F        first

#define S        second

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

#define ii       pair<int,int>

#define endl     "\n"

#define que_max  priority_queue <int>

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



typedef tree < int ,  null_type ,  greater <int> ,  rb_tree_tag ,  tree_order_statistics_node_update > pbds;



int pw(int b, int p) { int r = 1; while (p > 0) { if (p & 1) r = r * b;

        p = p >> 1; b = b * b; } return r; }





int n,k;

vector <int> arr(1e5);

vector <int> dp(1e5 , -1);



int solve(int id)

{

    if(id == n-1)

        return 0;



    if(dp[id]!=-1)

    {

        return dp[id];

    }

    int ans = INT_MAX;



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

        if(id + i >= n) break;

        ans = min(ans, solve(id + i) + abs(arr[id + i] - arr[id]));

    }



        return dp[id] = ans;

}

int main()

{

    cin>>n>>k;



    arr.resize(n);

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

    {

        cin>>arr[i];

    }

    cout<<solve(0)<<endl;

}


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

#include<ext/pb_ds/assoc_container.hpp>



using namespace std;

using namespace __gnu_pbds;

#define ll 		 long long int

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

#define mod 	 1000000007

#define MOD      998244353

#define mp       make_pair

#define pb       push_back

#define F        first

#define S        second

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

#define ii       pair<int,int>

#define endl     "\n"

#define que_max  priority_queue <int>

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



typedef tree < int ,  null_type ,  greater <int> ,  rb_tree_tag ,  tree_order_statistics_node_update > pbds;



int pw(int b, int p) { int r = 1; while (p > 0) { if (p & 1) r = r * b;

        p = p >> 1; b = b * b; } return r; }





const int INF = 1e9+5;

int main()

{

	ll n , k;

	cin>>n>>k;

	vector <ll> v(n);

	for(auto &i : v)

		cin>>i;



	vector <ll> dp(n,INF);

	dp[0] = 0;



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

	{

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

		{

			if(j<n)

			{

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

			}

		}

	}

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

	return 0;



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

#include <string>

using namespace std;

int main(){

	

	string s="", ent;

	cin>>ent;

	

	for(int i=0 ; i<ent.size() ; i++){

		if(ent[i]=='0')

		s += '0';

		else if(ent[i]=='1')

		s += '1'; 

		else if(s.size()>=1){

				s.erase(s.end()-1); 

			}

		

		

	}

	cout<<s<<"\n";

	

	return 0;

	}

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

#include <string.h>



void hekerman(char x[105]);



int main() {



    char x[105];



    scanf("%s", x);



    hekerman(x);



    return 0;

}



void hekerman(char x[105]) {



    int i, cnt = 0;

    char y[105];

    

    for(i = 0; i < strlen(x); i++) {

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

            cnt--;

        } else {

            y[cnt++] = x[i];

        }



        if(cnt < 0) {

            cnt = 0;

        }

    }



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

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

    }

    printf("\n");



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

using namespace std;

int n, k;

long long h[100005];

long long dp[100005];



long long solve(int i){

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

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



	dp[i] = 1e17;

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

		if(i+j <= n-1)

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

	return dp[i];

}



int main(){

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

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

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

	memset(dp, -1, sizeof dp);

	cout<<solve(0)<<endl;

	return 0;

}

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

#define x first

#define y second

#define pii pair<int,int>

#define ll long long

#define pll pair<ll,ll>

#define mp make_pair

#define pb push_back

#define pf push_front

#define popb pop_back

#define popf pop_front

#define xmod 100000007

using namespace std;



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

int main (){

	ios::sync_with_stdio(false);

	cin >> n >> m;

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

		cin >> a[i];

	}

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

		dp[i]=1e9;

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

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

		}

	}

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

    return 0;

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

using namespace std;

int main()

{

    int n,k;

    cin>>n>>k;

    int a[n],cal[n];

    for(int i=0;i<n;i++){cal[i]=1e9+7;cin>>a[i];}

    cal[0]=0;

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

    {

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

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

        }

    }

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

}




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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn=1e5 + 5;

int main()

{

	int dp[maxn];

	int h[maxn];

	int n,k;

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

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

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

		dp[1] = 0;

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

	    	dp[i]=1e9;

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

				if(i==j) break;

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

				}

	}

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

	}

	return 0;

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

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<algorithm>

#include<iostream>

using namespace std;

int main(){

	int A,B,C;

	cin>>A>>B>>C;

	int n;

	n=C%B;

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

		if((n+B*i)%A==0){

			printf("YES\n");

			return 0;

		}

	}

	printf("NO\n");

}


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

#include<cmath>



using namespace std;



int main()

{

	int a,b,c;

	int i,n,flag;

	long long sum;

	while(~scanf("%d %d %d",&a,&b,&c))

	{

		flag=0;

		n = c % b;

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

		{

			sum = (i + 1) * a;

			if(sum % b == n)

			{

				flag=1;

				break;

			}

		}

		if(flag==1)

			printf("YES\n");

		if(flag==0)

			printf("NO\n");

	}

	return 0;

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

using namespace std;

#define ll long long

#define inf 0x3f3f3f3f

const int N=1e5+10;

ll a[N],dp[N]={0};

int main()

{

	int n,k,i,j;

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

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

	{

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

	} 

	dp[1]=0;

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

	{

		dp[i]=inf;

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

		{

			if(i<=j) break;

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

		}

	}

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

	return 0;

}

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

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cstring>

#include <climits>

#include <cctype>

#include <map>

#include <list>

#include <stack>

#include <queue>

#include <vector>

#include <set>

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

using namespace std;

const int INF=0x3f3f3f3f;

const double PI=acos(-1.0);

const double eps=1e-12;

const int MAX=1000000+10;

const int EDGE=100000+10;//边的条数

typedef long long ll;

const int mod=1000000000+7;

ll mul2(ll a,ll b)

{

	ll ans=0;

	while(b)

	{

		if(b&1)

		{

			ans=(ans+a)%mod;

		}

		a=(a<<1)%mod;

		b>>=1;

	}

	return ans;

}

int main()

{

	ll n,s,i;

	while(~scanf("%lld",&n))

	{

		s=1;

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

		{

			s=mul2(s,i);

		}

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

	}

	return 0;

}

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

#include <algorithm>

using namespace std;



int main()

{

	int n,i;

	long long sum=1;

	scanf("%d",&n);

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

	{

		sum*=i;

		sum%=(1000000000+7);

	}

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

	return 0;

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



using namespace std;



typedef long long int ll;

#define inf 0x3f3f3f3f

#define endl '\n'

// #define case(i) "Case #" << i << ": "



int n, k;

vector<int> v;

int dp[100001];



int solve(int i) {

    if(i == 0) return 0;

    else {

        int mn = inf;

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

            if(dp[i-j] == -1) dp[i-j] = solve(i-j);

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

        }

        return mn;

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);



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



    cin >> n >> k;

    v.resize(n);



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



    cout << solve(n-1) << endl;

}

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



using namespace std;



typedef long long int ll;

#define inf 0x3f3f3f3f

#define endl '\n'

// #define case(i) "Case #" << i << ": "



int n, k;

vector<int> v;

int dp[100001];



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);



    cin >> n >> k;

    v.resize(n);



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



    dp[0] = 0;



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

        int mn = inf;

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

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

        }

        dp[i] = mn;

    }

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

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

using namespace std;

const int MAXN = 20;

struct number

{

	int f,s;

}a[1<<MAXN];

int n;

int main()

{

	scanf("%d", &n);

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

	{	

		int x;

		scanf("%d", &x);

		a[i].f=x; 

	}

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

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

			if(i>>j & 1) 

			{

				int x=i^(1<<j); 

				number ans;

				ans.f=max(a[i].f,a[x].f); 

				if(a[i].f>a[x].f) 

					ans.s=max(a[i].s,a[x].f); 

				else

					ans.s=max(a[i].f,a[x].s);

				a[i]=ans;

			}

	int ans=0;

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

	{

		ans=max(ans,a[i].f+a[i].s); 

		cout<<ans<<endl;

	}

	cout<<endl;

	return 0;

}

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


#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#define inf 20021225

#define ll long long

using namespace std;

int a[(1<<18)|1];

int mx[1<<18][2];

int ans[1<<18];

bool cmp(int x,int y){return a[x]<a[y];}

int main()

{

	int n;

	scanf("%d",&n);

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

	{

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

		mx[i][0] = i;

		mx[i][1] = (1<<n);

	}

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

	{

		int tmp[4]={0};

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

			if((i>>j)&1)

			{

				int _i = i^(1<<j);

				tmp[0] = mx[i][0]; tmp[1] = mx[i][1];

				tmp[2] = mx[_i][0]; tmp[3] = mx[_i][1];

				sort(tmp,tmp+4,cmp);

				mx[i][0] = tmp[3]; mx[i][1] = tmp[2]==tmp[3]?tmp[1]:tmp[2];

				//printf("%d %d\n",mx[i][0],mx[i][1]);

			}

		ans[i] = a[mx[i][0]] + a[mx[i][1]];

	}

	for(int i=1;i<(1<<n);i++)	ans[i] = max(ans[i],ans[i-1]);

	for(int i=1;i<(1<<n);i++)	printf("%d\n",ans[i]);

	return 0;

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

using namespace         std;

#define                 int long long

#define                 pb push_back

#define                 mp make_pair

#define st(arr,a)       memset(arr,a,sizeof arr)

#define                 nl cout<<endl

#define                 real signed

#define                 endl '\n'              

#define bitcount(x)     __builtin_popcountll(x)

const int MOD = 1000000007ll;

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

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



int arr[100000+50000],n,k;



int dp[150000];



int ans(int ind)

{

    if(ind==n)return 0;

    if(ind>n)return MOD*MOD;



    if(dp[ind]>-1)return dp[ind];





//    dp[ind]=min(abs(arr[ind]-arr[ind+1])+ans(ind+1),abs(arr[ind]-arr[ind+2])+ans(ind+2));

  dp[ind]=MOD*MOD;



  forn(i,ind+1,ind+k)

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

    return dp[ind];

}



signed main() 

{

	ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin>>n>>k;

    st(dp,-1);

    st(arr,MOD);

    forn(i,1,n)cin>>arr[i];



    cout<<ans(1);



    



     

     









     return 0;



}



//       g++ -g c2.cpp ; ./a.exe

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

using namespace         std;

#define                 int long long

#define                 pb push_back

#define                 mp make_pair

#define st(arr,a)       memset(arr,a,sizeof arr)

#define                 nl cout<<endl

#define                 real signed

#define                 endl '\n'              

#define bitcount(x)     __builtin_popcountll(x)

const int MOD = 1000000007ll;

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

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

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

#define pi pair<int,int>

#define X first

#define Y second

#define N 1014159

#define  vi vector<int>

#define  v  vector





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



int k;

void solve()

{

    cin>>n>>k;

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

    

    dp[1] = 0;

    

    forn(i,2,n)

    {

        dp[i] = MOD*MOD;

        forn(j,max(1LL,i-k),i-1)

        {

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

        }

    }

    cout<<dp[n];

    

}





signed main() 

{

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

    int t = 1;

    //cin>>t;

    while(t--)

    {

        solve();

    }







    return 0;



}



//       g++ -g c.cpp ; ./a.exe
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <string>

#include <cmath>

#include <cstring>

#include <iomanip>



using namespace std;

typedef long long ll;

const int maxn=1e5+1111;



int arr[maxn];

int dp[maxn];

int main(){

    int n,k;

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

    dp[0]=dp[1]=0;

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

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

        if(i>1) dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);

        for(int j=2;j<=k&&i-j>0;++j){

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

        }

    }

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6604272790098211x):
#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:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int N=2e5+5;

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

int main(){

	cin>>n>>k;

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

		cin>>a[i];

	dp[1]=0;

    dp[0]=0;

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

    	dp[i]=inf;

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

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

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

		cout<<dp[n];

	return 0;

} 

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

const int N = 1e5+1;



vector<int> v(N, 0);

vector<int> memo(N, -1);



int cost(int pos, int n, int x){

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

    else if (pos == n) return 0;

    else {

        int min_cost = INT_MAX;

        int curr_cost = 0;

        for (int k=pos+1; k<=min(n, pos+x); k++){

            curr_cost = abs(v[pos] - v[k]) + cost(k, n, x);

            min_cost = min(curr_cost, min_cost);

        }

        memo[pos] = min_cost;

        return memo[pos];

    }

}



int main(){

    int n, x; cin >> n >> x;

    

    for (int i = 1; i!=n+1; i++) cin >> v[i];

    cout << cost(1, n, x) << endl;



    return 0;

}

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

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

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

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

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

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

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

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

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

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



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



int main() {

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

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

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

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

      for1(j, k) {

         if(i - j < 1) break;

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

      }

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

   return 0;

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

#include<string>

using namespace std;



int main(){

    int k;

    string s;

    while(cin>>k){

        cin >> s;

        if(k<s.size()){

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

                cout << s[i];

            }

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

        }

        else

            cout << s << endl;

    }

    return 0;

}

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

#include<string.h>



int main()

{

	int n;

	scanf("%d",&n);

	char str[102];

	scanf("%s",&str);

	int len=strlen(str);

	if(len>n)

	{

		str[n]='.';

		str[n+1]='.';

		str[n+2]='.';

		str[n+3]='\0';

	}

	printf("%s",str);

	return 0;

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

using namespace std;



int main(){

	string s;

	cin>>s;

	string res=s;

	int p = 0;

	for (int i = 0; i < s.length(); i++){

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

			res[p++] = '0';

		}else if(s[i]=='1'){

			res[p++] = '1';

		}else{

			p += p>0?-1:0;

		}

	}

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

		cout<<res[i];

	}

	cout<<endl;

	return 0;

}

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

#include<stdlib.h>

#include<cstring>

int main()

{

	char s[100],ss[100];

	int i=0,j=0,a=0;

	int b[100];

	for(i = 0 ; i < 10 ; i++)b[i] = 1;

	scanf("%s",s);

	a = strlen(s);

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

	{

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

		{

			b[i]=0;

			for(j = i; j >=0 ;j--)

			{

				if(b[j]!=0)

				{

					b[j]=0;

					break;

				}

			}

		}

	}

	j = 0;

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

	{

		if(b[i]==1){

			ss[j]=s[i];

			j++;

		}

	}

	ss[j] = 0;

	printf("%s\n", ss);

	return 0;

}