#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXN 65536
#define MAXLG 17
char A[MAXN];
struct entry
{
int nr[2];
int p;
} L[MAXN];
int P[MAXLG][MAXN];
int N,i;
int stp, cnt;
int cmp(struct entry a, struct entry b)
{
return a.nr[0]==b.nr[0] ?(a.nr[1]<b.nr[1] ?1: 0): (a.nr[0]<b.nr[0] ?1: 0);
}
int main()
{
gets(A);
for(N=strlen(A), i = 0; i < N; i++)
P[0][i] = A[i] - 'a';
for(stp=1, cnt = 1; cnt < N; stp++, cnt *= 2)
{
for(i=0; i < N; i++)
{
L[i].nr[0]=P[stp- 1][i];
L[i].nr[1]=i +cnt <N? P[stp -1][i+ cnt]:-1;
L[i].p= i;
}
sort(L, L+N, cmp);
for(i=0; i < N; i++)
P[stp][L[i].p] =i> 0 && L[i].nr[0]==L[i-1].nr[0] && L[i].nr[1] == L[i- 1].nr[1] ? P[stp][L[i-1].p] : i;
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNzdHJpbmc+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIE1BWE4gNjU1MzYKI2RlZmluZSBNQVhMRyAxNwoKY2hhciBBW01BWE5dOwoKc3RydWN0IGVudHJ5CnsKICAgIGludCBuclsyXTsKICAgIGludCBwOwp9IExbTUFYTl07CgppbnQgUFtNQVhMR11bTUFYTl07CmludCBOLGk7CmludCBzdHAsIGNudDsKCmludCBjbXAoc3RydWN0IGVudHJ5IGEsIHN0cnVjdCBlbnRyeSBiKQp7CiAgICByZXR1cm4gYS5uclswXT09Yi5uclswXSA/KGEubnJbMV08Yi5uclsxXSA/MTogMCk6IChhLm5yWzBdPGIubnJbMF0gPzE6IDApOwp9CgppbnQgbWFpbigpCnsKICAgIGdldHMoQSk7CiAgICBmb3IoTj1zdHJsZW4oQSksIGkgPSAwOyBpIDwgTjsgaSsrKQogICAgICAgIFBbMF1baV0gPSBBW2ldIC0gJ2EnOwoKICAgIGZvcihzdHA9MSwgY250ID0gMTsgY250IDwgTjsgc3RwKyssIGNudCAqPSAyKQogICAgewogICAgICAgIGZvcihpPTA7IGkgPCBOOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBMW2ldLm5yWzBdPVBbc3RwLSAxXVtpXTsKICAgICAgICAgICAgTFtpXS5uclsxXT1pICtjbnQgPE4/IFBbc3RwIC0xXVtpKyBjbnRdOi0xOwogICAgICAgICAgICBMW2ldLnA9IGk7CiAgICAgICAgfQogICAgICAgIHNvcnQoTCwgTCtOLCBjbXApOwogICAgICAgIGZvcihpPTA7IGkgPCBOOyBpKyspCiAgICAgICAgICAgIFBbc3RwXVtMW2ldLnBdID1pPiAwICYmIExbaV0ubnJbMF09PUxbaS0xXS5uclswXSAmJiBMW2ldLm5yWzFdID09IExbaS0gMV0ubnJbMV0gPyBQW3N0cF1bTFtpLTFdLnBdIDogaTsKICAgIH0KICAgIHJldHVybiAwOwp9