e-olymp
favorite We need a little bit of your help to keep things running, click on this banner to learn more
Competitions

Simple Combinatorics

ABA

The string of letters is given. How many subsequences "ABA" does it contain? The letters "ABA" don't have to be consecutive. But the order of letters should be the same.

Input

One line that contains only capital Latin letters. The length of the string is no more than 106.

Output

Print the number of subsequences "ABA" in the string.

Time limit 1 second
Memory limit 128 MiB
Input example #1
YARBRBAQ
Output example #1
2
Input example #2
ABAYBATATBBAZA
Output example #2
29