All problems

Problem 847

Count Number of Homogenous Substrings

Medium · 20 pts · String, Math

Problem

A substring is homogenous if all its characters are the same, like aaa or b. Count the homogenous substrings of S, counting substrings at different positions separately, and print the count modulo 1000000007. Split S into runs of equal characters: a run of length L contains L × (L + 1) / 2 homogenous substrings, so add that for every run, or add the current run length at every position. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).

Input

A single string S of lowercase letters.

Output

Print the number of homogenous substrings modulo 1000000007.

Constraints

1 <= |S| <= 100000

Example input

abbcccaa

Example output

13

Explanation

abbcccaa has runs a, bb, ccc and aa, giving 1 + 3 + 6 + 3 = 13 homogenous substrings.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Decoded String at Index Next: Number of Wonderful Substrings