All problems

Problem 842

Vowels of All Substrings

Medium · 20 pts · String, Math, Combinatorics

Problem

For every non-empty substring of WORD (counted by position), count its vowels (a, e, i, o, u), and print the total over all substrings. Listing the substrings is O(N²). Instead, count how many substrings contain each vowel: the vowel at position i is inside every substring that starts at or before i and ends at or after it, which is (i + 1) × (N - i) substrings. The total can exceed 2^31.

Input

A single string WORD of lowercase letters.

Output

Print the total number of vowels over all substrings.

Constraints

1 <= |WORD| <= 100000

Example input

aba

Example output

6

Explanation

For aba the substrings are a, ab, aba, b, ba and a, with 1, 1, 2, 0, 1 and 1 vowels. The total is 6.

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

Previous: Word Subsets Next: Maximum Number of Vowels in a Substring of Given Length