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

using namespace std;



int main(){

	int x, y, s;

	int a;

	int a2, b2, s2, res;

	int lb, ub, mid;

	

	while(true){

		scanf("%d%d%d", &x, &y, &s);

		if(x == 0 && y == 0 && s == 0) break;

		

		res = 0;

		for(a = 1; a < s; a++){

			ub = s; lb = 0;

			while(ub - lb > 1){

				mid = (ub + lb) / 2;

				if(mid * (100 + x) / 100 > a){

					ub = mid;

				}

				else{

					lb = mid;

				}

			}

			if(lb * (100 + x) / 100 == a){

				a2 = lb;

				ub = s; lb = 0;

				while(ub - lb > 1){

					mid = (ub + lb) / 2;

					if(mid * (100 + x) / 100 > s - a){

						ub = mid;

					}

					else{

						lb = mid;

					}

				}

				if(lb * (100 + x) / 100 == s - a){

					b2 = lb;

					s2 = (a2 * (100 + y) / 100) + (b2 * (100 + y) / 100);

					if(s2 > res){

						res = s2;

					}

				}

			}

		}

		

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

	}

	return 0;

}

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

using namespace std;



int main() {

	int x, y, s;

	int a, b;

	int p, q, res;



	while (true) {

		scanf("%d%d%d", &x, &y, &s);

		if (x == 0 && y == 0 && s == 0) {

			break;

		}



		res = 0;

		for (a = 1;a < s;a++) {

			p = (100 + x)*a / 100;

			q = s - p;

			if (q > 0) {

				if ((int)100 * q / (100 + x) != (int)100 * (q + 1) / (100 + x)) {

					if ((int)100 * (q + 1) / (100 + x) == (double)100 * (q + 1) / (100 + x)) {

						b = 100 * q / (100 + x);

					}

					else {

						b = 100 * (q + 1) / (100 + x);

					}

					if ((int)a*(100 + y) / 100 + (int)b*(100 + y) / 100 > res) {

						res = (int)a*(100 + y) / 100 + (int)b*(100 + y) / 100;

					}

				}

			}

		}



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

	}



	return 0;

}

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

using namespace std;



int main() {

  int x, y, s;

  while (cin >> x >> y >> s, x) {

    int ans = 0;

    auto f = [](int p, int x) { return p * (100 + x) / 100; };

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

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

        if (f(i, x) + f(j, x) != s) continue;

        ans = max(ans, f(i, y) + f(j, y));

      }

    }

    cout << ans << endl;

  }

  return 0;

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



using namespace std;



int n, k, m, s, ac[1000005],sub[100005],cor,pen;

int main()

{

    cin >> n >> m;

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

    {

        int x;

        char y[5];

        cin >> x >> y;

        if(y[0] == 'A')

        {

            ac[x] = true;

        }

        else if(ac[x] == false)

        {

            ++sub[x];

        }

    }

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

    {

        if(ac[i] == true)

            ++cor, pen += sub[i];

    }

    cout << cor << ' ' << pen;

    return 0;

}


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

#include <map>

#include <string>

using namespace std;

long long n,m,i,p,nra,nrg;

string s;

bool ma[100005];

int nrgr[100005];

int main()

{

    cin>>n>>m;

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

    {

        cin>>p>>s;

        if(s=="AC")

        {

            if(ma[p]==false)

            {

                nra++;

                nrg+=nrgr[p];

            }

            ma[p]=true;

        }

        else

        {

            if(ma[p]==false)

                nrgr[p]++;

        }

    }

    cout<<nra<<' '<<nrg;

}


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

#include <vector>

using namespace std;

int main ()

{

	int n, m, acc=0, pen=0; cin>>n>>m;

	bool test[n+1]={false};

	int arr[n+1]={0};

	int p[m];

	string s[m];

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

	{

		cin>>p[i];

		cin>>s[i];

		if (test [p[i]]==false && s[i]=="AC")

		{

			test[p[i]]=true;

			acc++;

			pen+=arr[p[i]];

		}

		if (test[p[i]]==false && s[i]=="WA")

		{

			arr[p[i]]++;

		}

	}

	cout<<acc<<endl<<pen<<endl;

	return 0;

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



using namespace std;

#define tam 100001

#define infinito 10001

int dp[tam],A[tam],n,k;

int solver(int index)

{

    if(dp[index] != -1)

        return dp[index];

    dp[index] = infinito;

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

    {

        if(dp[index-j] + abs(A[index]-A[index-j]) <  dp[index])

            dp[index] = solver(index-j) + abs(A[index]-A[index-j]);

    }

    return dp[index];

}

int main()

{

    cin>>n>>k;

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

        cin>>A[i];

    memset(dp,-1,sizeof dp);

    dp[0]=0;

    cout<<solver(n-1)<<"\n";

    return 0;

}


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

using namespace std;



const int maxn = 100050;

const int INF = 0x3f3f3f3f;

int a[100050];

int dp[maxn];



int main()

{

	int n,k;

	cin>>n>>k;

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

	    cin>>a[i];

	

	dp[0] = 0,dp[1] = 0;

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

	    dp[i] = INF;

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

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

	}

	

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

using namespace std;

using ll = long long;

using ii = pair<int,int>;



const int mx = 2e5+5;



int n, m;

ll dp[1<<16];

int a[16][16];

ll values[1<<16];



ll fun(int mark){

    if(mark == 0) return 0;



    ll &ans = dp[mark];

    if(~ans) return ans;



    ans = LLONG_MIN;

    for(int cur=mark; cur>0; cur=(cur-1)&mark)

        ans = max(ans, values[cur]+fun(mark ^ cur));

    return ans;

}



int main(){

    cin.tie(nullptr);

    ios_base::sync_with_stdio(0);



    cin >> n;

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

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

            cin >> a[i][j];

    m = (1<<n) - 1;



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

        vector<int> v;

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

            if(i & (1<<j))

                v.push_back(j);

        ll tot = 0;

        for(int j=0; j<v.size(); j++)

            for(int k=j+1; k<v.size(); k++)

                tot += a[v[j]][v[k]];

        values[i] = tot;

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



    ll ans = fun(m);

    cout << ans << "\n";



    return 0;

}




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

using namespace std;

#define int long long

int n, a[20][20], val[100100], f[100000];

main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    cin >> n;

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

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

            cin >> a[i][j];

    int tmp = (1 << n);

    for (int mask = 1; mask < tmp; mask++)

    {

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

            if ((mask >> i) & 1)

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

                    if ((mask >> j) & 1)

                        val[mask] += a[i][j];

    }

    for (int mask = 1; mask < tmp; mask++)

    {

        f[mask] = max(f[mask], val[mask]);

        for (int preMask = mask; preMask > 0; preMask = (preMask - 1) & mask)

            f[mask] = max(f[mask], f[preMask] + f[(mask ^ preMask)]);

    }

    cout << f[tmp - 1];

}


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

#include <algorithm>

#include <vector>

#include <cassert>



using namespace std;





int main() {



  int N;



  cin >> N;

  vector< vector<long long> > A(N, vector<long long>(N));



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

  for (auto j=0;j <N; j++) cin >> A[i][j];



  vector<long long> F( 1<<17, 0);



  // consider all sub sets of {1..N}

  vector<int> l(16, 0);

  for (long long s = 1; s < (1<<N); s++) {

    l.resize(0);



    auto ss= s;

    int c = 0;

    while(ss != 0) {

      if (ss & 1 ) l.push_back(c);

      ss = ss >> 1;

      c++;

    }



    // for (auto tt=0; tt<l.size(); tt++) 

    // cout << "l" << l[tt] << "  ";

    // cout << endl;

    F[s] = 0;

    for (auto i=0; i < l.size(); i++)

    for (auto j=i+1; j < l.size(); j++) F[s] += A[l[i]][l[j]];



    auto L = l.size();



    for (int j = s; j; j = (j-1)&s) {

      F[s] = max( F[s], F[s^j]+F[j]);

    }



    // cout << endl;

  }





  cout << F[ (1<<N)-1] << endl;



  return 0;

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

using namespace std;

typedef long long int ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

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

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

#define reep(i,n) for(ll i = n; i >-1; i--)

#define deb(variable) cout<<#variable<<"="<<variable<<endl

#define MMOD(i) ((i%MOD)+MOD)%MOD;

#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))

const ll INF=99999999999999999;

const ll MOD=128;

const ll MAX_N=500010;

ll a,b,c,d,e,x,y,z,k,m,n,l,q,ans=0;

vl v,v1;

vp p[100010];

string s;

ll solve(void){

    if(v.back()>v1[0])return 0;

    return v1[0]-v.back()+1;

}

int main(){

    cin>>n>>m;

    rep(i,m){

     cin>>a>>b;

     v.push_back(a);

     v1.push_back(b);

    }

 

    sort(v.begin(),v.end());

    sort(v1.begin(),v1.end());

 

    cout<<solve()<<endl;

}

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

using namespace std;

typedef long long int ll;

typedef vector<ll> vl;

typedef pair<ll, ll> PP;

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

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

bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }

bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }

const ll INF = 999999999999999;

const ll MOD = 1000000007;

const ll MAX_N=500010;

ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;

int main() {

    cin>>n>>m;

    x=INF;

    y=0;

    rep(i,m){

        cin>>a>>b;

        x=min(b,x);

        y=max(a,y);

    }



    cout<<max(0LL,x-y+1)<<endl;

}


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

using namespace std;



int main()

{

    int N, M;

    cin >> N >> M;

    int LMax = 1;

    int RMin = N;

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

    {

        int L;

        int R;

        cin >> L >> R;

        LMax = max(LMax, L);

        RMin = min(RMin, R);

    }

    if(RMin + 1 >= LMax)

        cout << RMin - LMax + 1 << endl;

    else

        cout << "0" << endl;

    return 0;

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



using namespace std;



int main()

{

    int n{};

    int k{};

    cin >> n >> k;

    int h{};

    int cnt;

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

        cin >> h;

        if (h>=k)

            ++cnt;

    }

    cout << cnt << endl;

    return 0;

}


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



int main()

{

    int n,k,ans=0;

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

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

    {

        int x;

        scanf("%d",&x);

        if(x>=k)ans++;

    }

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

    return 0;

}

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

using namespace std ;

 

int main()

{

  int n , k , a , answer ;

  cin >> n >> k ;

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

  {

    cin >> a ;

    if(a >= k)

      answer++ ;

  }

  cout << answer << endl ;

}
// Original C++ solution (slower):
//参加気分でさ



#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please





int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, K;

	cin >> N >> K;

	

	int kotae = 0;

	rep(i, N) {

		int H;

		cin >> H;



		if (H >= K) kotae++;

	}



	cout << kotae << endl;





	Would you please return 0;

}

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

#include<cstdio>

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 19;

char cn[cm], * ci = cn;

inline int getint() {

	char C = *ci++;

	int A = C - '0';

	while ((C = *ci++) >= '0') A = A * 10 + C - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);



	fread(cn, 1, cm, stdin);



	int N = getint(), K = getint();

	int kotae = 0;

	rep(i, N) if (getint() >= K) kotae++;

	printf("%d", kotae);



	Would you please return 0;

}

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

using namespace std ;

 

int main()

{

  int n , k , a , answer ;

  cin >> n >> k ;

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

  {

    cin >> a ;

    if(a >= k)

      answer++ ;

  }

  cout << answer << endl ;

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

#include <string>



#define MAXN 1000



using namespace std;



string S, T;



string mov(string str, int N)

{

    string strr = str;

    int i = 0, j;

    while(i < N)

    {

        char c = strr[strr.length() - 1];

        for(j = strr.length() - 1; j >  0; j--)

        {

            strr[j] = strr[j - 1];

        }

        strr[0] = c;

        i++;

    }

    return strr;

}

int main()

{

    cin>>S;

    cin>>T;

    for(int i = 0; i < S.length(); i++ )

    {

        if(mov(S, i) == T)

        {

            printf("Yes\n");

            return 0;

        }

    }

    printf("No\n");

    return 0;

}


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

#include <cstring>

#include <algorithm>

char s[110];

char t[110];



int main(){

    scanf("%s%s", s, t);

    int len1 = strlen(s);

    int len2 = strlen(t);

    if(len1 != len2){

        printf("No\n");

        return 0;

    }

    else{

        int len = len1;

        if(strcmp(s,t) == 0){

            printf("Yes\n");

            return 0;

        }else{



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

                char temp[110];

                strcpy(temp, s);

                std::reverse(temp, temp + len - i);

                std::reverse(temp + len - i, temp + len);

                std::reverse(temp, temp + len);

                if(strcmp(temp, t) == 0){

                    printf("Yes\n");

                    return 0;

                }

            }



        }

    }

    printf("No\n");

    return 0;



}


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

#include<string>

#include<vector>

#include<algorithm>

#include<cmath>

#include<set>

#include<map>

#include<iomanip>



#define INF 1<<29



using namespace std;



int main(void) {

	string s, t;

	cin >> s >> t;

	bool ans = false;

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

		if (s == t) {

			ans = true;

			break;

		}

		s = s.back() + s.substr(0, s.size() - 1);

	}

	if (ans) {

		cout << "Yes";

	}

	else {

		cout << "No";

	}

	return 0;

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

using namespace std;

#define    sz    100110

#define    ll    long long int

ll n,c=0,p,q,k;

ll num[sz];

ll vis[sz];

ll dp[sz];





ll tani(ll pos)

{

    ll mn=100000000000;



    if(pos>=n )return 0;

    if(vis[pos]==1)return dp[pos];



    vis[pos]=1;



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

    {

        mn=min(mn,abs(num[pos]-num[pos+i])+tani(pos+i));

    }

   // cout<<mn<<endl;

    return dp[pos]=mn;

}



int main()

{

    ll t,i;



    for(i=1; i<sz; i++)num[i]=10000000000;



    cin>>n>>k;



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

    {

        cin>>num[i];

    }

    t=tani(1);

    cout<<t<<endl;

    return 0;

}




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

#include<cstring>

#include<algorithm>

#include<cstdio>

using namespace std;

#define MAXN 100000 + 10

#define ll long long int

ll N[MAXN];

ll dp[MAXN];

#define INF 0x3f3f3f3f;

int main()

{

    ll n,k;

    cin>>n>>k;

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

        cin>>N[i],dp[i] = INF;

    dp[0] = 0;

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

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

            if(j >= 0)

            dp[i] = min(dp[i] ,dp[j]+ abs(N[i] - N[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 <bits/stdc++.h>

using namespace std;



int main() {

	long long n, N = 1e5+7, h, q, b, c, s = 0, a[N];

	memset(a, 0, sizeof(a));

	cin >> n;

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

		cin >> h;

		s += h;

		a[h]++;

	}

	cin >> q;

	while(q--){

		cin >> b >> c;

		s += a[b] * (c - b);

		cout << s << '\n';

		a[c] += a[b];

		a[b] = 0;

	}

}

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

using namespace std;

int a[100005];

long long sum1;

int k;

int A,B;

int main()

{

	int x;

	int n;

	cin>>n;

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

	{

		cin>>x;

		a[x]++;

		sum1+=x;

	}

	cin>>k;

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

	{

		cin>>A>>B;

		a[B]+=a[A];

		sum1+=(B-A)*a[A];

		a[A]=0;

		cout<<sum1<<endl;

	}

}

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

using namespace std;

#define ll long long

#include <string>

const int mxN=1e5;

const int maxN=5e3;

#define ld long double

#define pb push_back

#define mp make_pair

#define ins insert

#define vi vector<int>



int main()

{

    int n;

    cin >> n;

    int cnt[100000]={};

    ll s=0;

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

    {

        int x;

        cin >> x;

        cnt[x-1]++;

        s+=x;

    }

    int q;

    cin >> q;

    while(q--)

    {

        int b,c;

        cin >> b >> c;

        s+=cnt[b-1]*(c-b);

        cnt[c-1]+=cnt[b-1];

        cnt[b-1]=0;

        cout << s << "\n";

    }

}
// Original C++ solution (slower):
//g++ -std=gnu++14 a.cpp

//#include <bits/stdc++.h>

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

#include <math.h>



using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main(){

  int  N,K;

  cin >> N >> K;

  vector<int> h(1000000);

  vector<int> dp(1000000, INF);

  for(int i = 1;i <= N;i++) cin >> h.at(i);

  dp[1] = 0;

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

    }

  }

  cout << dp[N] << endl;

}


// Optimized solution to the same problem (faster):
//g++ -std=gnu++14 a.cpp



#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

#include <math.h>



using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main(){

  ll N,K;

  cin >> N >> K;

  vector<ll> h(100010);

  rep(i,N){

    cin >> h[i];

  }

  vector<ll> dp(100010,INFL);

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

    }

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

    //if(i >= 2)dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i]-h[i-2]));

  }

  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;





}