1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 70000
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 using namespace std;
19 inline int read()
20 {
21 int x=0,f=1;char ch=getchar();
22 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
23 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
24 return x*f;
25 }
26 inline bool cmp(int *r,int a,int b,int l)
27 {
28 return r[a]==r[b]&&r[a+l]==r[b+l];
29 }
30 int wa[maxn],wb[maxn],wr[maxn],sa[maxn],rank[maxn],a[maxn],n;
31 void da(int *r,int *sa,int n,int m)
32 {
33 int i,j,p,*x=wa,*y=wb,*t;
34 for(i=0;i<m;i++)wr[i]=0;
35 for(i=0;i<n;i++)wr[x[i]=r[i]]++;
36 for(i=1;i<m;i++)wr[i]+=wr[i-1];
37 for(i=n-1;i>=0;i--)sa[--wr[x[i]]]=i;
38 for(j=1,p=1;p<n;j<<=1,m=p)
39 {
40 for(p=0,i=n-j;i<n;i++)y[p++]=i;
41 for(i=0;i<n;i++)if(sa[i]>=j)y[p++]=sa[i]-j;
42 for(i=0;i<m;i++)wr[i]=0;
43 for(i=0;i<n;i++)wr[x[y[i]]]++;
44 for(i=1;i<m;i++)wr[i]+=wr[i-1];
45 for(i=n-1;i>=0;i--)sa[--wr[x[y[i]]]]=y[i];
46 for(t=x,x=y,y=t,p=1,i=1,x[sa[0]]=0;i<n;i++)
47 x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;
48 }
49 }
50 int main()
51 {
52 n=read();
53 for(int i=0;i<n;i++)
54 {
55 char ch=‘ ‘;
56 while(ch<‘A‘||ch>‘Z‘)ch=getchar();
57 a[i]=int(ch-‘A‘+1);
58 }
59 int tot=2*n+1;
60 a[n]=0;a[tot]=0;
61 for(int i=1;i<=n;i++)a[n+i]=a[n-i];
62 da(a,sa,tot+1,28);
63 //for(int i=0;i<=tot;i++)cout<<i<<‘ ‘<<sa[i]<<endl;
64 for(int i=1;i<=tot;i++)rank[sa[i]]=i;
65 //for(int i=0;i<=tot;i++)cout<<i<<‘ ‘<<rank[i]<<endl;
66 int l=0,r=n+1;
67 while(l+r-n-1<n)
68 {
69 if(rank[l]<rank[r])putchar(a[l++]+‘A‘-1);else putchar(a[r++]+‘A‘-1);
70 if(!((l+r-n-1)%80))putchar(‘\n‘);
71 }
72 return 0;
73 }