/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.09.09 02:28:30
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


template< typename T >
struct SparseTable {
    using Func = std::function<T(T, T)>;
    std::vector<std::vector< T > > st;
    std::vector< int > lookup;
    Func F;
    SparseTable() {}
    SparseTable(const std::vector< T > &v, Func F) : F(F) {
        int b = 0;
        while ((1 << b) <= v.size()) ++b;
        st.assign(b, std::vector< T >(1 << b));
        for(int i = 0; i < v.size(); i++) st[0][i] = v[i];
        for(int i = 1; i < b; i++) for (int j = 0; j + (1 << i) <= (1 << b); j++) st[i][j] = F(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
        lookup.resize(v.size() + 1);
        for(int i = 2; i < lookup.size(); i++) lookup[i] = lookup[i >> 1] + 1;
    }
    
    inline T rmq(int l, int r) {
        int b = lookup[r - l];
        return F(st[b][l], st[b][r - (1 << b)]);
    }
};
template<typename T>
struct SuffixArray {
private:
    std::vector< int > rank;
    std::vector< T > s;
    SparseTable< int > st;
    
    bool lt_substr(std::vector< T >& t, int si = 0, int ti = 0)
    {
        int sn = s.size(), tn = t.size();
        while (si < sn && ti < tn) {
            if (s[si] < t[ti]) return (true);
            if (s[si] > t[ti]) return (false);
            ++si, ++ti;
        }
        return (si >= sn && ti < tn);
    }
    
    
    int lower_bound(std::vector< T >& t)
    {
        int low = -1, high = SA.size();
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (lt_substr(t, SA[mid])) low = mid;
            else high = mid;
        }
        return high;
    }
    
    
    std::pair<int, int> lower_upper_bound(std::vector< T >& t) {
        int idx = lower_bound(t);
        int low = idx - 1, high = SA.size();
        t.back()++;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (lt_substr(t, SA[mid])) low = mid;
            else high = mid;
        }
        t.back()--;
        return {idx, high};
    }
public:
    std::vector< int > SA, LCP;
    SuffixArray(const std::vector< T >& str) : s(str)
    {
        SA.resize(s.size());
        iota(begin(SA), end(SA), 0);
        sort(begin(SA), end(SA), [&](const int& a, const int& b)
        {
            if (s[a] == s[b]) return(a > b);
            return (s[a] < s[b]);
        });
        std::vector< int > classes(s.size()), c(s.size()), cnt(s.size());
        for (int i = 0; i < (int)s.size(); i++) {
            c[i] = s[i];
        }
        for (int len = 1; len < (int)s.size(); len <<= 1) {
            for (int i = 0; i < (int)s.size(); i++) {
                if (i > 0 && c[SA[i - 1]] == c[SA[i]] && SA[i - 1] + len < (int)s.size() && c[SA[i - 1] + len / 2] == c[SA[i] + len / 2]) {
                    classes[SA[i]] = classes[SA[i - 1]];
                }
                else {
                    classes[SA[i]] = i;
                }
            }
            iota(begin(cnt), end(cnt), 0);
            copy(begin(SA), end(SA), begin(c));
            for (int i = 0; i < (int)s.size(); i++) {
                int s1 = c[i] - len;
                if (s1 >= 0) SA[cnt[classes[s1]]++] = s1;
            }
            classes.swap(c);
        }
    }
    int count(std::vector< T > &t) {
        std::pair<int, int> p = lower_upper_bound(t);
        return p.second - p.first;
    }
    
    
    std::vector<int> find(std::vector< T > &t) {
        std::vector<int> v;
        std::pair<int, int> p = lower_upper_bound(t);
        for (int i = p.first; i < p.second; i++) {
            v.push_back(SA[i]);
        }
        return v;
    }
    void print_sa() {
        for (int i = 0; i < (int)s.size(); i++) {
            std::cout << i << ": ";
            for (int j = SA[i]; j < s.size(); j++) {
                std::cout << s[j];
            }
            std::cout << std::endl;
        }
    }
    
    void build_lcp() {
        rank.resize(s.size());
        for (int i = 0; i < (int)s.size(); i++) rank[SA[i]] = i;
        LCP.resize(s.size());
        LCP[0] = 0;
        for (int i = 0, h = 0; i < (int)s.size(); i++) {
            if (rank[i] + 1 < (int)s.size()) {
                for (int j = SA[rank[i] + 1]; std::max(i, j) + h < s.size() && s[i + h] == s[j + h]; ++h);
                LCP[rank[i] + 1] = h;
                if (h > 0) --h;
            }
        }
        st = SparseTable<int>(LCP, [](int x, int y) {return std::min(x, y); });
    }
    void print_lcp() {
        std::cout << "No.\tLCP\tsuffix" << std::endl;
        std::cout << "----------------------" << std::endl;
        for (int i = 0; i < (int)s.size(); i++) {
            std::cout << i << ":\t" << LCP[i] << "\t";
            for (int j = SA[i]; j < s.size(); j++) {
                std::cout << s[j];
            }
            std::cout << std::endl;
        }
    }
    
    int get_lcp(int a, int b) {
        if (a == b) return (int)s.size() - a;
        return st.rmq(std::min(rank[a], rank[b]) + 1, std::max(rank[a], rank[b]) + 1);
    }
};
int main() {
    string s;cin >> s;
    ll n = (int)s.size();
    ll ans = n * (n + 1) / 2;
    vector<char> str(n);
    for (int i = 0; i < n; i++) {
        str[i] = s[i];
    }
    SuffixArray<char> sa(str);
    sa.build_lcp();
    for (int i = 0; i < n - 1; i++) {
        ans -= sa.get_lcp(sa.SA[i],sa.SA[i+1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 51676