aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

s = input()
arr = []
cnt = 0
for c in s:
    if c == "a":
        cnt+=1
    elif c == "b":
        if cnt > 0:
            arr.append(cnt)
            cnt = 0

arr.append(cnt)
sm  = arr[len(arr)-1] 
res = 0

if len(arr) > 1:
    for i in range(len(arr)-2,-1,-1):
        res+=(sm*arr[i])
        sm += arr[i]
    print(res+sum(arr))
else:
    print(sum(arr))