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

using namespace std;

int main(){

  int n,c,h[100005],dp[100005]={};

  int k;

  cin>>n>>k;

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

    cin>>h[i];

    dp[i]=1000000000;

  }

  dp[1]=0;

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

    c=min(i-1,k);

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

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

    }

  }

  cout<<dp[n]<<endl;

  return(0);

}


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

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

using namespace std;

int main(){

	cin.tie(0);

    ios::sync_with_stdio(false);

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

    cin>>n>>k;

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

        cin>>h[i];

    }

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

        dp[i]=10000000000;

    }

    dp[0]=0;

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

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

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

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

        }

    }

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

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

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

using namespace std;

long long a=1,n;

int main(){

cin>>n;

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

a=a*i%1000000007;

cout<<a;}

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

int n,i;

long long a;

int main ()

{

	scanf ("%d",&n);

	a=1;

	for (i=1;i<=n;i++) a=a*i%1000000007;

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

	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(){

    string s;

    string ans = "";

    int t = 0;



    cin >> s;

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

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

            ans[t++] = '0';

        }

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

            ans[t++] = '1';

        }

        else if(s[i]=='B'&&t > 0){

            t--;

        }

    }



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

        cout << ans[i];

    }

}


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

#include<string.h>

int main(){

    char G[100], H[100];

    int A=0;

    scanf("%s", G);

    int len=strlen(G);

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

    {

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

        {

            A--;

            if(A<0)

                A=0;

        }

        else

            H[A++]=G[i];

    }

    H[A]='\0';

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

    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):
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 1e5+5;



int n;

int k;

int h[N];

int mem[N];



int go(int idx){

    if(idx >= n)

        return 0;

    if(mem[idx] != -1)

        return mem[idx];

    int best = 1e9;

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

        if(idx + i <= n){

            best = min(best , go(idx + i) + abs(h[idx] - h[idx + i]));

        }

    }

    return mem[idx] = best;

}



int main(){

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

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

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

    }

    memset(mem , -1 , sizeof mem);

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

}


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

using namespace std;

const int N=100005;

int a[N],dp[N];

int main()

{

	int n,k;

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

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

		dp[i]=INT_MAX;

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

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

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

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

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

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

#include <cmath>

#include <algorithm>

using namespace std;



const int INF = pow(2,30);

const int MAX_N = pow(10,5);



int dp[MAX_N];



int main() {

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

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



  fill_n(dp,MAX_N,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]));

    }

  }

  // for (int i=0; i<N; i++) 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):
/* BISMILLAHIR RAHMANIR RAHIM */

#include <bits/stdc++.h>

using namespace std;



const int mxn = 100005;

const int inf = 1e7;

int n, k, h[mxn];

int ff[mxn];



int dfs( int pos ) 

{

  if( pos > n ) return 0;

  int& ret = ff[pos];

  if( ~ret ) return ret;

  

  ret = 0;

  if( pos < n )

  {

    ret = abs(h[pos] - h[pos + 1]) + dfs( pos + 1 );

    for(int i = 2; i <= k and pos + i <= n; i++)

    {

      ret = min(ret, abs(h[pos] - h[pos + i]) + dfs( pos + i ));

    }

  }

  return ret;

}



int main()

{

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

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

  { 

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

  }

  memset(ff, -1, sizeof ff);

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

  return 0;

}


// Optimized solution to the same problem (faster):
/* BISMILLAHIR RAHMANIR RAHIM */

#include <bits/stdc++.h>

using namespace std;



const int mxn = 100005;

int n, k, h[mxn];

int ff[mxn];



void solution()

{

  ff[n] = 0;

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

  {

    ff[i] = INT_MAX;

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

    {

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

    }

  }

}



int main()

{

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

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

  { 

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

  }

  solution();

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

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int main()

{

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

	for(int i = 1;i <= 1e5 + 5;i++)dp[i] = 1e9;

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

	for(int i = 1;i <= n;i++)scanf("%d",&a[i]);

	dp[1] = 0,dp[2] = abs(a[1] - a[2]);

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

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

			if(j == i) break;

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

		}

	}

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

	return 0;

}


// Optimized solution to the same problem (faster):
//才不露白

//还是青蛙跳还是动态规划

//唯一的是你不知道青蛙它从哪跳到了现在的石头上 如果你知道 那就好办了

//比如从k上面跳过来

//dp[i] = dp[k] + abs(h[i] - h[k])

//关键是你k不知道啊

//有想法就好 不用先急着自我否认

//枚举

//dp[1] = 0

//dp[2] = abs(h[2] - h[1])

//写个函数来算看起来不错

//dp[3] = min(从1跳过来,从2跳过来)

//dp[4] = min(从1跳,从2跳，从3跳)用循环 最后求min

//差不多2层吧 先写了试试看

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include <queue>

#include <stack>

#include <vector>

#include <algorithm>



using namespace std;



const int MAXN = 1e5;

int n,k;

int h[MAXN + 5],dp[MAXN + 5];//



int CHANGE(int i,int k)//

{

	if(i <= k + 1)//一跳就到

	{//从一开始选

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

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

		{

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

			{

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

			}

		}

		return min;

	}

	else

	{

		int min = dp[i - k] + abs(h[i] - h[i - k]);

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

		{

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

			{

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

			}

		}

		return min;

	}

}



int main()

{

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

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

			dp[i] = CHANGE(i,k);

		}

	}

	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;

long long n,h[100010],dp[100010],k;



int main()

{

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

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

	{

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

	}

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

	{

	//	printf("%d %d %d %d\n",dp[i-1],dp[i-2],h[i-1]-h[i],h[i-2]-h[i]);

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

		{

			if(i>j)

			{

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

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

			}

		}

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

	}

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

	return 0;

}

// Optimized solution to the same problem (faster):
//才不露白

//还是青蛙跳还是动态规划

//唯一的是你不知道青蛙它从哪跳到了现在的石头上 如果你知道 那就好办了

//比如从k上面跳过来

//dp[i] = dp[k] + abs(h[i] - h[k])

//关键是你k不知道啊

//有想法就好 不用先急着自我否认

//枚举

//dp[1] = 0

//dp[2] = abs(h[2] - h[1])

//写个函数来算看起来不错

//dp[3] = min(从1跳过来,从2跳过来)

//dp[4] = min(从1跳,从2跳，从3跳)用循环 最后求min

//差不多2层吧 先写了试试看

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include <queue>

#include <stack>

#include <vector>

#include <algorithm>



using namespace std;



const int MAXN = 1e5;

int n,k;

int h[MAXN + 5],dp[MAXN + 5];//



int CHANGE(int i,int k)//

{

	if(i <= k + 1)//一跳就到

	{//从一开始选

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

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

		{

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

			{

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

			}

		}

		return min;

	}

	else

	{

		int min = dp[i - k] + abs(h[i] - h[i - k]);

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

		{

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

			{

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

			}

		}

		return min;

	}

}



int main()

{

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

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

			dp[i] = CHANGE(i,k);

		}

	}

	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;

int a,b,c,d,cost[1000000],weight[100],INF=1e9;

vector<int>dp(1000000,1e9);



void func(int a,int k)

{

    dp[1]=0;

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

    {

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

        {

            if(j<=a)

            {

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

                //cout<<dp[j]<<endl;

            }

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

        }

    }

}



int main()

{

    int k;

    cin>>a>>k;

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

    {

        cin>>cost[i];

    }

    func(a,k);

    cout<<dp[a]<<endl;

    //cout<<nCr(a,b)<<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>



using namespace std;





int main()

{

	int n, k;

	cin >> n >> k;



	vector<int> h(n), dp(n, 1 << 30);    



	for(int &x : h)

		cin >> x;



	dp[0] = 0;

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

	{

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

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

	}



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



}

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

}


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



using namespace std;



int main(void) {

    int n, k;



    cin >> n >> k;



    int h[n];



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

        cin >> h[i];

    }



    int m[n + 1];



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

        m[i] = 999999999;

    }



    m[0] = 0;



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

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

            if (i + j < n) {

                m[i + j] = min(m[i + j],

                               m[i] + abs(h[i] - h[i + j]));

            }

        }

    }



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



    return 0;

}


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

}

// 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 i, n, k, x, tot=0;

	cin>>n>>k;

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

		cin>>x;

		if(x>=k){

			tot++;

		}

	}

	cout<<tot<<endl;

	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 ;

}