# 2. 题解

#include <bits/stdc++.h>

#define NS (1000005)

using namespace std;

typedef long long LL;

template<typename _Tp> inline void IN(_Tp& dig)
{
char c; bool flag = 0; dig = 0;
while (c = getchar(), !isdigit(c)) if (c == '-') flag = 1;
while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
if (flag) dig = -dig;
}

int n;

char str[NS];

LL ans;

struct N
{
int nxt[26], fa, mxl, sz;
int& operator [] (const char c) {return nxt[c - 'a'];}
} e[NS];

struct SAM
{
int sz, lst;
vector<int> g[NS];
SAM() {sz = lst = 1;}
void insert(char c)
{
int a = ++sz, p = lst;
e[a].mxl = e[p].mxl + 1, e[a].sz = 1, lst = a;
while (!e[p][c] && p) e[p][c] = a, p = e[p].fa;
if (!p) {e[a].fa = 1; return;}
int q = e[p][c];
if (e[q].mxl == e[p].mxl + 1) {e[a].fa = q; return;}
int nq = ++sz;
e[nq] = e[q], e[nq].mxl = e[p].mxl + 1, e[nq].sz = 0;
e[a].fa = e[q].fa = nq;
while (e[p][c] == q) e[p][c] = nq, p = e[p].fa;
}
void Dfs(int a)
{
int tmp = 0;
for (int i = 0; i < g[a].size(); i += 1)
Dfs(g[a][i]), tmp += e[g[a][i]].sz;
for (int i = 0; i < g[a].size(); i += 1)
{
ans -= 1ll * e[g[a][i]].sz * (tmp - e[g[a][i]].sz) * e[a].mxl;
ans -= 2ll * e[g[a][i]].sz * e[a].sz * e[a].mxl;
}
e[a].sz += tmp;
}
void run()
{
for (int i = 2; i <= sz; i += 1) g[e[i].fa].push_back(i);
ans = 1ll * (n - 1) * (1ll * (1 + n) * n / 2);
Dfs(1), printf("%lld\n", ans);
}
} sam;

int main(int argc, char const* argv[])
{
scanf("%s", str + 1), n = strlen(str + 1);
for (int i = n; i >= 1; i -= 1) sam.insert(str[i]);
sam.run();
return 0;
}