aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

s = input()
ans=s.count('a')
lst = []
ch = 1
for i in range(len(s)):
        if ch==0 and s[i]=='b':
                lst.append(s[i])
                ch=1
        elif s[i]=='a':
                lst.append(s[i])
                ch=0
ls = len(lst)
j=0
ch=1
#print(lst)
while(j<ls):
        #print(lst[j])
        if lst[j]=='b' and ch==1:
                #print(1)
                s=''.join(lst)
                x1 = lst[:j].count('a')
                x2 = lst[j:].count('a')
                ans+=x1*x2
                ch=0
        elif (lst[j]=='b' and ch==0):
                s=''.join(lst)
                x2 = lst[j:].count('a')
                if (x2!=1):
                        ans+=x2
        j+=1
        
print(ans)
