#include <bits/stdc++.h>
using namespace std;
namespace zzc {
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
const int maxn = 4e5 + 5;
long long n, ans;
char ch[maxn];
namespace suffix_automaton {
int tot = 1, lst = 1;
int t[maxn], sa[maxn], len[maxn], link[maxn], siz[maxn], trans[maxn][26];
void insert(int x) {
  int cur = ++tot, tmp = lst;
  lst = cur;
  siz[cur] = 1;
  len[cur] = len[tmp] + 1;
  for (; tmp && !trans[tmp][x]; tmp = link[tmp]) trans[tmp][x] = cur;
  if (!tmp) {
    link[cur] = 1;
  } else {
    int q = trans[tmp][x];
    if (len[tmp] + 1 == len[q]) {
      link[cur] = q;
    } else {
      int clone = ++tot;
      len[clone] = len[tmp] + 1;
      link[clone] = link[q];
      link[q] = link[cur] = clone;
      for (int i = 0; i <= 25; i++) trans[clone][i] = trans[q][i];
      for (; tmp && trans[tmp][x] == q; tmp = link[tmp]) trans[tmp][x] = clone;
    }
  }
}
void sort() {
  for (int i = 1; i <= tot; i++) t[len[i]]++;
  for (int i = 1; i <= tot; i++) t[i] += t[i - 1];
  for (int i = 1; i <= tot; i++) sa[t[len[i]]--] = i;
  for (int i = tot; i >= 1; i--) {
    int x = sa[i];
    siz[link[x]] += siz[x];
    ans += 1ll * (siz[x] + 1) * siz[x] / 2 * (len[x] - len[link[x]]);
  }
}
}  // namespace suffix_automaton
using namespace suffix_automaton;
void work() {
  scanf("%s", ch + 1);
  n = strlen(ch + 1);
  for (int i = 1; i <= n; i++) insert(ch[i] - 'a');
  sort();
  printf("%lld\n", ans);
}
}  // namespace zzc
int main() {
  zzc::work();
  return 0;
}
