func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int cnt2[maxn];   int cnt[maxn];   struct trie {     int nxt[maxn][26], fail[maxn], g[maxn];     int ed[maxn];     int rt, L;     int newnode() {       memset(nxt[L], -1, sizeof nxt[L]);       ed[L++] = 0;       return L - 1;     }     void init() {       L = 0;       rt = newnode();     }     void insert(const string& buf) {       int len = buf.size();       int now = rt;       for (int i = 0; i < len; ++i) {         if (nxt[now][buf[i] -  a ] == -1) nxt[now][buf[i] -  a ] = newnode();         now = nxt[now][buf[i] -  a ];       }       ed[now]++;     }     void build() {       queue<int> q;       fail[rt] = rt;       g[rt] = rt;       for (int i = 0; i < 26; ++i) {         if (nxt[rt][i] == -1)           nxt[rt][i] = rt;         else {           fail[nxt[rt][i]] = rt;           g[nxt[rt][i]] = rt;           q.push(nxt[rt][i]);         }       }       while (!q.empty()) {         int now = q.front();         q.pop();         for (int i = 0; i < 26; ++i) {           if (nxt[now][i] == -1)             nxt[now][i] = nxt[fail[now]][i];           else {             fail[nxt[now][i]] = nxt[fail[now]][i];             if (ed[fail[nxt[now][i]]]) {               g[nxt[now][i]] = fail[nxt[now][i]];             } else               g[nxt[now][i]] = g[fail[nxt[now][i]]];             q.push(nxt[now][i]);           }         }       }     }     void query(const string& buf) {       int len = buf.size();       int now = rt;       for (int i = 0; i < len; ++i) {         now = nxt[now][buf[i] -  a ];         int tmp = now;         while (tmp != rt) {           cnt[i] += ed[tmp];           tmp = g[tmp];         }       }     }   } a, b;   string t;   string s[maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     int n;     cin >> n;     a.init();     for (int i = 1; i <= n; ++i) {       cin >> s[i];       a.insert(s[i]);     }     a.build();     a.query(t);     memcpy(cnt2, cnt, sizeof cnt);     memset(cnt, 0, sizeof cnt);     b.init();     for (int i = 1; i <= n; ++i) {       reverse(s[i].begin(), s[i].end());       b.insert(s[i]);     }     b.build();     reverse(t.begin(), t.end());     b.query(t);     long long ans = 0;     for (int i = 0; i < t.size() - 1; ++i) {       ans += 1ll * cnt2[i] * cnt[t.size() - i - 2];     }     cout << ans;     return 0;   }   