Building Uppercase Sentences

Count the distinct uppercase sentences you can form by deleting letters and grouping the rest into blocks of three identical letters.

Medium6Dynamic programmingStringNo attempts yetTime limit1sMemory limit256 MB

Problem

You are given a string of lowercase letters. Turn it into a sentence of uppercase letters with these two steps.

  1. Delete any letters you want. There is no limit on how many letters you delete, the deleted letters do not have to be adjacent, and deleting nothing is allowed.
  2. Read the remaining string in groups of three from the left. Every group must consist of three copies of the same letter, and each group becomes one uppercase copy of that letter.

The second step works only when the remaining string is a concatenation of groups of three equal letters. The finished sentence contains at least one uppercase letter.

For example, bbcccaabbba produces these five sentences.

  1. Keeping only aaa gives A.
  2. Keeping only bbb gives B.
  3. Keeping only ccc gives C.
  4. Keeping only cccaaa gives CA.
  5. Keeping only cccbbb gives CB.

Two different sets of deletions that end in the same sentence count once. Count the distinct sentences you can build.

Input

The first line contains a string of lowercase letters. Its length is between 1 and 1,000.

Output

Print the number of distinct sentences you can build, modulo 1,000,000,007, on the first line.