aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

import java.util.*;
public class main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        char str[]=s.toCharArray();
        int i=0;
        int n=str.length;
        HashMap<Integer,Integer> map=new HashMap<>();
        int dp[]=new int[n+1];
        int ac[]=new int[n+1];
        long ans=0l;
        int lc=0;
        int prv=0;
        int acount=0;
        for(i=1;i<=n;i++){
            if(str[i-1] == 'a')
            {
                map.put(0,i+1);
                ans++;
                // if(i !=1 )
                // prv=i;
                ac[i]=ac[i-1]+1;
                break;
            }
        }
        i++;
        for(;i<=n;i++){
            char ch=str[i-1];
            if(ch == 'b')
            {
                  dp[i]=dp[i-1]+1;
                  ac[i]=ac[i-1];
                  if(i>=2 && str[i-2] == 'a') prv =i-1;
                  
            }
            else if(ch == 'a'){
               dp[i]=dp[i-1];
               ac[i]=ac[i-1]+1;
                ans++;
                // System.out.println("prv "+prv);
                ans=ans+(ac[prv]);
            }
            else {
                dp[i]=dp[i-1];
                ac[i]=ac[i-1];
            }
        }
        // for( int j:dp) System.out.print(j+" ");
        // System.out.println();
        // for( int j:ac) System.out.print(j+" ");
        
        //  System.out.println();
        
        System.out.println(ans);
    }
}