atcoder#ARC065D. [ARC065F] シャッフル
[ARC065F] シャッフル
Score : points
Problem Statement
There is a string of length consisting of characters 0
and 1
. You will perform the following operation for each :
- Arbitrarily permute the characters within the substring of starting at the -th character from the left and extending through the -th character.
Here, the sequence is non-decreasing.
How many values are possible for after the operations, modulo ?
Constraints
- consists of characters
0
and1
. - The length of equals .
Input
The input is given from Standard Input in the following format:
:
Output
Print the number of the possible values for after the operations, modulo .
5 2
01001
2 4
3 5
6
After the first operation, can be one of the following three: 01001
, 00101
and 00011
.
After the second operation, can be one of the following six: 01100
, 01010
, 01001
, 00011
, 00101
and 00110
.
9 3
110111110
1 4
4 6
6 9
26
11 6
00101000110
2 4
2 3
4 7
5 6
6 10
10 11
143