#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,n) for(int i = 0;i<((int)(n));i++) #define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++) #define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--) #define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--) typedef long long ll; typedef pair mp; ll mod = 1e9+7; ll inf = 1e18; //AC int main(void){ ll sum=0,last[400010],ans=0; string S; cin>>S; reg(i,0,2*S.size())last[i]=-2; last[sum+S.size()]=-1; rep(i,S.size()){ if(S[i]=='A'){ sum++; }else{ sum--; } if(last[sum+S.size()]!=-2)ans=max(ans,i-last[sum+S.size()]); last[sum+S.size()]=i; } cout<