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

#include<cmath>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<iostream>

#include<queue>

#include<string>

#include<map>

#include<set>

#include<stack>

#include<vector>

#define ll long long

#define mt(a) memset(a,0,sizeof(a))

#define MAXI 2000000000

#define PAI pair<int,int>



using namespace std;



ll a[200009], dp[200009];

int main()

{

	int n,k;

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

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

	{

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

		dp[i] = MAXI;

	}

	dp[1] = 0;

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

	{

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

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

	}

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





	return 0;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn=1e5 + 5;

int main()

{

	int dp[maxn];

	int h[maxn];

	int n,k;

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

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

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

		dp[1] = 0;

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

	    	dp[i]=1e9;

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

				if(i==j) break;

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

				}

	}

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

using namespace std;

int main(){

string a,b;

cin>>a>>b;

a=a+a;

 string::size_type idx;

 idx=a.find(b);

if(idx==string::npos){

	cout<<"No"<<endl;

}else

	cout<<"Yes"<<endl;

return 0;

}

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

#include<cstring>



using namespace std;



void exchange(char a[], int left, int right) {

	int i = left, j = right;

	char temp;

	while (i < j) {

		temp = a[i];

		a[i] = a[j];

		a[j] = temp;

		i++;

		j--;

	}

}



void reserve(char a[], int n, int i) {

	exchange(a, 0, i - 1);

	exchange(a, i, n - 1);

	exchange(a, 0, n - 1);

	return;

}



int main() {

	char str[110], str1[110];

	int n, round = 0;

	scanf("%s", str);;

	scanf("%s", str1);

	if (strlen(str) != strlen(str1)) {

		printf("No");

		return 0;

	}

	n = strlen(str);

	while (round <= n) {

		reserve(str, n, 1);

		if (strcmp(str, str1) == 0) {

			printf("Yes");

			return 0;

		}

		round++;

	}

	printf("No");

	return 0;

}

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

#include<string>

#include<vector>

#include<algorithm>

#include<cmath>

#include<set>

#include<map>

#include<iomanip>



#define INF 1<<29



using namespace std;



int main(void) {

	string s, t;

	cin >> s >> t;

	bool ans = false;

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

		if (s == t) {

			ans = true;

			break;

		}

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

	}

	if (ans) {

		cout << "Yes";

	}

	else {

		cout << "No";

	}

	return 0;

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

#include <cstdio>

#include <cstring>

using namespace std;

  

typedef long long llt;

  

const int MaxN = 16;

  

int N, fullSub;

int Log[1 << MaxN];

llt A[MaxN][MaxN];

llt dp[1 << MaxN];

  

void init() {

  scanf("%d", &N); fullSub = (1 << N) - 1;

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

    scanf("%lld", &A[i][j]);

  

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

    Log[i] = Log[i >> 1] + 1;

}

  

inline llt Calc_sum(int S) {

  int st[MaxN], tp = 0;

  llt res = 0;

  

  while (S > 0) {

    st[tp++] = Log[S & -S];

    S -= S & -S;

  }

  

  for (int i = 0; i < tp - 1; ++i) for (int j = i + 1; j < tp; ++j)

    res += A[st[i]][st[j]];

  return res;

}

  

void solve() {

  memset(dp, 0x80, sizeof dp); dp[0] = 0;

  for (int S = 0; S < (1 << N); ++S) {

    int Q = fullSub - S;

    for(int T = Q; T &= Q; --T)

      dp[S | T] = max(dp[S | T], dp[S] + Calc_sum(T));

  }

  

  printf("%lld\n", dp[(1 << N) - 1]);

}

  

int main() {

  init();

  solve();

  return 0;

}

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



const int MaxN = 16;



int N;

int A[MaxN][MaxN];

long long Weight[1 << MaxN];

long long F[1 << MaxN];

bool Vis[1 << MaxN];



template <typename Typ>

inline Typ max(Typ x, Typ y) { return x > y ? x : y; }



void init() {

  scanf("%d", &N);

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

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

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

}



inline long long count(long long s) {

  long long ans = 0;

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

    if (s & (1 << i)) {

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

        if (s & (1 << j))

          ans += A[i][j];

    }

  return ans;

}



long long dfs(int s) {

  if (s == 0) return F[s] = 0;

  if (Vis[s] == true) return F[s];

  Vis[s] = true;

  for (int q = s; q &= s; --q) {

    int t = s &~ q;

    F[s] = max(F[s], dfs(t) + Weight[q]);

  }

  return F[s];

}



void solve() {

  for (int i = 0; i < (1 << N); ++i) Weight[i] = count(i);

  printf("%lld\n", dfs((1 << N) - 1));

}



int main() {

  init();

  solve();

  return 0;

}

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

#include <algorithm>

#include <vector>

#include <cassert>



using namespace std;





int main() {



  int N;



  cin >> N;

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



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

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



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



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

  vector<int> l(16, 0);

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

    l.resize(0);



    auto ss= s;

    int c = 0;

    while(ss != 0) {

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

      ss = ss >> 1;

      c++;

    }



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

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

    // cout << endl;

    F[s] = 0;

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

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



    auto L = l.size();



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

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

    }



    // cout << endl;

  }





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



  return 0;

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

#include<cstring>

#include<string>

using namespace std;

int main(){

	int k;

	cin>>k;

	string str;

	cin>>str;

	int t=str.length();

	if(k>t||k==t){

		cout<<str<<endl;

	}

	else if(k<t){

		string str1=str.substr(0,k);

		cout<<str1<<"...";

	}

	return 0;

}

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

#define PI 3.14159265358979323

#define ll long long int

#define vi vector <int>

#define vl vector <ll>

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

#define pb push_back

 

ll power(ll a, ll b){//a^b

    ll res=1;

    while(b>0){

        if(b&1){res=(res*a);b--;}

        a=(a*a);

        b>>=1;

    }

    return res;

}

vl dp(100005,-1);

vl h(100005);

ll k;

ll jump(ll i){

	if(dp[i]!=-1)

		return dp[i];

	if(i==1){

		dp[1]=0;

		return dp[i];

	}

	ll mi=jump(i-1)+abs(h[i]-h[i-1]);

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

		if(i-j<1)

			break;

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

	}

	dp[i]=mi;

	return dp[i];

} 

 

 

int main(){

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll n;

	cin>>n;

	

	cin>>k;

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

		cin>>h[i];

	cout<<jump(n)<<"\n";

}

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

using namespace std;

#define PI 3.14159265358979323

#define ll long long int

#define vi vector <int>

#define vl vector <ll>

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

#define pb push_back

#define watch(x) cout << (#x) << " is " << (x) << "\n"

#define MOD 1000000007

ll power(ll a, ll b) { //a^b

	ll res = 1;

	while (b > 0) {

		if (b & 1) {res = (res * a); b--;}

		a = (a * a);

		b >>= 1;

	}

	return res;

}

ll n;

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}







int main() {

	

	ll n,k;

	cin>>n>>k;

	vector <ll> a(n);

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

		cin>>a[i];

	vector <ll> dp(n);

	dp[0]=0;

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

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

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

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

	}

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



using namespace std;

int abs(int a) {

	if (a < 0) {

		return -a;

	} else {

		return a;

	}

}

int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	int n, k;

	cin >> n >> k;

	if (n < k) {

		int h1, h2;

		cin >> h1;

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

			cin >> h2;

		}

		cout << abs(h2 - h1);

		return 0;

	}

	vector<int> heights;

	vector<int> costs = {0};

	int h1;

	cin >> h1;

	heights.push_back(h1);

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

		int h2;

		cin >> h2;

		heights.push_back(h2);

		costs.push_back(abs(h2 - h1));

	}

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

		int h2;

		cin >> h2;

		int best_cost = costs.back() + abs(heights.back() - h2);

		heights.push_back(h2);

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

			int cost = costs[costs.size() - j];

			int h1 = heights[costs.size() - j];

			best_cost = min(best_cost, cost + abs(h2 - h1));

		}

		costs.push_back(best_cost);

	}

	cout << costs.back();

	return 0;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn=1e5 + 5;

int main()

{

	int dp[maxn];

	int h[maxn];

	int n,k;

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

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

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

		dp[1] = 0;

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

	    	dp[i]=1e9;

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

				if(i==j) break;

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

				}

	}

	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 ll long long

ll h[100009];

ll dp[100009];

int main() {

    ios::sync_with_stdio(false);

    int n,k;

    cin>>n>>k;

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

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

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

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

        for(int j=i-1;j>=(i-k>0?i-k:1);j--)

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

    }

    cout<<dp[n]<<endl;

    return 0;

}


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

using namespace std;

int arr[100005], memo[100005],k;



int dp(int n){

    if(n==0) return 0;

    if(memo[n]!=-1) return memo[n];

    int cost=1e9;

    for(int i=1; i<=k&&i<=n; ++i) cost=min(dp(n-i)+abs(arr[n]-arr[n-i]),cost);

    return memo[n]=cost;

}



int main(){

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(0);

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

    int n;

    cin>>n>>k;

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

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

    //for(int i=0; i<n; ++i) cout<<memo[i]<<"\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 a[110], b[110];

int main() {

	int n;

	scanf("%d", &n);

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

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

	}

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

		bool is = false;

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

			if (b[j] > j) break;

			if (b[j] == j) {

				a[i] = j;

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

					b[k] = b[k + 1];

				}

				is = true;

				break;

			}

		}

		if (!is) {

			puts("-1");

			return 0;

		}

	}

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

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

	}

}

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

#include<algorithm>

#include<cmath>

#include<queue>

#include<list>

#include<cstdio>

using namespace std;

int A[100005];

int B[100005];

int C[100005];

int book[100005];

int  main()

{

    int n;

    cin>>n;

    long long sum=0;

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

    	{

    		cin>>A[i];

    		sum+=A[i];

    		book[A[i]]++;

    	}

    int m;

    cin>>m;

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

    	{

    		cin>>B[i]>>C[i];

    		sum=sum+book[B[i]]*(C[i]-B[i]);

    		cout<<sum<<endl;

    		book[C[i]] += book[B[i]];

    		book[B[i]]=0;

    	}



    return 0;

}




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

using namespace std;



int num[100050];



int main()

{

	long long sum=0;

	int N,Q,B,C,a;

	scanf("%d",&N);

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

		num[i]=0;

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

	{

		scanf("%d",&a);

		sum+=(long long)a;

		++num[a];

	}

	scanf("%d",&Q);

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

	{

		scanf("%d%d",&B,&C);

		sum+=(long long)(C-B)*num[B];

		num[C]+=num[B];

		num[B]=0;

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

	}

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

using namespace std;



#define pb push_back

#define eb emplace_back

#define mk make_pair

#define fi first

#define sec second

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

#define cc(x)	cout << #x << " = " << x << endl

#define ok		cout << "ok" << endl



typedef pair<int,int> ii;

typedef long long ll;

const int INF = 0x3f3f3f3f;

const double PI = acos(-1.0);



const long long N = 1e5 + 10; 

long long n, k, cost[N];

long long dp[N];



long long pog(long long at, long long n, long long k){

	if(at >= n) return 0;



	long long &r = dp[at];

	if(r != -1) return r;

	

	if(k == 1) r = pog(at+1, n, k) + abs(cost[at+1]-cost[at]);



	if(k != 1){

		long long L = pog(at+1, n, k) + abs(cost[at+1]-cost[at]);

		long long R = pog(at+2, n, k) + abs(cost[at+2]-cost[at]);



		r = min(L, R);



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

			r = min(r, pog(at+i, n, k) + abs(cost[at+i]-cost[at]));

	}	

	return r;

}



int main(){

	ios_base::sync_with_stdio(false);



	memset(dp, -1, sizeof dp);

	cin >>n >>k;



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

		cin >>cost[i];

	

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

		cost[n+i] = INF;



	cout <<pog(1, n, k) <<endl;

	return 0;

}


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

#include <algorithm> 

#include <vector> 



const int inf=0x3f3f3f3f;

using namespace std; 

int main()

{

  ios::sync_with_stdio(false); 

  cin.tie(0); cout.tie(0); 

  int n,k; 

  cin>>n>>k;

  vector <int> a(n);  

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

  vector <int> dp(n, inf); 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]));   

    }

  }

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

using namespace std;

int main ()

{

	int min, num, result{0};

	cin>>num>>min;

	int array;

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

	{

		cin>>array;

		if (array>=min) result++;

	}

	cout<<result;

}

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

using namespace std;



int main()

{

	int k;

	string s1;

	cin >> k;

	cin >> s1;

	if(s1.length() > k)

	{

		s1.erase(k,s1.length());

		s1 = s1 + "...";

	}

	cout << s1 << endl;

	

	

	return 0;

 } 

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

}