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

#define ll long long

#define pb push_back

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

#define mp make_pair

#define ff first

#define ss second

#define MAXN  1000005

#define endl "\n"

using namespace std;

vector<ll>v;

ll dp[100003];

ll a,n,k;

ll rec(int i){

    if(i==n-1)

        return 0;

    if(dp[i]!=-1)

        return dp[i];

    ll ans=LLONG_MAX;

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

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

    }

    return dp[i]=ans;

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cin>>n>>k;

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

        cin>>a;

        v.pb(a);

    }

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

    ll ans=rec(0);

    cout<<ans<<endl;







    return 0;

}




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

#define ll long long

#define pb push_back

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

#define mp make_pair

#define ff first

#define ss second

#define MAXN  1000005

#define endl "\n"

using namespace std;



const int INF = 1e9 + 5;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    int n, k, v[100005];

    vector<int>dp(100005, INF);

    cin>>n>>k;

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

        cin>>v[i];

    }

    dp[0]=0;



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

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

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

        }

    }

    cout<<dp[n-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 <bits/stdc++.h>

using namespace std;

int main()

{

    string s;

    int k;

    cin>>k>>s;

    if (s.size()>k)

    {

        for (int i=0;i<k;i++)cout<<s[i];

        cout<<"...";

    }

    else

        cout<<s;

    return 0;

}


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

#include<string.h>

int main(){

	int k;

	char s[105];

	scanf("%d",&k);

	getchar();

	scanf("%s",&s);

	if(strlen(s)>k){

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

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

		}

		printf("...");

		printf("\n");

	}

	else{

		int l = strlen(s);

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

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

		printf("\n");

	}

}

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

using namespace std;

typedef long long ll;

const int mod = 1000000007;

const double PI = acos(-1);



int main()

{

	int k;

	string s;

	cin >> k >> s;

	if (s.size() <= k) cout << s << endl;

	else cout << s.substr(0, k) + "..." << endl;

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

#include<iostream>

#define ll long long

using namespace std;

ll a[100000 +10];

ll dp[100000 +10];

ll inf = 0x3f3f3f3f3f3f3f;

int main()

{

//	cout<<inf<<endl;

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

	ll i,j;

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

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

	dp[1] =0;

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

	{

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

		{

			if(j>0)

			{

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

			} 

			else break;

		}

	}

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

	return 0;

}

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

using namespace std;



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



int fn(int i) {

    if (i <= 0) return 0;

    if (i == 1) return abs(h[1] - h[0]);

    if (~dp[i]) return dp[i];

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

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

        if (i - t >= 0) 

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

    }

    return dp[i]; 

}



int main() {

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

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

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

    }

    memset(dp, -1, sizeof dp);

    printf("%d\n", fn(n - 1));

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

using namespace std;

#include <cstdio>

#include <string>

#include <vector>

#include <queue>

#include <algorithm>

int main()

{

	

	int k ,x;

	cin>>k>>x;

	vector<int>res;

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

	{

		res.push_back(i);

	}

	

	bool tf = false;

	for(auto &x :res)

	{

		if(tf)

		cout<<" ";

		cout<<x;

		tf=true;

	}

	

	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):
/******

author :- Mahmoud Tarek.

*******/



#include<bits/stdc++.h>



using namespace std ;



#define rg register

#define dbg(v) cerr << #v << " " << v ;

typedef long long ll ;



int n, k;

vector<int> a ;

int mx = 0 ;

int mem[100002] ;



int solve(int i){

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

int & ret = mem[i];

if(~ret) return ret ;

ret = mx ;

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

    if(i + j < n){

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

    }

}

return ret ;

}



int main() {

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

     cin >> n >> k ;

     a.resize(n) ;



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

        cin >> a[i] ;

        if(i >= 1){

            mx += abs(a[i] - a[i - 1]) ;

        }

     }



     if(mx == 0) mx = a[0] ;





     memset(mem, -1, sizeof mem) ;



     cout << solve(0);

}



/*

  Empty set of troubles.

*/


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

using namespace std;

int n,k; vector<int>v;

long long dp[100005];



int main() {

	cin >> n>>k; 

	v.resize(n + 1);

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

	fill(dp, dp + n + 1, 1e18);

	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(v[i] - v[i+j]));

		}

	}

	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 <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



template <typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;

typedef complex<double> point;



#define X real()

#define Y imag()

#define angle(a) (atan2((a).imag(), (a).real()))

#define vec(a, b) ((b) - (a))

#define same(p1, p2) (dp(vec(p1, p2), vec(p1, p2)) < EPS)

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

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

#define length(a) (hypot((a).imag(), (a).real()))

#define normalize(a) (a) / length(a)

#define rotateO(p, ang) ((p)*exp(point(0, ang)))

#define rotateA(p, ang, about) (rotateO(vec(about, p), ang) + about)

#define reflectO(v, m) (conj((v) / (m)) * (m))

#define clr(a, b) memset(a, b, sizeof(a));



const ll N = 100005;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



ll n, k, h[N];

ll memo[N];



ll solve(int i)

{

	if(i == n - 1)

		return 0;



	ll& ret = memo[i];

	if(~ret)

		return ret;



	ret = solve(i + 1) + llabs(h[i] - h[i + 1]);

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

		ret = min(ret, solve(x) + llabs(h[i] - h[x]));



	return ret;

}



int main()

{

    ios::sync_with_stdio(false);

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

    cin >> n >> k;

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

    	cin >> h[i];

    clr(memo, -1);

    cout << solve(0) << endl;

}

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



using namespace std;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;



const ll N = 100005;

const ll INF = 1e9;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



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



int main() {

	ios::sync_with_stdio(false);

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

	cin >> n >> k;

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

		cin >> h[i];

	

	fill(dp, dp + n, INF);



	dp[0] = 0;

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

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

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



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

using namespace std;



long long n,k,a=0,arr[100005];

int main(){

	cin >>  n >> k;

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

		cin >> arr[i];

		if (arr[i]>=k){

			a++;

		}

	}

	cout << a << endl;

	

}

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

#include <algorithm>

using namespace std;

typedef long long ll;

#define MAX_N 100000

const ll INF = 1LL << 60;

int N, K;

ll dp[MAX_N + 1];



int main() {

    cin >> N >> K;

    int h[N + 1];

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

    for (int i = 0; i < MAX_N; i++) dp[i] = INF;

    dp[0] = 0;

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

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

            if (i + j >= N) break;

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

        }

    }

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

}

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

using namespace std;

#define MAX_N 100100

const int INF = 1e9;

int n, k;

int h[MAX_N];

int dp[MAX_N];



int main() {

    cin >> n >> k; 

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

    fill(dp, dp + MAX_N, INF);

    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(h[i] - h[i + j]));

            }

        }

    }

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

using namespace std;



typedef long long LL;

LL maxn = 1e9+7;

LL N,M;



int main()

{

    while(scanf("%lld",&N)!=EOF&&(N>=1&&N<=10e5))

    {

        M = 1;

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

        {

            M = (M%maxn)*(i%maxn)%maxn; //可以分别模除后再乘积

        }

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

    }

    return 0;

}

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

const long long MOD=1e9+7;

int n;

long long ans=1;

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++) ans=(ans*i)%MOD;

	printf("%lld",ans);

}

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

#include<climits>

using namespace std;



int main()

{

    //put here bitch 

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

    int h[1000001];

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

    int dp[1000001];

    dp[0]=0;

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

    {

        dp[i]=INT_MAX;

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

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

    }

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

}

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

using namespace std;

typedef int int__;

#define int long long

#define pb push_back

#define pi pair<int,int>

#define vpi vector<pi>

#define vi vector<int>

#define vvi vector<vi>

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

#define fi first

#define se second

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

#define sz(a) int__(a.size())

template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}

const int MAX = 1e9 + 7;

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

int Mod(int x){const int mm=998244353;x%=mm;if(x<0)x+=mm;return x;}

int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}

#define watch(x) cout << #x << " : " << x << endl;

int gcd(int x,int y){return y!=0 ? gcd(y,x%y) : x;}

 

int__ main() {

	fast;

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

	vi h(n);

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

	vi dp(n+k+1,1e12);

	dp[0] = 0;



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

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

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

		}

	}

	//watch(dp);

	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<string.h>

using namespace std;

int main() {

    long int K;

    cin >> K;

    string S;

    cin >> S;

    if (K>=S.size()){

        cout << S << endl;

    }

    else{

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

                cout << S[i];

            }

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

    }

}

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



int main(){

	int k, len = 0;

	char str[100];

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

	for(int i = 0; str[i] != '\0'; i++){

		len++;

	}

	if(len <= k){

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

	}

	else{

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

			if(i < k + 3){

				str[i] = '.';

			}

			else{

				str[i] = '\0';

			}

		}

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

	}

	return 0;

}

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

using namespace std;

typedef long long ll;

const int mod = 1000000007;

const double PI = acos(-1);



int main()

{

	int k;

	string s;

	cin >> k >> s;

	if (s.size() <= k) cout << s << endl;

	else cout << s.substr(0, k) + "..." << endl;

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

#include<string>

#include<algorithm>

#include<vector>

#include<cmath>



using namespace std;



// 無限大の値

const long long INF = 1LL << 60;

// DP テーブル

long long dp[100010];



template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



int main() {

    // DP テーブル全体を初期化

    for (int i = 0; i < 100010; ++i) dp[i] = INF;



    int N, K;

    cin >> N >> K;

    vector<int> h(N);

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

        cin >> h[i];

    }

    dp[0] = 0;

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

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

            if (i-k < 0) break;

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

        }

    }

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

    return 0;

}


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

#include <iostream>

#include <vector>



using namespace std;

using ll = long long;



int main() {

  int N, K;

  cin >> N >> K;

  vector<int> h(N);

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

    cin >> h[i];

  }

  vector<int> dp(N);

  dp[0] = 0;

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

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

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

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

      if (i - j < 0) break;

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

    }

    dp[i] = candi;

  }

  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;





}