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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string second;
  cin >> second;
  long long l = second.length(), i, j, c = 0, a = 0, ans = 0;
  vector<long long> v;
  for (i = 0; i < l; i++) {
    if (second[i] == 'b') {
      v.push_back(i);
    } else if (second[i] == 'a')
      a++;
  }
  if (v.size() == 0) {
    cout << a;
    return 0;
  }
  for (i = 0; i < v[0]; i++) {
    if (second[i] == 'a') c++;
  }
  ans = c * (a - c);
  for (i = 1; i < v.size() - 1; i++) {
    long long k = 0, p = 0;
    for (j = v[i - 1] + 1; j < v[i]; j++) {
      if (second[j] == 'a') k++;
    }
    for (j = v[i] + 1; j < l; j++) {
      if (second[j] == 'a') p++;
    }
    ans = ans + p * k;
  }
  cout << a + ans;
}
