aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

s = input()
ans = []
k = 0 
l = 0
for i in s:
    if i == 'a':
        k += 1
    elif i == 'b':
        if k != 0:
            ans.append(k)
            l += 1
            k = 0
if k != 0:
    ans.append(k)
    l += 1
    k = 0
ans1 = 0
ans2 = 0
for i in range(l):
    ans2 += ans[i]
    for j in range(i+1, l):
        m = ans[j]*ans[i]
        ans1 += m
        for k in range(j+1, l):
            m *= ans[k]
            ans1 += m
print(ans1+ans2)
