Little Y is a college student who is currently doing researches related to strings. Little Y learned about the following definitions regarding strings:
- Given a string
of length , we define its substring as the new string obtained by selecting in order and concatenating them. - Given a string
of length , we define its reversed result as the string obtained by concatenating in order, which is the string obtained by reversing the original string. - Given two strings
and of equal length , we define to be lexicographically smaller than if and only if there exists such that for any , and .
After understanding the above definitions, Little Y came up with the following problem:
Given a string
. is lexicographically smaller than .
Little Y would like to ask for your help in solving this problem.
Input Specification
This problem has multiple test data sets.
The first line of the input contains two integers
Then, each set of test data is given as input in order. For each set of test data:
The first line of input contains two positive integers,
The second line of input contains a string
Then
Output Specification
For each query of each set of test data, output a line containing an integer, representing the number of
Sample Input 1
0 2
9 3
abacababa
1 4
2 4
3 3
9 3
abaabaaba
1 4
2 4
3 3
Sample Output 1
4
0
3
2
0
2
Explanation for Sample Output 1
For the first set of test data in the sample:
- When
, , . - When
, , . - When
, , . - When
, , .
In all four cases,
Additional Samples
Sample inputs and outputs can be found here.
- Sample 2 (
ex_string2.in
andex_string2.ans
) corresponds to test case 5. - Sample 3 (
ex_string3.in
andex_string3.ans
). - Sample 4 (
ex_string4.in
andex_string4.ans
) corresponds to test cases 24-25.
Constraints
For all test data, it is guaranteed that:
Test ID | Additional Constraints | ||
---|---|---|---|
A | |||
None | |||
| | A | |
| |||
B | |||
None | |||
| | ||
| | ||
| |||
Additional Constraint A: It is guaranteed that the input string only consists of a
and b
, and each character is uniformly chosen from a
and b
at random.
Additional Constraint B: It is guaranteed that every pair of adjacent characters in the input string are distinct.
Comments