Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word.

A substring is a contiguous (non-empty) sequence of characters within a string.

Note: Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during the calculations.

&nbsp;
Example 1:

Input: word = "aba"
Output: 6
Explanation: 
All possible substrings are: "a", "ab", "aba", "b", "ba", and "a".
- "b" has 0 vowels in it
- "a", "ab", "ba", and "a" have 1 vowel each
- "aba" has 2 vowels in it
Hence, the total sum of vowels = 0 + 1 + 1 + 1 + 1 + 2 = 6. 


Example 2:

Input: word = "abc"
Output: 3
Explanation: 
All possible substrings are: "a", "ab", "abc", "b", "bc", and "c".
- "a", "ab", and "abc" have 1 vowel each
- "b", "bc", and "c" have 0 vowels each
Hence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3.


Example 3:

Input: word = "ltcd"
Output: 0
Explanation: There are no vowels in any substring of "ltcd".


&nbsp;
Constraints:


	1 &lt;= word.length &lt;= 105
	word consists of lowercase English letters.


class Solution:
    def countVowels(self, word: str) -> int:
        count = vowelIndexSum = 0
        vowels = {'a', 'e', 'i', 'o', 'u'}

        for i, c in enumerate(word, start=1):
            if c in vowels:
                vowelIndexSum += i
            count += vowelIndexSum
        
        return count
class Solution {

    boolean isVowel(char ch) {
        return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
    }

    public long countVowels(String word) {
        long count = 0;
        int len = word.length();

        for(int pos = 0; pos < len; pos++) {
            if(isVowel(word.charAt(pos))) {
                count += (long)(len - pos) * (long)(pos + 1);
            }
        }

        return count;
    }
}
class Solution {
public:
    bool isVowel(char ch) {
        return ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u';
    }

    long long countVowels(string word) {
        long long count = 0;
        int len = word.size();

        for(int pos = 0; pos < len; pos++) {
            if(isVowel(word[pos])) {
                count += (long)(len - pos) * (long)(pos + 1);
            }
        }

        return count;
    }
};
var countVowels = function(word) {
    const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
    let total = 0;
    let count = 0;
    for (let i = 0; i < word.length; i++) {
        if (vowels.has(word[i])) {
            count += i + 1;
        }
        total += count;
    }
    return total;
};
Vowels of All Substrings