#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  static unsigned long long splitmix64(unsigned long long x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(unsigned long long x) const {
    static const unsigned long long FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
mt19937 random_generator(
    chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e5 + 3;
string s;
void read() { cin >> s; }
struct suffix {
  int first, second, idx;
  bool operator<(const suffix &t) const {
    if (first != t.first) return first < t.first;
    return second < t.second;
  }
  suffix() {}
  suffix(int _first, int _second, int _idx) {
    first = _first, second = _second, idx = _idx;
  }
};
int idx[maxn][19];
suffix suffixes[maxn];
int suffix_array[maxn];
int lcp(int i, int j) {
  int ans = 0;
  int sz = s.size();
  for (int k = 18; k >= 0 && i <= sz && j <= sz; k--)
    if (idx[i][k] == idx[j][k]) ans += (1 << k), i += (1 << k), j += (1 << k);
  return ans;
}
pair<int, int> tr[maxn * 4];
int a[maxn];
void merge(int v) { tr[v] = min(tr[v * 2], tr[v * 2 + 1]); }
void build(int v, int l, int r) {
  if (l == r) {
    tr[v] = {a[l], l};
    return;
  }
  int mid = (l + r) / 2;
  build(v * 2, l, mid);
  build(v * 2 + 1, mid + 1, r);
  merge(v);
}
pair<int, int> get(int v, int l, int r, int ll, int rr) {
  if (l > rr || r < ll) return {INT_MAX, INT_MAX};
  if (l >= ll && r <= rr) return tr[v];
  int mid = (l + r) / 2;
  return min(get(v * 2, l, mid, ll, rr), get(v * 2 + 1, mid + 1, r, ll, rr));
}
long long f(int l, int r) {
  if (l > r) return 0;
  if (l == r) return a[l];
  int idx = get(1, 1, (int)s.size() - 1, l, r).second;
  long long ans = f(l, idx - 1) + f(idx + 1, r);
  ans += 1ll * (idx - l + 1) * (r - idx + 1) * a[idx];
  return ans;
}
void solve() {
  int sz = s.size();
  for (int i = 1; i <= sz; i++) idx[i][0] = s[i - 1] - 'a' + 1;
  for (int j = 1; j <= 18; j++) {
    for (int i = 1; i <= sz; i++)
      suffixes[i] = suffix(
          idx[i][j - 1],
          i + (1 << (j - 1)) <= sz ? idx[i + (1 << (j - 1))][j - 1] : 0, i);
    sort(suffixes + 1, suffixes + sz + 1);
    int curr_idx = 1;
    idx[suffixes[1].idx][j] = curr_idx;
    for (int i = 2; i <= sz; i++) {
      if (suffixes[i].first != suffixes[i - 1].first ||
          suffixes[i].second != suffixes[i - 1].second)
        curr_idx++;
      idx[suffixes[i].idx][j] = curr_idx;
    }
  }
  for (int i = 1; i <= sz; i++) suffix_array[idx[i][18]] = i;
  for (int i = 1; i <= sz - 1; i++)
    a[i] = lcp(suffix_array[i], suffix_array[i + 1]);
  build(1, 1, sz - 1);
  long long ans = 1ll * sz * (sz + 1) / 2;
  ans += f(1, sz - 1);
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
