Favorite subsequences

0

0 votes
Open, Open, Open, Dynamic Programming, String, Introduction to Dynamic Programming 1, Algorithms, approved
Problem

You are given a string S of length N.

A good subsequence is the one that can be represented in the form aibjck, where i1, j1 and k1. For example, if i=2j=1, and k=3, it represents the string aabccc. In other words, a good subsequence is a subsequence that first consist of i a characters, followed by j b characters, followed by k c characters, where i1, j1 and k1.

You are required to determine the number of good subsequences of string S. As the number of such subsequences can be rather large, print the answer Modulo 109+7.

Note: Two subsequences are considered different if the set of array indexes that are selected for the two subsequences are different.

Input format

The first and only line of the input contains S.

Output format

Print the required answer on a single line.

Constraints

1|S|105

Sample Input
abcabc
Sample Output
7
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Valid sub sequences are(1-based indexing):

{1,2,3}

{1,2,6}

{1,5,6}

{4,5,6}

{1,2,5,6}

{1,4,5,6}

{1,2,3,6}

Contributers:
Editor Image

?