All Tracks Basic Programming Implementation Basics of Implementation Problem

Counting Strings
Tag(s):

Algorithms, Easy

Problem
Editorial
Analytics

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.

SAMPLE INPUT
4
abcd
azazaz
abbzbba
flkjdh
SAMPLE OUTPUT
4
21
22
0
Time Limit: 5.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

September Rush

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications