func_code_string: #include <iostream>   #include <string>   #include <vector>      constexpr int N = 1000005;   constexpr int p = 1000000007;      inline int add(int x, int y) { return (x += y) >= p ? x - p : x; }   inline int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }   inline int mul(int x, int y) { return (long long)x * y % p; }   inline int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }      int n, q, k;   std::string s0, t, w;   int pow2[N], nxt[N];   int sum[N][26];   std::vector<std::string> str;      int main() {       std::ios::sync_with_stdio(false), std::cin.tie(nullptr);       std::cin >> n >> q;       std::cin >> s0 >> t;       pow2[0] = 1;       for (int i = 1; i <= n; ++i) pow2[i] = add(pow2[i - 1], pow2[i - 1]);       for (int i = 1; i <= n; ++i) {           for (int j = 0; j < 26; ++j) sum[i][j] = sum[i - 1][j];           sum[i][t[i - 1] -  a ] = add(sum[i][t[i - 1] -  a ], power(pow2[i], p - 2));       }       std::string tmp = s0;       str.push_back(tmp);       int x = 0;       while (tmp.length() < N << 1) {           tmp = tmp + t[x++] + tmp;           str.push_back(tmp);       }       while (q--) {           std::cin >> k >> w;           int x = 0;           while (str[x].length() < w.length() && x < k) ++x;           nxt[0] = -1;           int now = -1;           for (int i = 1; i < w.length(); ++i) {               while (~now && w[now + 1] != w[i]) now = nxt[now];               if (w[now + 1] == w[i]) ++now;               nxt[i] = now;           }           now = -1;           int cnt0 = 0;           std::string& s = str[x];           for (int i = 0; i < s.length(); ++i) {               while (~now && w[now + 1] != s[i]) now = nxt[now];               if (w[now + 1] == s[i]) ++now;               if (now == w.length() - 1) {                   ++cnt0;                   now = nxt[now];               }           }           int index = s.length();           int ans = mul(cnt0, power(pow2[x], p - 2));           for (int i = 0; i < 26; ++i) {               int cnt = -cnt0 << 1;               now = -1;               for (int j = 0; j < str[x + 1].length(); ++j) {                   char tmp = str[x + 1][j];                   if (j == index) tmp =  a  + i;                   while (~now && w[now + 1] != tmp) now = nxt[now];                   if (w[now + 1] == tmp) ++now;                   if (now == w.length() - 1) {                       ++cnt;                       now = nxt[now];                   }               }               ans = add(ans, mul(cnt, sub(sum[k][i], sum[x][i])));           }           std::cout << mul(ans, pow2[k]) <<   n ;       }       return 0;   }   