import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); char[] x = s.toCharArray(); int n = s.length(); int ans = 0; for(int i = 0 ; i < n ; i++) { for(int j = i ; j < n ; j++) { char work; if(s.charAt(i) == 'B' && s.charAt(j) == 'A') { work = s.charAt(i); x[i] = s.charAt(j); x[j] = work; ans++; } } } System.out.println(ans); } }