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;
const int INF = 1 << 30;
const int MOD = 998244353;
const int maxn = 100005;
int main() {
  string s;
  while (cin >> s) {
    int n = s.length();
    vector<int> a;
    int cnta = 0;
    long long sum = 0;
    int pre = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'b') {
        while (s[i] == 'b') i++;
        a.push_back(pre);
        sum += pre;
        pre = 0;
      }
      if (s[i] == 'a') {
        pre++;
        cnta++;
      }
    }
    if (pre) a.push_back(pre);
    long long ans = 0;
    ans += cnta;
    sum += pre;
    for (int i = 1; i < a.size(); ++i) {
      ans += a[i - 1] * (sum - a[i - 1]);
      sum -= a[i - 1];
    }
    cout << ans << endl;
  }
  return 0;
}
