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;
void find(string &s, long long arr[]) {
  long long res = 0, a = s.length() - 1;
  long long m[a + 1];
  long long idx = -1;
  m[0] = 0;
  for (long long i = 0; i <= a; ++i) {
    if (s[i] == 'a' && i < a)
      m[i + 1] = m[i] + 1;
    else if (i < a)
      m[i + 1] = m[i];
    if (s[i] == 'b' && m[i] > 0) idx = i;
    if (idx > 0 && m[idx] > 0 && s[i] == 'a')
      arr[i] = m[idx];
    else
      arr[i] = 0;
  }
}
int main() {
  string s;
  cin >> s;
  long long m = s.length() - 1, arr[s.length()], f[s.length()];
  f[0] = 0;
  find(s, arr);
  for (long long i = 0; i <= m; ++i) {
    if (i != 0)
      f[i] = f[i - 1] + (s[i] == 'a') + arr[i] * (s[i] == 'a');
    else
      f[i] = (s[i] == 'a');
  }
  cout << f[m];
}
