atcoder#YAHOOPROCON2019QUALF. Pass
Pass
Score : points
Problem Statement
There are Snukes lining up in a row.
You are given a string of length . The -th Snuke from the front has two red balls if the -th character in is 0
; one red ball and one blue ball if the -th character in is 1
; two blue balls if the -th character in is 2
.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure times, modulo :
- Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
- Takahashi receives the ball and put it to the end of his sequence.
Constraints
- consists of
0
,1
and2
.
Note that the integer is not directly given in input; it is given indirectly as the length of the string .
Input
Input is given from Standard Input in the following format:
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure times, modulo .
02
3
There are three sequences that Takahashi may have: rrbb
, rbrb
and rbbr
, where r
and b
stand for red and blue balls, respectively.
1210
55
12001021211100201020
543589959