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

using namespace std;



int n, k;

vector<int> arr(100004, 0);

vector<int> dp(100004, -1);



int main() {



	cin >> n >> k;

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



	dp[n-1] = 0;

	dp[n-2] = abs(arr[n-1] - arr[n-2]);



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

	{

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

		{

			if(i+j>=n) break;

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

			dp[i] = (dp[i]==-1) ? temp : min(dp[i], temp);

		}

	}



	cout << dp[0] << endl;



	return 0;

}

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

using namespace std;



int main() {

    int n, k;

    cin >> n >> k;



    vector<int> heights(n, 0);

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



    vector<int> dp(n, 0);

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

    {

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

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

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

    }

    

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



    return 0;

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

#include <algorithm>

#include <cstring>

#include <cstdio>

#include <cmath>

#include <cstdlib>



using namespace std;

int gcd(int a, int b)

{

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

}

const int mod = 1e9+7;

int main()

{

    int n;

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

    {

        long long ans = 1;

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

            ans *= i, ans %= mod;

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

    }

    return 0;

}

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

#include <algorithm>

using namespace std;



int main()

{

	int n,i;

	long long sum=1;

	scanf("%d",&n);

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

	{

		sum*=i;

		sum%=(1000000000+7);

	}

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

	return 0;

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

using namespace std;



int main() {

    int n,K;    cin>>n>>K;

    int a[n];

    long long dp[n];

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

    

    dp[0]=0;

    

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

        long long add=1e9;

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

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

        }

        dp[i]= add; 

        

    }

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

    return 0;

}

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



using namespace std;



int main()

{





    int n,m,newval;

    cin >> n>>m;

    newval=m;

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

        newval--;

    }

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

      cout << newval<<" ";

      newval++;

    }

    cout << m <<" ";

    newval=m;

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

        newval++;

        cout << newval<<" ";

    }



    return 0;

}


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

#include<stdio.h>

int main(){



int k,x,i,p,q,r;

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

p=(x-(k-1));

q=(x+(k-2));

r=(x+(k-1));

if(k==1)

{

    printf("%d",x);

}

else{

    for(i=p;i<=q;i++)    

    {

        printf("%d ",i);

    }

    printf("%d",r);

}



return 0;

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

#include <iostream>

#include <math.h>

#include <stdio.h>



#define arrayLength(array) (size_t)((sizeof array) / (sizeof array[0]))



int main() {

  int n = 0, m = 0, x = 0, y = 0, z = 0, a = 0, b = 0;



  char s[255];

  char t;



  //   scanf(" %d %d %d %d", &n, &m, &x, &y);

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

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

    scanf(" %d", &a);

    if (a >= m)

      x += 1;

  }

  printf("%d", x);



  return 0;

}


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

int main(){

	int i,m,k,t=0,cnt=0;

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

	int a[m];

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

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

	}

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

		if(a[i]>a[i+1]){

			t=a[i+1];

			a[i+1]=a[i];

			a[i]=t;

		}

	}

	if(a[m-1]<k){

		printf("0");

	}else{

	

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

		if(a[i]>=k)

		cnt++;

	}

	printf("%d",cnt);

}

	return 0;

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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<cmath>



using namespace std;



int main(){

	int a,b,c;

	scanf("%d%d%d",&a,&b,&c);

	int w=0;

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

		if((i*b+c)%a==0){w=1;break;}

	}

	if(w)printf("YES\n");

	else printf("NO\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.231624530280097x):
#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<bits/stdc++.h>

using namespace std;

int main()

{

    long long a;

    int n,i;

    cin>>n;

    a=1;

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

    a=a*i%1000000007;

    cout<<a<<endl;

    return 0;

}

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

#define ll long long

using namespace std;

const int mod=1e9+7;

ll jc(int x){

    ll ans=1;

    for(int i=1;i<=x;i++) ans*=i,ans%=mod;

    return ans;

}

int main(){

    int n;

    scanf("%d",&n);

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

    return 0;

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



using namespace std;



int main(int argc, char const *argv[])

{

    int n,k,h,s= 0;

    cin >> n >> k;

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

    {

        cin >> h;

        if(h >= k)

            s += 1;

    }

    cout << s;

    return 0;

}


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

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

using namespace std;

#define Me3za() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))

#define endl "\n"

int n,k;

int l;

int arr[100005];

long long mem[100005];

long long solve(int i,long long cur,int prev){

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

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

mem[i]=LLONG_MAX;

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

   long long sol=solve(i+j,arr[i+j],i)+abs(cur-arr[i+j]);

   //cout<<i<<" "<<sol<<" "<<i+j<<" "<<min(k,n-i)<<endl;

   mem[i]=min(sol,mem[i]);

}

return mem[i];

}

int main() {

Me3za();

cin>>n>>k;

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

    cin>>arr[i];

}

memset(mem,-1,sizeof mem);

cout<<solve(0,arr[0],0);

}




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

using namespace std;

const int maxn = 1e5 + 5;

int main(){

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

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

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

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

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

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

		}

	}

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

	return 0;

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

using namespace std;

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

#define endl '\n'

#define ft first

#define sd second

#define pb push_back

#define pob pop_back()

#define pf push_front

#define pof pop_front()

typedef long long ll;

typedef pair<int,int> pii;

typedef pair<char,char> pcc;

typedef pair<long long,long long> pll;



const int MAX=100005;

const int oo=1000000009;

int dp[MAX];



int main() {

    #ifndef LOCAL

    fastIO;

    #endif

    int n,k;

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

    cin >> n >> k;

    int alturas[n];

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

        cin >> alturas[i];

    }

    dp[0]=0;

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

        dp[i]=oo;

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

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

        }

    }

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

    return 0;

}




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



using namespace std;

typedef long long ll;

typedef unsigned long long ull;



const int mod  = 100003;

const int maxn = 1e5+10;



int a[maxn];

int dp[maxn];

int f(int a)

{

	if (a<0)

		a=-a;

	return a;

}

int k;

int solve(int n)

{

	if (dp[n]!=-1)

		return dp[n];

	int ans=1e9;

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

	{

		int tem=solve(n-i)+f(a[n]-a[n-i]);

		ans=min(tem,ans);

	}

	dp[n]=ans;

	return dp[n];

}

int main()

{

	int n;

	cin>>n>>k;

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

		dp[i]=-1;

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

		cin>>a[i];

	dp[1]=0;

	dp[2]=f(a[1]-a[2]);

	cout<<solve(n);

	return 0;

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

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

using namespace std;

typedef long long ll;

const int inf = 1001001001;







int main(){

  int n,k;

  cin >> n >>k;

  vector<int> h(n);

  rep(i,n){

  cin >> h.at(i);

  }

  

  vector<int> dp(1000000, inf);

  

  rep(i,n){

    if(i == 0) {dp.at(i) = 0; continue;}

    rep(j,k+1){

      if(j == 0) {continue;}

      if(i-j < 0){break;}

      dp.at(i) = min(dp.at(i), dp.at(i-j)+abs(h.at(i)-h.at(i-j)));

      //cout << i << " " << dp.at(i)  << endl;

    }

  }

  cout << dp.at(n-1) << endl;

}

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

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

using namespace std;

typedef long long ll;

const int inf = 1001001001;



int main(){

  int n,k;

  cin >> n >> k;

  vector<int> h(n);

  rep(i,n) cin >> h[i];

  int dp[100001];

  rep(i,100001) dp[i] = inf;

  dp[0] = 0; 



  

  rep(i,n) {

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

      if(i+j >= n) continue;

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

    }

  }

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

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

#include<cstring>

#include<cstdio>

using namespace std;

char s[105],ans[105];

int main()

{

	cin>>s;

	int len=strlen(s),tot=0;

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

	{

		if(s[i]=='0')	ans[++tot]='0';

		if(s[i]=='B'&&tot>0)	tot--;

		if(s[i]=='1')	ans[++tot]='1';

	}

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

	{

		cout<<ans[i];

	}

	return 0;

}

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

#include <string.h>



int main(){

	char str[15];

	char str2[15] = {0};

	int x = 0, ctr = 0, j = 0;

	scanf("%s", str);

	

	for(int i =0;i < strlen(str);i++){

		if(str[i] == '0'){

			str2[j++] = '0';

			ctr++;

		}

	    else if(str[i] == '1'){

			str2[j++] = '1';

			ctr++;

		}

        else{

			if(ctr > 0){

			j--;

			str2[j] = '\0';

			ctr--;

		}

		}

	}

	printf("%s", str2);

	return 0;

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

#include<cstring>

#include<cmath>

#include<map>

#include<algorithm>

#include <iostream>

using namespace std;

typedef long long LL;

const  LL MAXN = 1e9+7;

int main(){

	int n;

	LL ans = 1;

	scanf("%d",&n);

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

		ans *= i;

		ans %= MAXN;

	}

	printf("%lld",ans);

	return 0;

}

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

int main(int argc, char *argv[])

{

	int n;

	scanf("%d",&n);

	long long i=1;

	long long cc=1;

	//int flag=0;

	while(n--)

	{i=i*(cc++);i=i%1000000007;}

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

 	//if(flag) printf("\nPrint the answer modulo 109+7.\n");

	return 0;

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

#include <algorithm>

#include <string>

#include <cstring>

#include <iomanip>



using namespace std;

typedef long long ll;

const int maxn=1e6+1111;



int arr[maxn];

int dp[maxn];

int main(){

    int n,k;

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

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

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

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

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

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

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

        }

    }

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

    return 0;

}

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

#include <algorithm>

#include <string>

#include <cstring>

#include <iomanip>



using namespace std;

typedef long long ll;

const int maxn=1e5+1111;



int arr[maxn];

int dp[maxn];

int main(){

    int n,k;

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

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

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

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

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

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

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

        }

    }

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

    return 0;

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

using namespace std;

typedef long long int ll;

#define INF 1LL << 60;



int main() {

  int n, k;

  cin >> n >> k;

  int h[100110];

  for (int i = 0; i < 100010; i++) cin >> h[i];



  ll dp[100110];

  for (int i = 0; i < 100010; i++) dp[i] = INF;



  dp[0] = 0;

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

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

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

    }

  }



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

}


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

using namespace std;



typedef long long int ll;

ll MOD = 1000000007;

ll INFL = 1ll << 60;

ll INF = 1 << 28;



// ====================================================================

int main() {

  // 入力

  int n, k;

  cin >> n >> k;

  vector<int> v(n);

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

    cin >> v[i];

  }



  vector<ll> dp(n);

  for (int i = 0; i < n; i++) dp[i] = INFL;

  dp[0] = 0;

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

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

      if (i - j < 0) break;

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

    }

  }



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

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



using namespace std;



#define endl '\n'

#define tab " "

#define lli long long int

#define pb push_back



void read(){

    string s;

    lli si;



    cin >> si >> s;



    if(s.size() <= si) cout << s;

    else{

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

            cout << s[i];

        }

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

    }



    return;

}



int main(){

    read();

    return 0;

}

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

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

using namespace std;



int main() {

	int n,k;

	cin>>n>>k;

	vector<int>arr(n+1);

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

		cin>>arr[i];

	}

	vector<int>dp(n+1,INT_MAX);

	dp[1]=0;

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

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

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

		}

	}

	cout<<dp[n]<<endl;

	return 0;

}

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

using namespace std;



#define SENTINEL 1200000000



typedef long long hyper;

hyper cnt = 0;



void Merge(int* A, int left, int mid, int right)

{

    int* L; int* R;

    int i, j, k, n1, n2;

    n1 = mid - left;

    n2 = right - mid;



    L = new int [n1 + 1]; R = new int [n2 + 1];

    if(L == NULL || R == NULL) return;



    for(i = 0; i < n1; i++) L[i] = A[i + left];

    for(j = 0; j < n2; j++) R[j] = A[j + mid];



    L[n1] = SENTINEL;

    R[n2] = SENTINEL;

    i = j = 0;



    // sorting.

    for(k = left; k < right; k++){



        if(L[i] <= R[j]){ A[k] = L[i]; i++; }



        else{ A[k] = R[j]; j++; cnt = cnt + n1 - i; } // add n1 - i.

    }

	delete [] L; delete [] R;

}



void MergeSort(int* A, int left, int right)

{

    int mid;

    if(left + 1 < right){

        mid = (left + right) / 2;

        MergeSort(A, left, mid);

        MergeSort(A, mid, right);

        Merge(A, left, mid, right);

    }

}



int main()

{

    int* A;

    int i, n;

    cin >> n;



    A = new int [n];

    if(A == NULL) return 0;



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



    MergeSort(A, 0, n);

    cout << cnt << endl;



    delete [] A;



    return 0;

}

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



#define MAX 200000

#define SENTINEL 1200000000



typedef long long hyper;

hyper cnt = 0;



void Merge(int* A, int left, int mid, int right)

{

    int L[MAX], R[MAX];

    int i, j, k, n1, n2;

    n1 = mid - left;

    n2 = right - mid;

    for(i = 0; i < n1; i++) L[i] = A[i + left];

    for(j = 0; j < n2; j++) R[j] = A[j + mid];



    L[n1] = SENTINEL;

    R[n2] = SENTINEL;

    i = j = 0;



    // sorting.

    for(k = left; k < right; k++){



        if(L[i] <= R[j]){ A[k] = L[i]; i++; }



        else{ A[k] = R[j]; j++; cnt = cnt + n1 - i; } // add n1 - i.

    }

}



void MergeSort(int* A, int left, int right)

{

    int mid;

    if(left + 1 < right){

        mid = (left + right) / 2;

        MergeSort(A, left, mid);

        MergeSort(A, mid, right);

        Merge(A, left, mid, right);

    }

}



int main()

{

    int i, n, A[MAX];

    scanf("%d", &n);

    for(i = 0; i < n; i++) scanf("%d", &A[i]);



    MergeSort(A, 0, n);

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



    return 0;

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

#include <cstdio>  

#include <cstring>  

#include <algorithm>  

#include <cmath>  

#include <string>  

#include <map>  

#include <stack>  

#include <vector>  

#include <set>  

#include <queue>  

#include <string>

#include <iostream>

#include <cstdio>

#include <string>

#include <cstring>

#include <cctype>

#include <map>

#include <cctype>

#include <vector>

#include <cstdlib>

using namespace std;

long long mod = (long long)(1e9 + 7);



int main()

{

	long long  n;

	scanf("%lld", &n);



		long long sum = 1;

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

		{

			sum *= i;

			sum = sum%mod;

		}

		cout << sum%mod << '\n';



	return 0;

	

}

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

#include <algorithm>

using namespace std;



int main()

{

	int n,i;

	long long sum=1;

	scanf("%d",&n);

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

	{

		sum*=i;

		sum%=(1000000000+7);

	}

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

	return 0;

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



typedef   long long  int ll;

typedef  long double ld;

typedef std::vector<ll> vi;

typedef std::vector<std::vector<ll> > vv;



#define MOD 1000000007

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

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

#define mp make_pair

#define pb(x) push_back(x)

#define fi first

#define se second

#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;

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

#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];

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

using namespace std;



const int N = 1e5 + 5;





void solve(){

            ll i,j,n,m,k;

            

            

            cin>>n>>k;

            ll a[n];

            ll mincost[N];

            ms(mincost,0);

            input(a,0,n);

            

            fo(i,1,n)

            {

				ll minn = INT_MAX;

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

				{

					//if(i==n-1)

					//cout<<abs(a[i]-a[j])<<endl;

					minn = min(minn,mincost[j]+abs(a[j]-a[i]));//,mincost[i-2]+abs(a[i-2]-a[i]));

					

				}

				mincost[i] = minn;

			}

			//print(mincost,0,n);

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

            

    

            

						            



















}



int main()

{

    IO;

      ll t=1;

      //cin>>t;





      while(t--)

      {



          solve();

      }

    return 0;

}


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

#define ll long long

using namespace std;



int dp[100005], a[100005];

int n,k;



int solve(int n, int k)

{

    dp[0]=0;

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

    {

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

        {

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

        }

    }

    return dp[n-1];



}

int main()

{

    cin>>n>>k;

    memset(dp, 1000000, sizeof(dp));

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

        cin>>a[i];

    cout<< solve(n,k) <<endl;

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

using namespace std;

const int N = 1e5 + 5;

int n,k;

int a[N];

long long dp[N];



long long f(int idx){

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

  long long &ret = dp[idx];

  if (ret != -1) return ret;

  ret = 1e18;

  for(int i=idx+1; i<=min(idx+k,n-1); i++){

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

  }

  return ret;

}



int main(){

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

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

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

   }

   memset(dp,-1,sizeof dp);

   cout << f(0) << endl;

}

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

using namespace std;

const int N = 1e5 + 5;

int n,k;

int a[N];

int dp[N];



int f(int idx){

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

  int &ret = dp[idx];

  if (ret != -1) return ret;

  ret = 2e9;

  for(int i=idx+1; i<=min(idx+k,n-1); i++){

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

  }

  return ret;

}



int main(){

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

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

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

   }

   memset(dp,-1,sizeof dp);

   cout << f(0) << endl;

}