import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String S = scan.next(); scan.close(); int l = S.length(); int cnt1 = 0; //int cnt2 = 0; for(int i = 0; i < l; i++) { char c = S.charAt(i); if(c == 'A') { cnt1 ++; } } //cnt2 = l - cnt1; if(l == 1) { System.out.println(0); System.exit(0); } int k = l - 1; int sum = 0; for(int i = cnt1 - 1; i >= 0; i--) { char c = S.charAt(i); if(c == 'B') { for(int j = k; j >= cnt1 - 1; j --) { char c2 = S.charAt(j); if(c2 == 'A') { k = j - 1; sum += j - i; break; } } } } System.out.println(sum); } }