aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

data = input()
start=[]
end =[]
n = len(data)
count,count2=0,0
for i in range(n):
    if data[i]=='a':
        count+=1
    if data[i]=='b':
        if count >0:
            start.append(count)
        count=0
if count>0:
    start.append(count)
s = sum(start)
for i in range(len(start)):
    for j in range(i+1,len(start)):
        s+=start[i]*start[j]
print(s)
   

        
    
