func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int MAX = 1e6 + 5;   const long long MOD = 1000000007;   struct state {     int len, link, cnt;     int nx[26];   } st[MAX << 1];   int id, last, cur;   vector<int> v[MAX];   inline void sa_init() {     st[0].link = -1;     memset(st[0].nx, 0, sizeof st[0].nx);     id = last = st[0].cnt = 0;   }   inline void sa_extend(int c) {     int clone;     st[last].nx[c] = cur = ++id;     st[cur].len = st[last].len + 1;     v[st[cur].len].push_back(cur);     st[cur].cnt = 1;     int p = last;     while (1) {       if ((p = st[p].link) == -1) {         st[cur].link = 0;         break;       }       if (st[p].nx[c]) {         int q = st[p].nx[c];         if (st[p].len + 1 == st[q].len)           st[cur].link = q;         else {           clone = ++id;           st[clone] = st[q];           st[clone].cnt = 0;           st[clone].len = st[p].len + 1;           v[st[clone].len].push_back(clone);           st[q].link = st[cur].link = clone;           while (p != -1 && st[p].nx[c] == q) {             st[p].nx[c] = clone;             p = st[p].link;           }         }         break;       } else         st[p].nx[c] = cur;     }     last = cur;     return;   }   inline int lcs(string &s, string &t) {     sa_init();     for (char c : s) sa_extend(c -  a );     int best = 0, len = 0;     cur = 0;     for (char c : t) {       c -=  a ;       while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len;       if (st[cur].nx[c]) {         cur = st[cur].nx[c];         best = max(best, ++len);       }     }     return best;   }   bool vis[MAX << 1];   vector<int> del;   inline int solve(string &s) {     int n = s.size(), ans = 0, len = 0;     del.clear();     s += s;     cur = 0;     for (char c : s) {       c -=  a ;       while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len;       if (st[cur].nx[c]) {         cur = st[cur].nx[c], ++len;         if (len == n) {           if (!vis[cur]) ans += st[cur].cnt, vis[cur] = 1, del.push_back(cur);           --len;           if (len == st[st[cur].link].len) cur = st[cur].link;         }       }     }     for (int i : del) vis[i] = 0;     return ans;   }   string s;   int q;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     sa_init();     cin >> s;     for (char c : s) sa_extend(c -  a );     for (int i = s.size(); i >= 1; --i)       for (int j : v[i]) st[st[j].link].cnt += st[j].cnt;     cin >> q;     while (q--) {       cin >> s;       cout << solve(s) <<   n ;     }     return 0;   }   