atcoder#AGC037B. [AGC037B] RGB Balls
[AGC037B] RGB Balls
Score : points
Problem Statement
We have colored balls with IDs from to .
A string of length represents the colors of the balls. The color of Ball is red if is R
, green if is G
, and blue if is B
. There are red balls, green balls, and blue balls.
Takahashi will distribute these balls to people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition:
- Let be the IDs of the balls received by the -th person in ascending order.
- Then, should be as small as possible.
Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo . We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.
Constraints
- consists of
R
,G
, andB
, and each of these characters occurs times in .
Input
Input is given from Standard Input in the following format:
Output
Print the number of ways in which Takahashi can distribute the balls, modulo .
3
RRRGGGBBB
216
The minimum value of is when the balls are, for example, distributed as follows:
- The first person gets Ball , , and .
- The second person gets Ball , , and .
- The third person gets Ball , , and .
5
BBRGRRGRGGRBBGB
960