atcoder#ARC131F. [ARC131F] ARC Stamp
[ARC131F] ARC Stamp
Score : points
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.
ARCCARC
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 .
ARARCRCA
5
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 .
AARCRRARCC
0
1
We can get = AARCRRARCC
with operations in only one case in which from the beginning, or = AARCRRARCC
.
AAAAARRRRRCCCCC
131
1
In this case, there is just one string that could be : AAAAARRRRRCCCCC
.
CAARCACRAAARARARCRCRARCARARCRRARC
9
797833187
There are strings that could be , so print this count modulo , which is .