#include #include #define size(s) sizeof(s)/sizeof(s[0]) std::string str; int main(){ scanf("%s", str.c_str()); int ans = 0, cnt = 0, f = 0; for(;;){ f = 1; for(int i = 1; i < size(str); i++){ if(str[i - 1] == 'B' && str[i] == 'A'){ char tmp = str[i - 1]; str[i - 1] = str[i]; str[i] = tmp; ans++; f = 0; } } if(f) break; } printf("%d\n", ans); return 0; }