#include #define FOR(i,a,b) for(int i = (a); i < (b); ++i) #define REP(i,n) FOR(i,0,n) #define SZ(n) (int)(n).size() #define ALL(n) (n).begin(), (n).end() #define MOD % 1000000007 using namespace std; typedef long long LL; typedef vector VI; int main() { string s; cin >> s; if (SZ(s) == 1) cout << 0 << endl; else { int cnt = 0; REP(i, SZ(s)) { if (s[i] == 'B' && s[i + 1] == 'A') { swap(s[i], s[i + 1]); cnt++; i = 0; } } cout << cnt << endl; } return 0; }