#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 1e5 + 10, L = 20;
const long long E = 1e6;
int n, suff[N];
long long ans, cur, ind[L][N];
string s;
map<int, int, greater<int> > m;
map<int, int, greater<int> >::iterator it;
inline int LCP(int i, int j) {
  int lcp = 0;
  for (int l = L - 1; l >= 0; l--)
    if (ind[l][i] == ind[l][j]) {
      lcp += 1 << l;
      i += 1 << l;
      j += 1 << l;
    }
  return lcp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  n = s.length();
  vector<int> v;
  for (int i = 0; i < n; i++) v.push_back(s[i] - 'a' + 1);
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (int i = 0; i < n; i++)
    ind[0][i] =
        (lower_bound(v.begin(), v.end(), s[i] - 'a' + 1) - v.begin()) + 1;
  for (int l = 1; l < L; l++) {
    vector<long long> v;
    for (int i = 0; i < n; i++) {
      ind[l][i] = E * ind[l - 1][i];
      int next = i + (1 << l - 1);
      if (next < n) ind[l][i] += ind[l - 1][next];
      v.push_back(ind[l][i]);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for (int i = 0; i < n; i++)
      ind[l][i] = (lower_bound(v.begin(), v.end(), ind[l][i]) - v.begin()) + 1;
  }
  for (int i = 0; i < n; i++) suff[ind[L - 1][i] - 1] = i;
  ans = cur = n - suff[0];
  m[n - suff[0]]++;
  for (int i = 1; i < n; i++) {
    cur += n - suff[i];
    int l = LCP(suff[i], suff[i - 1]), cnt = 0;
    while (!m.empty() && m.begin()->first > l) {
      it = m.begin();
      cur -= it->second * (it->first - l);
      cnt += it->second;
      m.erase(it);
    }
    m[l] += cnt;
    m[n - suff[i]]++;
    ans += cur;
  }
  cout << ans << endl;
  return 0;
}
