#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const long long mod = 1000000007;
const int maxn = 1e5 + 100;
int wa[maxn * 3], wb[maxn * 3], wv[maxn * 3], wss[maxn * 3];
int c0(int *r, int a, int b) {
  return r[a] == r[b] && r[a + 1] == r[b + 1] && r[a + 2] == r[b + 2];
}
int c12(int k, int *r, int a, int b) {
  if (k == 2)
    return r[a] < r[b] || (r[a] == r[b] && c12(1, r, a + 1, b + 1));
  else
    return r[a] < r[b] || (r[a] == r[b] && wv[a + 1] < wv[b + 1]);
}
void sort(int *r, int *a, int *b, int n, int m) {
  int i;
  for (i = 0; i < n; i++) wv[i] = r[a[i]];
  for (i = 0; i < m; i++) wss[i] = 0;
  for (i = 0; i < n; i++) wss[wv[i]]++;
  for (i = 1; i < m; i++) wss[i] += wss[i - 1];
  for (i = n - 1; i >= 0; i--) b[--wss[wv[i]]] = a[i];
}
void dc3(int *r, int *sa, int n, int m) {
  int i, j, *rn = r + n;
  int *san = sa + n, ta = 0, tb = (n + 1) / 3, tbc = 0, p;
  r[n] = r[n + 1] = 0;
  for (i = 0; i < n; i++)
    if (i % 3 != 0) wa[tbc++] = i;
  sort(r + 2, wa, wb, tbc, m);
  sort(r + 1, wb, wa, tbc, m);
  sort(r, wa, wb, tbc, m);
  for (p = 1, rn[((wb[0]) / 3 + ((wb[0]) % 3 == 1 ? 0 : tb))] = 0, i = 1;
       i < tbc; i++)
    rn[((wb[i]) / 3 + ((wb[i]) % 3 == 1 ? 0 : tb))] =
        c0(r, wb[i - 1], wb[i]) ? p - 1 : p++;
  if (p < tbc)
    dc3(rn, san, tbc, p);
  else
    for (i = 0; i < tbc; i++) san[rn[i]] = i;
  for (i = 0; i < tbc; i++)
    if (san[i] < tb) wb[ta++] = san[i] * 3;
  if (n % 3 == 1) wb[ta++] = n - 1;
  sort(r, wb, wa, ta, m);
  for (i = 0; i < tbc; i++)
    wv[wb[i] = ((san[i]) < tb ? (san[i]) * 3 + 1 : ((san[i]) - tb) * 3 + 2)] =
        i;
  for (i = 0, j = 0, p = 0; i < ta && j < tbc; p++)
    sa[p] = c12(wb[j] % 3, r, wa[i], wb[j]) ? wa[i++] : wb[j++];
  for (; i < ta; p++) sa[p] = wa[i++];
  for (; j < tbc; p++) sa[p] = wb[j++];
}
void da(int str[], int sa[], int rank[], int height[], int n, int m) {
  for (int i = n; i < n * 3; i++) str[i] = 0;
  dc3(str, sa, n + 1, m);
  int i, j, k = 0;
  for (i = 0; i <= n; i++) rank[sa[i]] = i;
  for (i = 0; i < n; i++) {
    if (k) k--;
    j = sa[rank[i] - 1];
    while (str[i + k] == str[j + k]) k++;
    height[rank[i]] = k;
  }
}
int a[maxn * 3], sa[maxn * 3], rk[maxn * 3], height[maxn * 3];
long long cnt(int x) { return 1ll * x * (x + 1) / 2; }
char s[maxn];
int st[maxn];
vector<pair<pair<int, int>, int>> v;
int main() {
  scanf("%s", s);
  int l = (int)strlen(s);
  for (int i = 0; i < l; i++) a[i] = s[i] - 'a' + 1;
  a[l] = 0;
  da(a, sa, rk, height, l, 66);
  long long ans = 0;
  height[l + 1] = 0;
  sa[l + 1] = l;
  for (int i = 1; i < l + 2; i++) {
    while (!v.empty() && v.back().first.second > height[i]) {
      auto &end = v.back();
      if (end.first.first < height[i]) {
        ans += (end.first.second - height[i]) * cnt(i - end.second);
        end.first.second = height[i];
      } else {
        ans += (end.first.second - end.first.first) * cnt(i - end.second);
        v.pop_back();
      }
    }
    v.push_back({{height[i], l - sa[i]}, i});
  }
  printf("%lld\n", ans);
  return 0;
}
