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

using namespace std;

#define ll long long

vector<ll>v;

int main()

{

    ll a,b,ans,i,j,cur,tur,pos;

    cin>>a>>b;

    cur=a-1;

    tur=b+cur;

    pos=b-cur;

    for(i=pos;i<=b;i++){

        v.push_back(i);

    }

    for(i=b+1;i<=tur;i++)

        v.push_back(i);



    ll len=v.size();

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

        if(i==0)cout<<v[i];

        else cout<<" "<<v[i];

    }

}


// Optimized solution to the same problem (faster):
///d. one clue

#include <stdio.h>

#include <math.h>



int main()

{

    int k,x;

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



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

        printf("%d ",i);

    }

    return 0;

}

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

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

using namespace std;



int main(void) {

	int k, x;

	cin >> k >> x;

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

		if (i == x+k) cout << i << endl;

		else cout << i << " ";

	}

	return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;

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

const int nax = 1e5+103;

int n, k;

int dp[nax];

int a[nax];

int f(int i){

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

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

	int ans = abs(a[i]-a[i+1])+f(i+1);

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

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

	}

	return dp[i]=ans;

}

int main(){

	cin>>n>>k;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}

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

using namespace std;





#define x_ real()

#define y_ imag()

#define cross(a, b) (conj(a)*(b)).imag()

#define dot(a, b) (conj(a)*(b)).real()

#define PI acos(-1)

#define F first

#define S second

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

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

typedef long double ld;

typedef long long ll;

typedef unsigned long long ull;

typedef complex<ld> point;

typedef tuple<int, int, int> line;

typedef vector<point> polygon;

typedef pair<double, double> pd;

pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };

ll mod = 1e9 + 7;

ld eps = 1e-6;









int main() {

	fastIO;

	int n, k;

	cin >> n >> k;

	int dp[n+1], arr[n+1];

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

		cin >> arr[i];

	}

	dp[0] = 0;

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

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

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

			if (i - j < 0)

				continue;

			dp[i] = min(dp[i], abs(arr[i-j]-arr[i]) + dp[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;



int main() {

  int s; cin>>s;

  vector<int> A(pow(10,6)+1);

  A[0]=s;

  int i=0;

  while (true) 

  {

    if (A[i]%2 == 0) 

    {

      A[i+1] = A[i]/2;

    }

    else 

    {

      A[i+1] = 3*A[i]+1;

    }

    i++;



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

    {

      if (A[j] == A[i]) {

        cout << i+1 << endl;

        return 0;

      }

    }

  }

}

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

using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



const ll INF=(1LL<<60);

const int mod=1000000007;



int main(){

    int s; cin >> s;

    set<int> se;

    se.insert(s);

    int pre=s;

    int now;

    int id=1;



    while(true){

        id++;

        if(pre%2==0) now=pre/2;

        else now=3*pre+1;



        if(se.find(now)!=se.end()){

            cout << id << endl;

            return 0;

        }



        se.insert(now);

        pre=now;



    }

}

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



int main()

{

    int s;

    std::cin >> s;

    int list[1000000];

    int index = 0;

    int a_i;

    int a_pre = s;

    list[0] = s;

    index = index + 1;

    bool search_flag = false;

    while( true){

        if ( a_pre % 2 == 0){

            a_i = a_pre / 2;

        } else {

            a_i = 3 * a_pre + 1;

        }

        list[index] = a_i;

        index = index + 1;

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

            if ( list[i] == a_i) {

                search_flag = true;

                break;

            }

        }

        if (search_flag==true){

            break;

        } 

        a_pre = a_i;



    }

    std::cout << index << std::endl;

    return 0;

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

using namespace std;



int n, k;

vector<int> arr(100004, 0);

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



int main() {



	cin >> n >> k;

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



	dp[n-1] = 0;

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



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

	{

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

		{

			if(i+j>=n) break;

			int temp = abs(arr[i]-arr[i+j]) + dp[i+j];

			dp[i] = (dp[i]==-1) ? temp : min(dp[i], temp);

		}

	}



	cout << dp[0] << endl;



	return 0;

}

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

using namespace std;



int main() {

    int n, k;

    cin >> n >> k;



    vector<int> heights(n, 0);

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



    vector<int> dp(n, 0);

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

    {

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

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

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

    }

    

    cout << dp[n-1] << '\n';



    return 0;

}

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

#include <algorithm>

#include <cstring>

#include <cstdio>

#include <cmath>

#include <cstdlib>



using namespace std;

int gcd(int a, int b)

{

    return b?gcd(b, a%b):a;

}

const int mod = 1e9+7;

int main()

{

    int n;

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

    {

        long long ans = 1;

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

            ans *= i, ans %= mod;

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

    }

    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;

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

using namespace std;



int main() {

    int n,K;    cin>>n>>K;

    int a[n];

    long long dp[n];

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

    

    dp[0]=0;

    

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

        long long add=1e9;

        for(int k=1;k<=K;k++)if(i-k>=0){

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

        }

        dp[i]= add; 

        

    }

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

    return 0;

}

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

#include<algorithm>



int main(){

  int s,k;

  long long st[100001],p[100001];

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

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = 1000000001;

  }

  for(int i=3;i<=s;i++){

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

      if(i-j>=1){

	long long tmp;

	tmp = (st[i]-st[i-j] < 0) ? st[i-j]-st[i] : st[i]-st[i-j];

	if(p[i] > p[i-j]+tmp){

	  p[i] = p[i-j]+tmp;

	}

	if(tmp == 0) break;

      }else{

	break;

      }

    }

  }

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

  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>



using namespace std;



int main()

{





    int n,m,newval;

    cin >> n>>m;

    newval=m;

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

        newval--;

    }

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

      cout << newval<<" ";

      newval++;

    }

    cout << m <<" ";

    newval=m;

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

        newval++;

        cout << newval<<" ";

    }



    return 0;

}


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

}


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

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

using namespace std;



int main(void) {

	int k, x;

	cin >> k >> x;

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

		if (i == x+k) cout << i << endl;

		else cout << i << " ";

	}

	return 0;

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

#include <iostream>

#include <math.h>

#include <stdio.h>



#define arrayLength(array) (size_t)((sizeof array) / (sizeof array[0]))



int main() {

  int n = 0, m = 0, x = 0, y = 0, z = 0, a = 0, b = 0;



  char s[255];

  char t;



  //   scanf(" %d %d %d %d", &n, &m, &x, &y);

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

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

    scanf(" %d", &a);

    if (a >= m)

      x += 1;

  }

  printf("%d", x);



  return 0;

}


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

int main(){

	int i,m,k,t=0,cnt=0;

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

	int a[m];

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

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

	}

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

		if(a[i]>a[i+1]){

			t=a[i+1];

			a[i+1]=a[i];

			a[i]=t;

		}

	}

	if(a[m-1]<k){

		printf("0");

	}else{

	

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

		if(a[i]>=k)

		cnt++;

	}

	printf("%d",cnt);

}

	return 0;

}

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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<cmath>



using namespace std;



int main(){

	int a,b,c;

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

	int w=0;

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

		if((i*b+c)%a==0){w=1;break;}

	}

	if(w)printf("YES\n");

	else printf("NO\n");

	return 0;

}

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

#include<cmath>



int a,b,c;



int main()

{

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

	int flag = 0;

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

		if((b * k + c) % a == 0) {

			printf("YES\n");

			flag = 1;

			break;

		}

	}

	if(!flag) 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;

int main()

{

    long long a;

    int n,i;

    cin>>n;

    a=1;

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

    a=a*i%1000000007;

    cout<<a<<endl;

    return 0;

}

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

#define ll long long

using namespace std;

const int mod=1e9+7;

ll jc(int x){

    ll ans=1;

    for(int i=1;i<=x;i++) ans*=i,ans%=mod;

    return ans;

}

int main(){

    int n;

    scanf("%d",&n);

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

    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;

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



using namespace std;



int main(int argc, char const *argv[])

{

    int n,k,h,s= 0;

    cin >> n >> k;

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

    {

        cin >> h;

        if(h >= k)

            s += 1;

    }

    cout << s;

    return 0;

}


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

int main()

{

    int N,K,h[100000],n,i;

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

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

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

    if(h[i]>=K){

        n=n+1;

      }

    }

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

    return 0;

}

// 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 <bits/stdc++.h>

using namespace std;

#define Me3za() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))

#define endl "\n"

int n,k;

int l;

int arr[100005];

long long mem[100005];

long long solve(int i,long long cur,int prev){

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

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

mem[i]=LLONG_MAX;

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

   long long sol=solve(i+j,arr[i+j],i)+abs(cur-arr[i+j]);

   //cout<<i<<" "<<sol<<" "<<i+j<<" "<<min(k,n-i)<<endl;

   mem[i]=min(sol,mem[i]);

}

return mem[i];

}

int main() {

Me3za();

cin>>n>>k;

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

    cin>>arr[i];

}

memset(mem,-1,sizeof mem);

cout<<solve(0,arr[0],0);

}




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

using namespace std;

const int maxn = 1e5 + 5;

int main(){

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

	memset(dp,0x3f3f,sizeof(dp));

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

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

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

	dp[1] = 0;

	for(int i = 1;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 + j] - a[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 <bits/stdc++.h>

using namespace std;

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

#define endl '\n'

#define ft first

#define sd second

#define pb push_back

#define pob pop_back()

#define pf push_front

#define pof pop_front()

typedef long long ll;

typedef pair<int,int> pii;

typedef pair<char,char> pcc;

typedef pair<long long,long long> pll;



const int MAX=100005;

const int oo=1000000009;

int dp[MAX];



int main() {

    #ifndef LOCAL

    fastIO;

    #endif

    int n,k;

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

    cin >> n >> k;

    int alturas[n];

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

        cin >> alturas[i];

    }

    dp[0]=0;

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

        dp[i]=oo;

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

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

        }

    }

    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 unsigned long long ull;



const int mod  = 100003;

const int maxn = 1e5+10;



int a[maxn];

int dp[maxn];

int f(int a)

{

	if (a<0)

		a=-a;

	return a;

}

int k;

int solve(int n)

{

	if (dp[n]!=-1)

		return dp[n];

	int ans=1e9;

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

	{

		int tem=solve(n-i)+f(a[n]-a[n-i]);

		ans=min(tem,ans);

	}

	dp[n]=ans;

	return dp[n];

}

int main()

{

	int n;

	cin>>n>>k;

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

		dp[i]=-1;

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

		cin>>a[i];

	dp[1]=0;

	dp[2]=f(a[1]-a[2]);

	cout<<solve(n);

	return 0;

}


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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

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

using namespace std;

typedef long long ll;

const int inf = 1001001001;







int main(){

  int n,k;

  cin >> n >>k;

  vector<int> h(n);

  rep(i,n){

  cin >> h.at(i);

  }

  

  vector<int> dp(1000000, inf);

  

  rep(i,n){

    if(i == 0) {dp.at(i) = 0; continue;}

    rep(j,k+1){

      if(j == 0) {continue;}

      if(i-j < 0){break;}

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

      //cout << i << " " << dp.at(i)  << endl;

    }

  }

  cout << dp.at(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;

const int inf = 1001001001;



int main(){

  int n,k;

  cin >> n >> k;

  vector<int> h(n);

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

  int dp[100001];

  rep(i,100001) dp[i] = inf;

  dp[0] = 0; 



  

  rep(i,n) {

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

      if(i+j >= n) continue;

      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;





}