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 a;
  cin >> a;
  long long dem = 0;
  for (long long i = 0; i < a.length(); i++) {
    if (a[i] == 'a') dem++;
  }
  for (long long i = 0; i < a.length(); i++) {
    if (a[i] == 'a') {
      for (long long j = i + 1; j < a.length(); j++) {
        if (a[j] == 'a') {
          for (long long s = j; s >= i; s--) {
            if (a[s] == 'b') {
              dem++;
              break;
            }
          }
        }
      }
    }
  }
  cout << dem;
}
