#include #define rep(i,n) for(li i=0;i<(n);i++) #define red(i,n) for(li i=(n)-1;i>=0;i--) #define all(a) begin(a),end(a) #define pb(a) push_back(a) #define fi first #define se second using namespace std; using li = long long; using ul = unsigned long long; using vi = vector
  • ; using vs = vector; inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; } const int INF=1000000009; int main() { int ans=0; string s; cin>>s; for(bool F=1;F;){ F=0; for(int i=0;i<(int)s.size()-1;i++) if(s[i]=='B' && s[i+1]=='A')swap(s[i],s[i+1]),ans++,F=1; } cout<