#include <bits/stdc++.h>
#pragma GCC optimise("ofast")
#pragma GCC optimise("unroll-loops")
using namespace std;
const int N = 200000 + 10;
const long long MOD = 1000000000 + 7;
const long long INF = 1000000000000000000;
const long long LOG = 22;
int R[N][LOG], P[N], pw, n, q, l[N], r[N], lcp[N];
string s;
bool cmp(int x, int y) {
  if (R[x][pw] != R[y][pw]) return R[x][pw] < R[y][pw];
  if (max(x, y) + (1 << pw) > n) return x > y;
  return R[x + (1 << pw)][pw] < R[y + (1 << pw)][pw];
}
int GetLcp(int x, int y) {
  int res = 0;
  for (int i = LOG - 1; i >= 0; i--) {
    if (R[x][i] == R[y][i]) {
      res ^= (1 << i), x += (1 << i), y += (1 << i);
    }
  }
  return res;
}
void BuildSuffixArray() {
  for (int i = 1; i <= n; i++) {
    R[i][0] = s[i - 1];
    P[i] = i;
  }
  for (pw = 0; pw < LOG - 1; pw++) {
    sort(P + 1, P + n + 1, cmp);
    R[P[1]][pw + 1] = 1;
    for (int i = 2; i <= n; i++) {
      R[P[i]][pw + 1] = R[P[i - 1]][pw + 1] + cmp(P[i - 1], P[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    lcp[i] = GetLcp(P[i], P[i + 1]);
  }
  return;
}
void Main() {
  long long ans = 0;
  cin >> s;
  n = s.size();
  memset(R, 0, sizeof R);
  memset(P, 0, sizeof P);
  memset(l, 0, sizeof l);
  memset(r, 0, sizeof r);
  BuildSuffixArray();
  stack<int> st;
  st.push(0);
  lcp[0] = -1;
  for (int i = 1; i < n; i++) {
    while (lcp[st.top()] >= lcp[i]) st.pop();
    l[i] = st.top();
    st.push(i);
  }
  while (st.size()) st.pop();
  st.push(n);
  lcp[n] = -1;
  for (int i = n - 1; i > 0; i--) {
    while (lcp[st.top()] > lcp[i]) st.pop();
    r[i] = st.top();
    st.push(i);
  }
  for (int i = 1; i < n; i++) {
    ans += (r[i] - i) * 1ll * (i - l[i]) * lcp[i];
  }
  ans += n * 1ll * (n + 1) / 2;
  cout << ans;
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Main();
  return 0;
}
