1 #include<cstdio>
2 #include<cstring>
3 #define N 200001
4 using namespace std;
5 char ch[N];
6 int a[N],n,k;
7 int v[N],sa[2][N],rk[2][N];
8 void init(){
9 scanf("%s",ch+1);
10 n=strlen(ch+1);
11 for (int i=1;i<=n;i++){
12 a[i]=int(ch[i]);
13 ch[i+n]=ch[i];
14 a[i+n]=a[i];
15 }
16 n=n<<1;
17 }
18
19 void calsa(int sa[N],int rk[N],int SA[N],int RK[N]){
20 for (int i=1;i<=n;i++)v[rk[sa[i]]]=i;
21 for (int i=n;i>=1;i--)
22 if (sa[i]>k) SA[v[rk[sa[i]-k]]--]=sa[i]-k;
23 for (int i=n-k+1;i<=n;i++) SA[v[rk[i]]--]=i;
24 for (int i=1;i<=n;i++)
25 RK[SA[i]]=RK[SA[i-1]]+(rk[SA[i-1]]!=rk[SA[i]]||rk[SA[i-1]+k]!=rk[SA[i]+k]);
26
27 }
28
29 void work(){
30 int p=0,q=1;
31 for (int i=1;i<=n;i++)v[a[i]]++;
32 for (int i=1;i<=256;i++) v[i]+=v[i-1];
33 for (int i=1;i<=n;i++)sa[p][v[a[i]]--]=i;
34 for (int i=1;i<=n;i++)
35 rk[p][sa[p][i]]=rk[p][sa[p][i-1]]+(a[sa[p][i-1]]!=a[sa[p][i]]);
36 k=1;
37 while (k<n){
38 calsa(sa[p],rk[p],sa[q],rk[q]);
39 q^=1;p^=1;k=k<<1;
40 }
41 for (int i=1;i<=n;i++) if (sa[p][i]<=n/2)
42 printf("%c",ch[sa[p][i]+n/2-1]);
43 }
44
45 int main(){
46 init();
47 work();
48 }