atcoder#AGC020D. [AGC020D] Min Max Repetition
[AGC020D] Min Max Repetition
Score : points
Problem Statement
Let , where and are positive integers, be the string satisfying the following conditions:
- has length ;
- contains exactly letters
A
and exactly lettersB
; - The length of the longest substring of consisting of equal letters (ex.,
AAAAA
orBBBB
) is as small as possible under the conditions above; - is the lexicographically smallest string satisfying the conditions above.
For example, = BABAB
, and = AABAABAABB
.
Answer queries: find the substring of from position to position (1-based).
Constraints
- All input values are integers.
Partial Score
- points will be awarded for passing the testset satisfying .
Input
Input is given from Standard Input in the following format:
Output
For each query in order of input, print a line containing the substring of from position to position (1-based).
5
2 3 1 5
6 4 1 10
2 3 4 4
6 4 3 7
8 10 5 8
BABAB
AABAABAABB
A
BAABA
ABAB