aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

/**
 * https://codeforces.com/problemset/problem/1084/C
 * #dp
 * chien thuat:
 *      1. liet ke cac cach 
 *      2. sap xep lai cac cach de tim cthuc (ket thuc tai cung vi tri...)
 *          (cung la de kiem chung lai xem cach hieu co dung k)
 
 p: position

s[p_i] = ki tu tai vi tri p_i

p_i 'b' p_i1

abbaa

result = 0;
pre_b = 0;
                    *     *     *
                    *       *   *
                    a b b a a b b a
result              1 1 1 3 5 5 5 1+5+5=11
pre_b               0 1 2 2 2 5 5
=> 3 + 2 = 5. 

a b b a a b b a
*
      *
*     *
        *
*       *
              *
*             *
      *       *
        *     *
*     *       *
*       *     *



 */

import java.util.Scanner;
public class TheFairNutAndString {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        int[] result = new int[n];
        int preB = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'a') {
                if (i == 0) {
                    result[i] = 1;
                }
                else {
                    result[i] = result[i-1] + 1;
                    if (preB > 0) {
                        result[i] += result[preB - 1];
                    }
                }
            }
            else {
                if (s.charAt(i) == 'b') {
                    preB = i;
                }
                if (i > 0) {
                    result[i] = result[i-1];
                }
            }
        }
        System.out.println(result[n-1]);
    }
}