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() {
  long long i, a = 0, b = 0, c = 0, temp = 0;
  string s;
  cin >> s;
  long long n = s.length();
  for (i = 0; i < n; i++) {
    if (s[i] == 'b') {
      b = 1;
      while (s[i] == 'b' && i < n) {
        i++;
      }
      temp = 0;
    }
    if (s[i] == 'a') {
      temp = 0;
      while (s[i] == 'a' && i < n) {
        i++;
        temp++;
      }
      i--;
      if (a > 0 && b > 0) {
        c += temp + (a * temp);
        b = 0;
        a = temp;
        temp = 0;
      } else {
        c += temp;
        a = temp;
        b = 0;
        temp = 0;
      }
    }
  }
  cout << c;
  return 0;
}
