#include using namespace std; void palindromeSubStrs(string s) { map m; int n = s.size(); // table for storing results (2 rows for odd- // and even-length palindromes int R[2][n+1]; // Find all sub-string palindromes from the given input // string insert 'guards' to iterate easily over s s = "@" + s + "#"; for (int j = 0; j <= 1; j++) { int rp = 0; // length of 'palindrome radius' R[j][0] = 0; int i = 1; while (i <= n) { // Attempt to expand palindrome centered at i while (s[i - rp - 1] == s[i + j + rp]) rp++; // Incrementing the length of palindromic // radius as and when we find vaid palindrome // Assigning the found palindromic length to odd/even // length array R[j][i] = rp; int k = 1; while ((R[j][i - k] != rp - k) && (k < rp)) { R[j][i + k] = min(R[j][i - k],rp - k); k++; } rp = max(rp - k,0); i += k; } } // remove 'guards' s = s.substr(1, n); // Put all obtained palindromes in a hash map to // find only distinct palindromess m[string(1, s[0])]=1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= 1; j++) for (int rp = R[j][i]; rp > 0; rp--) m[s.substr(i - rp - 1, 2 * rp + j)]=1; m[string(1, s[i])]=1; } //printing all distinct palindromes from hash map //cout << "Below are " << m.size()-1 // << " palindrome sub-strings"; map::iterator ii; mapab; for (ii = m.begin(); ii!=m.end(); ++ii) { string sx=(*ii).first; int len=sx.length(); ab[len]++; } map::reverse_iterator rit; rit=ab.rbegin(); cout<second<<"\n"; } /* string findLongestPalindrome(string str) { // to stores freq of characters in a string int count[256] = { 0 }; // find freq of characters in the input string for (int i = 0; i < str.size(); i++) count[str[i]]++; // Any palindromic string consists of three parts // beg + mid + end string beg = "", mid = "", end = ""; // solution assumes only lowercase characters are // present in string. We can easily extend this // to consider any set of characters for (char ch = 'a'; ch <= 'z'; ch++) { // if the current character freq is odd if (count[ch] & 1) { // mid will contain only 1 character. It // will be overridden with next character // with odd freq mid = ch; // decrement the character freq to make // it even and consider current character // again count[ch--]--; } // if the current character freq is even else { // If count is n(an even number), push // n/2 characters to beg string and rest // n/2 characters will form part of end // string for (int i = 0; i < count[ch]/2 ; i++) beg.push_back(ch); } } // end will be reverse of beg end = beg; reverse(end.begin(), end.end()); // return palindrome string beg + mid + end; } */ int main() { string str; cin>>str; int T; cin>>T; while(T--) { int l,r; cin>>l>>r; string str1=""; for(int i=l-1;i