#include using namespace std; using ll = long long; int a[200005]; int b[200005]; int c[200005]; map mp; int main(){ string s; cin >> s; int n = s.size(); for(int i = 1; i <= n; i++){ if(s[i-1]=='A'){ a[i] = a[i-1]+1; b[i] = b[i-1]; }else{ a[i] = a[i-1]; b[i] = b[i-1]+1; } } int ans = 0; for(int i = 1; i <= n; i++) c[i] = a[i]-b[i]; for(int i = 0; i <= n; i++){ if(mp.find(c[i])==mp.end()) mp[c[i]] = i; else ans = max(ans, i-mp[c[i]]); } cout << ans << endl; return 0; }