Favorite Subsequence
Practice
4.6 (16 votes)
Dynamic programming
Easy
String manipulation
Approved
Problem
78% Success 4141 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a String S of length N.

Now, a good subsequence is one that can be represented in the form \(a^{i}b^{j}c^{k}\), where \( i \ge 1\), \( j \ge 1\) and \(k \ge 1 \). For example ,if \(i=2\),\(j=1\),\(k=3\), it represents the string \(aabccc\). In short, a good subsequence is a subsequence that first consist of i a characters, followed by j b characters, followed by k c characters, where \( i \ge 1\), \( j \ge 1\) and \( k \ge 1 \)

Now, you need to find the number of good subsequences of String S. As the number of such subsequences could be rather large, print the answer Modulo \(10^9+7\).

Note1: Two subsequences are considered different if the set of array indexes picked for the 2 subsequences are different.

Input Format:

The first and only line of input contains the S

Output Format :

Print the required answer on a single line.

Constraints:

\( 1 \le | S | \le 10^5 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
CombinatoricsDynamic ProgrammingAlgorithmsStringIntroduction to Dynamic Programming 1
Points:30
65 votes
Tags:
Dynamic ProgrammingAlgorithmsIntroduction to Dynamic Programming 1
Points:30
10 votes
Tags:
Basic ProgrammingDynamic ProgrammingAlgorithmsIntroduction to Dynamic Programming 1ImplementationBasics of Implementation