#include <bits/stdc++.h>
using namespace std;
#define fpos adla
const int inf = 1e9;
const int maxn = 1e4;
char s[maxn];
map<int, int> to[maxn];
int len[maxn], fpos[maxn], link[maxn];
int node, pos;
int sz = 1, n = 0;
int make_node(int _pos, int _len)
{
fpos[sz] = _pos;
len [sz] = _len;
return sz++;
}
void go_edge()
{
while(pos > len[to[node][s[n - pos]]])
{
node = to[node][s[n - pos]];
pos -= len[node];
}
}
void add_letter(int c)
{
s[n++] = c;
pos++;
int last = 0;
while(pos > 0)
{
go_edge();
int edge = s[n - pos];
int &v = to[node][edge];
int t = s[fpos[v] + pos - 1];
if(v == 0)
{
v = make_node(n - pos, inf);
link[last] = node;
last = 0;
}
else if(t == c)
{
link[last] = node;
return;
}
else
{
int u = make_node(fpos[v], pos - 1);
to[u][c] = make_node(n - 1, inf);
to[u][t] = v;
fpos[v] += pos - 1;
len [v] -= pos - 1;
v = u;
link[last] = u;
last = u;
}
if(node == 0)
pos--;
else
node = link[node];
}
}
int main()
{
len[0] = inf;
string s;
cin >> s;
int ans = 0;
for(int i = 0; i < s.size(); i++)
add_letter(s[i]);
for(int i = 1; i < sz; i++)
ans += min((int)s.size() - fpos[i], len[i]);
cout << ans << "\n";
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBmcG9zIGFkbGEKY29uc3QgaW50IGluZiA9IDFlOTsKY29uc3QgaW50IG1heG4gPSAxZTQ7CmNoYXIgc1ttYXhuXTsKbWFwPGludCwgaW50PiB0b1ttYXhuXTsKaW50IGxlblttYXhuXSwgZnBvc1ttYXhuXSwgbGlua1ttYXhuXTsKaW50IG5vZGUsIHBvczsKaW50IHN6ID0gMSwgbiA9IDA7CgppbnQgbWFrZV9ub2RlKGludCBfcG9zLCBpbnQgX2xlbikKewogICAgZnBvc1tzel0gPSBfcG9zOwogICAgbGVuIFtzel0gPSBfbGVuOwogICAgcmV0dXJuIHN6Kys7Cn0KCnZvaWQgZ29fZWRnZSgpCnsKICAgIHdoaWxlKHBvcyA+IGxlblt0b1tub2RlXVtzW24gLSBwb3NdXV0pCiAgICB7CiAgICAgICAgbm9kZSA9IHRvW25vZGVdW3NbbiAtIHBvc11dOwogICAgICAgIHBvcyAtPSBsZW5bbm9kZV07CiAgICB9Cn0KCnZvaWQgYWRkX2xldHRlcihpbnQgYykKewogICAgc1tuKytdID0gYzsKICAgIHBvcysrOwogICAgaW50IGxhc3QgPSAwOwogICAgd2hpbGUocG9zID4gMCkKICAgIHsKICAgICAgICBnb19lZGdlKCk7CiAgICAgICAgaW50IGVkZ2UgPSBzW24gLSBwb3NdOwogICAgICAgIGludCAmdiA9IHRvW25vZGVdW2VkZ2VdOwogICAgICAgIGludCB0ID0gc1tmcG9zW3ZdICsgcG9zIC0gMV07CiAgICAgICAgaWYodiA9PSAwKQogICAgICAgIHsKICAgICAgICAgICAgdiA9IG1ha2Vfbm9kZShuIC0gcG9zLCBpbmYpOwogICAgICAgICAgICBsaW5rW2xhc3RdID0gbm9kZTsKICAgICAgICAgICAgbGFzdCA9IDA7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYodCA9PSBjKQogICAgICAgIHsKICAgICAgICAgICAgbGlua1tsYXN0XSA9IG5vZGU7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgaW50IHUgPSBtYWtlX25vZGUoZnBvc1t2XSwgcG9zIC0gMSk7CiAgICAgICAgICAgIHRvW3VdW2NdID0gbWFrZV9ub2RlKG4gLSAxLCBpbmYpOwogICAgICAgICAgICB0b1t1XVt0XSA9IHY7CiAgICAgICAgICAgIGZwb3Nbdl0gKz0gcG9zIC0gMTsKICAgICAgICAgICAgbGVuIFt2XSAtPSBwb3MgLSAxOwogICAgICAgICAgICB2ID0gdTsKICAgICAgICAgICAgbGlua1tsYXN0XSA9IHU7CiAgICAgICAgICAgIGxhc3QgPSB1OwogICAgICAgIH0KICAgICAgICBpZihub2RlID09IDApCiAgICAgICAgICAgIHBvcy0tOwogICAgICAgIGVsc2UKICAgICAgICAgICAgbm9kZSA9IGxpbmtbbm9kZV07CiAgICB9Cn0KCmludCBtYWluKCkKewogICAgbGVuWzBdID0gaW5mOwogICAgc3RyaW5nIHM7CiAgICBjaW4gPj4gczsKICAgIGludCBhbnMgPSAwOwogICAgZm9yKGludCBpID0gMDsgaSA8IHMuc2l6ZSgpOyBpKyspCiAgICAgICAgYWRkX2xldHRlcihzW2ldKTsKICAgIGZvcihpbnQgaSA9IDE7IGkgPCBzejsgaSsrKQogICAgICAgIGFucyArPSBtaW4oKGludClzLnNpemUoKSAtIGZwb3NbaV0sIGxlbltpXSk7CiAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwp9Cg==