(i + 1) * (sz - i)
A vowel at position i appears in (i + 1) * (sz - i) substrings. \n\nSo, we just sum and return the appearances for all vowels.\n\nPython 3\npython\nclass Soluti
A vowel at position `i` appears in `(i + 1) * (sz - i)` substrings. \n\nSo, we just sum and return the appearances for all vowels.\n\n**Python 3**\n```python\nclass Solution:\n    def countVowels(self, word: str) -> int:\n        return sum((i + 1) * (len(word) - i) for i, ch in enumerate(word) if ch in \'aeiou\')\n```\n\n**C++**\n```cpp\nbool v[26] = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0};\nlong long countVowels(string w) {\n    long long res = 0, sz = w.size();\n    for (int i = 0; i < w.size(); ++i)\n        res += v[w[i] - \'a\'] * (i + 1) * (sz - i);\n    return res;\n}\n```\n**Java**\n```java\npublic long countVowels(String word) {\n    long res = 0, sz = word.length();\n    for (int i = 0; i < sz; ++i)\n        if ("aeiou".indexOf(word.charAt(i)) != -1)\n            res += (i + 1) * (sz - i);\n    return res;        \n}\n```
['C', 'Java', 'Python3']