#include<cstdio> #include<cstring> #include<algorithm> usingnamespace std; constint N = 2e5 + 10; char s[N]; int sa[N], rnk[N], ht[N], x[N], y[N], n, m, c[N]; voidSA() { for (int i = 1; i <= n; i++) c[x[i] = s[i]]++; for (int i = 1; i <= m; i++) c[i] += c[i - 1]; for (int i = n; i; i--) sa[c[x[i]]--] = i; for (int k = 1; k <= n; k <<= 1) { int cnt = 0; for (int i = n - k + 1; i <= n; i++) y[++cnt] = i; for (int i = 1; i <= n; i++) if (sa[i] > k) y[++cnt] = sa[i] - k; for (int i = 1; i <= m; i++) c[i] = 0; for (int i = 1; i <= n; i++) c[x[i]]++; for (int i = 2; i <= m; i++) c[i] += c[i - 1]; for (int i = n; i; i--) sa[c[x[y[i]]]--] = y[i]; for (int i = 1; i <= n; i++) y[i] = x[i]; for (int i = 1; i <= n; i++) x[i] = 0; x[sa[1]] = 1; cnt = 1; for (int i = 2; i <= n; i++) if (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]) x[sa[i]] = cnt; else x[sa[i]] = ++cnt; if (cnt == n) return; m = cnt; } } intmain() { scanf("%s", s + 1); n = strlen(s + 1); for (int i = 1; i <= n; i++) s[i + n] = s[i]; n <<= 1; m = 300; SA(); for (int i = 1; i <= n; i++) if (sa[i] <= (n >> 1)) printf("%c", s[sa[i] + (n >> 1) - 1]); return0; }