#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef vector VVL; typedef pair P; typedef pair PL; int main(){ string s; cin >> s; int ans = 0; REP(k,1000){ REP(i,s.length()-1){ if (s[i] == 'B' && s[i+1] == 'A'){ swap(s[i], s[i+1]); ans++; } } } cout << ans << endl; return 0; }