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

#define ll      	long long int

#define PI      	acos(-1)

#define read    	freopen("in.txt","r",stdin)

#define uu      	first

#define vv      	second

#define write   	freopen("out.txt","w",stdout)

#define pii     	pair<int,int>

#define pll         pair<ll,ll>

#define INF     	1e9

#define EPS     	1e-8

#define MAX     	1000006

#define MOD     	1000000007

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

using namespace std;

int n ,k;

ll ara[MAX] ,dp[MAX];



ll solve(int id) {

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

    ll &ret = dp[id];

    if( ret != -1) return ret;



    ret = INF;



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

//        cout<<id<<" "<<i<<endl;

        ret = min(ret , abs(ara[id+i] - ara[id]) + solve(id+i) );

    }

    return ret;

}



int main()

{

    fastRead;

    cin>>n>>k;

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

    memset(dp , - 1, sizeof dp);

    cout<<solve(0)<<endl;

    return 0;

}


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

#define MAX 1000006

#define INF 2e9

using namespace std;

int ara[MAX] , dp[MAX];



int main()

{

    int n , k;

    cin>>n >> k;

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



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



        int val = INF;

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



			if( i - j < 0 ) continue;

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

        }

        dp[i] = val;

	}

	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;

#define ll long long

const int N=100005;

int n,k;

int ar[N];

int mem[N];



int solve(int ind){

    if(ind==n-1){

        return 0;

    }

    if(ind>=n){

        return 1e9;

    }

    if(mem[ind]!=-1){

        return mem[ind];

    }

    int ret=1e9;

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

        ret=min(ret,solve(ind+i)+abs(ar[ind]-ar[ind+i]));

    }

    return mem[ind]=ret;

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(mem,-1,sizeof mem);

    cin>>n>>k;

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

        cin>>ar[i];

    }

    cout<<solve(0)<<endl;

    return 0;

}

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



using namespace std;

#define ll long long



const int INF = 1e9 + 5;



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n,k;

    cin >> n>>k;

    int ar[n];

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

        cin >> ar[i];

    }

    vector<int> dp(n, INF);

    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(dp[j], dp[i] + abs(ar[i] - ar[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>

#define ll long long

using namespace std;

const int maxn = 1e5+5;

int a[maxn], dp[maxn];



int main(){

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

	memset(dp, 0x3f, sizeof dp);

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

	dp[1] = 0;

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

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

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

		}

	}

	cout << dp[n] << endl;

}

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

using namespace std;

int n, k;

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n >> k;

	vector<int>dp(n, INT_MAX);

	vector<int>arr(n);

	//fill(dp.begin(), dp.end(), INT_MAX);

	//int arr[n+5];

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

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

		}

	}

	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;





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

#include<string>

using namespace std;

int main()

{

	int k;cin>>k;

	string s;cin>>s;

	if(s.length()<=k)

	{

		cout<<s<<endl;

	}

	else 

	{

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

		{

			cout<<s[i];

		}

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

	}

}

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

}


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

using namespace std;

long long a[100001],n,k;

int main()

{

	cin>>n>>k;

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

	long long f[100001];

	memset(f, 0x7F, sizeof(f));

	f[1]=0;

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

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

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

	cout<<f[n]<<endl;

	return 0;

}

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

#include<iostream>

#include<cmath>

using namespace std;

const int MAXN = 100010;

const int INF = 0x3f3f3f3f;

int n, k, a[MAXN], f[MAXN];

int main()

{

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

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

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

	f[1] = 0;

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

	{

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

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

	}

		

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

	return 0;

}

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

#define pf push_front

#define ll long long



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    ll x,n,q,sum=0,a,b;

    vector <ll> arr(100005);

    cin>>n;

    

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

        cin>>x;

        sum += x;

        arr[x]++;

    }



    cin>>q;

    while(q--){

        cin>>a>>b;

        sum -= (a*arr[a]);

        sum += (b*arr[a]);

        arr[b] += arr[a];

        arr[a] = 0;



        cout << sum << "\n";

    }

    

    return 0;

}

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

using namespace std;

#define pb push_back

#define pf push_front

#define ll long long



ll arr[100005];



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    ll x,n,q,sum=0,a,b;

   // vector <ll> arr(100005);

    cin>>n;

    

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

        cin>>x;

        sum += x;

        arr[x]++;

    }



    cin>>q;

    while(q--){

        cin>>a>>b;

        sum -= (a*arr[a]);

        sum += (b*arr[a]);

        arr[b] += arr[a];

        arr[a] = 0;



        cout << sum << "\n";

    }

    

    return 0;

}

// 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):
#include<iostream>

using namespace std;



#define MAX 100000



void swap(int& a, int& b)

{

    int c;

    c = a; a = b; b = c;

}



int partition(int* A, int p, int r)

{

    int i, j, x;

    x = A[r];

    i = p - 1;

    for(j = p; j < r; j++){

        if(A[j] <= x){ i++; swap(A[i], A[j]); }

    }

    swap(A[i + 1], A[r]);



    return i + 1;

}



int main()

{

    int i, n, A[MAX], q;

    cin >> n;

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



    q = partition(A, 0, n - 1);



    for(i = 0; i < q; i++){ cout << A[i] << " "; }



    cout << "[" << A[q] << "]";



    for(i = q + 1; i < n; i++){ cout << " " << A[i]; }



    cout << endl;



    return 0;

}

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



#define MAX 100000



void swap(int& a, int& b)

{

    int c;

    c = a; a = b; b = c;

}



int partition(int* A, int p, int r)

{

    int i, j, x;

    x = A[r];

    i = p - 1;

    for(j = p; j < r; j++){

        if(A[j] <= x){ i++; swap(A[i], A[j]); }

    }

    swap(A[i + 1], A[r]);



    return i + 1;

}



int main()

{

    int i, n, A[MAX], q;

    scanf("%d", &n);

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



    q = partition(A, 0, n - 1);



    for(i = 0; i < q; i++){ printf("%d ", A[i]); }



    printf("[%d]", A[q]);



    for(i = q + 1; i < n; i++){ printf(" %d", A[i]); }



    printf("\n");



    return 0;

}

// Fastest known solution for this problem:
#include<stdio.h>

#include<iostream>



#define MAX 100000



int partition(int* A, int p, int r)

{

    int i, j, x;

    x = A[r];

    i = p - 1;

    for(j = p; j < r; j++){

		if(A[j] <= x){ i++; std::swap(A[i], A[j]); }

    }

	std::swap(A[i + 1], A[r]);



    return i + 1;

}



int main()

{

    int i, n, A[MAX], q;

    scanf("%d", &n);

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



    q = partition(A, 0, n - 1);



    for(i = 0; i < q; i++){ printf("%d ", A[i]); }



    printf("[%d]", A[q]);



    for(i = q + 1; i < n; i++){ printf(" %d", A[i]); }



    printf("\n");



    return 0;

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

using namespace std;

#define int long long int



int n; //number of stones

int k; //farthest the frog can jump

vector<int> h; //height of the stones

vector<int> dp; //memorize heck



main(){

	cin >> n >> k;



	dp.assign(n, INT_MAX);

	

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

		int x;

		cin >> x;

		h.push_back(x);

	}



	dp[0] = 0;

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

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

			if(i-j>=0){

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

			}

		}

	}



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

	

}

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

#include <cstring>



using namespace std;



const int maxn = 1e5+5;

int n,K;

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	memset(f,0x3f,sizeof(f));

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

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

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

	}

	f[0] = f[1] = 0;

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

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

			f[i] = min(f[i-k]+abs(h[i],h[i-k]),f[i]);

		}

	}

	printf ("%d\n",f[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;

main()

{

   int i,j,k,l;

    while(cin>>l){

  int x[200000]={0};

    i=0;

    while(1){ i++;

       x[l]++;

       if(x[l]==2) {  break;}

       if(l%2==0) l/=2;

       else l=((3*l)+1);

    }

    cout<<i<<endl;

    } return 0;



}


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

using namespace std;



int main()

{

    map<int,int> mp,mp1;

    int n,c=1;

    cin>>n;

    mp[n]++;

    while(1)

    {

        if(n%2==0){

            n/=2;

            mp[n]++;

            if(mp[n]==2)break;

        }

        else{

            n=n*3 + 1;

            mp[n]++;

            if(mp[n]==2)break;

        }

        c++;

    }

    cout<<c+1<<endl;



    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 main(){



    int n, k;

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

    int num = 0;

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

        int x;

        scanf("%d", &x);

        num += x >= k;

    }

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

}

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

#include<cstring>

using namespace std;



int main()

{long long n,q,k;

 string s;

 while(cin>>k>>s)

 {if(s.size()<=k)

  cout<<s<<endl;

  else

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

 }

return 0;

} 

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

	# include <string.h>

	int main () {

		int a = 0;

		int c =0;

	char name [100];

		scanf ("%d",&a);

		scanf("%s%[^\n]",&name);

		c = strlen (name);

		if (c<=a) {

			printf ("%s",name);

		} else if (c>a) {

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

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

			}

			printf("...");

		}

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

using namespace std;

int main()

{

	string s;

	int n;

	cin>>n>>s;

	int k=s.size();

	if(k<=n)

	cout<<s;

	else

	{

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

		{

			cout<<s[i];

		}

		cout<<"...";

	}

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

#define maxn (int)(2e5)

#define INF 1<<30

#define i64 long long

#define pii pair<i64,i64>

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

#define LB(x,v) lower_bound(all(x), v) - x.begin()

#define fread() freopen("in.txt", "r", stdin);

using namespace std;



int h[maxn+2], dp[maxn+2], n, k;



void init(int n){

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

}



int solve(int cur){

    if(cur >= n) return INF;

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



    if(dp[cur] != INF) return dp[cur];



    //int res = INF;

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

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

    }



    return dp[cur];

}

int main() {

    /*BEFORE SUBMIT, CHECK

    sample i/o format

    statements for debugging are removed/comment out

    global values / stl containers are initialized/cleared for each test (if needed)

    all array size are sufficient

    loop variable or output value doesn't cross min/max limit of input

    // */

    // #ifndef ONLINE_JUDGE

    //     fread();

    // #endif

    

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

        init(n);

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

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

        }

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

    }    

    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;





}