func_code_string: #include <bits/stdc++.h>   using namespace std;   long long aa;   bool bb;   char ch;   long long scan() {     while (ch = getchar(), (ch <  0  || ch >  9 ) && ch !=  - )       ;     ch ==  -  ? (bb = 1, aa = 0) : (bb = 0, aa = ch - 48);     while (ch = getchar(), (ch >=  0  && ch <=  9 )) aa = aa * 10 + ch - 48;     return (bb ? (-aa) : (aa));   }   inline int Min(int u, int v) { return u < v ? u : v; }   const int INF = 2147483647;   int len_str;   char s[100000], str[100000];   int len[100000];   int pos[100000];   int g[100000][30] = {};   int fail[100000] = {}, sz = 0;   int K[100000], Q;   int n;   int ans[100000];   int set_num = 0, num[100000];   set<int> Set[100000];   queue<int> q;   struct E {     int to, next;   } e[100000];   int last[100000] = {}, tot = 0;   void add(int u, int v) {     e[++tot].next = last[u];     last[u] = tot;     e[tot].to = v;   }   void ins(int p) {     int i, u;     u = 0;     for (i = 0; i < len[p]; ++i) {       s[i] = s[i] -  a ;       if (!g[u][s[i]]) {         g[u][s[i]] = ++sz;       }       u = g[u][s[i]];     }     pos[u] = p;   }   void build_ac() {     int i, u, v;     for (i = 0; i < 26; ++i)       if (g[0][i]) q.push(g[0][i]);     while (!q.empty()) {       u = q.front();       q.pop();       for (i = 0; i < 26; ++i) {         if (g[u][i]) {           v = g[u][i];           q.push(v);           fail[v] = g[fail[u]][i];         } else if (u)           g[u][i] = g[fail[u]][i];       }     }   }   void build_tree() {     for (int i = 1; i <= sz; ++i) add(fail[i], i);   }   void dfs(int u) {     int max_node = u;     for (int i = last[u]; i; i = e[i].next) {       dfs(e[i].to);       if (Set[num[e[i].to]].size() > Set[num[max_node]].size())         max_node = e[i].to;     }     set<int>::iterator j;     for (int i = last[u]; i; i = e[i].next) {       if (e[i].to == max_node) continue;       for (j = Set[num[e[i].to]].begin(); j != Set[num[e[i].to]].end(); j++)         Set[num[max_node]].insert(*j);     }     if (max_node != u) {       for (j = Set[num[u]].begin(); j != Set[num[u]].end(); j++)         Set[num[max_node]].insert(*j);       num[u] = num[max_node];     }     if (pos[u]) {       vector<int> p;       for (j = Set[num[u]].begin(); j != Set[num[u]].end(); j++) p.push_back(*j);       int tmp = INF;       for (int k = K[pos[u]], h = k - 1; h < p.size(); ++h)         tmp = Min(tmp, p[h] - p[h - k + 1]);       if (tmp == INF)         ans[pos[u]] = -1;       else         ans[pos[u]] = tmp + len[pos[u]];     }   }   int main() {     scanf( %s , str);     len_str = strlen(str);     scanf( %d , &Q);     for (int i = 1; i <= Q; ++i) {       scanf( %d , &K[i]);       scanf( %s , s);       len[i] = strlen(s);       ins(i);     }     build_ac();     build_tree();     int u = 0;     for (int i = 0; i < len_str; ++i) {       u = g[u][str[i] -  a ];       if (!num[u]) num[u] = ++set_num;       Set[num[u]].insert(i);     }     dfs(0);     for (int i = 1; i <= Q; ++i) printf( %d n , ans[i]);     return 0;   }   