aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int count = 0, c1 = 0, c2 = 0;
  int n = s.size();
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'a') {
      ++count;
      ++c1;
    } else if (s[i] == 'b' && c1) {
      c2 = 0;
      for (int j = i + 1; j < n; ++j) {
        if (s[j] == 'a') ++c2;
      }
      count += (c1 * c2);
      c1 = 0;
    }
  }
  cout << count;
}
