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 n, i, j, k, sol;
  vector<long long> a;
  vector<long long> b;
  n = s.length();
  for (i = 0; i < n; i++) {
    if (s[i] == 'a') a.push_back(i);
    if (s[i] == 'b') b.push_back(i);
  }
  if (b.empty()) {
    cout << a.size() << endl;
    return 0;
  }
  long long count = 0, m;
  n = a.size();
  m = b.size();
  j = 0;
  bool bexist = true;
  count = a.size();
  for (i = 0; i < n; i++) {
    bexist = false;
    while (b[j] < a[i] && j < m) {
      j++;
    }
    if (j != m && b[j] > a[i])
      bexist = true;
    else if (j == m)
      break;
    if (bexist) {
      count += n - i - 1;
    }
  }
  cout << count << endl;
}
