func_code_string: #include <bits/stdc++.h>   using namespace std;   const int K = 26;   struct Vertex {     int next[K];     long long int leaf = 0;     int p = -1;     char pch;     int link = -1;     int go[K];     long long int count = -1;     int leaflink = 0;     Vertex(int p = -1, char ch =  $ ) : p(p), pch(ch) {       fill(begin(next), end(next), -1);       fill(begin(go), end(go), -1);     }   };   vector<Vertex> t(1);   void add_string(string const& s) {     int v = 0;     for (char ch : s) {       int c = ch -  a ;       if (t[v].next[c] == -1) {         t[v].next[c] = t.size();         t.emplace_back(v, ch);       }       v = t[v].next[c];     }     t[v].leaf++;   }   int go(int v, char ch);   int get_link(int v);   long long int cnt(int v) {     if (t[v].count == -1) {       if (v == 0)         t[v].count = 0;       else         t[v].count = cnt(get_link(v)) + t[v].leaf;     }     return t[v].count;   }   int get_link(int v) {     if (t[v].link == -1) {       if (v == 0 || t[v].p == 0)         t[v].link = 0;       else         t[v].link = go(get_link(t[v].p), t[v].pch);     }     return t[v].link;   }   int go(int v, char ch) {     int c = ch -  a ;     if (t[v].go[c] == -1) {       if (t[v].next[c] != -1)         t[v].go[c] = t[v].next[c];       else         t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);     }     return t[v].go[c];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string ts;     cin >> ts;     int n;     cin >> n;     vector<string> v;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       v.push_back(s);       reverse(s.begin(), s.end());       add_string(s);     }     int m = ts.size();     vector<long long int> a = vector<long long int>(m, 0);     int cs = 0;     for (int i = m - 1; i > -1; --i) {       get_link(cs);       cs = go(cs, ts[i]);       get_link(cs);       a[i] = cnt(cs);     }     t = vector<Vertex>(1);     for (int i = 0; i < n; ++i) {       add_string(v[i]);     }     cs = 0;     long long int sol = 0;     for (int i = 0; i < m - 1; ++i) {       get_link(cs);       cs = go(cs, ts[i]);       get_link(cs);       sol += cnt(cs) * a[i + 1];     }     cout << sol << endl;   }   