func_code_string: #include <bits/stdc++.h>   using namespace std;   int T, n;   char Ls[400000 + 5], ps[400000 + 5];   long long ans;   long long read() {     long long x = 0, F = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) F = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * F;   }   struct AC_automaton {     int tr[400000 + 5][26], cnt;     int C_end[400000 + 5], fail[400000 + 5], Ans[400000 + 5], lst[400000 + 5];     void Clear() {       cnt = 0;       fail[0] = 0;       memset(tr[0], 0, sizeof(tr[0]));       memset(Ans, 0, sizeof(Ans));     }     void Insert(char *s, int id) {       int p = 0, len = strlen(s);       for (int i = 0; i < len; i++) {         int num = s[i] -  a ;         if (!tr[p][num]) {           tr[p][num] = ++cnt;           C_end[cnt] = 0;           memset(tr[cnt], 0, sizeof(tr[cnt]));           fail[cnt] = 0;         }         p = tr[p][num];       }       C_end[p]++;     }     void Build() {       queue<int> Q;       for (int i = 0; i < 26; i++)         if (tr[0][i]) Q.push(tr[0][i]);       while (!Q.empty()) {         int k = Q.front();         Q.pop();         for (int i = 0; i < 26; i++)           if (tr[k][i]) {             int nxt = tr[k][i];             fail[nxt] = tr[fail[k]][i];             Q.push(nxt);             lst[nxt] = C_end[fail[nxt]] ? fail[nxt] : lst[fail[nxt]];           } else             tr[k][i] = tr[fail[k]][i];       }     }     void Query(char *s) {       int p = 0;       int len = strlen(s);       for (int i = 0; i < len; i++) {         if (s[i] <  a  || s[i] >  z ) {           p = 0;           continue;         }         p = tr[p][s[i] -  a ];         for (int j = p; j; j = lst[j]) Ans[i] += C_end[j];       }     }   } ac, ac2;   int main() {     ac.Clear();     ac2.Clear();     scanf( %s , Ls);     n = read();     int L;     for (int i = 1; i <= n; i++) {       scanf( %s , ps);       ac.Insert(ps, i);       L = strlen(ps);       reverse(ps, ps + L);       ac2.Insert(ps, i);     }     int len = strlen(Ls);     ac.Build(), ac2.Build();     ac.Query(Ls);     reverse(Ls, Ls + len);     ac2.Query(Ls);     for (int i = 0; i < len - 1; i++)       ans += 1LL * ac.Ans[i] * ac2.Ans[len - i - 2];     printf( %lld , ans);   }   