#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

template <size_t N>
struct SuffixArray {
  int s[N]; // last char must be smallest.
  int sa[N], r[N], height[N];
  int t[2][N], c[N];
  int n;

  void da(int m) {
    int *x = t[0], *y = t[1];
    fill(c, c + m, 0);
    for (int i = 0; i < n; ++i) c[x[i] = s[i]]++;
    for (int i = 1; i < m; ++i) c[i] += c[i - 1];
    for (int i = n - 1; i >= 0; --i) sa[--c[x[i]]] = i;
    for (int k = 1, p = 0; p < n; k <<= 1, m = p) {
      p = 0;
      for (int i = n - k; i < n; ++i) y[p++] = i;
      for (int i = 0; i < n; ++i) if (sa[i] >= k) y[p++] = sa[i] - k;
      fill(c, c + m, 0);
      for (int i = 0; i < n; ++i) c[x[y[i]]]++;
      for (int i = 1; i < m; ++i) c[i] += c[i - 1];
      for (int i = n - 1; i >= 0; --i) sa[--c[x[y[i]]]] = y[i];
      swap(x, y);
      x[sa[0]] = 0; p = 1;
      for (int i = 1; i < n; ++i) {
        x[sa[i]] = y[sa[i - 1]] == y[sa[i]] &&
          y[sa[i - 1] + k] == y[sa[i] + k] ? p - 1 : p++;
      }
    }
  }

  #define F(x) x/3+(x%3==1?0:tb)
  #define G(x) x>=tb?(x-tb)*3+2:x*3+1

  bool c0(int* r, int a, int b) {
    return r[a] == r[b] && r[a + 1] == r[b + 1] && r[a + 2] == r[b + 2];
  }

  bool c12 (int k, int* r, int a, int b) {
    if (k == 1) return r[a] < r[b] || (r[a] == r[b] && c[a + 1] < c[b + 1]);
    return r[a] < r[b] || (r[a] == r[b] && c12(1, r, a + 1, b + 1));
  }

  void sort(int* r, int* a, int* b, int n, int m) {
    fill(c, c + m, 0);
    for (int i = 0; i < n; ++i) c[r[a[i]]]++;
    for (int i = 1; i < m; ++i) c[i] += c[i - 1];
    for (int i = n - 1; i >= 0; --i) b[--c[r[a[i]]]] = a[i];
  }

  void dc3(int* r, int* sa, int n, int m) {
    int *san = sa + n, *rn = r + n, ta = 0, tb = (n + 1) / 3, tbc = 0, i, j, p;
    int *x = t[0], *y = t[1];
    for (i = 0; i < n; ++i) if (i % 3) x[tbc++] = i;
    r[n] = r[n + 1] = 0;
    sort(r + 2, x, y, tbc, m);
    sort(r + 1, y, x, tbc, m);
    sort(r, x, y, tbc, m);
    rn[F(y[0])] = 0;
    for (p = 1, i = 1; i < tbc; ++i) {
      rn[F(y[i])] = c0(r, y[i - 1], y[i]) ? p - 1 : p++;
    }
    if (p < tbc) dc3(rn, san, tbc, p);
    else for (i = 0; i < tbc; ++i) san[rn[i]] = i;
    for (i = 0; i < tbc; ++i) if (san[i] < tb) y[ta++] = san[i] * 3;
    if (n % 3 == 1) y[ta++] = n - 1;
    sort(r, y, x, ta, m);
    for (i = 0; i < tbc; ++i) c[y[i] = G(san[i])] = i;
    for (p = 0, i = 0, j = 0; i < ta && j < tbc; ++p) {
      sa[p] = c12(y[j] % 3, r, y[j], x[i]) ? y[j++] : x[i++];
    }
    for (; i < ta; ++i) sa[p++] = x[i];
    for (; j < tbc; ++j) sa[p++] = y[j];
  }

  int64 build_height() {
    int64 ret = 0;
    for (int i = 0; i < n; ++i) r[sa[i]] = i;
    for (int i = 0, k = 0; i < n - 1; ++i) {
      if (k) --k;
      int j = sa[r[i] - 1];
      while (s[i + k] == s[j + k]) ++k;
      height[r[i]] = k;
      ret += i + 1 - k;
    }
    return ret;
  }
};

const int SIGMA = 256;
const int N = 5e5 + 10;

int main() {
  string s;
  cin >> s;
  SuffixArray<N> sa;
  copy(s.begin(), s.end(), sa.s);
  sa.n = SZ(s) + 1;
  sa.s[SZ(s)] = 0;
  sa.dc3(sa.s, sa.sa, sa.n, SIGMA);
  cout << sa.build_height() << '\n';

  return 0;
}


Measured memory_bytes: 15820