#include<bits/stdc++.h>
#define maxv 51
using namespace std;
char ss[maxv];
int nex[maxv];
int n,k;

int getNext(char s[],int len){
	int j=0;
	for(int i=1;i<len;i++){
		while(j&&s[i]!=s[j]){
			j=nex[j];
		}
		if(s[i]==s[j]){
			nex[i+1]=++j;
		}
		//nex[i]=j;
	}
	cout<<s;
	return 0;
}
int main(){
	cin>>n>>k;
	cin>>ss;
	int len=strlen(ss);
	getNext(ss,len);
	for(int i=2;i<=k;i++){
		for(int j=nex[len];j<len;j++){
			cout<<ss[j];
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=100010;

char b[N];
int kmp[N];
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	scanf("%s",b+1);
	int len=strlen(b+1);
	int now=0;
	for(int i=2;i<=len;i++)
	{
		while(now&&b[now+1]!=b[i])now=kmp[now];
		if(b[i]==b[now+1])now++;
		kmp[i]=now;
	}
	int ans=kmp[n];
	printf("%s",b+1);
	k--;
	for(int i=1;i<=k;i++)
		for(int j=ans+1;j<=len;j++)
			printf("%c",b[j]);
	return 0;
}
/*
3 4
aba
*/


#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s,s1;
    int n,m,position,i;
    scanf("%d%d",&n,&m);
    cin>>s;
    cout<<s;
    for(i=n-1;i>=0;i--)
        if(s.substr(0,i)==s.substr(n-i,i))
        {
            position=i;
            break;
        }
    s1=s.substr(position);
    for(i=0;i<m-1;i++)
        cout<<s1;
    return 0;

}


#include<iostream>
#include<string>

using namespace std;

int the_next[55];
string strB;

void setNext() {
    the_next[0] = 0;
    int i = 1, j = 0;
    while(i < strB.length()) {
        if(strB[i] == strB[j]) {
            the_next[i++] = ++j;
        } else if(j != 0) {
            j = the_next[j - 1];
        } else {
            the_next[i++] = 0;
        }
    }
}

int main() {
    int n, k;
    cin>>n>>k;
    cin>>strB;
    setNext();
    cout<<strB;
    for (int i = 1; i < k; i++) {
        for (int j = the_next[n-1]; j < n; j++) cout<<strB[j];
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=100010;

char b[N];
int kmp[N];
int main()
{
	int n,k;
	scanf("%d %d",&len,&k);
	scanf("%s",b+1);
	int now=0;
	for(int i=2;i<=len;i++)
	{
		while(now&&b[now+1]!=b[i])now=kmp[now];
		if(b[i]==b[now+1])now++;
		kmp[i]=now;
	}
	int ans=kmp[n];
	printf("%s",b+1);
	k--;
	for(int i=1;i<=k;i++)
		for(int j=ans+1;j<=len;j++)
			printf("%c",b[j]);
	return 0;
}
/*
3 4
aba
*/


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
template <typename T> void read(T &x){
int f=1;x=0;char c=getchar();
for (;!isdigit(c);c=getchar()) if (c=='-') f=-f;
for (; isdigit(c);c=getchar()) x=x*10+c-'0';
x*=f;
}
void write(int x)
{
	if(x/10) write(x/10);
	putchar(x%10+48);
}
void writeln(int x)
{
	write(x);
	putchar('\n');
}
int nxt[N];
string s2;
int k,l2;
void pre()
{
	nxt[1]=0;
	for(int i=2,j=1;i<=l2;)
	{
		if(s2[i]==s2[j])
		{
			nxt[i]=j;
			j++,i++;
		}else
		{
			if(j>1) j-=j-1-nxt[j-1];
			else i++;
		}
	}
}
void kmp()
{
	char ch=s2[1];
	for(int j=1;;)
	{
		putchar(ch);
		if(ch==s2[j])
		{
			j++;
			if(j>l2)
			{
				k--;
				j-=j-1-nxt[j-1];
				if(!k)
				{
					putchar('\n');
					return;
				}
			}
			ch=s2[j];
		}
	}
}
int main()
{
	cin>>l2>>k>>s2;
	s2=' '+s2;
	pre();
	kmp();
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <functional>
#include <math.h>
#include <memory.h>
#include <map>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include<memory>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
int n,k;
string x;
cin>>n>>k>>x;k--;
map<string,bool> m;
for(int i=1;i<n;++i) m[x.substr(n-i,i)]=1;
int maxx=0;
for(int i=1;i<n;++i)if(m[x.substr(0,i)]) maxx=i;
string add=x.substr(maxx);
cout<<x;
while(k--) cout<<add;
return 0;
}


#include<cstdio>
char s[51];
int n,k;
bool F;
int main(){
	scanf("%d%d\n%s",&n,&k,&s);
	for(register int len=1;len<n;len++){
		F=1;
		for(register int i=0;i<n-len;i++){
			if(s[i]!=s[i+len]){
				F=0;
				break;
			}
		}
		if(F){
			printf("%s",s);
			for(register int i=2;i<=k;i++)for(register int j=n-len;j<n;j++)printf("%c",s[j]);
			return 0;
		}
	}
	for(register int i=1;i<=k;i++)printf("%s",s);
}


#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string a;
int n,k;
int f[55];
void get_next()
{
    f[0]=-1;
    for(int i=1;i<n;i++)
    {
        int j=f[i-1];
        while(f[j+1]!=f[i]&&(j>=0))
        {
            j=f[j];
        }
        if(f[j+1]==f[i])
        f[i]=j+1;
        else
        {
            f[i]=-1;
        }

    }

}
int main()
{
    scanf("%d%d",&n,&k);
    cin>>a;
   get_next();
    int p=f[n]+1;
    cout<<a;
    for(int i=1;i<k;i++)
    {
        for(int j=p;j<n;j++)
        cout<<a[j];
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;
char str[3000];
int prefix[3000]={0};
char strswap[3000];
void next(int x){
    int i = 1, j = 0;
    while(i < x){
        if(str[i] == str[j]){
            prefix[i++] = ++j;
        }else if(j != 0){
            j = prefix[j - 1];
        }else{
            prefix[i++] = 0;
        }
    }
}
int main(){
	int m, n;
	cin>>m>>n;
	scanf("%s", str);
	next(m);
	int k = prefix[m - 1];
	int i = 0;
	for(i = 0; i < m ; i++) {
		strswap[i] = str[i];
	}
	n--;
	while(n--) {

		for(int  j = k; j < m; j++ ) {
			strswap[i] = str[j];
			i++;
		}
	}
	cout<<strswap;
	return 0;
}


// luogu-judger-enable-o2
#include <iostream>
#include <cstring>
using namespace std;
int n,p;
char a[500010];
int maxx=0;
int ne[500010];
int main(){
	cin>>n>>p;
	cin>>a;
	for(int i=1,j=-1;i<strlen(a);i++){
		while(j>=0 && a[j+1]!=a[i])j=ne[j];
		if(a[j+1]==a[i])j++;
		ne[i]=j+1;
		maxx=max(maxx,ne[i]);
	}
	for(int i=1;i<=p;i++){
		if(i==1){
			cout<<a;
		}
		else
		for(int j=maxx;j<strlen(a);j++){
			cout<<a[j];
		}
	}
	return 0;
}


#include<cstdio>
#define pritnf printf
#define scnaf scanf
#define retrun return
#define sizoef sizeof
#define inl inline
#define br break
#define con continue
#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))
#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))
#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))
#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))
#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))
#define re register
#define stt struct
#define sl(sl_a) strlen(sl_a)
#define gt(gt_a) goto gt_a
#define infa (0x3f3f3f3f)
#define infb (0x7fffffff)
#define infd (0x7f)
#define abss(abss_x) ((abss_x)>(0)?(abss_x):(-1)*(abss_x))
#define maxx(maxx_a,maxx_b) ((maxx_a)>(maxx_b)?(maxx_a):(maxx_b))
#define minn(a,b) ((a)<(b)?(a):(b))
#define in(in_a) freopen("D:/""/in"in_a".in","r",stdin)
#define out(out_a) freopen("D:/""/out"out_a".out","w",stdout)
typedef long long ll;
typedef int itn,nti,tin,tni,nit;
using namespace std;
const nit maxa=54;
const nit maxb=24;
const nit maxc=34;
const tni maxd=500004;
#include<iostream>

tni l,n,p,t[maxa]={0},ls;
char x[maxa];

tni main()
{
	scanf("%d %d\n",&l,&n);
	fora(i,1,l)
	{
		x[i]=getchar();
	}
	//
	p=0;
	fora(i,2,l)
	{
		while((x[i]!=x[p+1])&&(p>0))
		{
			p=t[p];
		}
		if(x[i]==x[p+1])
		{
			++p;
		}
		//
		t[i]=p;
	}
	//
	ls=l-t[l];
	fora(i,1,n-1)
	{
		fora(j,1,ls)
		{
			pritnf("%c",x[j]);
		}
	}
	fora(i,1,l)
	{
		pritnf("%c",x[i]);
	}
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,k;
string s;
int main(){
	cin>>n>>k;
	cin>>s;
	int pos=0;
	for(int i=0;i<s.size();++i){
		if(s.substr(0,i)==s.substr(n-i,i)) pos=i;
	}
	cout<<s;
	for(int i=1;i<k;i++){
		cout<<s.substr(pos);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
int next1[1000001];
char s[1000001];
inline void get_next(char S[],int len) //求出next数组
{ //next数组是从 S[0到i-1]前子串 的前缀后缀最大值
    int t1=0,t2;
    next1[0]=t2=0;
    while(t1<len)
        if(t2==-1 || S[t1]==S[t2]) //类似于KMP的匹配
            next1[++t1]=++t2;
        else t2=next1[t2];//失配
}
int main(){
	int i;
	scanf("%d %d",&n,&k);
    scanf("%s",s);
    if (n==1)
    {
    	for(i=0;i<k;i++)
	    {
	    	printf("%s",s);
		}
		return 0;
	}
    get_next(s,n);
    printf("%s",s);
    for(i=1;i<k;i++)
    {
    	printf("%s",s[n-1]==s[next1[s[n-1]]]?(s+next1[s[n-1]]+1):(s+next1[s[n-1]])	);
	}
    return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;

const int N=105;
int n,m,next[N];
char c[N];

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while(c>'9'||c<'0')c=getchar();
   	if(c=='-')t=-1,c=getchar();
   	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
   	return s*t;
}

int main(void){
	scanf("%d %d",&n,&m);
	scanf("%s",c);
	printf("%s",c);
	next[0]=-1;
	int k=-1;
	int j=0;
	while(j<n){
		if(c[j]==c[k]||k==-1){
			j++;
			k++;
			next[j]=k;
		}
		else
		k=next[k];
	}
	for(int i=2;i<=m;i++){
		for(int j=next[n];j<n;j++)
		printf("%c",c[j]);
	}
}


#include <iostream>
#include <string.h>
using namespace std;
char t[100];
int n,k,kmp[100];
int main()
{
	cin>>n>>k;
	cin>>t+1;
	int j=0;
	for(int i=2;i<=n;i++)
	{
		if(j!=0&&t[j+1]!=t[i]) j=kmp[j];
		if(t[j+1]==t[i])
		{
			j++;
			//cout<<i;
		}
		kmp[i]=j;
	}
	for(int i=1;i<=n;i++) cout<<t[i];
	k--;
	while(k>0)
	{
		k--;
		for(int i=kmp[n]+1;i<=n;i++)
		{
			cout<<t[i];
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
int n, k;
char a[53];
int ne[53];
int main()
{
	cin >> n >> k;
	cin >> a + 1;
	for (int i = 2, j = 0;i <= n;i++)
	{
		while (a[j + 1] != a[i] && j)   j = ne[j];
		if (a[j + 1] == a[i])     j++;
		ne[i] = j;
	}
	for (int i = 1;i <= n;i++)
		cout << a[i];
	int ans = k - 1;
	while (ans--)
		cout << a+ne[n]+1;
	return 0;
}


#include<cstdio>
using namespace std;
const int N=100005;
int n,k,next[N];
char s[N],ans[N];
bool b[N];
bool bbb(int i){
	int j=0;
	for(;ans[i+j];j++)
		if(ans[i+j]!=s[j])return 0;
	for(;j<n;j++)
		ans[i+j]=s[j];
}
int main(){
	cin>>n>>k>>s;
	for(int i=0,cnt=1;cnt<=k;i++){
		if(!ans[i]){
			for(int j=0;j<n;j++)
				ans[j+i]=s[j];
			cnt++;
		}
		else if(bbb(i))cnt++;
	}
	printf("%s",ans);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int n,k;
string a;

int main()
{
	cin>>n>>k;
	cin>>a;

	int i, j;
	for(i=0,j=a.length()-1;i<a.length()/2 && j>=a.length()/2;i++,j--)
	{
		if(a[i]!=a[j]) break;
	}

	string c=a.substr(i, a.length()-i);

	cout<<a;
	for(j=1;j<k;j++) cout<<c;

	return 0;
}


#include<iostream>
using namespace std;
int n,s,next[51],j,k; char a[51];
void pre()
{
	next[0]=-1; j=-1; k=0;
	while(k<n) {if(j<0||a[k]==a[j]) {j++; k++; next[k]=j;} else j=next[j];}
}
void cc()
{
	for(int i=0; i<n; i++)cout<<a[i];
	for(int i=2; i<=s; i++) {for(int j=next[n]; j<n; j++)cout<<a[j];}
}
int main() {cin>>n>>s>>a; pre(); cc();}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;
string s1,s2;
ll n,m;
const ll maxn=1e6+5;
ll next[maxn],f[maxn],c[maxn],ans;
void fid_next()
{
	next[1]=0;  //i-j+1----i  0abcdefg
	for(ll i=2,j=0;i<=n;i++)
	{
		while(j>0&&s2[i]!=s2[j+1]) j=next[j];
		if(s2[i]==s2[j+1]) j++;
		next[i]=j;
	}
}
/*void fid_f()
{
	for(ll i=1,j=0;i<=s1.size()-1;i++)
	{
		while(j>0&&s1[i]!=s2[j+1]) j=next[j];
		if(s1[i]==s2[j+1]) j++;
		f[i]=j;
		if(f[i]==(s2.size()-1))
		{
			cout<<i-s2.size()+2<<endl;
			j=next[j];
		}
	}
}*/
int main()
{
	cin>>n>>m;
	cin>>s2;
	s2.insert(0,"0");
	fid_next();
	for(ll i=1;i<=m;i++)
	{
		for(ll j=1;j<=n-next[n];j++)
		cout<<s2[j];
	}
	for(ll i=1;i<=next[n];i++) cout<<s2[i];
	return 0;
}


#include<stdio.h>
#include<string.h>

#define maxn  52
char B[maxn];
int p[maxn];
int main()
{
    int n,k;
    scanf("%d%d%s",&n,&k,B+1);
    p[1]=0;
    int j=0;
    for(int i=1;i<n;i++)
    {
        while(B[i+1]!=B[j+1] && j) j=p[j];
        if(B[i+1]==B[j+1]) j++;
        p[i+1]=j;
    }
    printf("%s",B+1);
    for(int i=1;i<k;i++)
        for(int j=p[n]+1;j<=n;j++) printf("%c",B[j]);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string a;
int n,k;
int f[55];
void get_next()
{
    f[0]=-1;
    for(int i=1;i<n;i++)
    {
        int j=f[i-1];
        while(a[j+1]!=a[i]&&(j>=0))
       j=f[j];

        if(a[j+1]==a[i])
        {f[i]=j+1;
        continue;
        }
        f[i]=-1;

    }

}
int main()
{
    scanf("%d%d",&n,&k);
    cin>>a;
   get_next();
    int p=f[n-1]+1;

    cout<<a;
    for(int i=1;i<k;i++)
    {
        for(int j=p;j<n;j++)
        cout<<a[j];
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int f[60],n,k;
char s[60];
void next()
{
	f[0]=-1;
	for(int i=1; i<n; i++)
	{
		int j=f[i-1];
		while(s[j+1]!=s[i]&&(j>=0))
			j=f[j];

		if(s[j+1]==s[i])
		{
			f[i]=j+1;
			continue;
		}
		f[i]=-1;

	}
}
int main()
{
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	printf("%s",s);
	next();
	for(int i=1; i<k; i++)
	{
		for(int j=f[n]; j<n; j++)
			printf("%c",s[j]);
	}
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int n,k,nxt[100],j;
string a;
int main(){
	cin>>n>>k;
	cin>>a;
	for(int i=1;i<n;i++){
		while(j>0&&a[j]!=a[i])j=nxt[j-1];
		if(a[i]==a[j])j++;
		nxt[i]=j;
	}
	cout<<a;
	for(int i=1;i<k;i++){
		for(int h=j;h<n;h++){
			cout<<a[h];
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 200005;
char s1[maxn];
int nex[maxn];
int n, k;
void getnex(char *s,int *ne)
{
	int i = 0, j = -1;
	nex[i] = -1;
	int len = strlen(s1);
	while (i < len)
	{
		if (j == -1 || s1[i] == s1[j])
		{
			i++; j++; nex[i] = j;
		}
		else j = nex[j];
	}
	return;
}
int main()
{
	scanf("%d%d", &n, &k); char temp = getchar();
	for (int i = 0; i < n; ++i)
		scanf("%c", &s1[i]);
	int len = strlen(s1);
	getnex(s1,nex);
	/*for (int i = 0; i <= len; ++i)
		printf("%d ", nex[i]);*///调试
	int maxx = -2;
	for (int i = 1; i <= len; ++i)
		if (nex[i] > maxx)  maxx = nex[i];
	cout << s1;
	for (int i = 1; i < k; ++i)
	{
		for (int j = maxx; j < len; ++j)
			printf("%c", s1[j]);
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N=55;
char s[N],p[N];
int ne[N];
int main()
{
    int n,k;
    cin>>n>>k>>p+1;
    for(int i=2,j=0;i<=n;i++)
    {
        while(j && p[j+1]!=p[i])    j=ne[i];
        if(p[j+1]==p[i])     j++;
        ne[i]=j;
    }
    for(int i=1;i<=n;i++)  cout<<p[i];
    for(int i=1;i<k;i++)
        for(int j=ne[n]+1;j<=n;j++)
            cout<<p[j];
    cout<<endl;
    return 0;
}


#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N=55;
char s[N],p[N];
int ne[N];
int main()
{
    int n,k;
    scanf("%d%d%s",&n,&k,p+1);
    for(int i=2,j=0;i<=n;i++)
    {
        while(j && p[j+1]!=p[i])    j=ne[j];
        if(p[j+1]==p[i])     j++;
        ne[i]=j;
    }
    for(int i=1;i<=n;i++)  printf("%c",p[i]);
    for(int i=1;i<k;i++)
        for(int j=ne[n]+1;j<=n;j++)
            printf("%c",p[j]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define endl '\n'

//__builtin_popcount(n)
ll npr(ll n, ll r)// n!/(n-r)!
{
    ll res = 1;
    for (ll i = n; i>n - r; i--)res *= i;
    return res;
}
ll ncr(ll n, ll r)// n!/r!(n-r)!
{
    if (r>n)return 0;
    if (r * 2> n)r = n - r;
    if (r == 0)return 1;
    ll res = n;
    for (ll i = 2; i <= r; i++)
    {
        res *= (n - i + 1);
        res /= i;
    }
    return res;
}
string to_str( ll n )
{
    stringstream ss;
    ss << n;
    return ss.str();
}
ll to_int(string str)
{
    ll val;
    stringstream stream;
    stream << str;
    stream >> val;
    return val;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll n1, ll n2)
{
    ll m=n1*n2 / gcd(n1, n2);
    return m;
}
string binary( ll n )
{
    string result;
    do result.push_back( '0' + (n & 1) );
    while (n >>= 1);
    reverse( result.begin(), result.end() );
    return result;
}
ll fast_power(ll x, ll y)
{
    if (y == 0)return 1;
    ll temp = fast_power(x, y / 2);
    temp = (temp*temp);
    if (y % 2 != 0)temp = temp*x;
    return temp;
}
bool comp( pair<int,int>v1, pair<int,int>v2)
{
    if(v1.first==v2.first)
    {
        if(v1.second<v2.second)return true;
        else return false;
    }
    return (v1.first>v2.first);
}
//freopen("palindrome.in","r",stdin);freopen("azerah.out", "w", stdout);
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int j=0; j<n; j++)

ll n,x,y,z,c,c1,c2,c3,c4,k,k1,k2,t,arr;
//for(int i=0; i<n; i++)
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0; i<n/2; i++)
    {
        if(s[i]==s[n-i-1])
            c++;
        else break;
    }
    if(c==n/2&&c&1&&s[0]==s[n/2])c++;
    for(int i=0; i<k; i++)
    {
        if(!i)cout<<s;
        else
        {
            for(int j=c; j<n; j++)cout<<s[j];
        }
    }

    return 0;
}
/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define endl '\n'

//__builtin_popcount(n)
ll npr(ll n, ll r)// n!/(n-r)!
{
    ll res = 1;
    for (ll i = n; i>n - r; i--)res *= i;
    return res;
}
ll ncr(ll n, ll r)// n!/r!(n-r)!
{
    if (r>n)return 0;
    if (r * 2> n)r = n - r;
    if (r == 0)return 1;
    ll res = n;
    for (ll i = 2; i <= r; i++)
    {
        res *= (n - i + 1);
        res /= i;
    }
    return res;
}
string to_str( ll n )
{
    stringstream ss;
    ss << n;
    return ss.str();
}
ll to_int(string str)
{
    ll val;
    stringstream stream;
    stream << str;
    stream >> val;
    return val;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll n1, ll n2)
{
    ll m=n1*n2 / gcd(n1, n2);
    return m;
}
string binary( ll n )
{
    string result;
    do result.push_back( '0' + (n & 1) );
    while (n >>= 1);
    reverse( result.begin(), result.end() );
    return result;
}
ll fast_power(ll x, ll y)
{
    if (y == 0)return 1;
    ll temp = fast_power(x, y / 2);
    temp = (temp*temp);
    if (y % 2 != 0)temp = temp*x;
    return temp;
}
bool comp( pair<int,int>v1, pair<int,int>v2)
{
    if(v1.first==v2.first)
    {
        if(v1.second<v2.second)return true;
        else return false;
    }
    return (v1.first>v2.first);
}
//freopen("palindrome.in","r",stdin);freopen("azerah.out", "w", stdout);
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int j=0; j<n; j++)

ll n,x,y,z,c,c1,c2,c3,c4,k,k1,k2,t,arr;
//for(int i=0; i<n; i++)
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0; i<n/2; i++)
    {
        if(s[i]==s[n-i-1])
            c++;
        else break;
    }
    if(c==n/2&&s[0]==s[n/2])c=n-1;
    for(int i=0; i<k; i++)
    {
        if(!i)cout<<s;
        else
        {
            for(int j=c; j<n; j++)cout<<s[j];
        }
    }

    return 0;
}
/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define endl '\n'

//__builtin_popcount(n)
ll npr(ll n, ll r)// n!/(n-r)!
{
    ll res = 1;
    for (ll i = n; i>n - r; i--)res *= i;
    return res;
}
ll ncr(ll n, ll r)// n!/r!(n-r)!
{
    if (r>n)return 0;
    if (r * 2> n)r = n - r;
    if (r == 0)return 1;
    ll res = n;
    for (ll i = 2; i <= r; i++)
    {
        res *= (n - i + 1);
        res /= i;
    }
    return res;
}
string to_str( ll n )
{
    stringstream ss;
    ss << n;
    return ss.str();
}
ll to_int(string str)
{
    ll val;
    stringstream stream;
    stream << str;
    stream >> val;
    return val;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll n1, ll n2)
{
    ll m=n1*n2 / gcd(n1, n2);
    return m;
}
string binary( ll n )
{
    string result;
    do result.push_back( '0' + (n & 1) );
    while (n >>= 1);
    reverse( result.begin(), result.end() );
    return result;
}
ll fast_power(ll x, ll y)
{
    if (y == 0)return 1;
    ll temp = fast_power(x, y / 2);
    temp = (temp*temp);
    if (y % 2 != 0)temp = temp*x;
    return temp;
}
bool comp( pair<int,int>v1, pair<int,int>v2)
{
    if(v1.first==v2.first)
    {
        if(v1.second<v2.second)return true;
        else return false;
    }
    return (v1.first>v2.first);
}
//freopen("palindrome.in","r",stdin);freopen("azerah.out", "w", stdout);
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int j=0; j<n; j++)

ll n,x,y,z,c,c1,c2,c3,c4,k,k1,k2,t,arr;
//for(int i=0; i<n; i++)
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    string s;
    cin>>s;
    c1=(n&1)?n/2+1:n/2;
    for(int i=c1; i<n; i++)
    {
        if(s[i]==s[0])
        {
            x=0;
            for(int j=i; j<n; j++)
            {
                if(s[j]==s[x])
                    c++;
                else
                {
                    c=0;
                    break;
                }
                x++;
            }
            if(!c)break;
        }
    }
    for(int i=0; i<n; i++)
        if(s[i]!=s[0])
        {
            c4=1;
            break;
        }
    if(!c4)c=n-1;
    for(int i=0; i<k; i++)
    {
        if(!i)cout<<s;
        else
        {
            for(int j=c; j<n; j++)cout<<s[j];
        }
    }

    return 0;
}
/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define endl '\n'

//__builtin_popcount(n)
ll npr(ll n, ll r)// n!/(n-r)!
{
    ll res = 1;
    for (ll i = n; i>n - r; i--)res *= i;
    return res;
}
ll ncr(ll n, ll r)// n!/r!(n-r)!
{
    if (r>n)return 0;
    if (r * 2> n)r = n - r;
    if (r == 0)return 1;
    ll res = n;
    for (ll i = 2; i <= r; i++)
    {
        res *= (n - i + 1);
        res /= i;
    }
    return res;
}
string to_str( ll n )
{
    stringstream ss;
    ss << n;
    return ss.str();
}
ll to_int(string str)
{
    ll val;
    stringstream stream;
    stream << str;
    stream >> val;
    return val;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll n1, ll n2)
{
    ll m=n1*n2 / gcd(n1, n2);
    return m;
}
string binary( ll n )
{
    string result;
    do result.push_back( '0' + (n & 1) );
    while (n >>= 1);
    reverse( result.begin(), result.end() );
    return result;
}
ll fast_power(ll x, ll y)
{
    if (y == 0)return 1;
    ll temp = fast_power(x, y / 2);
    temp = (temp*temp);
    if (y % 2 != 0)temp = temp*x;
    return temp;
}
bool comp( pair<int,int>v1, pair<int,int>v2)
{
    if(v1.first==v2.first)
    {
        if(v1.second<v2.second)return true;
        else return false;
    }
    return (v1.first>v2.first);
}
//freopen("palindrome.in","r",stdin);freopen("azerah.out", "w", stdout);
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int j=0; j<n; j++)

ll n,x,y,z,c,c1,c2,c3,c4,k,k1,k2,t,arr;
//for(int i=0; i<n; i++)
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0; i<n/2; i++)
    {
        if(s[i]==s[n-i-1]&&s[i]==s[0])
            c++;
        else break;
    }
    if(c==n/2&&s[0]==s[n/2])c=n-1;
    for(int i=0; i<k; i++)
    {
        if(!i)cout<<s;
        else
        {
            for(int j=c; j<n; j++)cout<<s[j];
        }
    }

    return 0;
}
/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define endl '\n'

//__builtin_popcount(n)
ll npr(ll n, ll r)// n!/(n-r)!
{
    ll res = 1;
    for (ll i = n; i>n - r; i--)res *= i;
    return res;
}
ll ncr(ll n, ll r)// n!/r!(n-r)!
{
    if (r>n)return 0;
    if (r * 2> n)r = n - r;
    if (r == 0)return 1;
    ll res = n;
    for (ll i = 2; i <= r; i++)
    {
        res *= (n - i + 1);
        res /= i;
    }
    return res;
}
string to_str( ll n )
{
    stringstream ss;
    ss << n;
    return ss.str();
}
ll to_int(string str)
{
    ll val;
    stringstream stream;
    stream << str;
    stream >> val;
    return val;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll n1, ll n2)
{
    ll m=n1*n2 / gcd(n1, n2);
    return m;
}
string binary( ll n )
{
    string result;
    do result.push_back( '0' + (n & 1) );
    while (n >>= 1);
    reverse( result.begin(), result.end() );
    return result;
}
ll fast_power(ll x, ll y)
{
    if (y == 0)return 1;
    ll temp = fast_power(x, y / 2);
    temp = (temp*temp);
    if (y % 2 != 0)temp = temp*x;
    return temp;
}
bool comp( pair<int,int>v1, pair<int,int>v2)
{
    if(v1.first==v2.first)
    {
        if(v1.second<v2.second)return true;
        else return false;
    }
    return (v1.first>v2.first);
}
//freopen("palindrome.in","r",stdin);freopen("azerah.out", "w", stdout);
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int j=0; j<n; j++)

ll n,x,y,z,c,c1,c2,c3,c4,k,k1,k2,t,arr;
//for(int i=0; i<n; i++)
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    string s;
    cin>>s;
    c1=(n&1)?n/2+1:n/2;
    for(int i=c1; i<n; i++)
    {
        if(s[i]==s[0])
        {
            x=0;
            for(int j=i; j<n; j++)
            {
                if(s[j]==s[x])
                    c++;
                else
                {
                    c=0;
                    break;
                }
                x++;
            }
            if(c)break;
        }
    }
    for(int i=0; i<n; i++)
        if(s[i]!=s[0])
        {
            c4=1;
            break;
        }
    if(!c4)c=n-1;
    for(int i=0; i<k; i++)
    {
        if(!i)cout<<s;
        else
        {
            for(int j=c; j<n; j++)cout<<s[j];
        }
    }

    return 0;
}
/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define endl '\n'

//__builtin_popcount(n)
ll npr(ll n, ll r)// n!/(n-r)!
{
    ll res = 1;
    for (ll i = n; i>n - r; i--)res *= i;
    return res;
}
ll ncr(ll n, ll r)// n!/r!(n-r)!
{
    if (r>n)return 0;
    if (r * 2> n)r = n - r;
    if (r == 0)return 1;
    ll res = n;
    for (ll i = 2; i <= r; i++)
    {
        res *= (n - i + 1);
        res /= i;
    }
    return res;
}
string to_str( ll n )
{
    stringstream ss;
    ss << n;
    return ss.str();
}
ll to_int(string str)
{
    ll val;
    stringstream stream;
    stream << str;
    stream >> val;
    return val;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll n1, ll n2)
{
    ll m=n1*n2 / gcd(n1, n2);
    return m;
}
string binary( ll n )
{
    string result;
    do result.push_back( '0' + (n & 1) );
    while (n >>= 1);
    reverse( result.begin(), result.end() );
    return result;
}
ll fast_power(ll x, ll y)
{
    if (y == 0)return 1;
    ll temp = fast_power(x, y / 2);
    temp = (temp*temp);
    if (y % 2 != 0)temp = temp*x;
    return temp;
}
bool comp( pair<int,int>v1, pair<int,int>v2)
{
    if(v1.first==v2.first)
    {
        if(v1.second<v2.second)return true;
        else return false;
    }
    return (v1.first>v2.first);
}
//freopen("palindrome.in","r",stdin);freopen("azerah.out", "w", stdout);
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int j=0; j<n; j++)

ll n,x,y,z,c,c1,c2,c3,c4,k,k1,k2,t,arr;
//for(int i=0; i<n; i++)
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=1; i<n; i++)
    {
        if(s[i]==s[0])
        {
            x=0;
            for(int j=i; j<n; j++)
            {
                if(s[j]==s[x])
                    c++;
                else
                {
                    c=0;
                    break;
                }
                x++;
            }
            if(c)break;
        }
    }
    for(int i=0; i<n; i++)
        if(s[i]!=s[0])
        {
            c4=1;
            break;
        }
    if(!c4)c=n-1;
    for(int i=0; i<k; i++)
    {
        if(!i)cout<<s;
        else
        {
            for(int j=c; j<n; j++)cout<<s[j];
        }
    }

    return 0;
}
/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define endl '\n'

//__builtin_popcount(n)
ll npr(ll n, ll r)// n!/(n-r)!
{
    ll res = 1;
    for (ll i = n; i>n - r; i--)res *= i;
    return res;
}
ll ncr(ll n, ll r)// n!/r!(n-r)!
{
    if (r>n)return 0;
    if (r * 2> n)r = n - r;
    if (r == 0)return 1;
    ll res = n;
    for (ll i = 2; i <= r; i++)
    {
        res *= (n - i + 1);
        res /= i;
    }
    return res;
}
string to_str( ll n )
{
    stringstream ss;
    ss << n;
    return ss.str();
}
ll to_int(string str)
{
    ll val;
    stringstream stream;
    stream << str;
    stream >> val;
    return val;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll n1, ll n2)
{
    ll m=n1*n2 / gcd(n1, n2);
    return m;
}
string binary( ll n )
{
    string result;
    do result.push_back( '0' + (n & 1) );
    while (n >>= 1);
    reverse( result.begin(), result.end() );
    return result;
}
ll fast_power(ll x, ll y)
{
    if (y == 0)return 1;
    ll temp = fast_power(x, y / 2);
    temp = (temp*temp);
    if (y % 2 != 0)temp = temp*x;
    return temp;
}
bool comp( pair<int,int>v1, pair<int,int>v2)
{
    if(v1.first==v2.first)
    {
        if(v1.second<v2.second)return true;
        else return false;
    }
    return (v1.first>v2.first);
}
//freopen("palindrome.in","r",stdin);freopen("azerah.out", "w", stdout);
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int j=0; j<n; j++)

ll n,x,y,z,c,c1,c2,c3,c4,k,k1,k2,t,arr;
//for(int i=0; i<n; i++)
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0; i<n/2; i++)
    {
        if(s[i]==s[n-i-1])
            c++;
        else break;
    }
    for(int i=0; i<k; i++)
    {
        if(!i)cout<<s;
        else
        {
            for(int j=c; j<n; j++)cout<<s[j];
        }
    }

    return 0;
}
/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define endl '\n'

//__builtin_popcount(n)
ll npr(ll n, ll r)// n!/(n-r)!
{
    ll res = 1;
    for (ll i = n; i>n - r; i--)res *= i;
    return res;
}
ll ncr(ll n, ll r)// n!/r!(n-r)!
{
    if (r>n)return 0;
    if (r * 2> n)r = n - r;
    if (r == 0)return 1;
    ll res = n;
    for (ll i = 2; i <= r; i++)
    {
        res *= (n - i + 1);
        res /= i;
    }
    return res;
}
string to_str( ll n )
{
    stringstream ss;
    ss << n;
    return ss.str();
}
ll to_int(string str)
{
    ll val;
    stringstream stream;
    stream << str;
    stream >> val;
    return val;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll n1, ll n2)
{
    ll m=n1*n2 / gcd(n1, n2);
    return m;
}
string binary( ll n )
{
    string result;
    do result.push_back( '0' + (n & 1) );
    while (n >>= 1);
    reverse( result.begin(), result.end() );
    return result;
}
ll fast_power(ll x, ll y)
{
    if (y == 0)return 1;
    ll temp = fast_power(x, y / 2);
    temp = (temp*temp);
    if (y % 2 != 0)temp = temp*x;
    return temp;
}
bool comp( pair<int,int>v1, pair<int,int>v2)
{
    if(v1.first==v2.first)
    {
        if(v1.second<v2.second)return true;
        else return false;
    }
    return (v1.first>v2.first);
}
//freopen("palindrome.in","r",stdin);freopen("azerah.out", "w", stdout);
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int j=0; j<n; j++)

ll n,x,y,z,c,c1,c2,c3,c4,k,k1,k2,t,arr;
//for(int i=0; i<n; i++)
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0; i<n/2; i++)
    {
        if(s[i]==s[n-i-1])
            c++;
        else break;
    }
    if(c==n/2&&c&1&&s[0]==s[n/2+1])c++;
    for(int i=0; i<k; i++)
    {
        if(!i)cout<<s;
        else
        {
            for(int j=c; j<n; j++)cout<<s[j];
        }
    }

    return 0;
}
/**

**/


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j=1,count=0;
		while(j<s.length()&&i<s.length()){
			if(s[i]==s[j]){
				if(s[i+1]==s[j+1]&&i<s.length()-1&&j<s.length()-1){
					//cout<<"+"<<endl;
					i++;
					count++;
				}
				if(j==s.length()-1){
					count++;
					break;
				}
				j++;

			}
			else{
				j++;
				i=0;
				count=0;
			}
		}
		//cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j,count=0,flag;
		int mark[50]={0};
		int c=0;
		for(int m=1;m<s.length();m++){
			if(s[m]==s[0]){
				mark[c++]=m;
			}
		}
	//	cout<<c<<endl;
		int con=c;
//		for(int k=0;k<c;k++){
//			cout<<mark[k]<<" ";
//		}
//		cout<<endl;
		if(c==0){
			j=1;
		}
		else{
			c=0;
			j=mark[c];
		}

		while(j<s.length()&&i<s.length()){
			if(s[i]==s[j]){
				if(s[i+1]==s[j+1]&&i<s.length()-1&&j<s.length()-1){
					i++;
					count++;
					//cout<<"1"<<endl;
					j++;
				}
				else if(s[i+1]!=s[j+1]&&(i<s.length()-1)&&(j<s.length()-1)){
					i=0;
					if(c<con){
						j=mark[c++];
					}
					else{
						count=0;
						break;
					}

				//	cout<<"j="<<j<<endl;
				//	j-=count;
					count=0;
				}
				if(j==s.length()-1){
				//	cout<<"2"<<endl;
					count++;
					break;
				}

			}
			else{
				j++;
				i=0;
				count=0;
				//cout<<"no"<<endl;
			}
		}
		//cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j=1,count=0;
		while(j<s.length()){
			if(s[i]==s[j]){
				i++;
				j++;
				count++;
			}
			else{
				j++;
				i=0;
				count=0;
			}
		}
		//cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j=1,count=0;
		while(j<s.length()){
			if(s[i]==s[j]){
				i++;
				j++;
				count++;
				if(s[i+1]!=s[j+1]&&i<s.length()-1&&j<s.length()-1){
					i--;
				}
			//	cout<<"count="<<count<<endl;
			}
			else{
			//	cout<<"no"<<endl;
				j++;
				i=0;
				count=0;
			}
		}
//		if(count!=0){
//			if(s[i]==s[j]){
//				count++;
//			}
//		}

	//	cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j=1,count=0;
		while(j<s.length()){
			if(s[i]==s[j]){
				i++;
				j++;
				count++;
				if(s[i+1]!=s[j+1]&&i<s.length()-1&&j<s.length()-1){
					i--;
					count--;
				}
			//	cout<<"count="<<count<<endl;
			}
			else{
			//	cout<<"no"<<endl;
				j++;
				i=0;
				count=0;
			}
		}
//		if(count!=0){
//			if(s[i]==s[j]){
//				count++;
//			}
//		}

	//	cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j,count=0,flag;
		int mark[50]={0};
		int c=0;
		for(int m=1;m<s.length();m++){
			if(s[m]==s[0]){
				mark[c++]=m;
			}
		}
	//	cout<<c<<endl;
		int con=c;
//		for(int k=0;k<c;k++){
//			cout<<mark[k]<<" ";
//		}
//		cout<<endl;
		if(c==0){
			j=1;
		}
		else{
			c=0;
			j=mark[c];
		}

		while(j<s.length()&&i<s.length()){
			if(s[i]==s[j]){
				if(s[i+1]==s[j+1]&&i<s.length()-1&&j<s.length()-1){
					i++;
					count++;
					//cout<<"1"<<endl;
					j++;
				}
				else if(s[i+1]!=s[j+1]&&(i<s.length()-1)&&(j<s.length()-1)){
					i=0;
					if(c<con){
						j=mark[c++];
					}
					else{
						break;
					}

				//	cout<<"j="<<j<<endl;
				//	j-=count;
					count=0;
				}
				if(j==s.length()-1){
				//	cout<<"2"<<endl;
					count++;
					break;
				}

			}
			else{
				j++;
				i=0;
				count=0;
				//cout<<"no"<<endl;
			}
		}
	//	cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j=1,count=0;
		while(j<s.length()&&i<s.length()){
			if(s[i]==s[j]){
				if(s[i+1]==s[j+1]&&i<s.length()-1&&j<s.length()-1){
					//cout<<"+"<<endl;
					i++;
					count++;
				}
				else if(s[i+1]!=s[j+1]&&(i<s.length()-1)&&(j<s.length()-1)){
				//	cout<<"yes"<<endl;
					i=0;
					count=0;
				}
				if(j==s.length()-1){
					count++;
					//cout<<"yes"<<endl;
					break;
				}
				j++;

			}
			else{
				j++;
				i=0;
				count=0;
				//cout<<"no"<<endl;
			}
		}
		//cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j=1,count=0;
		while(j<s.length()&&i<s.length()){
			if(s[i]==s[j]){
				if(s[i+1]==s[j+1]&&i<s.length()-1&&j<s.length()-1){
					i++;
				}
				if(j==s.length()-1){
					if(count==0){
						count++;
					}
					break;
				}
				//i++;
				j++;
				count++;
			//	cout<<"+"<<endl;
			//	cout<<"count="<<count<<endl;
			}
			else{
			//	cout<<"no"<<endl;
				j++;
				i=0;
				count=0;
			}
		}
//		if(count!=0){
//			if(s[i]==s[j]){
//				count++;
//			}
//		}

	//	cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j=1,count=0;
		while(j<s.length()&&i<s.length()){
			if(s[i]==s[j]){
				if(s[i+1]==s[j+1]&&i<s.length()-1&&j<s.length()-1){
					//cout<<"+"<<endl;
					i++;
					count++;
				}
				if(j==s.length()-1){
//					if(count==0){
//						count++;
//
//					}
					//	cout<<"yes"<<endl;
					break;
				}
				j++;

			}
			else{
				j++;
				i=0;
				count=0;
			}
		}
//		if(count!=0){
//			if(s[i]==s[j]){
//				count++;
//			}
//		}

		//cout<<"count="<<count<<endl;
		for(int p=count+1;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j,count=0,flag;
		int mark[50]={0};
		int c=0;
		for(int m=1;m<s.length();m++){
			if(s[m]==s[0]){
				mark[c++]=m;
			}
		}
//		for(int k=0;k<=c;k++){
//			cout<<mark[k]<<" ";
//		}
		if(c==0){
			j=1;
		}
		else{
			c=0;
			j=mark[c];
		}

		while(j<s.length()&&i<s.length()){
			if(s[i]==s[j]){
				if(s[i+1]==s[j+1]&&i<s.length()-1&&j<s.length()-1){
					i++;
					count++;
					j++;
				}
				else if(s[i+1]!=s[j+1]&&(i<s.length()-1)&&(j<s.length()-1)){
					i=0;
					j=mark[c++];
				//	j-=count;
					count=0;
				}
				if(j==s.length()-1){
					count++;
					break;
				}

			}
			else{
				j++;
				i=0;
				count=0;
				//cout<<"no"<<endl;
			}
		}
	//	cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
	int n,k;
	string s,ss;
	while(cin>>n>>k){
		cin>>s;
		int i=0,j=1,count=0;
		while(j<s.length()){
			if(s[i]==s[j]){
				i++;
				j++;
				count++;
				if(s[i+1]!=s[j+1]&&i<s.length()-1&&j<s.length()-1){
					i--;
					count--;
				}
			//	cout<<"count="<<count<<endl;
			}
			else{
			//	cout<<"no"<<endl;
				j++;
				i=0;
				count=0;
			}
		}
//		if(count!=0){
//			if(s[i]==s[j]){
//				count++;
//			}
//		}

		cout<<"count="<<count<<endl;
		for(int p=count;p<s.length();p++){
			ss.push_back(s[p]);
		}
		cout<<s;
		for( i=1;i<k;i++){
			cout<<ss;
		}
		cout<<endl;
		ss.clear();
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n,k;
    int pos1,pos2;
    int num=0;
    char s[110],ans[110],s1[110];
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    int len=strlen(s+1);
    //rintf("%d!\n",len);
    int maxlen=0;
    for(int l=1;l<len;l++)
    {
        int flag=0;
        pos1=1;pos2=len-l+1;
        for(int o=0;o<l;o++)
        {
            //printf("%d %d %c %c\n",pos1+o,pos2+o,s[pos1+o],s[pos2+o]);
            if(s[pos1+o]!=s[pos2+o])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            maxlen=l;
        }
    }
    maxlen=len-maxlen;
    //printf("%d\n",maxlen);
    strcpy(ans,s+1);
    int j=0;
    for(int i=len-maxlen+1;i<=len;i++)
    {
        s1[j++]=s[i];
    }
    for(int i=0;i<k-1;i++)
    {
        strcat(ans,s1);
    }
    printf("%s\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n,k;
    int pos1,pos2;
    int num=0;
    char s[110],ans[110],s1[110];
    scanf("%d%d",&n,&k);
    gets(s+1);
    int len=strlen(s+1);
    //rintf("%d!\n",len);
    int maxlen=0;
    for(int l=1;l<len;l++)
    {
        int flag=0;
        pos1=1;pos2=len-l+1;
        for(int o=0;o<l;o++)
        {
            //printf("%d %d %c %c\n",pos1+o,pos2+o,s[pos1+o],s[pos2+o]);
            if(s[pos1+o]!=s[pos2+o])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            maxlen=l;
        }
    }
    maxlen=len-maxlen;
    //printf("%d\n",maxlen);
    strcpy(ans,s+1);
    int j=0;
    for(int i=len-maxlen+1;i<=len;i++)
    {
        s1[j++]=s[i];
    }
    for(int i=0;i<k-1;i++)
    {
        strcat(ans,s1);
    }
    printf("%s\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
int n,k;
int pos1,pos2;
int num=0;
char s[110],ans[110],s1[110];
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    //printf("%d!\n",len);
    int maxlen=0;
    for(int l=1;l<len;l++)
    {
        int flag=0;
        pos1=0;pos2=len-l;
        for(int o=0;o<l;o++)
        {
            //printf("%d %d %c %c\n",pos1+o,pos2+o,s[pos1+o],s[pos2+o]);
            if(s[pos1+o]!=s[pos2+o])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            maxlen=l;
        }
    }
    maxlen=len-maxlen;
    //printf("%d\n",maxlen);
    strcpy(ans,s);
    int j=0;
    for(int i=len-maxlen;i<len;i++)
    {
        s1[j++]=s[i];
    }
    for(int i=0;i<k-1;i++)
    {
        strcat(ans,s1);
    }
    printf("%s\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
int n,k;
int pos1,pos2;
int num=0;
char s[110],ans[110],s1[110];
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    //printf("%d!\n",len);
    int maxlen=0;
    for(int l=1;l<len;l++)
    {
        int flag=0;
        pos1=0;pos2=len-l;
        for(int o=0;o<l;o++)
        {
            //printf("%d %d %c %c\n",pos1+o,pos2+o,s[pos1+o],s[pos2+o]);
            if(s[pos1+o]!=s[pos2+o])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            maxlen=l;
        }
    }
    maxlen=len-maxlen;
    printf("%d\n",maxlen);
    strcpy(ans,s);
    int j=0;
    for(int i=len-maxlen;i<len;i++)
    {
        s1[j++]=s[i];
    }
    for(int i=0;i<k-1;i++)
    {
        strcat(ans,s1);
    }
    printf("%s\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(0);
#define PI      3.14159265358979323846/*pi*/
#define MAX     2000000
string s,t;
int a,b,n,k,ans,sum,tmp,cnt,flag;
int main(){
    FastIO;
    cin>>n>>k;
    cin>>s;
    t = s;
    int i,j;
    for(i=0,j=s.size()-1; i<j; i++,j--){
        if(s[i]==s[j])cnt++;
        else break;
    }
    if(s[i-1]==s[j])cnt++;
    //cout<<cnt<<endl;
    s.erase(0, cnt);
    for(int i=1; i<k; i++){
        t += s;
    }
    cout<<t<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(0);
#define PI      3.14159265358979323846/*pi*/
#define MAX     2000000
string s,t,str1,str2;
int i,j,a,b,n,k,ans,sum,tmp,cnt,cnt2=1,flag;
int main(){
    FastIO;
    cin>>n>>k;
    cin>>s;
    t = s;
    for(i=1; i<s.size(); i++){
        if(s[i-1]==s[i])cnt2++;
    }
    //cout<<cnt2<<endl;
    if(cnt2==n){
        k--;
        while(k--){
            t += s[0];
        } return  cout<<t<<endl,0;
    }
    for(i=0,j=s.size()-1; i<j; i++,j--){
        str1 = s.substr (0,i+1);
        str2 = s.substr (j,s.size()-1);
        if(str1==str2)cnt = i+1;
        //cout<<str1<<" "<<str2<<" "<<cnt<<endl;
    }

    //cout<<cnt<<" "<<cnt2<<endl;
    str1 = s.substr(0,cnt);
    while(cnt>0){
        str2 = s.substr (0,cnt);
        if(str1==str2 && s.size()>str1.size())s.erase(0, cnt);
        else break;
    }
    for(int i=1; i<k; i++){
        t += s;
    }
    cout<<t<<endl;
    //cout<<t.size()<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(0);
#define PI      3.14159265358979323846/*pi*/
#define MAX     2000000
string s,t;
int a,b,n,k,ans,sum,tmp,cnt,flag;
int main(){
    FastIO;
    cin>>n>>k;
    cin>>s;
    t = s;
    int i,j;
    char tm = s[0];
    for(i=0,j=s.size()-1; i<j; i++,j--){
        if(s[i]==s[j]&&s[i]==tm)cnt++;
        else break;
    }
    if(s[i-1]==s[j]&&i==j)cnt++;
    //cout<<cnt<<endl;
    s.erase(0, cnt);
    for(int i=1; i<k; i++){
        t += s;
    }
    cout<<t<<endl;
    //cout<<t.size()<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(0);
#define PI      3.14159265358979323846/*pi*/
#define MAX     2000000
string s,ans,str1,str2;
int n,k,cnt;
int main()
{
    FastIO;
    cin>>n>>k;
    cin>>s;
    ans = s;
    for(int i=1; i<n; i++){
        //cout<<s.substr(i)<<" : "<<s.substr(0,n-i)<<endl;
        if(s.substr(i) == s.substr(0, n-i)){
            cnt = n-i;
            break;
        }
    }
    s.erase(0, cnt); k--;
    while(k--){
        ans += s;
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(0);
#define PI      3.14159265358979323846/*pi*/
#define MAX     2000000
string s,t;
int a,b,n,k,ans,sum,tmp,cnt,flag;
int main(){
    FastIO;
    cin>>n>>k;
    cin>>s;
    t = s;
    int i,j;
    char tm = s[0];
    for(i=0,j=s.size()-1; i<j; i++,j--){
        if(s[i]==s[j]&&s[i]==tm)cnt++;
        else break;
    }
    if(s[i-1]==s[j])cnt++;
    //cout<<cnt<<endl;
    s.erase(0, cnt);
    for(int i=1; i<k; i++){
        t += s;
    }
    cout<<t<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(0);
#define PI      3.14159265358979323846/*pi*/
#define MAX     2000000
string s,t;
int a,b,n,k,ans,sum,tmp,cnt,flag;
int main(){
    FastIO;
    cin>>n>>k;
    cin>>s;
    t = s;
    for(int i=0,j=s.size()-1; i<j; i++,j--){
        if(s[i]==s[j])cnt++;
        else break;
    }
    s.erase(0, cnt);
    for(int i=1; i<k; i++){
        t += s;
    }
    cout<<t<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(0);
#define PI      3.14159265358979323846/*pi*/
#define MAX     2000000
string s,t;
int a,b,n,k,ans,sum,tmp,cnt,cnt2=1,flag;
int main(){
    FastIO;
    cin>>n>>k;
    cin>>s;
    t = s;
    int i,j;
    char tm = s[0];
    string tm1,tm2;
    for(i=1; i<s.size(); i++){
        if(s[i-1]==s[i])cnt2++;
    }
    //cout<<cnt2<<endl;
    if(cnt2==n){
        k--;
        while(k--){
            t += s[0];
        } return  cout<<t<<endl,0;
    }
    for(i=0,j=s.size()-1; i<j; i++,j--){
        if(s[i-1]==s[i]&&i)cnt2++;
        string str1 = s.substr (0,i+1);
        string str2 = s.substr (j,s.size()-1);
        //cout<<str1<<" "<<str2<<endl;
        if(str1==str2)cnt = i+1;
    }

    //cout<<cnt<<" "<<cnt2<<endl;
    s.erase(0, cnt);
    for(int i=1; i<k; i++){
        t += s;
    }
    cout<<t<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
string str;
cin>>str;
for(int i=0;i<n;i++){
    if(str[i]==str[0]){
        int p=0;
        int flag=1;
        for(int q=i;q<n;q++){
            if(str[q]!=str[p]){
                flag--;
                break;
            }
            else{p++;
            }
        }
        if(flag){
            for(int e=0;e<k;e++){
                for(int j=0;j<i;j++){
                cout<<str[j];
            }
            }
            for(int j=i;j<n;j++){
                cout<<str[j];
                return 0;
            }
        }

    }
}

for(int r=0;r<n;r++){
    cout<<str;
}

}


#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
    int n,t,k=0,i;
    cin>>n>>t>>s;
    for(i=0;i<n-1;i++)
        if(s.substr(0,i+1)==s.substr(n-i-1))
            k=i+1;
    cout<<s;
    for(i=1;i<t;i++)
        cout<<s.substr(k);
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, i = 0, sol = 0, maxsol = 0, l = 0;
    int a[1000100];
    scanf("%d", &n);
    while(n--){
        scanf("%d", &a[i]);
        if(a[i] == 1)
            sol++;
        else if(a[i] == 0){
            if(sol != 0)
                maxsol = sol;
            sol = 0;
        }
        if(n == 0){
            if(a[i] == 1){
                while(a[l] == 1){
                    sol++;
                    if(sol >= maxsol)
                        maxsol = sol;
                    l++;
                }
                if(sol >= maxsol)
                        maxsol = sol;
            }
        }
        i++;
    }
    printf("%d", maxsol);
    return 0;
}


#include<stdio.h>
main()
{
 long long int n;
 scanf("%lld", &n);
 long long int a[n],i, br=0, max=-1111;
 for(i=0;i<n;i++)
 scanf("%lld", &a[i]);
 if(a[n-1]==1 && a[0]==1)
 {
         //     printf("as");
              for(i=n-1;i>=0;i--)
              {
              if(a[i]==0)
              break;
              br++;
              }
              for(i=0;i<n;i++)
              {
                              if(a[i]==0)
              break;
              br++;
                              }
              }

              if(br>max)
              max=br;
              br=0;
              for(i=0;i<n;i++)
              {
                              if(a[i]==0)
                              {
                                         if(br>max)
                                         max=br;
                                         br=0;
                                         }
                                         if(a[i]==1)
                                         br++;
                                         if(br>max)
                                         max=br;
                              }
                              printf("%lld", max);
   return 0;
      }


#include<stdio.h>
main()
{
 long long int n;
 scanf("%lld", &n);
 long long int a[n],i, br=0, max=-1111;
 for(i=0;i<n;i++)
 scanf("%lld", &a[i]);
 if(a[n-1]==1 && a[0]==1)
 {
         //     printf("as");
              for(i=n-1;i>=0;i--)
              {
              if(a[i]==0)
              break;
              br++;
              }
              for(i=0;i<n;i++)
              {
                              if(a[i]==0)
              break;
              br++;
                              }
              }

              if(br>max)
              max=br;
              br=0;
              for(i=0;i<n;i++)
              {
                              if(a[i]==0)
                              {
                                         if(br>max)
                                         max=br;
                                         br=0;
                                         }
                                         if(a[i]==1)
                                         br++;
                              }
                              printf("%lld", max);
   system("pause");
      }


#include<stdio.h>
main()
{
 long long int n;
 scanf("%lld", &n);
 long long int a[n],i, br=0, max=-1111;
 for(i=0;i<n;i++)
 scanf("%lld", &a[i]);
 if(a[n-1]==1 && a[0]==1)
 {
         //     printf("as");
              for(i=n-1;i>=0;i--)
              {
              if(a[i]==0)
              break;
              br++;
              }
              for(i=0;i<n;i++)
              {
                              if(a[i]==0)
              break;
              br++;
                              }
              }

              if(br>max)
              max=br;
              br=0;
              for(i=0;i<n;i++)
              {
                              if(a[i]==0)
                              {
                                         if(br>max)
                                         max=br;
                                         br=0;
                                         }
                                         if(a[i]==1)
                                         br++;
                              }
                              printf("%lld", max);
   return 0;
      }


#include <stdio.h>
#include <stdlib.h>

int main() {
    int n, r, l, i, *arr;
    scanf("%d", &n);
    arr = (int*) malloc(sizeof(int));
    for (i = 0; i < n; i++) {
        scanf("%d", arr+i);
    }
    for (i = r = l = 0; i < n * 2; i++) {
        if (arr[i % n]) {
            l++;
            r = r < l? l : r;
        } else {
            l = 0;
        }
    }
    printf("%d", r);
}


#include <stdio.h>
#include <stdlib.h>

int main() {
    int n, r, l, i, *arr;
    scanf("%d", &n);
    arr = (int*) malloc(sizeof(int)*n);
    for (i = 0; i < n; i++) {
        scanf("%d", arr+i);
    }
    for (i = r = l = 0; i < n * 2; i++) {
        if (arr[i % n]) {
            l++;
            r = r < l? l : r;
        } else {
            l = 0;
        }
    }
    printf("%d", r);
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,k,num[1000000],length,ans,mainans,l,start,start2,m;
    scanf("%d",&length);
    j=0;
    ans=0;
    start=0;
    start2=1;
    for (i=0;i<length ;i++ )
    {
        scanf("%d",&num[i]);
    }
    /*for (i=0;i<length ;i++ )
    {
        printf("%d ",num[i]);
    }*/
    for (i=0;i<length ;i++ )
    {
        j=0;
        if(num[i]!=1){
            start2=1;
        }
        if(num[i]==1&&start2==0){

            continue;
        }
        if(num[i]==1&&start2==1){
            j++;
            start2=0;
        for (k=i;k<length ;k++ )
        {
            l=k+1;
            m=k;
            if(l==length){
                l=0;
                start2=1;
                k=-1;

            }
            if(num[m]==num[l]){
               j++;
            }
            if(num[m]!=num[l]){
                    if(start==0){
                        ans=j;
                        //printf("j=%d, ans is %d",j,ans);
                        start=1;
                    }
                if(ans<j){
                    ans=j;
                }
                break;
            }
        }
        }
    }
    printf("%d",ans);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,k,num[10000000],length,ans,mainans,l,start,start2,m;
    scanf("%d",&length);
    j=0;
    ans=0;
    start=0;
    start2=1;
    for (i=0;i<length ;i++ )
    {
        scanf("%d",&num[i]);
    }
    /*for (i=0;i<length ;i++ )
    {
        printf("%d ",num[i]);
    }*/
    for (i=0;i<length ;i++ )
    {
        j=0;
        if(num[i]!=1&&start2==0){
            start2=1;
        }
        if(num[i]==1&&start2==0){

            continue;
        }
        if(num[i]==1&&start2==1){
            j++;
            start2=0;
        for (k=i;k<length ;k++ )
        {
            l=k+1;
            m=k;
            if(l==length){
                l=0;
                start2=1;
                k=-1;

            }
            if(num[m]==num[l]){
                //printf("k=%d ",num[k]);
               // printf("l=%d",num[l]);
               j++;
               //printf("j=%d",j);
            }
            if(num[m]!=num[l]){
                    if(start==0){
                        ans=j;
                        //printf("j=%d, ans is %d",j,ans);
                        start=1;
                    }
                if(ans<j){
                    ans=j;
                }
                break;
            }
        }
        }
    }
    printf("%d",ans);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,k,num[1000000],length,ans,mainans,l,start,start2,m;
    scanf("%d",&length);
    j=0;
    ans=0;
    start=0;
    start2=1;
    for (i=0;i<length ;i++ )
    {
        scanf("%d",&num[i]);
    }
    /*for (i=0;i<length ;i++ )
    {
        printf("%d ",num[i]);
    }*/
    for (i=0;i<length ;i++ )
    {
        j=0;
        if(num[i]!=1){
            start2=1;
        }
        if(num[i]==1&&start2==0){

            continue;
        }
        if(num[i]==1&&start2==1){
            j++;
            start2=0;
        for (k=i;k<length ;k++ )
        {
            l=k+1;
            m=k;
            if(l==length){
                l=0;
                //start2=1;
                k=-1;

            }
            if(num[m]==num[l]){
               j++;
            }
            if(num[m]!=num[l]){
                    if(start==0){
                        ans=j;
                        //printf("j=%d, ans is %d",j,ans);
                        start=1;
                    }
                if(ans<j){
                    ans=j;
                }
                break;
            }
        }
        }
    }
    printf("%d",ans);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,k,num[100000],length,ans,mainans,l,start,start2,m;
    scanf("%d",&length);
    j=0;
    ans=0;
    start=0;
    start2=0;
    for (i=0;i<length ;i++ )
    {
        scanf("%d",&num[i]);
    }
    /*for (i=0;i<length ;i++ )
    {
        printf("%d ",num[i]);
    }*/
    for (i=0;i<length ;i++ )
    {
        j=0;
        start2=0;
        if(num[i]==1){
            j++;
        for (k=i;k<length ;k++ )
        {
            l=k+1;
            m=k;
            if(l==length){
                l=0;
                start2=1;
                k=-1;

            }
            if(num[m]==num[l]){
                //printf("k=%d ",num[k]);
               // printf("l=%d",num[l]);
               j++;
               //printf("j=%d",j);
            }
            if(num[m]!=num[l]){
                    if(start==0){
                        ans=j;
                        //printf("j=%d, ans is %d",j,ans);
                        start=1;
                    }
                if(ans<j){
                    ans=j;
                }
                break;
            }
        }
        }
    }
    printf("%d",ans);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,k,num[1000],length,ans,mainans,l,start,start2,m;
    scanf("%d",&length);
    j=0;
    ans=0;
    start=0;
    start2=0;
    for (i=0;i<length ;i++ )
    {
        scanf("%d",&num[i]);
    }
    /*for (i=0;i<length ;i++ )
    {
        printf("%d ",num[i]);
    }*/
    for (i=0;i<length ;i++ )
    {
        j=0;
        start2=0;
        if(num[i]==1){
            j++;
        for (k=i;k<length ;k++ )
        {
            l=k+1;
            m=k;
            if(l==length){
                l=0;
                start2=1;
                k=-1;

            }
            if(num[m]==num[l]){
                //printf("k=%d ",num[k]);
               // printf("l=%d",num[l]);
               j++;
               //printf("j=%d",j);
            }
            if(num[m]!=num[l]){
                    if(start==0){
                        ans=j;
                        //printf("j=%d, ans is %d",j,ans);
                        start=1;
                    }
                if(ans<j){
                    ans=j;
                }
                break;
            }
        }
        }
    }
    printf("%d",ans);
    return 0;
}


#include <stdio.h>

int main()
{
	int n, _max = -1, first_length = 0, current_length = 0;
	scanf("%d", &n);
	while (n--)
	{
		int temp;
		scanf("%d", &temp);
		if (temp)
		{
			if (first_length >= 0)
			{
				first_length++;
			}
			current_length++;
		} else
		{
			_max = current_length > _max ? current_length : _max;
			current_length = 0;
			first_length = first_length > 0 ? -first_length : first_length;
		}
	}
	printf("%d", _max > current_length - first_length ? _max : current_length - first_length);
}


#include <stdio.h>

int main()
{
	int n, _max = -1, first_length = 0, current_length = 0;
	int isFirst = 1;
	scanf("%d", &n);
	while (n--)
	{
		int temp;
		scanf("%d", &temp);
		if (temp)
		{
			if (isFirst > 0)
			{
				first_length++;
			}
			current_length++;
		} else
		{
			_max = current_length > _max ? current_length : _max;
			current_length = 0;
			isFirst = -1;
		}
	}
	printf("%d", _max > current_length + first_length ? _max : current_length + first_length);
}


#include<stdio.h>

int main()
{
    int n, c=0, p=0, i;
    scanf("%d", &n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d", &a[i]);

        if(a[i]==1 && i==0)
            p+=2;
        else if(a[i]==1)
            p++;
        else
        {
            if(c<p)
                c=p;
            p=0;
        }
    }
    printf("%d\n", c);
    return 0;
}


#include<stdio.h>

int main()
{
    int n, c=0, p=0, i;
    scanf("%d", &n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d", &a[i]);

        if(a[i]==1)
            p++;
        else
        {
            if(c<p)
                c=p;
            p=0;
        }
    }
    if(a[0]==1)
    {
        for(i=0;i<n;i++)
        {
            if(a[i]==1)
                p++;
            else
                break;
        }
    }
    if(c<p)
       c=p;
    printf("%d\n", c);
    return 0;
}


#include<stdio.h>

int main()
{
    int n, c=0, p=0, i;
    scanf("%d", &n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d", &a[i]);

        if(a[i]==1 && i==0)
            p+=2;
        else if(a[i]==1)
            p++;
        else
        {
            if(c<p)
                c=p;
            p=0;
        }
    }
    if(c<p)
       c=p;
    printf("%d\n", c);
    return 0;
}


#include<stdio.h>

int main()
{
    int n, c=0, p=0, i;
    scanf("%d", &n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d", &a[i]);

        if(a[i]==1)
            p++;
        else
        {
            if(c<p)
                c=p;
            p=0;
        }
    }
    if(a[0]==1)
        p++;
    if(c<p)
       c=p;
    printf("%d\n", c);
    return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
	int N;
	scanf("%d",&N);
	char h[700000]={0};
	char a[200000]={0};
	for(int i=0;i<N;i++){
		getchar();
		scanf("%c",&a[i]);
	}
	strcat(h,a);
	strcat(h,a);
	strcat(h,a);
	int cnt=0,x=0;
	for(int i=0;i<3*strlen(a);i++){
		if(h[i]=='1'){
			x++;
			if(x>cnt){
				cnt=x;
			}
		}
		else{
			x=0;
		}
	}
	printf("%d",cnt);
}


#include <stdio.h>

int main()
{
  int n;
  scanf(" %d" , &n);

  int ar[n];

  for(int i=0; i<n; i++)
  {
     scanf(" %d", &ar[i]);
  }

  int max = 0, sum = 0, i = 0;

    while(i<n)
    {
        if(ar[i] == 1)
        {
          sum++;
        }

        else
        {
            if(sum >= max)
            {
                max = sum;
                sum = 0;
            }
        }

        i++;
    }

    if(sum > max)
    {
        max = sum;
    }

    i=0;

    if(ar[n-1] == 1 && sum != 0)
    {
        while(1)
        {
            if(ar[i] == 1)
            {
                sum++;
            }
            else
            {
                break;
            }

            i++;
        }
    }

    if(sum > max)
    {
        max = sum;
    }

    printf("%d", max);

  return 0;
}


#include <stdio.h>

int main()
{
  int n;
  scanf(" %d" , &n);

  int ar[n];

  for(int i=0; i<n; i++)
  {
     scanf(" %d", &ar[i]);
  }

  int max = 0, sum = 0, i = 0;

    while(i<n)
    {
        if(ar[i] == 1)
        {
          sum++;
        }

        else
        {
            if(sum >= max)
            {
                max = sum;
            }

            sum = 0;
        }

        i++;
    }

    if(sum >= max)
    {
        max = sum;
    }

        i=0;

        if(ar[n-1] == 1 && sum != 0)
        {
            while(1)
            {
                if(ar[i] == 1)
                {
                    sum++;
                }
                else
                {
                    break;
                }

                i++;
            }
        }

        if(sum > max)
        {
            max = sum;
        }

    printf("%d", max);

  return 0;
}


#include <stdio.h>

int main()
{
  int n;
  scanf(" %d" , &n);

  int ar[n];

  for(int i=0; i<n; i++)
  {
     scanf(" %d", &ar[i]);
  }

  int max = 0, sum = 0, i = 0;

    while(i<n)
    {
        if(ar[i] == 1)
        {
          sum++;
        }

        else
        {
            if(sum > max)
            {
                max = sum;
                sum = 0;
            }
        }

        i++;
    }

    if(sum > max)
    {
        max = sum;
    }

    i=0;

    if(ar[n-1] == 1 && sum != 0)
    {
        while(1)
        {
            if(ar[i] == 1)
            {
                sum++;
            }
            else
            {
                break;
            }

            i++;
        }
    }

    if(sum > max)
    {
        max = sum;
    }

    printf("%d", max);

  return 0;
}


#include <stdio.h>

int main()
{
  int n;
  scanf(" %d" , &n);

  int ar[n];

  for(int i=0; i<n; i++)
  {
     scanf(" %d", &ar[i]);
  }

  int max = 0, sum = 0, i = 0;

    while(i<n)
    {
        if(ar[i] == 1)
        {
          sum++;
        }

        else
        {
            if(sum >= max)
            {
                max = sum;
                sum = 0;
            }
        }

        i++;
    }

    if(sum > max)
    {
        max = sum;
    }

    if(max == n)
    {
        printf("%d", max);
    }

    else
    {
        i=0;

        if(ar[n-1] == 1 && sum != 0)
        {
            while(1)
            {
                if(ar[i] == 1)
                {
                    sum++;
                }
                else
                {
                    break;
                }

                i++;
            }
        }

        if(sum > max)
        {
            max = sum;
        }

    printf("%d", max);

    }

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
        int n,i,s=0,m=0;
        scanf("%d",&n);
        int a[n];
        for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        }
        for(i=0;i<n;i++){

                if(a[i]==1)
                s++;
        else
                s=0;
        if(s>=m)
                m=s;
                if(i==n-1)
                {
                if(a[0]==1)
                s++;
        else
                s=0;
                if(s>=m)
                m=s;
                }
        }
        printf("%d\n",m);

        return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
        int n,i,s=0,m=0,j;
        scanf("%d",&n);
        int a[n];
        for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        }
        for(i=0;i<n;i++){

                if(a[i]==1)
                s++;
        else
                s=0;
        if(s>=m)
                m=s;
                if(i==n-1)
                {
                for(j=0;j<n;j++){
                if(s>=m)
                m=s;
                if(a[j]==1)
                s++;
        else
                break;
                }
                }
        }
        printf("%d\n",m);

        return 0;
}


#include<stdio.h>

int main()
{
    int n,i,b,count=1,max=0;
    scanf("%d",&n);
    int a[2*n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=n,b=0;i<2*n;i++,b++)
    {
        a[i]=a[b];
    }
    for(i=1;i<2*n;i++)
    {
        if(a[i]==1&&a[i-1]==1)
        {
            count++;
            if(max<count)
                max=count;
        }
        else
            count=1;
    }
    printf("%d\n",max);
    return 0;
}


#include<stdio.h>

int main()
{
    int n,i,b,c=0,count=1,max=0;
    scanf("%d",&n);
    int a[2*n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=n,b=0;i<2*n;i++,b++)
    {
        a[i]=a[b];
    }
    for(i=1;i<2*n;i++)
    {
        if(a[i]==1)
        {
            c++;
        }
        if(a[i]==1&&a[i-1]==1)
        {
            count++;
            if(max<count)
                max=count;
        }
        else
            count=1;
    }
    if(c>0&&max==0)
        printf("1\n");
    else
        printf("%d",max);
    return 0;
}


#include<stdio.h>
int max(int n, int m)
{
   if(n>m)
   {
       return n;
   }
   else
   {
       return m;
   }

}
int main()
{
    int n, hour[400001],i,count1=0,count=0,c=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&hour[i]);
        hour[i+n]=hour[i];
    }
    n=2*n;
    for(i=0;i<n;i++)
    {
        if(hour[i]==1)
        {
            count1++;
        }
        else
        {
            c=max(c,count1);
            count1=0;
        }
    }
    printf("%d",c);
    return 0;
}


#include<stdio.h>
int max(int n, int m)
{
   if(n>m)
   {
       return n;
   }
   else
   {
       return m;
   }

}
int main()
{
    int n, hour[200000],i,count1=0,count=0,c=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&hour[i]);
        hour[i+n]=hour[i];
    }
    n=2*n;
    for(i=0;i<n;i++)
    {
        if(hour[i]==1)
        {
            count1++;
        }
        else
        {
            c=max(c,count1);
            count1=0;
        }
    }
    printf("%d",c);
    return 0;
}


#include <stdio.h>

int main()
{
    int n, max=0, c=0, a, i, j=0;
    scanf("%d",&n);
    int cc[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(a==1)c++;
        if(a==0||i==n-1)
            {cc[j++]=c;if(c>max)max=c;c=0;}
    }
    c=cc[0]+cc[j-1];
    if(c>max) max=c;
    printf("%d",max);
}


#include <stdio.h>

int main()
{
    int n, max=0, c=0, a, i, j=0;
    scanf("%d",&n);
    int cc[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(a==1)c++;
        if(a==0||i==n-1)
            {cc[j++]=c;if(c>max)max=c;c=0;}
    }
    c=cc[0]+cc[j-1];
    if(c>max&&a) max=c;
    printf("%d",max);
}


#include<stdio.h>

int main()
{
    int n,max=0,r;
    scanf("%d",&n);
    int ar[2*n];
    for(int i=0;i<n;i++)
    {
    scanf("%d",&ar[i]);
    ar[n+i]=ar[i];
    }
    for(int i=0;i<2*n;i++)
    {
    if(ar[i]==1)
    r++;
    else
    r=0;
    if(r>max)
    max=r;
    }
    printf("%d",max);
    return 0;
}


#include<stdio.h>

int main()
{
    int n,max=0,r=0;
    scanf("%d",&n);
    int ar[2*n];
    for(int i=0;i<n;i++)
    {
    scanf("%d",&ar[i]);
    ar[n+i]=ar[i];
    }
    for(int i=0;i<2*n;i++)
    {
    if(ar[i]==1)
    r++;
    else
    r=0;
    if(r>max)
    max=r;
    }
    printf("%d",max);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int j,n,c=0,i,max=0;
    scanf("%lli", &n);
    long long int inpt[n+n];
    for(i=0;i<(n+2);i++)
        inpt[i]=0;
    for(i=0;i<n;i++)
    {
        scanf("%lli", &inpt[i]);
        if(inpt[i]==1)
        {
            c=1;
        }
    }
    for(j=0;j<n;i++,j++)
    {
        inpt[i]=inpt[j];
    }
    max=c;
    for(i=0;i<=(n*2);i++)
    {
        if(inpt[i]==1 && inpt[i+1]==1)
        {
            c++;
            if(inpt[i+2]==0)
            {
                if(max<c)
                {
                    max=c;
                }
                c=1;
            }
        }
    }
    printf("%lli", max);
    return 0;
}


#include<stdio.h>
int main()
{
	long long int m,n,div,count=0;
	scanf("%I64d%I64d",&n,&m);
	if(m%n!=0){
		printf("-1");
		return 0;
	}
	if(m==n)
	{
	printf("0");
	return 0;
}
div=m/n;
	while(div%2==0)
	{

	div/=2;
	count++;
}
while(div%3==0)
{
	div/=3;
	count++;
}
if(div!=1)
{
	printf("-1");
	return 0;
}

printf("%I64d",count);
return 0;
}


#include <stdio.h>

int main()
{
	int n, i, frst=0, last, prev=0, crnt=1, tmp, max=0;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &tmp);
		if (!tmp && !frst) frst=i;
		if (!tmp) last=i;
		if (prev && tmp) crnt++;
		else crnt=1;
		if (crnt>max) max=crnt;
		if (tmp) prev=i;
	}
	if (!prev) max = 0;
	else max--;
	if ((n-last+frst-1)>max) max = (n-last+frst-1);
	printf("%d\n", max);
	return 0;
}


#include <stdio.h>
int main()
{
    int n, i, max = 0, first, crnt, last, hnd, sum = 0, mxi;
    scanf("%d", &n);
    scanf("%d", &first);
    for (i = 0; i < n-1; i++)
    {
        if (i == 0) hnd = first;
        else hnd = crnt;
        scanf("%d", &crnt);
        if (crnt == hnd && hnd == 1)
        {
            max++;
            if (max >= sum)
            {
                sum = max;
                mxi = i;
            }
        }
        else max = 0;
        if (mxi == n-2) last = crnt;
        else last = -1;
    }
    if (sum != 0) sum += 1;
    if (first == last && first == 1) sum += 1;
    printf("%d\n", sum);
    return 0;
}


#include <stdio.h>
int main()
{
    int n, i, j = 0, max = 0, sum = 0, hnd, crnt, num_i = 0;
    scanf("%d", &n);
    int inp[n];
    for (i = 0; i < n; i++)
    {
        scanf("%d", &inp[i]);
        if (inp[i] == 1) num_i++;
    }
    if (inp[0] == 1 && inp[n-1] == 1)
    {
        for (i = 0; j < 2; i++)
        {
            if (i == n)
            {
                i = 0; j++;
            }
            if (j == 2) break;
///            printf("i = %d\n", i);///extra
            if (j == 0)
            {
                if (i == 0) hnd = inp[0];
                else hnd = crnt;
                if (i != 0) crnt = inp[i];
                else crnt = inp[1];
            }
            else
            {
                hnd = crnt;
                crnt = inp[i];
            }
            if (crnt == hnd && hnd == 1)
            {
                max++;
                if (max >= sum) sum = max;
            }
            else max = 0;
        }
        if (sum == 0 && num_i != 0) printf("%d\n", 1);
        if (sum != 0) sum += 1;
        printf("%d\n", sum);
    }
    else if (n == 2)
    {
        printf("%d\n", num_i);
    }
    else
    {
        for (i = 0; i < n; i++)
        {
            if (i == 0) hnd = inp[0];
            else hnd = crnt;
            if (i != 0) crnt = inp[i];
            else crnt = inp[1];
            if (crnt == hnd && hnd == 1)
            {
                max++;
                if (max >= sum) sum = max;
            }
            else max = 0;
        }
        if (sum == 0 && num_i != 0) printf("%d\n", 1);
        if (sum != 0) sum += 1;
        printf("%d\n", sum);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    int n, i, max = 0, first, crnt, last, hnd, sum = 0, mxi;
    scanf("%d", &n);
    scanf("%d", &first);
    for (i = 0; i < n-1; i++)
    {
        if (i == 0) hnd = first;
        else hnd = crnt;
        scanf("%d", &crnt);
        if (crnt == hnd && hnd == 1)
        {
            max++;
            if (max >= sum)
            {
                sum = max;
                mxi = i;
            }
        }
        else max = 0;
        if (i == n-2) last = crnt;
    }
    if (sum != 0) sum += 1;
    if (first == last && first == 1) sum += 1;
    printf("%d\n", sum);
    return 0;
}


#include <stdio.h>
int main()
{
    int n, i, j = 0, max = 0, sum = 0, hnd, crnt, num_i = 0;
    scanf("%d", &n);
    int inp[n];
    for (i = 0; i < n; i++)
    {
        scanf("%d", &inp[i]);
        if (inp[i] == 1) num_i++;
    }
    if (inp[0] == 1 && inp[n-1] == 1)
    {
        for (i = 0; j < 2; i++)
        {
            if (i == n)
            {
                i = 0; j++;
            }
            if (j == 2) break;
///            printf("i = %d\n", i);///extra
            if (j == 0)
            {
                if (i == 0) hnd = inp[0];
                else hnd = crnt;
                if (i != 0) crnt = inp[i];
                else crnt = inp[1];
            }
            else
            {
                hnd = crnt;
                crnt = inp[i];
            }
            if (crnt == hnd && hnd == 1)
            {
                max++;
                if (max >= sum) sum = max;
            }
            else max = 0;
        }
        if (sum == 0 && num_i != 0) printf("%d\n", 1);
        if (sum != 0) sum += 1;
        printf("%d\n", sum);
    }
    else if (n == 2)
    {
        printf("%d\n", num_i);
    }
    else
    {
        for (i = 0; i < n; i++)
        {
            if (i == 0) hnd = inp[0];
            else hnd = crnt;
            if (i != 0) crnt = inp[i];
            else crnt = inp[1];
            if (crnt == hnd && hnd == 1)
            {
                max++;
                if (max >= sum) sum = max;
            }
            else max = 0;
        }
        if (sum == 0 && num_i != 0) printf("%d\n", 1);
        if (sum != 0)
        {
            sum += 1;
            printf("%d\n", sum);
        }
    }
    return 0;
}


#include <stdio.h>
int main()
{
    int n, i, max = 0, first, crnt, last_in, last_ex, hnd, sum = 0, mxi;
    scanf("%d", &n);
    scanf("%d", &first);
    for (i = 0; i < n-1; i++)
    {
        if (i == 0) hnd = first;
        else hnd = crnt;
        scanf("%d", &crnt);
        if (crnt == hnd && hnd == 1)
        {
            max++;
            if (max >= sum)
            {
                sum = max;
                mxi = i;
            }
        }
        else max = 0;
        if (mxi == n-2) last_in = crnt;
        if (i == n-2) last_ex = crnt;
    }
    if (sum != 0) sum += 1;
    if (first == last_in && first == 1) sum += 1;
    if ((first == last_ex && first == 1) && sum == 0) sum = 2;
    printf("%d\n", sum);
    return 0;
}


#include <stdio.h>
int main()
{
    int n, i, j = 0, max = 0, sum = 0, hnd, crnt;
    scanf("%d", &n);
    int inp[n];
    for (i = 0; i < n; i++) scanf("%d", &inp[i]);
    if (inp[0] == 1 && inp[n-1] == 1)
    {
        for (i = 0; j < 2; i++)
        {
            if (i == n)
            {
                i = 0; j++;
            }
            if (j == 2) break;
///            printf("i = %d\n", i);///extra
            if (j == 0)
            {
                if (i == 0) hnd = inp[0];
                else hnd = crnt;
                if (i != 0) crnt = inp[i];
                else crnt = inp[1];
            }
            else
            {
                hnd = crnt;
                crnt = inp[i];
            }
            if (crnt == hnd && hnd == 1)
            {
                max++;
                if (max >= sum) sum = max;
            }
            else max = 0;
        }
        if (sum != 0) sum += 1;
        printf("%d\n", sum);
    }
    else if (n == 2)
    {
        for (i = 0; i < n; i++) if (inp[i] == 1) sum++;
        printf("%d\n", sum);
    }
    else
    {
        for (i = 0; i < n; i++)
        {
            if (i == 0) hnd = inp[0];
            else hnd = crnt;
            if (i != 0) crnt = inp[i];
            else crnt = inp[1];
            if (crnt == hnd && hnd == 1)
            {
                max++;
                if (max >= sum) sum = max;
            }
            else max = 0;
        }
        if (sum != 0) sum += 1;
        printf("%d\n", sum);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    int n, i, j = 0, max = 0, sum = 0, hnd, crnt, num_i = 0;
    scanf("%d", &n);
    int inp[n];
    for (i = 0; i < n; i++)
    {
        scanf("%d", &inp[i]);
        if (inp[i] == 1) num_i++;
    }
    if (inp[0] == 1 && inp[n-1] == 1)
    {
        for (i = 0; j < 2; i++)
        {
            if (i == n)
            {
                i = 0; j++;
            }
            if (j == 2) break;
///            printf("i = %d\n", i);///extra
            if (j == 0)
            {
                if (i == 0) hnd = inp[0];
                else hnd = crnt;
                if (i != 0) crnt = inp[i];
                else crnt = inp[1];
            }
            else
            {
                hnd = crnt;
                crnt = inp[i];
            }
            if (crnt == hnd && hnd == 1)
            {
                max++;
                if (max >= sum) sum = max;
            }
            else max = 0;
        }
        if (sum == 0 && num_i != 0) printf("%d\n", 1);
        if (sum != 0) sum += 1;
        printf("%d\n", sum);
    }
    else
    {
        for (i = 0; i < n; i++)
        {
            if (i == 0) hnd = inp[0];
            else hnd = crnt;
            if (i != 0) crnt = inp[i];
            else crnt = inp[1];
            if (crnt == hnd && hnd == 1)
            {
                max++;
                if (max >= sum) sum = max;
            }
            else max = 0;
        }
        if (sum == 0 && num_i != 0) printf("%d\n", 1);
        if (sum != 0) sum += 1;
        printf("%d\n", sum);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,m,c=0,max=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    m=n;
    while(a[m-1]==1)
	{
        c++;
        m--;
    }
    for(i=0;i<n;i++)
	{
        if(a[i]==1)
        c++;
        else
		c=0;
        if(c>max)
        max=c;
    }
    if(max>n)
    printf("%d",n);
    else
    printf("%d",max);
	return 0;
}


#include<stdio.h>
int main()
{
    int a,b,i,max=0,j=1;
    scanf("%d",&a);
    while(a--){
        scanf("%d",&i);
        if(i==1){
            j++;
            if(j>=max)max=j;
        }
        else j=0;
    }
    printf("%d",max);
}


#include<stdio.h>
int main()
{
    int a,b,i,max=0,j=1;
    scanf("%d",&a);
    while(a--){
        scanf("%d",&i);
        if(i==1){
            j++;
            if(j>=max)max=j;
        }
        else if(i==0) j=0;
    }
    printf("%d",max);
}


#include<stdio.h>
int main()
{
   int  days,max=0,count=0,i,num;
   scanf("%d",&days);
   int arr[2*days];
   for(i=0;i<days;i++)
   {
       scanf("%d",&num);
       arr[i]=num;
       arr[i+days]=num;
   }
   for(i=0;i<2*days;i++)
   {
       if(arr[i]==1&&arr[i+1]==1)
       count++;
       else
       count=0;
       if(count>max)
       max=count;
   }
   if(max>0)
   printf("%d",max+1);
   else
   printf("%d",max);
}


#include<stdio.h>
int main()
{
   int  days,max=0,count=0,i,num,flag=0;
   scanf("%d",&days);
   int arr[2*days];
   for(i=0;i<days;i++)
   {
       scanf("%d",&num);
       arr[i]=num;
       arr[i+days]=num;
   }
   for(i=0;i<2*days;i++)
   {
       if(arr[i]==1)
       flag=1;
       if(arr[i]==1&&arr[i+1]==1)
       count++;
       else
        count=0;
       if(count>max)
       max=count;
   }
   if(max>0)
   printf("%d",max+1);
   else if(max==0&&flag==1)
   printf("1");
   else
   printf("%d",max);

}


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let str = "";
    for(let i = 1 ; i < inputs.length ; i++) {
        str += " " + inputs[i];
    }
    str = str + " " + str;
    //console.log(str);
    let count = 0, mn = 0;
    str.split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val == 1) count++;
        else if(val == 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split(" ").map(_ => parseInt(_))[0];
    const arr = inputs[1].split(" ").map(_ => parseInt(_));
    let s = arr[n - 1];
    let count = s;
    let i = 0;
    let mn = 0;
    while(i < n) {
        mn = Math.max(count, mn);
        if(arr[i] === 1) count++;
        if(arr[i] === 0) {
            count = 0;
        }
        i++;
    }
    console.log(Math.min(n, mn));
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let str = "";
    for(let i = 1 ; i < inputs.length ; i++) {
        str += " " + inputs[i];
    }
    let s = str[str.length - 1];
    let count = parseInt(s);
    let mn = 0;
    str.split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val == 1) count++;
        else if(val == 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let str = "";
    for(let i = 1 ; i < inputs.length ; i++) {
        str += " " + inputs[i];
    }
    str = str + " " + str;
    let count = 0, mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val == 1) count++;
        else if(val == 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let s = inputs[1][inputs[1].length - 1];
    let count = parseInt(s);
    let mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val == 1) count++;
        else if(val == 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let s = inputs[1][inputs[1].length - 1];
    let count = parseInt(s);
    let mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val === 1) count++;
        else if(val === 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split(" ").map(_ => parseInt(_))[0];
    let s = inputs[1][inputs[1].length - 1];
    let count = parseInt(s);
    let i = 0;
    let mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        mn = Math.max(count, mn);
        if(val === 1) count++;
        else if(val === 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
        i++;
    });
    console.log(Math.min(n, mn));
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split(" ").map(_ => parseInt(_))[0];
    let s = inputs[1][inputs[1].length - 1];
    let count = parseInt(s);
    let i = 0;
    let mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val === 1) count++;
        else if(val === 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
        i++;
    });
    console.log(Math.min(n, mn));
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split(" ").map(_ => parseInt(_))[0];
    const arr = inputs[1].split(" ").map(_ => parseInt(_));
    let s = arr[n - 1];
    let count = s;
    let i = 0;
    let mn = 0;
    while(i < n) {
        mn = Math.max(count, mn);
        if(arr[i] === 1) count++;
        if(arr[i] === 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
        i++;
    }
    console.log(Math.min(n, mn));
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  let arr = d.split(' ').map(Number);
  let ans = 0;
  let count = 0;

  for (let i = 0; i < 2 * arr.length; i++) {
    if (arr[i % arr.length] === 1) {
      count++;
    }
    else {
      count = 0;
    }

    ans = Math.max(ans, count);
  }

  console.log(ans);

  // const idxZero = arr.indexOf(0);

  // if (idxZero !== -1) {
  //   arr = [...arr.slice(idxZero + 1), ...arr.slice(0, idxZero + 1)];
  // }

  // for (let i = 0; i < arr.length; i++) {
  //   if (arr[i] === 1) {
  //     count++;
  //   }
  //   else {
  //     count = 0;
  //   }

  //   ans = Math.max(ans, count);
  // }

  // console.log(ans);

  c++;
});


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  let arr = d.split(' ').map(Number);
  const idxZero = arr.indexOf(0);
  let ans = 0;
  let count = 0;

  if (idxZero !== -1) {
    arr = [...arr.slice(idxZero + 1), ...arr.slice(0, idxZero + 1)];
  }

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === 1) {
      count++;
    }
    else {
      count = 0;
    }

    ans = Math.max(ans, count);
  }

  console.log(ans);

  c++;
});


let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	let n = nl.num();
	let a = nl.nums();
	a = a.concat(a);
	let cnt = 0;
	let c = 0;
	for(let i of a){
		if (i === 1){
			c++;
		} else if (c > cnt){
			cnt = c;
			c = 0;
		} else {
			c = 0;
		}
	}
	if (c > cnt) cnt = c;
	console.log(cnt);

};

process.stdin.on('end', sol);


using System;
using System.Collections.Generic;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split();
            List<int> a = new List<int>();
            foreach (var c in input)
                a.Add(int.Parse(c));
            foreach (var c in input)
                a.Add(int.Parse(c));
            int result = 0;
            int len = 0;
            for (int i = 0; i < n*2; i++)
            {
                if (a[i] == 1)
                {
                    len++;
                    result = Math.Max(result, len);
                }
                else
                    len = 0;
            }
            Console.WriteLine(result);

        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split();
            List<int> a = new List<int>();
            foreach (var c in input)
                a.Add(int.Parse(c));
            foreach (var c in input)
                a.Add(int.Parse(c));
            int result = 0;
            int len = 0;
            for (int i = 0; i < n; i++)
            {
                if (a[i] == 1)
                {
                    len++;
                    result = Math.Max(result, len);
                }
                else
                    len = 0;
            }
            Console.WriteLine(result);

        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split();
            List<int> a = new List<int>();
            foreach (var c in input)
                a.Add(int.Parse(c));
            foreach (var c in input)
                a.Add(int.Parse(c));
            int result = 0;
            int len = 0;
            for (int i = 0; i <= n; i++)
            {
                if (a[i] == 1)
                {
                    len++;
                    result = Math.Max(result, len);
                }
                else
                    len = 0;
            }
            Console.WriteLine(result);

        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split();
            List<int> a = new List<int>();
            foreach (var c in input)
                a.Add(int.Parse(c));
            int result = 0;
            int len = 0;
            for(int i =0; i<2*n; i++)
            {
                if (a[i % n] == 1)
                {
                    len++;
                    result = Math.Max(result, len);
                }
                else
                    len = 0;
            }
            Console.WriteLine(result);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] hours = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int best = 0;
            int r = 0;
            for(int i = 0; i < 2 * hours.Length; ++i)
            {
                if(hours[i % hours.Length] == 0)
                {
                    best = Math.Max(best, r);
                    r = 0;
                    continue;
                }
                ++r;
            }
            Console.WriteLine(best);
        }
    }
}