func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, Q;   string s[200200];   int ep[200200];   int len[200200];   struct data {     int to, nxt;   } mp[400400];   int head[200200], cnt;   void link(int x, int y) {     mp[++cnt].to = y;     mp[cnt].nxt = head[x];     head[x] = cnt;   }   int id[200200], clk;   int siz[200200];   void dfs(int x) {     id[x] = ++clk;     siz[x] = 1;     for (int i = head[x]; i; i = mp[i].nxt)       dfs(mp[i].to), siz[x] += siz[mp[i].to];   }   struct Bit {     int C[200200];     int ma;     int lb(int x) { return x & (-x); }     void ins(int x) {       while (x <= ma) C[x]++, x += lb(x);     }     int ask(int x) {       int r = 0;       while (x) r += C[x], x -= lb(x);       return r;     }     int query(int l, int r) { return ask(r) - ask(l - 1); }   } bit;   struct AC_AM {     int ch[200200][26], tot;     void ins(int x) {       int u = 1, c;       for (int i = 0; i < len[x]; ++i) {         c = s[x][i] -  a ;         if (!ch[u][c]) {           ch[u][c] = ++tot;         }         u = ch[u][c];       }       ep[x] = u;     }     queue<int> q;     int fail[200200];     void getfail() {       for (int i = 0; i < 26; ++i)         if (ch[1][i]) q.push(ch[1][i]), fail[ch[1][i]] = 1;       int u, v;       while (!q.empty()) {         u = q.front();         q.pop();         for (int c = 0; c < 26; ++c) {           v = ch[u][c];           if (!v)             ch[u][c] = max(ch[fail[u]][c], 1);           else {             fail[v] = max(ch[fail[u]][c], 1);             q.push(v);           }         }       }       for (int i = 2; i <= tot; ++i) link(fail[i], i);     }     void in(int x) {       int u = 1, c;       for (int i = 0; i < len[x]; ++i) {         bit.ins(id[u]);         c = s[x][i] -  a ;         u = ch[u][c];       }       bit.ins(id[u]);     }   } AC;   struct Que {     int k, p, sym, id;     bool operator<(const Que &o) const { return p < o.p; }   } que[1000100];   int tq;   int ans[500500];   int calc(int x) { return bit.query(id[ep[x]], id[ep[x]] + siz[ep[x]] - 1); }   int main() {     scanf( %d%d , &n, &Q);     AC.tot = 1;     for (int i = 1; i <= n; ++i) {       cin >> s[i];       len[i] = s[i].size();       AC.ins(i);     }     AC.getfail();     dfs(1);     int xx, yy, kk;     for (int i = 1; i <= Q; ++i) {       scanf( %d%d%d , &xx, &yy, &kk);       que[++tq] = (Que){kk, xx - 1, -1, i};       que[++tq] = (Que){kk, yy, 1, i};     }     sort(que + 1, que + tq + 1);     int cur = 1;     while (que[cur].p == 0) cur++;     bit.ma = AC.tot;     for (int i = 1; i <= n; ++i) {       AC.in(i);       while (que[cur].p == i && cur <= tq) {         ans[que[cur].id] += que[cur].sym * calc(que[cur].k), cur++;       }     }     for (int i = 1; i <= Q; ++i) printf( %d n , ans[i]);     return 0;   }   