aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
from sys import stdin, stdout
import math

#N = int(input())
s = input() 
#N,M = [int(x) for x in stdin.readline().split()]
 
res = 0
idx = -1
for i in range(len(s)):
    if s[i]=='a':
        res = 1
        idx = i
        break
    
if idx==-1:
    print(0)
    quit()

stack = [1]
cur = 0
for i in range(idx+1,len(s)):
    if s[i]=='b':
        cur = stack[-1]
    if s[i]=='a':
        res += 1 + cur
        stack.append(res)
        
print(res)