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

using namespace std;



#define ll long long



int dp[100001];

int n, k, arr[100001];

int pound(int pos)

{

    if (dp[pos] != -1)

        return dp[pos];

    

    int mn = INT_MAX;

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

        mn = min(mn, abs(abs(arr[pos] - arr[pos - i - 1])) + pound(pos - i - 1));

    return dp[pos] = mn;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    cin >> n >> k;

    k = min(n, k);



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

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

        cin >> arr[i];



    dp[0] = 0;

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

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



    cout << pound(n - 1);



    return 0;

}


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

using namespace std;



#define ll long long



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int n, k;

    cin >> n >> k;



    k = min(n, k);



    int arr[n], dp[n];



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

    {

        cin >> arr[i];

        

        if (i < k)

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

    }

    

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

    {

        int mn = INT_MAX;



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

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



        dp[i] =  mn;

    }



    cout << dp[n - 1];



    return 0;

}


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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

using namespace std;

const int N=1e5+1;

int n,k,arr[N],dp[N];    



int calc(int idx){

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

    if(idx>n-1)return 1e5;

    

    if(dp[idx]!=-1)

    return dp[idx];

    

    int mn=1e9+10;

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

        mn=min(mn,abs(arr[idx]-arr[i])+calc(i));



    return dp[idx]=mn;

}



int main(){

cin>>n>>k;

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

cin>>arr[i];



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



cout<<calc(0);

return 0;    

}

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

using namespace std;

const int N=1e5+1;



int main(){

int n,k,arr[N],dp[N];

cin>>n>>k;



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

    cin>>arr[i];

}



dp[0]=0;

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

    int mn=1e9;

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

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

    dp[i]=mn;

}

cout<<dp[n-1];



return 0;    

}

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

#include <cstring>

#include <cstdio>

#include <string>

using namespace std;

int main(){

    string s,t;

    cin >> s >> t;

    if(s.length() != t.length()){

        cout << "No" << endl;

    }

    else{

        int flag = 0;

        for(int i = 0; i < t.length(); i++){

            if(s == t){

                flag = 1;

                break;

            }

            string tmp = "";

            tmp += s[s.length()-1];

            tmp += s;

            tmp.erase(tmp.length()-1);

            s = tmp;

        }

        if(flag) cout << "Yes" << endl;

        else cout << "No" << 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 <bits/stdc++.h>

using ll = long long;

using namespace std;



ll dp[100100];

bool vis[100100];

ll n, k, h[100100];



ll func( int pos ) {

    if (pos == n) return 0;

    if (vis[pos]) return dp[pos];

    vis[pos] = 1;



    ll res = 2e9;

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

        res = min(

            res,

            abs(h[pos] - h[j]) + func(j)

        );

    }   



    return dp[pos] = res;

}





int main() {

    ios::sync_with_stdio(false);

    cin >> n >> k;

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



    cout << func( 1 ) << endl;

    return 0;

}


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

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

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

//比如从k上面跳过来

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

//关键是你k不知道啊

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

//枚举

//dp[1] = 0

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

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

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

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

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

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include <queue>

#include <stack>

#include <vector>

#include <algorithm>



using namespace std;



const int MAXN = 1e5;

int n,k;

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



int CHANGE(int i,int k)//

{

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

	{//从一开始选

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

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

		{

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

			{

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

			}

		}

		return min;

	}

	else

	{

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

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

		{

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

			{

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

			}

		}

		return min;

	}

}



int main()

{

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

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

}

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

using ll = long long;

using namespace std;



ll dp[100100];

bool vis[100100];

ll n, k, h[100100];



int main() {

    ios::sync_with_stdio(false);

    cin >> n >> k;

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



    dp[1] = 0;

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

        ll p = 2e9;

        for (int j = pos - 1; j >= 1 && j >= pos - k; --j)

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

        dp[pos] = p;

    }



    cout << dp[n] << endl;

    return 0;

}


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

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

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

//比如从k上面跳过来

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

//关键是你k不知道啊

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

//枚举

//dp[1] = 0

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

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

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

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

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

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include <queue>

#include <stack>

#include <vector>

#include <algorithm>



using namespace std;



const int MAXN = 1e5;

int n,k;

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



int CHANGE(int i,int k)//

{

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

	{//从一开始选

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

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

		{

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

			{

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

			}

		}

		return min;

	}

	else

	{

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

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

		{

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

			{

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

			}

		}

		return min;

	}

}



int main()

{

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

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

}

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

using namespace std;

int ar[100009][3];

void clr()

{

	int i,j;

	for(i=0; i<=100003; i++)

	{

		ar[i][0]=0;

		ar[i][1]=0;

	}

}

int main()

{

	 string st;

	 clr();

   int ac=0,wa=0,i,j,n,s,id;

   cin>>n>>s;

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

   {

      cin>>id>>st;

      if(ar[id][0]==0 && st=="WA") ar[id][1]++;

      if(ar[id][0]==0 && st=="AC") ar[id][0]=1;

   }



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

   {

   	 if(ar[i][0]==1)

   	 {

   	 	ac++;

   	 	wa+=ar[i][1];

   	 }

   }

   cout<<ac<<" "<<wa<<endl;

   return 0;

   

}

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

#include<iostream>

using namespace std;

int a[100010]={0};

int main()

{

	int n,m,i;

	cin>>n>>m;

	int x=0,y=0;

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

	{

		int s;string ss;

		cin>>s>>ss;

		if(a[s]>=0)

		{

			if(ss=="WA")

			{

				a[s]++;

			}

			else

			{

				x+=a[s];

				a[s]=-1;

				y++;

				

			}

		}

	}

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

}

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

#include <vector>

using namespace std;

int main ()

{

	int n, m, acc=0, pen=0; cin>>n>>m;

	bool test[n+1]={false};

	int arr[n+1]={0};

	int p[m];

	string s[m];

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

	{

		cin>>p[i];

		cin>>s[i];

		if (test [p[i]]==false && s[i]=="AC")

		{

			test[p[i]]=true;

			acc++;

			pen+=arr[p[i]];

		}

		if (test[p[i]]==false && s[i]=="WA")

		{

			arr[p[i]]++;

		}

	}

	cout<<acc<<endl<<pen<<endl;

	return 0;

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



using namespace std;

typedef long long ll;



ll n,arr[100005],mem[100005],k;



ll dp(ll pos){

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

    if(pos>=n)return 10000000000;

    ll res=10000000000;

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

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

        if(i<n)res=min(res,dp(i)+abs(arr[pos]-arr[i]));

    }

    return mem[pos]=res;

}



int main(){

    ios_base::sync_with_stdio(0);

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

    cin>>n>>k;

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

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

    cout<<dp(0);

}

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



using namespace std;

typedef long long ll;



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



int main(){

    ios_base::sync_with_stdio(0);

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

    cin>>n>>k;

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

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

        dp[i]=1000000000;

    }

    dp[0]=0;

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

        for(int j=i-1;j>=(max((ll)0,i-k));j--){

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

        }

    }

    cout<<dp[n-1];

}

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

typedef long long int ll;

#define faster ios_base::sync_with_stdio(0);

#define faster_tie cin.tie(0);

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

#define NL cout<<'\n'



ll n,k,x;

vector<ll>height;

vector <ll> sol(110000,-1);



ll solve(ll x)

{

    if(x==1)

    {

        sol[x]=0;

        return 0;

    }

    if(sol[x]!=-1)return sol[x];

    ll a=INT_MAX;



    for(ll i=x-1;i>x-1-k;i--)

    {

        if(i==0)break;

        a=min(a,solve(i)+abs(height[i]-height[x]));

    }

    sol[x]=a;

    return a;



}





int main()

{

    cin>>n>>k;

    height.push_back(-1);

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

    {

        sol[i]=-1;

    }

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

    {

        cin>>x;

        height.push_back(x);

    }



    ll ans=solve(n);

    cout<<ans;







    return 0;

}


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

using namespace std;

typedef long long int ll;

#define pb push_back

#define mp make_pair



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    ll n,k;

    cin>>n>>k;



    vector<ll>h(n+1);

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

    {

        cin>>h[i];

    }



    vector<ll>cost(n+5);

    cost[1]=0;



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

    {

        ll c=LONG_MAX;

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

        {

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

        }

        cost[i]=c;

    }



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

 

vector<int> vec;

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

 

int back(int i,int k){

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

        if(i+j==vec.size()-1) return abs(vec[i+j]-vec[i]);

    }

    // if(i+2==vec.size()-1) return abs(vec[i+2]-vec[i]);

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

    

    int ans=INT_MAX;

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

        if(i+j<vec.size()){

            ans= min(ans, abs(vec[i+j]-vec[i]) + back(i+j,k));

        }

    }

 

    dp[i]=ans;

    return dp[i];

}

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n,k;

    cin>>n>>k;

    

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

        int a;

        cin>>a;

        vec.push_back(a);

    }

    cout<<back(0,k);

	return 0;

}

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

using namespace std;

 

int mincost(int n ,int k,vector<int>&height)

{

     vector<int>dp(n,INT_MAX);

     dp[0]=0;

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

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

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

          if(i>j)

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

     }

    return dp[n-1];

}

int main(){

    int n,k ;

  cin>>n>>k;

  vector<int>height(n);

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

  {  cin>>height[i];

  }

  cout<<mincost(n,k,height)<<endl;

  

  return 0;

}

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

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





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

#include<cstdio>

#include<cmath>

#include<cstring>

#include<algorithm>

#include<iomanip>

#include<vector>

using namespace std;

int main()

{

	int k,i;

	cin>>k;

	string s;

	cin>>s;

	int len=s.size();

	if(len<=k)cout<<s<<endl;

	else 

	{

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

		{

			cout<<s[i];

		}

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

using namespace std;

int main(){

    int k;

    char s[105];

    cin>>k;cin>>s;

    if(strlen(s)<=k) cout<<s;

    else {

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

            cout<<s[i];

        cout<<"...";

    }

    return 0;

}

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

#include<string.h>

int main(){

	int k;

	char s[105];

	scanf("%d",&k);

	getchar();

	scanf("%s",&s);

	if(strlen(s)>k){

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

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

		}

		printf("...");

		printf("\n");

	}

	else{

		int l = strlen(s);

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

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

		printf("\n");

	}

}

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

}