#include using namespace std; int answerQuery(string w,int l, int r) { string s=w.substr(l,l-r+1); unordered_map m; for (int i = 0; i < s.length(); i++) { for (int j = 0; j <= i; j++) { if (!s[i + j]) break; if (s[i - j] == s[i + j]) { if ((i + j + 1) - (i - j) > 1) m[s.substr(i - j, (i + j + 1) - (i - j))]++; } else break; } for (int j = 0; j <= i; j++) { if (!s[i + j + 1]) break; if (s[i - j] == s[i + j + 1]) { if ((i + j + 2) - (i - j) > 1) m[s.substr(i - j, (i + j + 2) - (i - j))]++; } else break; } } int max=INT_MIN; int count1=0; for (unordered_map::iterator it=m.begin(); it!=m.end(); ++it){ //std::cout << it->first << " => " << it->second << '\n'; string a=it->first; int l=a.length(); if(l>max){ max=l; count1=1; }else if(l==max){ count1++; }else{} } return count1; } int main() { string s; cin >> s; int q; cin >> q; for(int a0 = 0; a0 < q; a0++){ int l; int r; cin >> l >> r; l-=1; r-=1; int result = answerQuery(s,l, r); cout << result << endl; } return 0; }