#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0;i> S; if(S.length() == 1) { printf("0\n"); return 0; } int ans = 0; while(!check()) { REP(i, S.length() - 1) { if(S[i] == 'B' && S[i+1] == 'A') { swap(S[i], S[i+1]); ans++; } } } printf("%d\n", ans); return 0; }