An Array of Characters and Almost Palindromes
This is an interactive problem.
A string is considered a palindrome if it reads the same from both sides. Formally, a string of length is considered a palindrome if for . For example, the strings "gg", "ara", "abacaba", and "rotator" are palindromes, while the strings "array", "palindrome", and "uoi" are not.
We call a string a nearly palindrome if its characters can be rearranged to form a palindrome. For example, the strings "n", "ara", "arr", and "array" are nearly palindromes, while the strings "palindrome", "uoi", and "random" are not.
A substring of a string is a string that can be obtained by deleting some (possibly zero) elements from its beginning and end.
Let be the maximum length among the lengths of substrings of that are not nearly palindromes, or if there are no such substrings.
You are given a string of length consisting of lowercase Latin letters. You are also given queries of the form , . For each query, find the value of , where denotes the substring consisting of characters .
Input
The first line contains one integer () — the length of the string.
The second line contains a string consisting of lowercase Latin letters.
The third line contains one integer () — the number of queries.
The fourth line contains two integers () — the parameters of the first query.
You will receive the parameters of the next queries from the jury program (see section "Interaction Protocol
").
Interaction
The jury program will output two integers , () on separate lines for each query, starting from the second one.
The jury program will not output the parameters for the next query until it reads the response of your program to the previous query.
Make sure to call the flush
method after outputting each line. You can use:
fflush(stdout)
,cout << endl
, orcout.flush()
inC++
;System.out.flush()
inJava
;flush(output)
inPascal
;sys.stdout.flush()
inPython
;consult the documentation for other programming languages.
Output
For each -th query, output one integer — the value of , in a separate line.
Examples
8 aabaaaba 3 3 7 1 8 4 4
4 6 0
Note
In the first example, you need to find the answers to three queries:
"baaab", which has a substring "aaab" of length 4, which is not an almost palindrome;
"aabaaaba", which has a substring "aabaaa" of length 6, which is not an almost palindrome;
"a", all substrings of which are almost palindromes.
Scoring
( points): , , , is even, has the form "aabbaabbaa...";
( points): , , , ;
( points): , , , ;
( points): , , ;
( points): contains only letters
a
andb
;( points): for ;
( points): for ;
( points): contains only letters
a
,b
,c
,d
,e
, andf
;( points): is odd for ;
( points): without additional constraints.