atcoder#ARC110E. [ARC110E] Shorten ABC
[ARC110E] Shorten ABC
Score : points
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 .
5
ABAAC
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
.
50
AACCCCBBBACCCCABABCCCCABACCACACACCACABABBBABABACCB
256972022