1 #include <iostream>
2 #include <cstring>
3 #include <cstdlib>
4 #include <algorithm>
5 #include <cstdio>
6 #define N 220000
7 using namespace std;
8 #define rep(i,a,b) for(i=a;i<b;++i)
9 #define drep(i,a,b) for(i=a;i>=b;--i)
10 using namespace std;
11 int p[N],wc[N],wv[N],wa[N],wb[N],rank[N],sa[N];
12 char s[N];
13 inline bool cmp(int *r,int a,int b,int l) {
14 return r[a]==r[b]&&r[a+l]==r[b+l];
15 }
16 inline void tate(int *x,int *y,char *r,int n,int m,bool opt) {
17 int i;
18 rep(i,0,m) wc[i]=0;
19 rep(i,0,n) wc[opt?(x[i]=r[i]):wv[i]]++;
20 rep(i,1,m) wc[i]+=wc[i-1];
21 drep(i,n-1,0) sa[--wc[opt?x[i]:wv[i]]]=opt?i:y[i];
22 }
23 void f(char *r,int *sa,int n,int m) {
24 int i,j,p,*x=wa,*y=wb,*t;
25 tate(x,y,r,n,m,1);
26 for (j=1,p=1;p<n;j<<=1,m=p) {
27 p=0;
28 rep(i,n-j,n) y[p++]=i;
29 rep(i,0,n) if(sa[i]>=j) y[p++]=sa[i]-j;
30 rep(i,0,n) wv[i]=x[y[i]];
31 tate(x,y,r,n,m,0);
32 for (t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1;i<n;++i)
33 x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;
34 }
35 }
36 int main() {
37 scanf("%s",s);
38 int slen=strlen(s);
39 int n=slen*2;
40 for(int i=0;i<slen;i++) s[slen+i]=s[i];
41 s[n-1]=0;
42 f(s,sa,n,300);
43 for(int i=0;i<n;i++) rank[sa[i]]=i;
44 for(int i=0;i<slen;i++) p[rank[i]]=s[i+slen-1];
45 for(int i=0;i<n;i++) if(p[i]) printf("%c",p[i]);
46 return 0;
47 }