Note: in the following statement, represents an integer written out in binary notation, where is the most significant bit, and is the least significant bit.
Roxanne the space witch, while riding her broomstick throughout the galaxy, came across a planet in which everybody danced a strange dance: planet BR-PERM. In this dance, the participants stand in a line, and then reorder themselves. Suppose people are dancing. Then, the person at position goes to position (indexed from ).
Roxanne noticed also that every person on BR-PERM wears one of colors of clothing. These colors are represented by the letters of the Latin alphabet.
The BR-PERM-ians place special significance on rows of dancers where the sequence of colors of clothing that people are wearing before and after the dance are the same. They call such sequences nice. For instance, when , we have a row of four dancers , , , , that after the dance become ordered like so: , , , . So, the sequence of clothing colors abba
is nice, but abca
is not.
Task
The BR-PERM-ians have asked Roxanne to help them with a difficult matter (space witches always seem to have to help people with their problems). They show her a long row of dancers, and ask her several questions: "is the sequence of length starting at dancer nice?".
Interaction protocol
The contestant must implement two functions. The first of them is the following:
void init (int n, const char s[]);
This function will be called exactly once, at the beginning of the interaction, and supplies the contestant with the string of clothing colors of the dancers, through parameter .
The second function that the contestant must implement is:
int query (int i, int k);
This function will be called exactly times and must return if and only if the contiguous subsequence of starting at the dancer (indexed from ), and of length , is nice. It must return otherwise.
Constraints and clarifications
# | Points | Constraints |
---|---|---|
1 | 13 | |
2 | 37 | |
3 | 17 | contains only the characters a and b . The colors are independently randomly chosen with a certain fixed probability for each testcase. |
4 | 33 | No additional constraints |
Example
input
init(8, "axxyxxyb")
output
query(0, 3) = true
query(1, 1) = true
query(1, 2) = false
query(3, 2) = true