#include #include #include #include #include #include using namespace std; int answerQuery(int l, int r,string s) { string x = s.substr (l,r); map m; int n = x.size(); int MEG[2][n+1]; x = "@" + x + "#"; for (int j = 0; j <= 1; j++) { int r1 = 0; MEG[j][0] = 0; int i = 1; while (i <= n) { while (x[i - r1 - 1] == x[i + j + r1]) r1++; MEG[j][i] = r1; int k = 1; while ((MEG[j][i - k] != r1 - k) && (k < r1)) { MEG[j][i + k] = min(MEG[j][i - k],r1 - k); k++; } r1 = max(r1 - k,0); i += k; } } x = x.substr(1, n); m[string(1, x[0])]=1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= 1; j++) for (int r1 = MEG[j][i]; r1 > 0; r1--) m[x.substr(i - r1 - 1, 2 * r1 + j)]=1; m[string(1, x[i])]=1; } return (m.size()-2)%1000000007; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ string s; getline(cin,s); int q; cin >> q; for(int a0 = 0; a0 < q; a0++){ int l; int r; cin >> l >> r; int result = answerQuery(l, r,s); cout << result << endl; } return 0; }