#arc110e. [arc110_e]Shorten ABC
[arc110_e]Shorten ABC
Problem Statement
We have a string of length consisting of A
, B
, and C
.
You can do the following operation on zero or more times:
- Choose such that . Replace with the character (among
A
,B
, andC
) that is different from both and , and remove from .
Find the number of distinct strings that can be after zero or more operations, and print the count modulo .
Constraints
- is a string of length consisting of
A
,B
, andC
.
Input
Input is given from Standard Input in the following format:
Output
Print the number of distinct strings that can be after zero or more operations, modulo .
Sample Input 1
5
ABAAC
Sample Output 1
11
For example, the following sequence of operations turns into ACB
:
- First, choose . We replace with
C
and remove , turning intoACAC
. - Then, choose . We replace with
B
and remove , turning intoACB
.
Sample Input 2
50
AACCCCBBBACCCCABABCCCCABACCACACACCACABABBBABABACCB
Sample Output 2
256972022