#include using namespace std; int main() { string S; cin >> S; map< int, int > mp; mp[0] = -1; int sum = 0, ret = 0; for(int i = 0; i < S.size(); i++) { sum += S[i] == 'A' ? 1 : -1; if(mp.count(sum)) ret = max(ret, i - mp[sum]); else mp[sum] = i; } cout << ret << endl; }