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;
  long long ans = 0;
  for (int i = 0; i < s.size(); i++) {
    ans += (s[i] == 'a' ? 1 : 0);
    bool bol = false, b = false;
    ;
    long long mult = 1, bol2 = 0;
    if (s[i] == 'a')
      for (int j = i; j < s.size(); j++) {
        if (s[j] == 'a' && bol) {
          ans += mult;
          bol2++;
          b = true;
        }
        if (s[j] == 'b' && bol2) mult += bol2;
        if (s[j] == 'b') {
          if (b) bol2 = 0;
          bol = true;
          b = false;
        }
      }
  }
  cout << ans << endl;
  return 0;
}
