#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct SuffixArray{
    vector<int> suffix_array;
    const string s;
    const int n;

    SuffixArray(const string& str) : s(str), n((int)str.size()) {
        suffix_array.resize(n + 1);
        vector<int> rank(n + 1), nxt_rank(n + 1);
        for(int i = 0; i <= n; ++i){
            suffix_array[i] = i;
            rank[i] = i < n ? s[i] : -1;
        }

        for(int k = 1; k <= n; k <<= 1){
            auto comp = [&](int i, int j) -> bool {
                if(rank[i] != rank[j])  return rank[i] < rank[j];
                else{
                    int ni = i + k <= n ? rank[i + k] : -1;
                    int nj = j + k <= n ? rank[j + k] : -1;
                    return ni < nj;
                }
            };
            sort(begin(suffix_array), end(suffix_array), comp);
            
            nxt_rank[suffix_array[0]] = 0;
            for(int i = 1; i <= n; ++i){
                nxt_rank[suffix_array[i]] = nxt_rank[suffix_array[i - 1]]
                                            + comp(suffix_array[i - 1], suffix_array[i]);
            }
            copy(begin(nxt_rank), end(nxt_rank), begin(rank));
        }
    }

    int operator[](int k) const { return suffix_array[k]; }

    int size() const { return n; }

    // s 中に t があるか O(|t|*log|s|)
    bool is_contain(const string& t){
        int lb = 0, ub = n;
        while(ub - lb > 1){
            int mid = (lb + ub) / 2;
            if(s.compare(suffix_array[mid], t.length(), t) < 0) lb = mid;
            else    ub = mid;
        }
        return s.compare(suffix_array[ub], t.length(), t) == 0;
    }

    void output() {
        for(int i = 0; i <= n; ++i){
            cout << i << "(" << suffix_array[i] << "):" << s.substr(suffix_array[i]) << '\n';
        }
    }
};

// suffix array で隣り合う文字列の最長共通接頭辞配列
struct LongestCommonPrefixArray{
    const SuffixArray& SA;
    vector<int> LCP, rank;
    const int n;

    LongestCommonPrefixArray(const SuffixArray& SA) : SA(SA), n(SA.size()) {
        LCP.resize(n + 1);
        rank.resize(n + 1);
        for(int i = 0; i <= n; ++i) rank[SA[i]] = i;
        
        int h = 0;
        LCP[0] = 0;
        for(int i = 0; i < n; ++i){
            // 文字列中での位置 i の接尾辞と、接尾辞配列中でその一つ前の接尾辞の LCP を求める
            int j = SA[rank[i] - 1];

            // 先頭の分をデクリメント
            if(h > 0)   --h;
            for(; j + h < n && i + h < n; ++h){
                if(SA.s[j + h] != SA.s[i + h])  break;
            }
            LCP[rank[i] - 1] = h;
        }
    }

    int operator[](int k) const { return LCP[k]; }

    size_t size() const { return LCP.size(); }

    void output() {
        for(int i = 0; i < (int)size(); ++i){
            cout << i << ':' << LCP[i] << ',' << SA.s.substr(SA[i]) << '\n';
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;
    int n = s.length();
    SuffixArray sa(s);
    LongestCommonPrefixArray lcp(sa);
    ll ans = (ll)n * (n + 1) / 2;
    for(int i = 0; i < (int)lcp.size(); ++i)	ans -= lcp[i];
    cout << ans << endl;
}

Measured memory_bytes: 10072