#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int rk[N], len, n;
char ch[N], v[N];
int a[N];
namespace lzr {
int sa[N], lcp[N];
struct cmp {
  const int h, *g;
  cmp(int h, int *g) : h(h), g(g) {}
  bool operator()(int l, int r) {
    return g[l] != g[r] ? g[l] < g[r] : g[l + h] < g[r + h];
  }
};
void build(const char *t, int n) {
  static int g[N], rk[N];
  for (int(i) = (0); (i) <= (n); (i)++) sa[i] = i, g[i] = t[i];
  rk[0] = rk[n] = 0;
  sort(sa, sa + n + 1, cmp(0, g));
  for (int h = 1; rk[n] != n; h *= 2) {
    cmp a(h, g);
    sort(sa, sa + n + 1, a);
    for (int(i) = (0); (i) <= (n - 1); (i)++)
      rk[i + 1] = rk[i] + a(sa[i], sa[i + 1]);
    for (int(i) = (0); (i) <= (n); (i)++) g[sa[i]] = rk[i];
  }
  for (int(i) = (0); (i) <= (n); (i)++) rk[sa[i]] = i;
  int h = 0;
  for (int(i) = (0); (i) <= (n - 1); (i)++) {
    const int j = sa[rk[i] - 1];
    while (j + h < n && i + h < n && t[j + h] == t[i + h]) h++;
    lcp[rk[i]] = h;
    if (h) h--;
  }
  lcp[0] = -1;
}
};  // namespace lzr
using namespace lzr;
inline long long f(int x) { return (long long)x * (x + 1) / 2; }
int main() {
  scanf("%s", ch);
  n = strlen(ch);
  build(ch, n);
  long long ans = 0;
  vector<pair<pair<int, int>, int> > v;
  lcp[n + 1] = 0;
  sa[n + 1] = n;
  for (int(i) = (1); (i) <= (n + 1); (i)++) {
    while (!v.empty() && v.back().first.second > lcp[i]) {
      pair<pair<int, int>, int> &now = v.back();
      if (now.first.first < lcp[i]) {
        ans += (now.first.second - lcp[i]) * f(i - now.second);
        now.first.second = lcp[i];
      } else
        ans += (now.first.second - now.first.first) * f(i - now.second),
            v.pop_back();
    }
    v.push_back(make_pair(make_pair(lcp[i], n - sa[i]), i));
  }
  printf("%I64d", ans);
  return 0;
}
