#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector")
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
template <class T>
auto dud(T *x) -> decltype(cerr << *x, 0);
template <class T>
char dud(...);
struct debug {
  template <class T>
  debug &operator<<(const T &) {
    return *this;
  }
};
struct SuffixAutomaton {
  vector<map<char, int> > trie;
  vector<int> link, len;
  vector<long long> occ, mem;
  int last;
  SuffixAutomaton() { last = newNode(); }
  int newNode() {
    trie.push_back({}), link.push_back(-1), len.push_back(0), occ.push_back(0),
        mem.push_back(-1);
    return int(trie.size()) - 1;
  }
  void extend(char c) {
    int u = newNode();
    occ[u] = 1;
    len[u] = len[last] + 1;
    int p = last;
    while (p != -1 && !trie[p].count(c)) {
      trie[p][c] = u;
      p = link[p];
    }
    if (p == -1)
      link[u] = 0;
    else {
      int q = trie[p][c];
      if (len[p] + 1 == len[q])
        link[u] = q;
      else {
        int clone = newNode();
        len[clone] = len[p] + 1;
        trie[clone] = trie[q];
        link[clone] = link[q];
        while (p != -1 && trie[p][c] == q) {
          trie[p][c] = clone;
          p = link[p];
        }
        link[q] = link[u] = clone;
      }
    }
    last = u;
  }
  void occurs() {
    vector<int> who;
    for (auto u = (1) - ((1) > (int(trie.size())));
         u != int(trie.size()) - ((1) > (int(trie.size())));
         u += 1 - 2 * ((1) > (int(trie.size()))))
      who.push_back(u);
    sort(begin(who), end(who), [&](int u, int v) { return len[u] > len[v]; });
    for (int u : who) occ[link[u]] += occ[u];
  }
  long long dp(int u) {
    long long &ans = mem[u];
    if (ans == -1) {
      ans = 0;
      for (auto &[c, v] : trie[u]) {
        ans += dp(v);
        ans += occ[v] * (occ[v] + 1) / 2;
      }
    }
    return ans;
  }
} sam;
string second;
int main() {
  cin.tie(0)->sync_with_stdio(0), cout.tie(0);
  while (cin >> second) {
    sam = SuffixAutomaton();
    for (char c : second) sam.extend(c);
    sam.occurs();
    cout << sam.dp(0) << '\n';
  }
  return 0;
}
