aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

from sys import stdin, stdout
string = stdin.readline()
m = 10**9 + 7

lst = []
for i in string:
    if i == 'a':
        lst.append(0)
    elif i == 'b':
        if lst == [] or lst[-1] == 1:
            continue
        else:
            lst.append(1)

ans = 0
prev = 0
curr = 0
for i in lst:
    if i == 0:
        ans += 1
        curr += 1
    else:
        ans += curr * prev
        prev = curr
        curr = 0
ans += curr * prev

stdout.write(str(ans))
