aaaaabb
 aabaaaa
 babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb
 baaahbbbba
 ababavvvv
 abnxabbaab
 krflnzhter
 amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb
 babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab

5
 14
 42467327
 7
 7
 11
 0
 98718509
 813881762

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		while(in.hasNext()) {
			String q=in.nextLine();
			char s[]=q.toCharArray();
			int a[]=new int[100000];
			int w=0;
			for(int i=0;i<s.length;i++) {
				if(s[i]=='a') {
					a[w]=i;
					w++;
				}
			}
			int sum=w;
			for(int i=0;i<w-1;i++) {
				int e=0;
				for(int j=a[i]+1;j<a[i+1];j++) {
					if(s[j]=='b') {
						e=1;
					}
				}
				if(e==1) {
					sum=sum+w-i-1;
				}
			}
			System.out.println(sum);
		}
	}
}
