#include #include #include #include using namespace std; int main(){ string S; cin >> S; map> AB; int depth = 0; AB[depth].push_back(-1); for(int i = 0; i < S.size(); i++){ if(S[i] == 'A'){ depth++; }else{ depth--; } AB[depth].push_back(i); } int ans = 0; for(auto i: AB){ ans = max(ans, i.second.back() - i.second.front()); } cout << ans << endl; }