aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

import java.util.Scanner;
import java.util.Stack;

public class stack {

		public static void main(String args[])
		{
			Scanner scan=new Scanner(System.in);
			String x=scan.next();
			boolean go=false;
			boolean start=false;
			int score=0;
			int dp[]=new int[x.length()];
			for(int k=0;k<x.length();k++){
			go=false;start=false;
			if(x.charAt(k)=='a'){
			
				for(int i=k;i<x.length();i++){
					
				if(x.charAt(i)=='a' && go && start){
					score++;
				}
				else if(x.charAt(i)=='a'){
					
				if(dp[i]==0){
					score++;}
						dp[i]=1;
				start=true;
				}else if (start && x.charAt(i)=='b'){
					go=true;
					
				}
			}
			}}
			System.out.println(score);
}

}