#include using namespace std; string str; void initialize(string s) { // This function is called once before all queries. str = s; } void swap(char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } bool isPalindrome(char *s){ string actual_string(s); int length = actual_string.length(); for (int i = 0; i < length; i++){} int j = length - i - 1; printf("%c",s[i]); printf("%c",s[j]); if (s[i] != s[j]) return false; } return true; } int permute(char* s, int l, int r, int max){ int i; if (l == r){ printf("%s\n",s); if (isPalindrome(s)){ cout << "YES\n"; string actual_string(s); int length = actual_string.length(); if (length > max){ max = length; } } else cout << "NO\n"; } else { for (i = l; i <= r; i++) { swap((s+l), (s+i)); int curr_max = permute(s, l+1, r, max); if (curr_max > max) max = curr_max; swap((s+l), (s+i)); //backtrack } } return max; } int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. string substring = str.substr(l-1,r); // cout << substring << "\n"; char char_array[substring.length()]; // copying the contents of the // string to char array strcpy(char_array, substring.c_str()); return permute(char_array, 0, substring.length()-1, 0); return 0; } int main() { string s; cin >> s; initialize(s); int q; cin >> q; for(int a0 = 0; a0 < q; a0++){ int l; int r; cin >> l >> r; int result = answerQuery(l, r); cout << result << endl; } return 0; }