Counting a^i b^j c^k subsequences
Time limit2sMemory limit512 MB
Count subsequences of a string of a, b, c that read as some positive number of a's, then b's, then c's, modulo 1e9+7.
- Level
Medium5 of 10
- Topics
- Dynamic programming, String, Combinatorics
- Solved
- No attempts yet
Problem
You are given a string built from the letters a, b, and c only. Count the subsequences of that have the form , where , , and .
is the string with copies of a, then copies of b, then copies of c. For example, is aabbbc and is aaabcccccc.
A subsequence is what remains after deleting zero or more characters of and keeping the rest in their original order. Two subsequences that use different sets of positions count separately, even when the remaining strings are equal.
Input
The first line contains the string , built from the letters a, b, and c only. The length of is at most 1,000,000.
Output
On the first line, print the number of subsequences of of the form , modulo 1,000,000,007.