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



using namespace std;



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

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

#define pb push_back

#define MP make_pair

#define SZ(v) ((int)((v).size()))

typedef long long ll;



const ll MOD = 1e9 + 7;

const int OO = (int)1e9;

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

const int K = 105;

void init(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

int n;

int k;

int dp[N];

int a[N];

int solve(int idx){

    if(idx>n)return OO;

    if(idx==n-1)

        return 0;

    int &ret = dp[idx];

    if(~ret)

        return ret;

    ret =OO;

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

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

    }

    return ret;

}   

int main() {

	#   ifdef LOCAL_PROJECT

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

    #   endif

    scanf("%d",&n);

    scanf("%d",&k);

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

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

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

    }

    

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

    return 0;

}

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

#define ll long long

#define ull unsigned long long

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

#define endl '\n'

#define main() int main()

#define ff1(i,n) for(int i=1;i<=n;++i)

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

#define pi acos(-1.0)

#define ms(a, x) memset(a, x, sizeof(a))

#define lowbit(x) ((x)&(-(x)))

#define pb push_back

#define binarycount __builtin_popcount(x)

#define tr t[root]

#define lson t[root << 1]

#define rson t[root << 1 | 1]

#define fir first

#define sec second

#define debug(x) cout<<x<<'\n'

#define sa(a) scanf("%d", &a)

#define sab(a, b) scanf("%d%d", &a, &b)

#define pa(a) printf("%d",a)

#define pab(a,b) printf("%d%d",a,b)

#define pii pair<string,int>

using namespace std;



#define maxn 100010

const int inf = 0x3f3f3f3f;

const int mod = 9973;

const double eps = 1e-8;

ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}

ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}

int max(int x,int y){if(x>y) return x;return y;}

ll powmod(ll a,ll b){

    ull ans = 1, pow = a%mod;

    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }

    return ans%mod;

}

main(){

	IO;

    int n,k;

	cin>>n>>k;

	vector<int> a(n+1);

	ff1(i,n) cin>>a[i];

	int dp[n+1];

	ms(dp,inf);

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

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

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

			if(i-j>=1){

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

			}

		}

	}

	cout<<dp[n]<<endl;

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

#include<climits>



using namespace std;

#define ll long long int

#define Max 110000



int main() {

	int n,k;

	cin>>n>>k;

	int arr[n];

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

	{

		cin>>arr[i];

	}

	ll dp[Max+1];

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

	{

		dp[i]=INT_MAX;

	}

	dp[0]=0;

	//cout<<dp[1];

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

		}

	}

	cout<<dp[n-1];

	return 0;

}

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

#define ll long long int

using namespace std;

ll solve(int cost[],int n,int k)

{

	ll dp[n];

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

		dp[i]=INT_MAX;

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

	}

	return dp[n-1];

}

int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	int n,k;

	cin>>n>>k;

	int cost[n];

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

		cin>>cost[i];

	long long int ans=solve(cost,n,k);

	cout<<ans;

	return 0;

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

#include <cmath>

using namespace std;

char c[232],top; 

int main() {

	char ch;

	while(cin>>ch) {

		if(ch=='B'&&top)top--;

		if(ch!='B')c[top++]=ch;

	}

	for(int i=0;i<top;++i) cout<<c[i]; cout<<endl;

	return 0;

}

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

#include<cstring>

using namespace std;

char s[20], S[20];

int main()

{

	scanf("%s", s);

	int len = strlen(s);

	int cnt = 0;

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

	{

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

		{

			S[cnt] = '1';

			cnt++;

		}

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

		{

			S[cnt] = '0';

			cnt++;

		}

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

		{

			if(cnt)cnt--;

			S[cnt] = '\0';

		}

	}

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

	return 0;

}
// Slower C++ solution:
// # Problem A - Frog 2 - Algoritmos e Grafos - MATA52

#include<bits/stdc++.h>

#include<cstdlib>

using namespace std;



int frog2(int stones[], int n, int h[], int k_max){

    stones[0] = 0;

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

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

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

            int w1 = stones[i];

            int w2 = abs(h[i - j] - h[i]);

            stones[i] = min(w1, stones[i - j] + w2);

        }

    }

    return stones[n - 1];

}



int main() {

    int n, k_max;

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

    int stones[n], h[n];

    for(int i = 0; i < n; stones[i] = INT_MAX, scanf("%d", &h[i]), i++);

    printf("%d", frog2(stones, n, h, k_max));

    

    return 0;

}

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

int n, a[100005], sum[100005];

long long m;

namespace BIT

{

	long long c[500005];

	inline long long lowbit(long long x) { return x & (~x + 1); }

	inline void add(long long x, long long val)

	{

		for (long long i = x; i < 4 * n; i += lowbit(i))	c[i] += val;

	}

	inline long long sum(long long x)

	{

		long long res = 0;

		for (long long i = x; i; i -= lowbit(i))	res += c[i];

		return res;

	}

}

bool check(int x)

{

	long long cnt = 0;

	sum[0] = 0;

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

	{

		sum[i] = (a[i] >= x);

		sum[i] += sum[i - 1];

	}

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

	{

		sum[i] = (2 * sum[i] - i) + n + 1;

	}

	memset(BIT::c, 0, sizeof(BIT::c));

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

	{

		cnt += BIT::sum(sum[i]);

		BIT::add(sum[i], 1);

	}

	return cnt >= (m+1)/2;

}

int main()

{

	int l = 1000000005, r = 1, ans, mid;

	scanf("%d", &n);

	m = 1ll*n * (n + 1) / 2;

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

	{

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

		l = min(l, a[i]);

		r = max(r, a[i]);

	}

	while (l <= r)

	{

		mid = (l + r) >> 1;

		if (check(mid))	l = mid + 1, ans = mid;

		else r = mid - 1;

	}

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

	return 0;

}


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

//#define IORD

#define eps 1e-8

#define inf 0x3f3f3f3f

//#define mod (1000000007)



using namespace std;

typedef long long LL;

typedef pair<int,int> pp;



const int N=1e5+10;

const int maxn=N*2+10;

int n,a[N],b[N],ais[N];

LL cnt=0;



int bit[maxn+1];

int lb(int x)

{

    return x&-x;

}



int sum(int i)

{

    int s=0;

    while(i>0)

    {

        s+=bit[i];

        i-=lb(i);

    }

    return s;

}



void add(int i,int x)

{

    while(i<=maxn)

    {

        bit[i]+=x;

        i+=lb(i);

    }

}



int Che(int x)

{

    memset(bit,0,sizeof(bit));

    memset(ais,0,sizeof(ais));

    for(int i=1;i<=n;i++) ais[i]=(ais[i-1]+(a[i]>=x?1:-1));

    cnt=0;

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

    {

        cnt+=sum(ais[i]+N);

        add(ais[i]+N,1);

    }

    return cnt>=1ll*(n+1)*n/4;

}



int Sol()

{

    memcpy(b,a,sizeof(a));

    sort(b+1,b+n+1);

    int l=0,r=n+1,m=(l+r)/2;

    while(l+1<r)

    {

        if(Che(b[m])) l=m;else r=m;

        m=(l+r)/2;

    }

    return b[l];

}



int main()

{

    #ifdef IORD

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

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

	#endif // IORD

    scanf("%d",&n);

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

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

    return 0;

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

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

#define r(i, j) for (int i = 1; i <= j; i++)

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

using ll = long long;

using namespace std;

template <typename T>

using vec = std::vector<T>;







int main() {

    int N, M, Q;

    cin >> N >> M >> Q;

    vec<int> A(Q),B(Q),C(Q),D(Q);

    rep(i, Q) {

        cin >> A[i] >> B[i] >> C[i] >> D[i];

        --A[i];--B[i];

    }



    ll ans = 0;

    for (int a = 1; a <= M; ++a) {

        r(b, a) r(c, b) r(d, c) r(e, d) r(f, e) r(g, f) r(h, g) r(i, h)  r(j, i){

            // vec<int> Z ={a,b,c,d,e,f,g,h,i};

            vec<int> Z ={j,i,h,g,f,e,d,c,b,a};

            ll tmpans = 0;

            rep(k,Q){

                if(Z[B[k]] - Z[A[k]] == C[k]) tmpans += D[k];

            }

            ans = max(ans,tmpans);

        }

    }



    cout << ans << endl;

}

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

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

#define r(i, j) for (int i = 1; i <= j; i++)

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

using ll = long long;

using namespace std;

template <typename T>

using vec = std::vector<T>;



int N, M, Q;

int A[55], B[55], C[55], D[55];

int ans = 0;



void dfs(vec<int> Z) {

    int size = Z.size();

    if (size == N) {

        int tmpans = 0;

        rep(i, Q) {

            if (Z[B[i]] - Z[A[i]] == C[i]) tmpans += D[i];

        }

        ans = max(ans, tmpans);

        return;

    }



    Z.push_back(Z.back());

    for (int i = Z.back(); i <= M; ++i) {

        Z[size] = i;

        dfs(Z);

    }

}



int main() {

    cin >> N >> M >> Q;



    rep(i, Q) {

        cin >> A[i] >> B[i] >> C[i] >> D[i];

        --A[i];

        --B[i];

    }

    dfs(vec<int>(1, 1));

    cout << ans << endl;

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

#include <bits/stdc++.h>

#define mod 998244353

typedef long long ll;



using namespace std;



void Fastio(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}



ll fact[1000006], inv[1000006];



ll fp(ll base, ll exp)

{

    if (exp == 0)

        return 1;

    ll ans = fp(base, exp / 2);

    ans = (ans * ans) % mod;

    if (exp % 2 != 0)

        ans = (ans * (base % mod)) % mod;

    return ans;

}



void calcFacAndInv(ll n)

{

    fact[0] = inv[0] = 1;

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

    {

        fact[i] = (i * fact[i - 1]) ;

        inv[i] = fp(fact[i], mod - 2);

    }

}



ll ncr(ll n, ll r)

{

    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;

}



ll npr(ll n, ll r)

{

    return (fact[n] * inv[n - r]) % mod;

}



long double  NCR(int n, int m){

    long double res = 1;

    m = min(m, n - m);

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

        res = res * ( n - i) / (i + 1);

 }

    return res;

}

ll tol(string a){

    ll res=0;

    while(a[0]=='0'){

        a.erase(a.begin());

    }

    if(a=="")a="0";

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

        res*=10; res+=a[i]-'0';

    }

    return res;

}

int check(string a, string b){

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

        if(a[i]>b[i])return 1;

        if(b[i]>a[i])return -1;

    }

    return 0;

}

class data{

public:

    ll v,d,p;

    data(){}

    data(ll vv, ll dd, ll pp){

        v=vv;  d=dd; p=pp;

    }

};



int primeFactors(int n)

{

    ll c=0;

    while (n % 2 == 0)

    {

        c++;

        n = n/2;

    }

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

    {

        while (n % i == 0)

        {

            c++;

            n = n/i;

        }

    }

    if (n > 2)

        c++;

    return c;

}



int main()

{

    Fastio();

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

    int arr[n];

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

    ll dp[n]={0};

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

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

        ll ans=1e18;

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

            if(y<=i)ans=min(abs(arr[i]-arr[i-y])+dp[i-y], ans);

        }

        dp[i]=ans;

    }

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



    return 0;

}


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

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

#include<queue>

#include<string>

#include<cstring>

#include<cmath>

#include<map>

#include<iostream>

#include<algorithm>

#define ll long long

const ll mod = 1e9+7;

using namespace std;

int a,b,c;

int main()

{

	while(~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 ;

}

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

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

#include <vector>

#include <map>

using namespace std;



int N, K;

int h[111111];

int dp[111111];

int main(){

    cin >> N >> K;

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

        cin >> h[i];



    fill_n(dp, 111111, 1<<30);

    dp[0] = 0;

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

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

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

        }

    }

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

    return 0;

}


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

using namespace std;

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

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(int i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }

template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }



int main(){

    int N, K;

    cin >> N >> K;

    vector<int> h(N);

    REP(i, N) cin >> h[i];



    vector<int> dp(N, 1<<30);

    dp[0] = 0;



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

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

            int to = i + j;

            if(to >= N) continue;

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

        }

    }

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

    return 0;

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

using namespace std;

long long dp[100200];

int main(){

	int n, K;

	cin >> n >> K;

	vector<int> h(n);

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

		cin >> h[i];

	}

  

for(int i = 0; i < 100200;i++) dp[i] = 10000000000;

  	dp[0] = 0;

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

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

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

      }

    }

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

	

}


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

using namespace std;

long long  dp[100004];

int main(){

	int n, K;

	cin >> n >> K;

	vector<int> h(n);

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

		cin >> h[i];

	}

  	long long tmp;

  	dp[0] = 0;

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

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

      tmp = 10000000000;

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

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

      }

      dp[i] = tmp;

    }

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

	

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

using namespace std;





int main() {

    int k, x;

    cin >> k >> x;

    int begin = x - (k-1);

    int end = x + (k-1);



    vector<int> v(2000001);

    for (int i = begin; i <= end; ++i) {

        cout << i << " "s;

    }

}

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

using namespace std;





int main() {

    int k, x;

    cin >> k >> x;

    int begin = x - (k-1);

    int end = x + (k-1);



    for (int i = begin; i <= end; ++i) {

        cout << i << " "s;

    }

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

#include<algorithm>

#include<string>

#include<iomanip>

#include<cmath>

using namespace std;



int main() {

	int k;

	cin >> k;

	string s;

	cin >> s;

	int len = s.size();

	if (len <= k)cout << s;

	else {

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

			cout << s[i];

		}

		cout << "...";

	}



}


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

#include <string.h>

int main(){

	int k;

	scanf("%d",&k);

	char s[100];

	scanf("%s",&s);

	int lol = strlen(s);

	s[k] = '\0';

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

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

	}

	if(k<lol){

		printf("...");

	}

return 0;

}
// Slower C++ solution:
/*

				" اللهم صلي و سلم علي سيدنا محمد و علي اله وصحبه اجمعين "

*/





#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

#define f for

#define ll long long

#define ull unsigned long long

#define endl "\n"

using namespace std;

#define BI  acos(-1)

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

void Open()

{

#ifndef ONLINE_JUDGE

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

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

#endif

}

ll gcd(ll a, ll b)

{

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

}

void madesetprobblem()

{

	//$ $

	//less than or equal => $ 1 \leq 100 $

	//  $(1 \le A,B \le 10^5 )$

	// a[i] => $a_i$

	// a[i][j] => $a_{i,j}$

	// double qoutes ''yext''

	/*

		image

		\begine{center}

		\includegraphics{image.jpg}

		\end{center}

	*/

	/*

		list

		\begin{itemize}

			\item first one

			\item second one

		\end{itemize}

	*/

}

int n,k;

vector<int>a(1e5 + 2),dp(1e5+2,-1);

int ans(int c = 0)

{

	if (c == n-1)

		return 0;

	int ans1 = INT_MAX, ans2 = INT_MAX;

	if (dp[c] != -1)

		ans1 = dp[c];

	else

	{

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

		{

			if (c + i < n)

				ans1 = min(ans1,(abs(a[c] - a[c + i]) + ans(c + i)));

		}

		dp[c] = ans1;

	}

	//cout <<c<<" "<< ans1 << " " << ans2 << endl;

	return ans1	;

}

int main()

{

	// توكلت علي الله 

//Open();

	ios::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);

	cin >> n>>k;

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

	{

		cin >> a[i];

	}

	cout << ans();

}

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

using namespace std;



const int N=1e5+30;

typedef long long ll;

int n,k,arr[N];

int dp[N];

ll solve(int i){

    if(i>=n)return 1e15;

    if(i==n-1){

        return 0;

    }



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

    ll mn=1e18;

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

        ll path1=abs(arr[i]-arr[i+j])+solve(i+j);

        mn=min(path1,mn);

    }

    return dp[i]= mn;

}

int main()

{

    memset(dp,-1,sizeof dp);

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

    for(int i=0;i<n;i++)scanf("%d",arr+i);

    cout<<solve(0)<<endl;

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

#include<math.h>

#include<algorithm>

#include<iostream>

#include<cstring> 

#include<cstdlib>

#include<set>

#include<vector>

using namespace std;

#define ll long long

const int maxn = 2e5 + 5;

const int inf =9999999;



int main()

{     int t;

	cin>>t;

    char a[100];

    cin>>a;

    if(strlen(a)<=t)

    cout<<a<<endl;

    else{

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

    cout<<a[i];

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

}

    

	

}

	 

		

	  	

	  

	  


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

#include <string.h>

int main(){

	int k;

	scanf("%d",&k);

	char s[100];

	scanf("%s",&s);

	int lol = strlen(s);

	s[k] = '\0';

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

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

	}

	if(k<lol){

		printf("...");

	}

return 0;

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

#define ll long long

#define ull unsigned long long

using namespace std;

ll n,k,a[100009],dp[100009];

	

int main (){

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

	cin >> n >> k;

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

		cin >> a[i];

	}

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

		ll tmp=1e15;

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

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

		}

		if (tmp!=1e15)dp[i]=tmp;

	}

	cout << dp[1] << endl;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn=1e5 + 5;

int main()

{

	int dp[maxn];

	int h[maxn];

	int n,k;

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

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

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

		dp[1] = 0;

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

	    	dp[i]=1e9;

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

				if(i==j) break;

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

				}

	}

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

	}

	return 0;

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

using namespace std;

#define ll long long

#define pb push_back

ll n,k;

ll h[100001];

ll dp[100001];



ll jump()

{

    dp[1] = 0;

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

    {

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

        {

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

        }

    }

    //cout<<dp[1];

    return dp[n];

}



int main()

{

    cin>>n>>k;

    //cout<<n<<k<<"\n";

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

        dp[i] = INT_MAX;



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

    {

        cin>>h[i];

    }



    cout<<jump()<<"\n";



    return 0;

}


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

| Name: Ayush Kumar              |

| Site: atcoder                  |

| Email: ayushkr667@gmail.com    |

*-------------------------------*/



#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define mp make_pair

#define mod 1000000007

#define INF (ll) 1e18

const double PI = 3.141592653589793238460;

int main()

{

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

    ll n, k;

    cin>>n>>k;

    ll arr[n+1];

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

    {

        cin >> arr[i];

    }

    ll dp[n+1];

    dp[1] = 0;

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

    {

        dp[i] = INF;

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

        {

            if( i-j >= 1)

            {

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

            }

        }

    }

    cout<<dp[n];

    return 0;

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

#include<cstring>

using namespace std;

int main(){

	int k;

	string s;

	cin>>k;

	cin>>s;

	if(k>=s.length()){

		cout<<s<<endl;

	}else{

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

			if(i==k-1){

				cout<<s[i]<<"..."<<endl;

			}else{

				cout<<s[i];

			}

		}

	}

	return 0;

}

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



int main(){

	int k;

	char word[100];

	scanf("%d", &k);

	scanf("%s", &word);

	

	int len = 0;

	

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

		len++;

	}

	

	if(len <= k){

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

	}

	else{

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

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

		}

		printf("...\n");

	}

	return 0;

}