stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#pragma GCC optimize("O3")



#include <bits/stdc++.h>



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

#define F first

#define S second

#define pii pair<int,int>

#define pll pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define vii vector<pii>

#define read(FILE)  freopen(FILE, "r", stdin);

#define out(FILE) freopen(FILE, "w", stdout);

#define clr(x, y) memset(x,y,sizeof(x));

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

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

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

#define forr(i, m, n) for(int i=m ; i<=n ; i++)

#define endl '\n'

#define pb push_back

#define re return

const int N = 1e5 + 5;

const int OO = 1e9 + 7;

using namespace std;

int n, a[N], k;

int dp[N];



int solve(int i) {

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

    if (i > n - 1) re OO;

    int &res = dp[i];

    if (~res) re res;

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

    if (i < n - 2) {

        forr(j, 2, k) {

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

        }

    }

    re res;

}



int main() {

    IO;

    cin >> n >> k;

    rep(i, 0, n) cin >> a[i];

    memset(dp, -1, sizeof dp);

    cout << solve(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 endl '\n'

#define INF 0x3f3f3f3f



const int N = 1e5;



int dp[N+5];

int arr[N+5];



int main(){



	ios_base::sync_with_stdio(0);

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

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

	arr[0] = arr[1];

	

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

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

		int temp = INF;

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

			if(i-j > 0){ 						

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

			} 

			else break;

		}

		dp[i] = temp;

	}

	

	cout <<dp[n] <<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;



int main()

{





    int k;

    cin>>k;

    string s;

    cin>>s;



    if(s.length()>k)

    {

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

        {

            cout << s[i];

        }

        cout << "...";

    }

    else cout << s << endl;







    return 0;

}


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

#include<string.h>



int main()

{

	int n;

	scanf("%d",&n);

	char str[102];

	scanf("%s",&str);

	int len=strlen(str);

	if(len>n)

	{

		str[n]='.';

		str[n+1]='.';

		str[n+2]='.';

		str[n+3]='\0';

	}

	printf("%s",str);

	return 0;

}

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

using namespace std;

typedef long long ll;

const int mod = 1000000007;

const double PI = acos(-1);



int main()

{

	int k;

	string s;

	cin >> k >> s;

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

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

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

#include <set>

#include <vector>

#include <map>

#include <queue>

#include <stdio.h>

#include <string.h>

#include <algorithm>

#define ll long long



using namespace std;



int n, k, arr[100005];

int dp[100005];



int solve(int i)

{

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

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

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

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

	{

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

	}

	return dp[i];

}



int main()

{

	memset(dp, -1, sizeof dp);

	cin >> n >> k;

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

	cout << solve(0) << '\n';

	return 0;

}

// Optimized solution to the same problem (faster):


#include <bits/stdc++.h>



#define ReadFile freopen("input.txt","r",stdin)

#define WriteFile freopen("output.txt","w",stdout)

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

#define M_PI 3.14159265358979323846

#define mod 1000000007

#define endl "\n"

using namespace std;

using ll = long long;

using lli = long long int;

using ld = long double;





const int N = 5e5 + 6, inf = 2e9;

int n,k;

int arr[N], dp[N];

int main()

{

	MEGA_MIND



		cin >> n >>k;

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

	{

		dp[i] = inf;

		cin >> arr[i];

	}



	dp[0] = 0;

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

	{

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

		{

			if(j<n)

				dp[j] = min(abs(arr[i] - arr[j]) + dp[i], dp[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<iostream>

#include<stdio.h>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<vector>

#include<map>

#include<queue>

#define ll long long

int pos(int n)

{

    if(n<0)

        return 0;

    else

        return n;

}

using namespace std;

int main()

{

    int n;

    cin>>n;

    int a[n],b[n];

    int cnt=0;

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

    {

        cin>>a[i];

    }

    if(a[0]>1)

    {

        cout<<-1<<endl;

    }

    else

    {

        int nn=n;;

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

        {

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

            {

                if(a[j]==j+1)

                {

                    b[cnt++]=a[j];

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

                    {

                        a[k]=a[k+1];

                    }

                    n--;

                    break;

                }

            }

        }

        if(cnt!=nn)

        {

            cout<<-1<<endl;

        }

        else

        {

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

            {

                cout<<b[i]<<endl;

            }

        }

    }

    return 0;

}


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



using namespace std;



int a[101];

int b[101];

int main(){

	int n;

	scanf("%d",&n);

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

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

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

		int o=0;

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

			if(a[j]==j)o=j;

		if(o==0){

			printf("-1\n");

			return 0;

		}

		b[++b[0]]=o;

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

			a[j]=a[j+1];

	}

	for(int i=b[0];i;i--)

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

}

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



#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))



using namespace std;

using ll = long long;

using pii = pair<int, int>;

using pipipii = pair<ll, pair<int, pii>>;



constexpr int MOD = 1'000'000'007;

constexpr int INF = 1'000'000'001;

constexpr ll LLINF = 4'000'000'000'000'000'001;

// constexpr int INF = 2147483647; // 2 * 1e9

// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18



const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};

const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout << fixed << setprecision(10);

    int n;

    cin >> n;

    vector<int> b(n);

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

        cin >> b[i];

    }

    vector<int> ans(n);

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

        for(int j = (int)b.size() - 1; j >= 0; --j){

            if(j+1 == b[j]){

                ans[i] = j+1;

                b.erase(b.begin() + j);

                goto SUCCESS;

            }

        }

        cout << "-1\n";

        return 0;

        SUCCESS:;

    }

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

        cout << ans[i] << "\n";

    }

    return 0;

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

using namespace std;

const int N=2e5+5;



long long arr[N];

int solve()

{

    string s;

    cin>>s;

    int n=s.size();

    stack<char> ans;

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

    {

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

           if (ans.size())

               ans.pop();

       }

       else

           ans.push(s[i]);

    }

    s="";

    while(ans.size())

    {

        s+=ans.top();

        ans.pop();

    }

    reverse(s.begin(), s.end());

    cout<<s;

    return 0;

}



int main()

{

#ifndef ONLINE_JUDGE

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

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

#endif

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



   // int t;

   // cin>>t;

   // while(t--)

        solve();



    return 0;

}

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

#include<string.h>

int main(){

    char G[100], H[100];

    int A=0;

    scanf("%s", G);

    int len=strlen(G);

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

    {

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

        {

            A--;

            if(A<0)

                A=0;

        }

        else

            H[A++]=G[i];

    }

    H[A]='\0';

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

    return 0;

}


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

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

#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

#define pb push_back



using ll = long long;

using namespace std;

using pint = pair<int,int>;

using pll = pair<ll,ll>;

const int INFint = 1e9;

const ll INFll = 1e18;

ll MOD=1e9+7;



ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数

ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数



// aのn乗をMODで割りながら計算する

ll modpow(ll a, ll n) {

  long long res = 1;

  while (n > 0) {

    if (n & 1) res = res * a % MOD;

    a = a * a % MOD;

    n >>= 1; // right shift

  }

  return res;

}



// MODを法としたaの逆元を計算する

ll modinv(ll a) {

  return modpow(a, MOD - 2);

}



int main(){

  string s;

  cin>>s;

  int N = int(s.size());

  string ans;

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

    //cout << ans << endl;

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

      if (int(ans.size()) != 0){

        ans = ans.substr(0,int(ans.size())-1);

      }

    }else{

      ans += s[i];

    }

  }

  cout << ans << endl;

  return 0;

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

#include<cmath>

#include<cstring>

#include<iostream>

#include<algorithm>

#include<cstdlib>

using namespace std;

int N,K,h[100005],dp[100005];

int main(){

	scanf("%d%d",&N,&K);

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

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

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

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

		dp[i] = 0x3f3f3f3f;

		for(int j = K;j >= 1;j--){

		if(i-j>0)

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

		}

	}

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

	return 0;

}

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

#include <algorithm>

#include <cmath>

using namespace std;



int h[(int)1e5], dp[(int)1e5], K, N;





int main()

{

	K = N = 0;

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

	{

		dp[j] = 1e9;

	}

	scanf("%d %d", &N, &K);

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

	{

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

	}

	dp[1] = 0;

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

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

	{

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

		{

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

		}

	}

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

	return 0;	

}


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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

#include<iomanip>

#include<stdio.h>

using namespace std;



int main(){

	int N,K;

	cin>>N>>K;

	int cnt=0;

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

		int t;

		cin>>t;

		if(t>=K)

			cnt++;

	}

	cout<<cnt<<endl;

	return 0;

}

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

int main()

{

    int N,K,h[100000],n,i;

    scanf("%d%d",&N,&K);

    for(i=0,n=0;i<N;i++){

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

    if(h[i]>=K){

        n=n+1;

      }

    }

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

    return 0;

}

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

using namespace std ;

 

int main()

{

  int n , k , a , answer ;

  cin >> n >> k ;

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

  {

    cin >> a ;

    if(a >= k)

      answer++ ;

  }

  cout << answer << endl ;

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

#include<cstring>

using namespace std;

int main()

{

	int n;

	cin>>n;

	string s;

	cin>>s;

	int d=s.length();

	if(d<=n)

    cout<<s;

    else

    {

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

    	cout<<s[i];

	    cout<<"...";

	}

}

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

}

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

using namespace std;



int const N=1e5+5, M=1e9+7, OO = 0x3f3f3f3f;



int n,k;

int arr[N];



int mem[N];

int solve(int i)

{

    if(i==n-1)

        return 0;

    if(mem[i]!=-1)

        return mem[i];

    int ret=OO;

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

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

    return mem[i]=ret;

}





int main()

{

//    freopen("input.txt","rt",stdin);

//    freopen("output.txt","wt",stdout);

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

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

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

    memset(mem, -1, sizeof mem);

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



    return 0;

}


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

using namespace std;

int n,k; vector<int>v;

long long dp[100005];



int main() {

	cin >> n>>k; 

	v.resize(n + 1);

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

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

	dp[1] = 0;

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

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

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

		}

	}

	cout << dp[n];

}

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

using namespace std;

#define ll long long

#define ld long double

#define sf scanf

#define pf printf

#define pb push_back

#define llu unsigned long long

#define U unsigned int

#define SIZE 10000000

#define pie 3.14159265358979323

#define minuss 1e-6

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



#define BIG 100000000000000



ll  lcm(ll a,ll b)

{

    ll GCD=__gcd(a,b);

    ll lcm=(a*b)/GCD;

    return lcm;

}

ll dp[1000005];

ll weight[1000005];

ll total,val;

int main()

{

    cin>>total>>val;

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

        cin>>weight[i];



    weight[0]=SIZE;

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

    {

        dp[i]=BIG;

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

            if(i-j>=1)

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



    }

    cout<<dp[total]<<endl;

    return 0;

}




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

}

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

#include<algorithm>

#include<queue>

using namespace std;

int n,k;

long long ans;

int main()

{

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

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

    {

        ans+=n/b*(b-k);

        if(k>0)ans+=max(0,n%b-k+1);

        else ans+=max(0,n%b-k);

    }

    printf("%lld",ans);

}

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

#include<algorithm>

using namespace std;

int N,K;

long long ans=0;

int main() {

	#ifdef LOACL

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

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

	#endif

	scanf("%d %d",&N,&K);

	if(K==0)ans=1ll*N*N;

	else {

		for(int b=K+1;b<=N;b++) {

			int x1=b-K;

			int x2=N/b;

			int k=N-x2*b;

			if(k>=K)ans+=k-K+1;

			ans+=x1*x2;

		}

	}

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

#include <iostream>

#include <iomanip>

#include <math.h>

#include <string>

using namespace std;

int main () { 

	long long x,y = 1;

	cin >> x;

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

			y = y * i % (1000000007);

		}

	cout << y << endl;

} 			


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

const long long MOD=1e9+7;

int n;

long long ans=1;

int main()

{

	scanf("%d",&n);

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

	printf("%lld",ans);

}

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

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

using namespace std;

using ll = long long;

using P = pair<ll, ll>;

const string ln = "\n";

constexpr int INF = 1001001001;

constexpr int MOD = 1000000007;



int main() {

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  int n;

  cin >> n;



  ll ans = 1;



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

    ans *= i % MOD;

    ans %= MOD;

  }



  cout << ans << ln;



  return 0;

}