#include using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) int main() { string s; cin >> s; int n = s.size(); int a = 0, ans = 0; map mp; mp[0] = -1; rep(i,n) { a += s[i] == 'A' ? 1 : -1; if (mp.count(a))ans = max(ans, i - mp[a]); else mp[a] = i; } cout << ans << "\n"; return 0; }