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;
inline size_t key(int i, int j) { return (size_t)i << 32 | (unsigned int)j; }
int main() {
  string s;
  cin >> s;
  int cnt = 0;
  int flg = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'a') cnt++;
    if (flg == 1 && s[i] == 'a' && cnt > 0) cnt++;
    if (cnt > 0 && s[i] == 'b') flg = 1;
  }
  cout << cnt << endl;
  return 0;
}
