#include <bits/stdc++.h>
using namespace std;
struct state {
  int len, link;
  map<char, int> next;
};
state node[2 * 1000000 + 5];
int sz, last;
long long cnt[2 * 1000000 + 5];
long long mark[2 * 1000000 + 5] = {0};
vector<pair<int, int> > vt;
inline void init() {
  sz = last = 0;
  node[0].len = 0;
  node[0].link = -1;
  ++sz;
}
inline void Insert(char c) {
  int cur = sz++;
  node[cur].len = node[last].len + 1;
  int p;
  for (p = last; p != -1 && !node[p].next.count(c); p = node[p].link)
    node[p].next[c] = cur;
  if (p == -1) {
    node[cur].link = 0;
  } else {
    int q = node[p].next[c];
    if (node[p].len + 1 == node[q].len) {
      node[cur].link = q;
    } else {
      int clone = sz++;
      node[clone].len = node[p].len + 1;
      node[clone].next = node[q].next;
      node[clone].link = node[q].link;
      for (; p != -1 && node[p].next[c] == q; p = node[p].link)
        node[p].next[c] = clone;
      node[q].link = node[cur].link = clone;
      cnt[clone] = 0ll;
      vt.push_back(make_pair(node[clone].len, clone));
    }
  }
  cnt[cur] = 1ll;
  vt.push_back(make_pair(node[cur].len, cur));
  last = cur;
  return;
}
char s[1000000 + 5];
long long dp[2 * 1000000 + 5];
inline long long solve(int u) {
  if (dp[u] != -1ll) return dp[u];
  dp[u] = cnt[u];
  for (pair<char, int> x : node[u].next) {
    dp[u] += solve(x.second);
  }
  return dp[u];
}
int main() {
  init();
  scanf("%s", s);
  int n = strlen(s);
  for (int i = 0; i < n; i++) {
    Insert(s[i]);
  }
  sort(vt.rbegin(), vt.rend());
  mark[last] = 1;
  for (pair<int, int> x : vt) {
    cnt[node[x.second].link] += cnt[x.second];
    long long y = cnt[x.second];
    cnt[x.second] = y * (y + 1ll) / 2ll;
  }
  cnt[0] = 0ll;
  memset((dp), (-1ll), sizeof((dp)));
  ;
  printf("%lld\n", solve(0));
  ;
  return 0;
}
