func_code_string: #include <bits/stdc++.h>   using namespace std;   const int iinf = 1e9 + 7;   const int oo = 0x3f3f3f3f;   const long long linf = 1ll << 60;   const double dinf = 1e60;   template <typename T>   inline void scf(T &x) {     bool f = 0;     x = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) {       f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     if (f) x = -x;     return;   }   template <typename T1, typename T2>   void scf(T1 &x, T2 &y) {     scf(x);     return scf(y);   }   template <typename T1, typename T2, typename T3>   void scf(T1 &x, T2 &y, T3 &z) {     scf(x);     scf(y);     return scf(z);   }   template <typename T1, typename T2, typename T3, typename T4>   void scf(T1 &x, T2 &y, T3 &z, T4 &w) {     scf(x);     scf(y);     scf(z);     return scf(w);   }   inline char mygetchar() {     char c = getchar();     while (c ==     || c ==   n ) c = getchar();     return c;   }   template <typename T>   inline bool chkmax(T &x, const T &y) {     return y > x ? x = y, 1 : 0;   }   template <typename T>   inline bool chkmin(T &x, const T &y) {     return y < x ? x = y, 1 : 0;   }   const int maxn = 1e6 + 10;   struct node {     node *go[26], *par;     int len, siz, tag;     node() {       memset(go, 0, sizeof go);       par = 0;       len = siz = tag = 0;     }     inline void cpy(node *u) {       memcpy(go, u->go, sizeof go);       par = u->par;       return;     }   } * root, *last;   vector<node *> lvl[maxn];   char s[maxn];   inline void expand(int id) {     node *p = last, *np = new node;     np->len = p->len + 1;     np->siz = 1;     while (p && !p->go[id]) p->go[id] = np, p = p->par;     if (!p)       np->par = root;     else {       node *q = p->go[id];       if (q->len == p->len + 1)         np->par = q;       else {         node *nq = new node;         nq->cpy(q);         q->par = np->par = nq;         nq->len = p->len + 1;         while (p && p->go[id] == q) p->go[id] = nq, p = p->par;       }     }     last = np;     return;   }   inline void dfs(node *u) {     if (!~u->tag) return;     u->tag = -1;     lvl[u->len].push_back(u);     for (int i = 0, _end_ = (26); i < _end_; ++i)       if (u->go[i]) dfs(u->go[i]);     return;   }   int main() {     root = new node;     last = root;     char c = getchar();     while (c <  a  || c >  z ) c = getchar();     while (c >=  a  && c <=  z ) expand(c -  a ), c = getchar();     dfs(root);     for (int i = last->len; i; --i)       for (int j = 0, _end_ = ((int)lvl[i].size()); j < _end_; ++j)         if (lvl[i][j]->par) lvl[i][j]->par->siz += lvl[i][j]->siz;     int q;     scf(q);     while (q--) {       scanf( %s , s);       int n = strlen(s), matched = 0, ans = 0;       node *u = root;       for (int i = 0, _end_ = (n << 1); i < _end_; ++i) {         int id = s[i % n] -  a ;         while (u && !u->go[id]) u = u->par, matched = u ? u->len : 0;         if (!u)           u = root;         else {           u = u->go[id];           ++matched;           while (u->par && u->par->len >= n) u = u->par, matched = u->len;           if (matched >= n && u->tag != q) u->tag = q, ans += u->siz;         }       }       printf( %d n , ans);     }     return 0;   }   