#include <bits/stdc++.h>
const int oo = 2139063143;
const int N = 1010000;
const int mod = 1000000007;
using namespace std;
inline void sc(int &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
struct SAM {
  int len, fa, son[28], siz;
} sam[N];
int tot = 1;
int pre = 1;
void addchar(int c) {
  int f = pre, p = ++tot;
  pre = p;
  sam[p].len = sam[f].len + 1, sam[p].siz = 1;
  while (f && !sam[f].son[c]) sam[f].son[c] = p, f = sam[f].fa;
  if (!f) {
    sam[p].fa = 1;
    return;
  }
  int x = sam[f].son[c];
  if (sam[x].len == sam[f].len + 1) {
    sam[p].fa = x;
    return;
  }
  int y = ++tot;
  sam[y].len = sam[f].len + 1, sam[y].fa = sam[x].fa, sam[x].fa = sam[p].fa = y;
  memcpy(sam[y].son, sam[x].son, sizeof(sam[y].son));
  while (f && sam[f].son[c] == x) sam[f].son[c] = y, f = sam[f].fa;
}
char s[N];
queue<int> q;
int deg[N];
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) addchar(s[i] - 'a' + 1);
  for (int i = 1; i <= tot; i++) ++deg[sam[i].fa];
  for (int i = 1; i <= tot; i++)
    if (!deg[i]) q.push(i);
  while (q.size()) {
    int u = q.front(), f = sam[u].fa;
    q.pop();
    sam[f].siz += sam[u].siz;
    if (!(--deg[f])) q.push(f);
  }
  long long ans = 0;
  for (int i = 1; i <= tot; i++)
    ans += 1LL * sam[i].siz * (sam[i].siz + 1) / 2 *
           (sam[i].len - sam[sam[i].fa].len);
  printf("%lld\n", ans);
  return 0;
}
