func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 1, ans = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       ans = ans * 10 + c -  0 ;       c = getchar();     }     return f * ans;   }   const int MAXN = 4e5 + 11;   vector<int> vec[MAXN];   int ch[MAXN][27], las = 1, tot = 1, TT = 0, N, Q, len[MAXN], fa[MAXN], rt[MAXN],                     all;   char S[MAXN];   struct Segment {     int ls[MAXN * 34], rs[MAXN * 34];     void Modify(int &k, int l, int r, int ps) {       if (!k) k = ++TT;       if (l == r) return;       int mid = (l + r) >> 1;       if (ps <= mid) Modify(ls[k], l, mid, ps);       if (mid < ps) Modify(rs[k], mid + 1, r, ps);       return;     }     void print(int k, int l, int r) {       if (!k) return;       if (l == r) {         printf( %d  , l);         return;       }       int mid = (l + r) >> 1;       print(ls[k], l, mid), print(rs[k], mid + 1, r);     }     int merge(int p, int q) {       if (!p || !q) return p + q;       int u = (++TT);       ls[u] = merge(ls[p], ls[q]), rs[u] = merge(rs[p], rs[q]);       return u;     }     bool Query(int k, int l, int r, int x, int y) {       if (!k) return 0;       if (x <= l && r <= y) return 1;       int mid = (l + r) >> 1;       bool res = 0;       if (x <= mid) res |= Query(ls[k], l, mid, x, y);       if (mid < y) res |= Query(rs[k], mid + 1, r, x, y);       return res;     }     void debug(int k) {       print(rt[k], 1, N);       printf(  n );       return;     }   } T;   void ins(int c) {     int p = las, np = las = ++tot;     len[np] = len[p] + 1;     T.Modify(rt[np], 1, N, len[np]);     for (; p && !ch[p][c]; p = fa[p]) ch[p][c] = np;     if (!p) {       fa[np] = 1;       return;     }     int q = ch[p][c];     if (len[p] + 1 == len[q]) {       fa[np] = q;       return;     }     int nq = ++tot;     len[nq] = len[p] + 1, fa[nq] = fa[q];     for (int i = 0; i < 27; i++) ch[nq][i] = ch[q][i];     fa[q] = fa[np] = nq;     for (; p && ch[p][c] == q; p = fa[p]) ch[p][c] = nq;     return;   }   void dfs(int u) {     for (auto v : vec[u]) dfs(v), rt[u] = T.merge(rt[u], rt[v]);   }   int L, R, LEN;   char Ans[MAXN];   bool ff = 1;   void calc(int now, int len, bool f) {     if (!f) {       for (int i = 1; i < len; i++) printf( %c , Ans[i]);       printf(  n );       ff = 0;       return;     }     int be;     if (!f || len > LEN)       be = 0;     else       be = S[len] -  a ;     for (int i = be; i < 26; i++) {       int u = ch[now][i];       if (!u) continue;       if (!T.Query(rt[u], 1, N, L + len - 1, R)) continue;       Ans[len] = i +  a ;       calc(u, len + 1, f & (i == (S[len] -  a )));       if (!ff) return;     }   }   int main() {     scanf( %s , S + 1);     N = strlen(S + 1);     Q = read();     for (int i = 1; i <= N; i++) ins(S[i] -  a );     for (int i = 2; i <= tot; i++) vec[fa[i]].push_back(i);     dfs(1);     while (Q--) {       L = read(), R = read();       scanf( %s , S + 1);       LEN = strlen(S + 1);       ff = 1;       calc(1, 1, 1);       if (ff) printf( -1 n );     }   }   