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

using namespace std;



int main () {

  int n,k;

  cin>>n>>k;

  int a[n];

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

    cin>>a[i];

  }

  int dp[100101];

  long long p=100000000000;

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

    dp[i]=p;

  }

  dp[0]=0;

  if (n==2) {

    cout<<abs(a[1]-a[0])<<endl;

  }

  else {

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

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

        if (dp[i+j]>dp[i]+abs(a[i]-a[i+j])) {

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

        }

      }

    }

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

  }

}

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

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

using namespace std;

typedef long long ll;

int main() {

  int n,k;cin>>n>>k;

  

  vector<int> vec(n);

  

  rep(i,n) cin>>vec[i];

  

  vector<ll> dp(n+k+10);

  rep(i,n+k)dp[i]=100000000000;

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

  

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

    

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

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

#include<math.h>

#include<vector>

#include<algorithm>

#include<set>

#include<map>

#include<queue>

#include<climits>

#define fi first

#define se second

#define pb push_back

#define pii pair<int,int>

#define ll long long

#define pll pair<ll,ll>

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

#define repd(i,from,till) for(int i=from;i>=till;i--)

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

#define inf 1000000001

#define mod 1e9+7

#define inf1 1e18+1

#define pie 3.14159265358979323846

#define N 100005



using namespace std;



int n,k;

ll a[100002];

ll dp[100002];



int rec(int i){

	if(i+k>=n)return abs(a[i]-a[n-1]);

	if(dp[i]!=inf)return dp[i];

	rep(j,0,k){

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

	}

	return dp[i];

}



int solve(){

	rep(i,0,100002)dp[i]=inf;

    cin>>n>>k;

	rep(i,0,n)cin>>a[i];

	cout<<rec(0)<<endl;

	return 0;

}

int main(){

    waste;

    int t;

    //cin>>t;

    t=1;

    while(t--){

       	solve();

    }

}


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

#include<vector>

#include<algorithm>

#define inf 1000000009

using namespace std;

int main(){

	int n,k;

	cin>>n>>k;

	vector<int> dp(n,inf);

	vector<int> a(n);

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

		cin>>a[i];

	}

	dp[0]=0;

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

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

			if(i+j<n){

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

			}

		}

	}

	cout<<dp[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>

using namespace std;



#define INF 0x3f3f3f3f

#define ii pair<int,int >

#define MAXN 100005



int memo[MAXN], a[MAXN];

int n, k;



int f(int idx){



	if(idx == n) return 0;

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

	int ans = INF;

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

		if(idx+i <= n) ans = min(f(idx+i) + abs(a[idx] - a[idx+i]), ans);

	}

	return memo[idx] = ans;

}



int main(){



	while(cin >> n >> k){

		//cout << n << endl;

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

		for(int i=1; i<=n; i++) cin >> a[i];

		cout << f(1) << endl;

	}	



	return 0;

}

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

using namespace std;



#define ll long long

#define ii pair<int,int>

#define INF 1e9 + 7

#define vi vector<int>

#define add emplace_back





int main(){ios_base::sync_with_stdio(false);

    

    int n, k;

    cin >> n >> k;

    vi a(n);

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

    

    vi dp(n, INF);

    dp[0] = 0;

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

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

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

        }

    }

    

    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;





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

#include<cstring>

#include<cstdio>

using namespace std;

char s[105],ans[105];

int main()

{

	cin>>s;

	int len=strlen(s),tot=0;

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

	{

		if(s[i]=='0')	ans[++tot]='0';

		if(s[i]=='B'&&tot>0)	tot--;

		if(s[i]=='1')	ans[++tot]='1';

	}

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

	{

		cout<<ans[i];

	}

	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):
#include<bits/stdc++.h>

#define int long long int

#define pb push_back

#define inf 1e9

#define pp pop_back

#define pii pair<int,int>

#define vec vector<int>

#define mp make_pair

using namespace std;

int h[100001],dp[100001];

int ans(int n,int k)

{

  if(n==1)

    return 0;

  if(dp[n]!=-1)

    return dp[n];

  int res=inf;

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

    res=min(res,abs(h[n]-h[n-i])+ans(n-i,k));

  return dp[n]=res;

}

int32_t main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  cout.tie(NULL);

  int t=1;

  //cin>>t;

  while(t--)

  {

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

    int n,k;

    cin>>n>>k;

    int i;

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

        cin>>h[i];

    cout<<ans(n,k);

  }

}


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

#define int long long int

#define pb push_back

#define inf 1e9

#define pp pop_back

#define pii pair<int,int>

#define vec vector<int>

#define mp make_pair

using namespace std;

int32_t main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  cout.tie(NULL);

  int t=1;

  //cin>>t;

  while(t--)

  {

    int n,k;

    cin>>n>>k;

    int i,h[n+1];

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

        cin>>h[i];

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

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

    {

      int res=inf;

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

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

      dp[i]=res;

    }

    cout<<dp[n];

  }

}


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

}

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

}

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

using namespace std ;

 

int main()

{

  int n , k , a , answer ;

  cin >> n >> k ;

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

  {

    cin >> a ;

    if(a >= k)

      answer++ ;

  }

  cout << answer << endl ;

}
// Original C++ solution (slower):
#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;

	}

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



}

// 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):
#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;

}

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

}

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

}




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

}


// 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<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");

}


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

}

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

using ll = long long;

using namespace std;



int main() {

  int A,B,C;

  cin>>A>>B>>C;

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

    if ((A*i-C)%B==0&&(A*i-C)>=0){

      cout << "YES"<<endl;

      return 0;

    }

  }

  cout << "NO"<<endl;

  return 0;

}
// Original C++ solution (slower):
#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;

}

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

}

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

}


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

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

using namespace std;

using ll = long long;

using P = pair<ll, ll>;

const string ln = "\n";

constexpr int INF = 1001001001;

constexpr int MOD = 1000000007;



int main() {

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  int n;

  cin >> n;



  ll ans = 1;



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

    ans *= i % MOD;

    ans %= MOD;

  }



  cout << ans << ln;



  return 0;

}