Natural Language Understanding is the subdomain of Natural Language Processing where people used to design AI-based applications have the ability to understand the human languages. HashInclude Speech Processing team has a project named Virtual Assistant. For this project, they appointed you as a data engineer (who has good knowledge of creating clean datasets by writing efficient code). As a data engineer, your first task is to make vowel recognition dataset. In this task, you have to find the presence of vowels in all possible substrings of the given string. For each given string you have to print the total number of vowels.
Input: First-line contains an integer T, denoting the number of test cases.
Each of the next lines contains a string, the string contains both lower case and upper case.
Output: Print the vowel sum.
Answer for each test case should be printed in a new line.
Input Constraints
1<=T<=10
1<=|S|<=100000
SAMPLE INPUT
1
baceb
SAMPLE OUTPUT 16
Now I have 2 questions to ask
q1) I came up with the below code with my own but I can not figure out how to write the code for the sum, for the number of vowels found in the substrings that I have stored in the 'r' variable
q2) while finding substrings of 'geeks' the 'e' will be repeated twice and I want to add 1 to the sum for the 1st occurrence of 'e' only not the 2nd one.
T=int(input())
for i in range(T):
print('Enter the string:')
l=input().lower()
r=[l[i:j] for i in range(len(l))
for j in range(i+1,len(l)+1)]
#print(r)
for i in range(len(r)):
if r[i] =='aeiou':
sum += 1
print(sum)
Note: I am aware of the below code but I am finding the expression "sum+=((n-i)*(i+1))" too difficult to understand
for _ in range(int(input())):
s=input()
n=len(s)
sum=0
for i in range(n):
if s[i] in ("aeiouAEIOU"):
sum+=((n-i)*(i+1))
print(sum)