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



using namespace std;



int main() {

    vector<int> predas;

    vector<int> cutsos;

    int n, k;

    cin >> n >> k;



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

        int c;

        cin >> c;

        predas.push_back(c);

    }

    cutsos.push_back(0);



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

        int min = cutsos[i - 1] + abs(predas[i-1] - predas[i]);

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

            if (cutsos[j] + abs(predas[j] - predas[i]) < min) min = cutsos[j] + abs(predas[j] - predas[i]);

        }

        cutsos.push_back(min);

    }



    cout << cutsos.back() << "\n";

}

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

#include<algorithm>

using namespace std;



#define ll long long 



#define file_io 0



ll i,t,j;

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



int main(){

	if (file_io){

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

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

	}

	

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

	

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

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

	}

	

	dp[1]=0;

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

		dp[i]=2e9;

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

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

		}

	}

	

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

	

	return 0;

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



using namespace std;

int main(){

	long long int n,a;

	cin >> n;

	a=1;

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



		a*=i;

			a=a%(10*10*10*10*10*10*10*10*10+7);

		//cout<<a<<endl;

	}

	cout<<a;

	

	return 0;

}

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

#include<stdlib.h>

 

long long int n,a,b,c,i;



 

 

int main(void){

scanf("%d",&n);

b = 1;

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



b = b * i;

b=b % (10*10*10*10*10*10*10*10*10 + 7);

}

c = b;

//b=b % (10*10*10*10*10*10*10*10*10 + 7);

printf("%lld",c);

return 0;

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

#include <string>

#include <algorithm>

using namespace std;



int f(int n) {

    if(n % 2 == 0) {

        return n/2;

    }

    else {

        return 3*n + 1;

    }

}



int main() {

    int s;

    cin >> s;

    const int k = 1000000;

    int a[k];



    a[0] = s;

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

        a[i] = f(a[i-1]);

    }



    int ans;

    if(s == 1 || s == 2) { ans = 4; }

    else {

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

            if(a[i] == 4) {

                ans = i + 4;

                break;

            }

        }

    }



    cout << ans;



    cout << endl;

    return 0;

}

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

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <functional>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

typedef vector<vector<pair<ll, ll>>> vvpll;

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

#define exrep(i, a, b) for(ll i = a; i <= b; i++)

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

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

#define rall(a) a.rbegin(), a.rend()

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_N = 100010;



ll f(ll n) {

    if(n%2 == 0) {

        return n/2;

    }

    else {

        return 3*n + 1;

    }

}



int main() {

    ll s;

    cin >> s;



    set<ll> st;

    ll a = s;

    st.insert(a);

    for(ll i = 2; ; i++) {

        a = f(a);

        st.insert(a);

        if(st.size() < i) {

            out(i);

            re0;

        }

    }



    re0;

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

#include<climits>

using namespace std;



int dp_compute(int a[],int n,int k){

	int dp[100009]={};

	dp[0]=0;



	int best=INT_MAX;

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

		best=INT_MAX;

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

			if(i-j>=0){

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

			}

		}

		dp[i]=best;

	}

	return dp[n-1];

}

int main(){

	int n,k;

	cin>>n>>k;

	int a[n];

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

		cin>>a[i];

	}

	int ans=dp_compute(a,n,k);

	cout<<ans<<endl;

	return 0;

}


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

using namespace std;

#define ll  long long

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

#define endl '\n'

#define mod 1000000007



void inp()

{

    #ifndef ONLINE_JUDGE

    // for getting input from input.txt

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

    // for writing output to output.txt

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

    #endif

} 

ll min(ll a,ll b)

{

    if(a<b)

        return a;

    else

        return b;

}

 

ll max(ll a,ll b)

{

    if(a>b)

        return a;

    else

        return b;

}

int main() {

    //inp();

    fio;

    ll n,k;

    cin>>n>>k;



    vector<int> nums(n);

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

    {

    	cin>>nums[i];

    }



    vector<int> dp(n,INT_MAX);

    dp[0]=0;

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

    {

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

        {

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

        }

    }

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



    return 0;

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



using namespace std;



typedef long long ll;

typedef vector <int> vi;

typedef vector <ll> vl;

typedef pair <ll, ll> dl;

typedef pair <int, int> ii;

typedef vector <ii> vii;

typedef vector <vi> graph;



int n, k;

ll arr[100010];

ll dp[100010];



ll piedra(int id) {

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

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

	ll temp, menor = 1000000000;

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

	{

		temp = abs(arr[id] - arr[id + i]) + piedra(id + i);

		menor = min(temp, menor);

	}

	return dp[id] = menor;

}



int main() {

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);



	cin >> n >> k;

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

	{

		cin >> arr[i];

	}

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

	{

		dp[i] = -1;

	}

	cout << piedra(0) << "\n";

    return 0;

}


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

#define tam 100010

#define inf 1000000000



using namespace std;



typedef long long ll;

typedef vector <int> vi;

typedef vector <ll> vl;

typedef pair <ll, ll> dl;

typedef pair <int, int> ii;

typedef vector <ii> vii;

typedef vector <vii> graph;



bool comp(int a, int b) {

	return a > b;

}



int main() {

	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);



	int n, k;

	cin >> n >> k;

	int arr[n];

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

	{

		cin >> arr[i];

	}

	vi dp(n, inf);

	dp[0] = 0;

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

	{

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

		{

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

		}

	}

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

	return 0;

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

using namespace std;

int main()

{

	

	int k;

     string s;

     cin>>k>>s;

     if(s.length()>k)

	 {

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

	 	cout<<s[i];

	 	cout<<"...";

	 }

	else

	cout<<s;

	

	

	

	

	return 0;

 } 

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

	# include <string.h>

	int main () {

		int a = 0;

		int c =0;

	char name [100];

		scanf ("%d",&a);

		scanf("%s%[^\n]",&name);

		c = strlen (name);

		if (c<=a) {

			printf ("%s",name);

		} else if (c>a) {

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

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

			}

			printf("...");

		}

		return 0;

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



using namespace std;

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

int solve(int index)

{

    if(index==n-1)

        return 0;

    if(dp[index]!=-1)

        return dp[index];

    int ans=1e9;

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

        if(index+i<n)

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





    return dp[index]=ans;

}

int main()

{

    cin>>n>>k;

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

        cin>>arr[i];

    memset(dp,-1,sizeof dp);



    cout << solve(0);

    return 0;

}


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



using namespace std;



int v[100007];

int main() {

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

vector<int> dp(n+1);

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

dp[n] = 0;

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

    dp[i] = 0x3f3f3f3f;

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

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

}



cout << dp[1] << endl;

}
// Slower C++ solution:
/// TOP-DOWN - RECURSIVA;



#include <iostream>

#include <algorithm>

#include <cmath>

#include <cstring>



using namespace std;



int pedras[100100];

long long dp[100100]; ///Guardo os valores da funcao frog;



int n,k;

const int inf =1e9;



int frog2(int i,int j){



    if(dp[i] != -1){

        return dp[i];

    }



    int menor = inf;



    if(i>=j) return dp[i]=0;



    ///**OUU ASSIM COM ESSE MEU FOR ,,

    /*

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

        if(i+x <= j){

            long long cost = (frog2(i+x,j)+ abs(pedras[i]-pedras[i+x]));



            if(cost < menor){

                menor = cost;

            }

        }

    }*/



    ///**OUU ASSIM COM OQ VI NA NET,,



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

        if(i+x <= j){

            int cost = (frog2(i+x,j)+ abs(pedras[i]-pedras[i+x]));

            menor = min(menor,cost);

        }

    }



    return dp[i] = menor;

}



int main(){



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



    cin >>n>>k;



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

        cin >> pedras[i];

    }



    cout<<frog2(0,n-1)<<endl;

}

/**/


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

#include <algorithm>

#include <cmath>

#include <cstring>



using namespace std;



int pedras[100100];

int dp[100100]; ///Guardo os valores da funcao frog;



int n,k;

const int inf =1000000/*1e9*/;



int main(){



    memset(dp,inf,sizeof(dp));

    cin >>n>>k;



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

        cin >> pedras[i];

    }



    ///Comeca aki a bagaca

    dp[n-1]=0;



    for(int i=n-2;i>=0;i--){



        ///int menor=inf;



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

            if(i+j<=n-1){

                int cost = abs(pedras[i]-pedras[i+j]);

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

                /*menor = min(menor,dp[i+j]+cost);*/

            }

        }



        ///dp[i]=menor;

    }



    cout<<dp[0];



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



using namespace std;



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

#define ll long long

#define endl '\n'



int main()

{

	int n,k,coun = 0,a;

	cin >> n >> k;

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

	{

		cin >> a;

		if(a >= k) coun++;

	}

	cout<< coun << endl;

	return 0;

}


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

int main()

{

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

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

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

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

		if(h[a]>=k){

			cnt++;

		}

	}

	printf("%d",cnt);

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

using namespace std;



#define forl(V, N) for(int V = 0; V < N; V++)

#define forll(V, S, E) for(int V = S; V < E; V++)

#define forlc(V, S, E, I) for(int V = S; V < E; V += I)

#define fore(E, X) for(auto &E:X)

#define print(X) cout << X

#define printsp(X) cout << X << " "

#define println(X) cout << X << endl

#define rem(X) X.top(); X.pop()

#define mid(A, B) ((A+B) / 2)

#define setmin(A, B) A = min(A, B)

#define graph unordered_map<int, unordered_set<int>>

#define vi vector<int>

#define pb push_back

#define ll long long



int N, K;

int H[100101];

int DP[100101];



int main() {

    cin >> N >> K;

    forl(i, N) cin >> H[i];

    fill_n(DP, 100000, INT_MAX);

    DP[0] = 0;

    forl(i, N-1) {

        for(int j = i+1; j < i+K+1; j++) setmin(DP[j], abs(H[i]-H[j]) + DP[i]);

    }

    println(DP[N-1]);

}


// Faster C++ solution for the same problem (measured speedup: 1.3783897804479561x):
// Justin Choi

#include <bits/stdc++.h>

using namespace std;



string FILENAME = "template";

#define io ifstream fin(FILENAME + ".in"); ofstream fout(FILENAME + ".out")

#define fwrite(X) fout << X;

#define fwriteln(X) fout << X << endl;



#define forl(V, N) for(int V = 0; V < N; V++)

#define fore(E, X) for(auto &E:X)

#define print(X) cout << X

#define println(X) cout << X << endl

#define printe(X) for(auto &E:X) cout << E << " "; cout << endl

#define rem(X) X.top(); X.pop()

#define mid(A, B) ((A+B) / 2)

#define setmin(A, B) A = min(A, B)

#define setmax(A, B) A = max(A, B)

#define graph unordered_map<int, unordered_set<int>>

#define vi vector<int>

#define pb push_back

#define ll long long



int main() {

    int N, K;

    cin >> N >> K;

    vi stones(N);

    forl(i, N) cin >> stones[i];

    vector<ll> dp(2*N+K+10);

    fill(dp.begin(), dp.end(), 999999999999);

    dp[0] = 0;

    forl(i, N) {

        forl(j, K) setmin(dp[i+j+1], dp[i]+abs(stones[i]-stones[i+j+1]));

    }

    println(dp[N-1]);

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



using namespace std;

#define ll long long

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



int cost(int i){

	//base case

	if(i>= n-1){

		return 0;

	}

	//recursive case

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



	int ans=INT_MAX;



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

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

	}



	dp[i]=ans;

	return dp[i];

}



int main(){

	ios_base::sync_with_stdio(false);

    cin.tie(NULL);

	cin>>n>>k;

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

		cin>>h[i];

	}

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

	cout<<cost(0);

}

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



*/

#include <bits/stdc++.h>



using namespace std;



#define ll           long long int

#define mp           make_pair

#define pb           push_back

#define fi           first

#define si           second

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

#define F(a,n)       for(int i=0;i<n;i++){cin>>a[i];}

#define F1(a,n)      for(int i=1;i<=n;i++){cin>>a[i];}

#define P(a,n)       for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;

#define P1(a,n)      for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;

#define NF(a,n,m)    for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}

#define NF1(a,n,m)   for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}

#define PNF(a,n,m)   for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

const int nax = 1e7;

const int mod = 1e9+7;







int main(){

fastIO

	ll n, k; cin>>n>>k;

	ll *h = new ll[n];

	F(h, n);

	ll *dp = new ll[n];

	dp[0] = 0;

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

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

		dp[i] = INT_MAX;

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

			if(i-j >= 0){

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

			}

			else{

				break;

			}

		}

	}

	cout<<dp[n-1];

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

#include <sstream>

#include <cstring>

#include <fstream>

using namespace std;

const int N = 50000;

bool prime[N+1];



void make_prime(void)

{

	int i,j;

	memset (prime, true , sizeof(prime ) );



	prime[0] = false;

	prime[1] = false;



	for (j = 0; j <= N; ++j){

		if (prime[j]){

			int p = j;

			for (i = 2*p; i <= N; i += p ){

				if (prime[i] ){

					prime[i] = false;

				} // end if

			} // end for

		} // end if	

	} // end for

}



int main()

{

//	cut here before submit 

//	freopen ("testcase.goldbach", "r", stdin);

	string str = "";

	make_prime();



	while (getline (cin, str ) ){

		int n;

		stringstream ss(str);

		ss >> n;

		if (n == 0 ){

			break;

		} // end if

		int res = 0;

		int i;



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

			if (prime[i] && prime[n-i] ){

				++res;

			} // end for

		} // end for

		cout << res << endl;

	} // end loop

		

	return 0;

}

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

#include <cstring>	// require memset 



using namespace std;



const int N = 50000;

bool prime[N+1];



void make_prime (void)

{

	memset (prime, true , sizeof(prime ) );



	prime[0] = false;

	prime[1] = false;



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

		if (prime[i] ) {

			for (int j = i*i; j <= N; j += i ) {

				prime[j] = false;

			} // end for

		} // end if

	} // end for

}



int main()

{

	make_prime();



	int n;

	while (cin >> n && n ) {

		int res = 0;



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

			if (prime[i] && prime[n-i] ){

				++res;

			} // end for

		} // end for

		cout << res << endl;

	} // end loop

		

	return 0;

}
// Slower C++ solution:


#include <bits/stdc++.h>



using namespace std;



const int N = 1e5 + 5;

const int INF = 2e9;



int h[N];

int n , k;



int mem[N];



int dp(int i){

    // base case

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



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



    int ans = INF;

    // try to jump 1 or 2 or ,,,, or k stones

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

            if(i + j <= n-1){

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

            }

    }



    mem[i] = ans;

    return mem[i];

}



main(){



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



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

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

    }



    memset(mem , -1 , sizeof mem);

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



    return 0;

}


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


#include <bits/stdc++.h>



using namespace std;



/*



    bottom up



*/



const int N = 1e5 + 5;

const int INF = 2e9;



int n , k;

int h[N];

int dp[N];



main(){



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



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

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

    }



    // initialize dp table

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

            dp[i] = INF;

    }

    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]);

            }

    }



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



    return 0;

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

#include <bits/stdc++.h>

#define f first

#define se second

#define ll long long

#define mp make_pair

#define pb push_back

#define ull unsigned long long



using namespace std;

const int N = (int)(1e5 + 123);

const int INF = (int)(1e9 + 7);



int dp[N] , a[N]; 



int main() {

	int n , k;

	cin >> n >> k;

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

		cin >> a[i];

	}                     

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

		dp[i] = INF;

	}                    

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

		int rep = 1;

		while (i+rep <= n && rep <= k) {

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

			rep++;

		}

	}

	cout <<dp[n];

	return 0;

}

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

#include <cstring>

#include <algorithm>

#include <cmath>

using namespace std;

int n,k,a[100005],f[100005];

int main()

{

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

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

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

	memset(f,0x3f,sizeof(f));

	f[1]=0;

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

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

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

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

	return 0;

}
// Slower C++ solution:
#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];

    }

}


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

}
// Slower C++ solution:
#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;

}

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



}
// Slower C++ solution:
#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;

      }

    }

  }

}

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



    }

}