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

using namespace std;

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



int f(int n) {

    if (n % 2 == 0) return n / 2;

    else return 3 * n + 1;

}



int main() {

    int s;

    cin >> s;

    int n = 1000000;

    vector<int> a(n);

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

        if (i == 1) a[i] = s;

        else {

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

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

                if (a[j] == a[i]) {

                    cout << i << endl;

                    goto out;

                }

            }

        }

    }

    out:

    return 0;

}

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

using namespace std;

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



int f(int n) {

    if (n % 2 == 0) return n / 2;

    else return 3 * n + 1;

}



int main() {

    int s;

    cin >> s;

    // int n = 1e6+1;

    // vector<int> a(n);

    int prev = s;

    set<int> m;

    m.insert(s);

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

        prev = f(prev);

        if (m.count(prev)) {

            cout << i << "\n";

            break;

        } else {

            m.insert(prev);

        }

    }

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

    //     if (i == 1) {

    //         a[i] = s;

    //     } else {

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

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

    //             if (a[j] == a[i]) {

    //                 cout << i << endl;

    //                 goto out;

    //             }

    //         }

    //     }

    // }

    // out:

    return 0;

}

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



int main()

{

    int s;

    std::cin >> s;

    int list[1000000];

    int index = 0;

    int a_i;

    int a_pre = s;

    list[0] = s;

    index = index + 1;

    bool search_flag = false;

    while( true){

        if ( a_pre % 2 == 0){

            a_i = a_pre / 2;

        } else {

            a_i = 3 * a_pre + 1;

        }

        list[index] = a_i;

        index = index + 1;

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

            if ( list[i] == a_i) {

                search_flag = true;

                break;

            }

        }

        if (search_flag==true){

            break;

        } 

        a_pre = a_i;



    }

    std::cout << index << std::endl;

    return 0;

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

using namespace std;

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

int solve(int idx){

    if(idx >= n - 1)

        return 0;

    int &ans = dp[idx];

    if(ans != -1)

        return ans;

    ans = 1e9;

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

        if(idx + i < n)

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

    }

    return ans;

}

int main()

{

    ios::sync_with_stdio(0);

    cin >> n >> k;

    memset(dp , -1, sizeof dp);

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

        cin >> a[i];

    cout << solve(0) << endl;

    return 0;

}


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

using namespace std;

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

int solve(int idx){

    if(idx >= n - 1)

        return 0;

    int &ans = dp[idx];

    if(ans != -1)

        return ans;

    ans = 1e9;

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

        if(idx + i < n)

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

    }

    return ans;

}

int main()

{

    ios::sync_with_stdio(0);

    cin >> n >> k;

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

        cin >> a[i], dp[i] = 1e9;

    dp[n - 1] = 0;

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

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

            if(i - j > -1)

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

        }

    }

    cout << dp[0] << endl;

    return 0;

}

		

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

# include <cstdio>



using namespace std;



const int inf = 1e9 + 7;

const int N = 1e6 + 5;



int n, k;

long long ans;



int main(){

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



      for(int b = k + 1; b <= n; b ++){

            if(k == 0)

                  ans += max(0, b - k - 1);

            else

                  ans += b - k;

            for(int a = b; a <= n; a += b){

                  int l = a + k, r = a + b - 1;

                  r = min(n, r);

                  ans += max(r - l + 1, 0);

            }

      }



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

}


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

#include <stdlib.h>

#include <string.h>

#include <math.h>



int main () {

    long long int n, k, i, j, ans, c1 ;

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

    ans = 0 ;

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

        if ( i == 0 ) {

            ans = n * n ;

            break ;

        }

        c1 = n / i ;

        ans += ( i - k ) * c1 ;

        j = n % ( c1 * i ) ;

        if ( j - k + 1 > 0 ) {

            ans += j - k + 1 ;

        }

    }

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

    return 0 ;

}


// Fastest known solution for this problem:


#include <iostream>

#include <cstdio>



using namespace std;



int main()

{

    long long n,k;

    long long i,j;

    long long ans;

    while (scanf("%lld%lld",&n,&k)!=EOF)

    {

        ans=0;

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

        {

            j=i+k;

            ans+=(n/j)*i;

            if(n%j-k>=0)

                ans+=n%j-k+1;

        }

        if (k==0)

            ans=n*n;

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

    }

    return 0;

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

#include<string> 



using namespace std; 



int main() 

{

	int k; 

	string s; 

	cin >> k >> s; 



	if(k < s.size()) 

	{

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

			cout << s[i]; 

		cout << "...\n"; 

	}

	else 

	{

		cout << s << "\n"; 

	}



	return 0; 

}

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

typedef long long ll;

using namespace std;

const int N=100010;

int main(){

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

	long long i,j,n,a[N],dp[N],k;

	cin>>n>>k;

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

	dp[0]=0;

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

		dp[i]=abs(a[i]-a[0]);

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

	}

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

		dp[i]=dp[i-k]+abs(a[i]-a[i-k]);

		for(j=i-k+1;j<i;++j) dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);

	}

	cout<<dp[n-1];

}


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

}


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

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

#define pii pair<int,int>

#define ll long long int

#define ull unsigned long long int

#define inf LONG_MAX;

using namespace std;

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

int main()

{

    fast_io

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

        dp[i]=inf;

    cin>>n>>k;

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

        cin>>h[i];

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

    }

    cout<<dp[n]<<endl;

}


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

using namespace std;

#define ll long long

#define mod 10000007



int main()

{

    ll n,k;

    cin>>n;

    cin>>k;

    ll cost[n+1];

    ll dp[n+1];

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

    {

        cin>>cost[i];



    }

    dp[n]=0;

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

    {

        dp[i]=INT_MAX ;

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

        {    if(i+j<=n)

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

            }



        }

    }

    //

    cout<<dp[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>

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

//cout<<fixed<<setprecision(6)<<n<<endl;

// transform(s.begin(), s.end(), s.begin(), ::tolower);

//double PI=3.14159265359,c=0;

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

#define endl '\n'

#define ll long long

//#define f(n) for(int i=;i<n;i++)

double PI = acos(-1);

using namespace std;

void fast()

{

    std::ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

ll arr[100000];

int main()

{

    fast();

    ll n,t,x,mn=0,k;

    cin>>n>>k;

    vector<ll>v(n,1e12);

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

        cin>>arr[i];



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

    {

        x=v[i];

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

        {

           if(i+j+1<n)

           {

                if(i==0)

                    x=0;

                mn=x+abs(arr[i]-arr[i+j+1]);

                v[i+1+j]=min(v[j+i+1],mn);



           }



        }

        //cout<<v[i]<<" ";

    }

    cout<<v[v.size()-1]<<endl;



    return 0;

}


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

#include <algorithm>

#include <vector>

using namespace std;

 

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

int main(){

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

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

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

	}

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

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

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

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

 

#define mp make_pair

#define pb push_back

#define st first

#define nd second

#define lb lower_bound

#define ub upper_bound

 

typedef long long ll;

typedef long double ld;

typedef pair<int,int> pi;

typedef pair<ll,ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<pi> vpi;

typedef vector<pll> vpll;

 

const ll oo=1e18;

const int MOD=1000000007;

const int INF=1000000000;

const ld EPS=0.000000001;

 

int dp[100005],h[100005],n,k=2;

 

signed main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL);

    cout.tie(NULL);

    memset(dp,0x3f3f,sizeof dp);

    dp[1]=0;

    h[0]=0;

    cin>>n>>k;

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

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

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

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

        }

    }

    cout<<dp[n];

    return 0;

}

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

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <sstream>

#include <queue>

#include <deque>

#include <bitset>

#include <iterator>

#include <list>

#include <stack>

#include <map>

#include <set>

#include <functional>

#include <numeric>

#include <utility>



#include <cmath>

#include <iomanip>



using namespace std;



int main()

{

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n;

  cin >> n;

  int k;

  cin >> k;

  int h[n];

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

    int cur;

    cin >> cur;

    h[i] = cur;

  }

  int minCosts[n];

  minCosts[0] = 0;

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

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

    int cur = abs(h[i]-h[i-1])+minCosts[i-1];

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

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

    }

    minCosts[i] = cur;

  }

  cout << minCosts[n-1] << "\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>



#define fr first

#define sc second

#define OK puts("OK");

#define pb push_back

#define mk make_pair

#define ll long long

using namespace std;





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

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



ll a,b;

ll ans;

ll p[N];



 main () {

    cin >> a >> b;



    if (b == 0) {

        cout << a * 1ll * a << endl;

        return 0;

    }

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

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

            p[j] ++;

    }

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

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



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

        ans += (a - i);

        ll x = i - b;



        ans += (i - (p[i] - p[x]) - b);

    }

    cout << ans << endl;

}


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

using namespace std;

const int MAXN = 101010;

typedef long long int LL;

int n, k;

int q[MAXN], p[MAXN];

long long int ans;

int main(){

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

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

        p[i] = n / i;

        q[i] = n % i;

    }

 

    if(k == 0){

        printf("%lld", (LL)n * (LL)n);

        return 0;

    }

 

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

        if(i <= k)

            continue;

        ans += (LL)(i - k) *  p[i];

        ans += q[i] >= k ? q[i] - k + 1 : 0;

    }

    printf("%lld", ans);

 

}


// Fastest known solution for this problem:


#include <iostream>

#include <cstdio>



using namespace std;



int main()

{

    long long n,k;

    long long i,j;

    long long ans;

    while (scanf("%lld%lld",&n,&k)!=EOF)

    {

        ans=0;

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

        {

            j=i+k;

            ans+=(n/j)*i;

            if(n%j-k>=0)

                ans+=n%j-k+1;

        }

        if (k==0)

            ans=n*n;

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

    }

    return 0;

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



using namespace std;



int main(){

    int n, i, k , j;

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

    int height[n+5];

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

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

    }

    int ans = 1e9;

    int dp[n+5];

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

        dp[i] = 1e9;

    }

    dp[1] = 0;

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

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

            if(i > j) dp[i] = min(dp[i], dp[i-j] + abs(height[i] - height[i-j]));

        }

    }

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

    return 0;

}


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

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

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

//比如从k上面跳过来

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

//关键是你k不知道啊

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

//枚举

//dp[1] = 0

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

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

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

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

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

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include <queue>

#include <stack>

#include <vector>

#include <algorithm>



using namespace std;



const int MAXN = 1e5;

int n,k;

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



int CHANGE(int i,int k)//

{

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

	{//从一开始选

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

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

		{

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

			{

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

			}

		}

		return min;

	}

	else

	{

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

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

		{

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

			{

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

			}

		}

		return min;

	}

}



int main()

{

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

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

}

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

#include<cmath>

#include<cstring>

using namespace std;

int h[100005];

int dp[100005];

int main()

{

	int n,k;

	cin>>n>>k;

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

	cin>>h[i];

	memset(dp,0x3f3f3f,sizeof(dp));

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

	dp[1]=0;

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

		int d=0;

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

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

		}

	}	

	cout<<dp[n]<<endl;

}

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

using namespace std;

int main()

{

	int n,x;

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

	int a[n];

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

	{

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

	}

	long long b[n];

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

	{

		b[i]=0x3f3f3f3f;

	}

	b[0]=0;

	b[1]=abs(a[1]-a[0]);

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

	{

		for(int t=1;t<=x;t++)

		{

			if(i-t<0)break;

			b[i]=min(b[i-t]+abs(a[i]-a[i-t]),b[i]);

		}

	}

	printf("%lld",b[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;





}