#arc131f. [arc131_f]ARC Stamp
[arc131_f]ARC Stamp
Problem Statement
On a string consisting of A
, R
, and C
, we did the following operation at most times: choose three consecutive characters and overwrite them with ARC
. The result is the string .
How many strings are there that could be the initial string ? Find this count modulo .
Constraints
- is a string consisting of
A
,R
, andC
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
ARCCARC
1
Sample Output 1
53
Below are some examples of the initial string from which we can get the string = ARCCARC
with at most operation.
- =
ARCCARC
: we can choose to do nothing to getARCCARC
. - =
CRACARC
: we can choose the -st, -nd, -rd characters and overwrite them withARC
to getARCCARC
. - =
ARCCCCC
: we can choose the -th, -th, -th characters and overwrite them withARC
to getARCCARC
.
There are many other strings that could be , for a total of .
Sample Input 2
ARARCRCA
5
Sample Output 2
2187
If the intial string is AAAAAAAA
, one way to get = ARARCRCA
with at most operations is as follows.
- Step : choose the -rd, -th, -th characters and overwrite them with
ARC
to get the stringAAARCAAA
. - Step : choose the -th, -th, -th characters and overwrite them with
ARC
to get the stringAAARARCA
. - Step : choose the -st, -nd, -rd characters and overwrite them with
ARC
to get the stringARCRARCA
. - Step : choose the -rd, -th, -th characters and overwrite them with
ARC
to get the stringARARCRCA
.
There are many other strings that could be , for a total of .
Sample Input 3
AARCRRARCC
0
Sample Output 3
1
We can get = AARCRRARCC
with operations in only one case in which from the beginning, or = AARCRRARCC
.
Sample Input 4
AAAAARRRRRCCCCC
131
Sample Output 4
1
In this case, there is just one string that could be : AAAAARRRRRCCCCC
.
Sample Input 5
CAARCACRAAARARARCRCRARCARARCRRARC
9
Sample Output 5
797833187
There are strings that could be , so print this count modulo , which is .