func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 + 1;   char s[maxn];   const int ci = 26;   struct vertex {     vertex *go[ci];     vertex *suf;     bool term;     int len;     int d[2];     vertex(int _len = 0) : suf(0), term(0), len(_len) {       for (int i = 0; i < ci; i++) go[i] = 0;     }   };   vertex vs[2 * maxn];   vertex *last;   int m;   void addch(int ch) {     vs[m++] = vertex();     vertex *newlast = &vs[m - 1];     newlast->len = last->len + 1;     for (; last && !last->go[ch]; last = last->suf) last->go[ch] = newlast;     if (!last)       newlast->suf = &vs[0];     else {       vertex *next = last->go[ch];       if (last->len + 1 == next->len)         newlast->suf = next;       else {         vs[m++] = *next;         vertex *clone = &vs[m - 1];         clone->len = last->len + 1;         next->suf = clone;         newlast->suf = clone;         for (; last && last->go[ch] == next; last = last->suf)           last->go[ch] = clone;       }     }     last = newlast;   }   int checked[maxn];   void dfscheck(vertex *v, string s, string now) {     if (v->term) {       assert(now == string(s, (int)s.length() - (int)now.length()));       checked[(int)now.length()]++;     }     for (int i = 0; i < ci; i++)       if (v->go[i]) dfscheck(v->go[i], s, now + (char)( a  + i));   }   vertex *fivs[2 * maxn];   const int maxl = 2 * maxn;   int cnt[maxl];   int head[maxl];   int main() {     while (scanf( %s , s) >= 1) {       m = 0;       vs[m++] = vertex();       last = &vs[0];       int n = strlen(s);       for (int i = 0; i < n; i++) {         addch(s[i] -  a );       }       for (vertex *now = last; now; now = now->suf) now->term = 1;       memset(cnt, 0, sizeof(cnt));       for (int i = 0; i < m; i++) cnt[vs[i].len]++;       head[0] = 0;       for (int i = 1; i < m; i++) head[i] = head[i - 1] + cnt[i - 1];       for (int i = 0; i < m; i++) fivs[head[vs[i].len]++] = &vs[i];       reverse(fivs, fivs + m);       for (int i = 0; i < m; i++) {         vertex *v = fivs[i];         v->d[0] = (int)v->term;         for (int j = 0; j < ci; j++)           if (v->go[j]) v->d[0] += v->go[j]->d[0];         v->d[1] = 0;       }       fivs[m - 1]->d[1] = 1;       for (int i = m - 1; i >= 0; i--) {         vertex *v = fivs[i];         for (int j = 0; j < ci; j++)           if (v->go[j]) v->go[j]->d[1] += v->d[1];       }       long long ans = 0;       for (int i = 0; i < m - 1; i++) {         int f = fivs[i]->d[0], s = fivs[i]->d[1];         ans += (long long)s * (long long)f * (f + 1) / 2;       }       printf(            %lld              n ,           ans);     }     return 0;   }   