Counting Strings
Practice
4.4 (26 votes)
Algorithms
Easy
Problem
28% Success 9377 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Alice got a message M. It is in an alien language. A string in an alien language is said to be valid if it contains the letter a or z. Alice decided to count the number of valid substrings of the message M. Help him to do this. Two substrings are different if it occurs at different positions in the message.

Input
First line of the input contains the number of test cases T. It is followed by T lines. Each line has a single string M.

Output
For each test case, output a single number, the number of valid substrings.

Constraints
|M| <= 10^6
M contains only lower case latin latters, that is characters a to z.

Read the editorial here.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
495 votes
Tags:
ApprovedData StructuresEasyImplementation
Points:20
97 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyGreedy AlgorithmsImplementation
Points:20
111 votes
Tags:
Ad-HocApprovedEasyOpenString Manipulation