logo AlgoBeat OnlineJudge
登录 注册

#212682. [ICPC 2025 NAC] Popping Balloons

内存限制:2048 MiB 时间限制:15000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

The ICPC logo has three colors: blue, yellow, and red. The NAC volunteers have just inflated a huge number of balloons in these colors and arranged them in a line. They next need to sort the balloons by color before they can give them out to contestants.

Unfortunately, due to the Orlando heat, the balloons begin to randomly pop: each second, a random remaining balloon pops (and the volunteers remove the debris from the line). This isn't all bad: maybe if the NAC volunteers wait long enough, the balloons will become sorted by chance? Compute the expected number of seconds until the first time that all blue balloons come before all yellow and red balloons, and all yellow balloons come before all red balloons. (These conditions are satisfied even if they are vacuously true: for example, if there are no blue balloons at all remaining, then it is true that all blue balloons come before all yellow and red balloons.)

输入格式

The input has one line: a string () where each character is one of , , or representing blue, yellow, and red respectively ---the colors of the initial balloons in the line.

输出格式

Print the expected number of seconds that elapse before the first time that all blue balloons come before all yellow and red balloons, and all yellow balloons come before all red balloons. Since this number might not be an integer, print it modulo .

Formally, let . It can be shown that the answer can be expressed as an irreducible fraction , where and are non-negative integers and . Print the integer with and .

样例

样例输入 1

RYBB

样例输出 1

831870297

样例输入 2

YRBBR

样例输出 2

598946615

数据范围与提示

In Sample Input 1, the expected time until the balloon colors first become sorted in the correct order is seconds: the only way for the balloon colors to be sorted correctly after seconds is if the first two balloons to pop are the yellow and red balloon (in either order). The probability that these balloons pop before either blue balloon is . Otherwise (with probability ) the balloon colors will automatically be sorted after seconds, when there is only one balloon left. Since , the answer is .