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;
string vow = "aeiou";
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const long double pie = 3.14159265358979;
const long long mod = 1e9 + 7;
void solve(int test_case) {
  string s;
  cin >> s;
  s = 'b' + s;
  int n = s.size();
  vector<int> pref(n);
  for (int i = 1; i < n; i++) pref[i] = pref[i - 1] + (s[i] == 'a');
  long long ans = pref[n - 1];
  int indx = 1;
  for (int i = 1; i < n; i++) {
    for (; i < n && s[i] != 'b'; i++)
      ;
    if (i == n) break;
    i++;
    for (; i < n && s[i] == 'b'; s[i] = '.', i++)
      ;
  }
  for (int i = 1; i < n; i++) {
    if (s[i] != 'b') continue;
    ;
    ans += 1LL * pref[i - 1] * (pref[n - 1] - pref[i]);
  }
  cout << ans;
  cout << "\n";
}
int main() {
  int t = 1;
  for (int i = 0; i < t; i++) solve(i);
  return 0;
}
