import java.util.Scanner; import java.util.stream.IntStream; public class Main{ static IntStream REPS(int v){return IntStream.range(0,v);} static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);} static IntStream INS(int n) {return REPS(n).map(i->getInt());} static Scanner s=new Scanner(System.in); static int getInt(){return Integer.parseInt(s.next());} public static void main(String[]$){ int r=0,b=0; char[]c=s.next().toCharArray(); int n=c.length; int[]a=new int[n]; a[n-1]=c[n-1]=='A'?1:0; for(int i=n-2;i>=0;--i) { a[i]=a[i+1]+(c[i]=='A'?1:0); } for(int i=0;i