#include using namespace std; using Int = long long; //INSERT ABOVE HERE signed main(){ string s; cin>>s; Int cnt=0; while(1){ Int flg=0; for(Int i=1;i<(Int)s.size();i++){ if(s[i-1]=='B'&&s[i]=='A'){ flg=1; cnt++; swap(s[i-1],s[i]); } } if(!flg) break; } cout<