#define _USE_MATH_DEFINES #include #define int long long #define rep(i,n) for(int i=0;i=0;i--) #define vi vector #define vvi vector #define pb push_back #define pi pair #define vp vector> #define mp make_pair #define all(v) (v).begin(),(v).end() #define fi first #define se second #define MEMSET(a) memset(a,0,sizeof(a)) #define inf (1ll<<60) #define Yes(f) cout<<(f?"Yes":"No")<()) #define VI(a,n) vi a(n); rep(i,n)cin>>a[i]; using namespace std; const int mod=1e9+7; void run(); void init() { ios::sync_with_stdio(false); cin.tie(0); cout<>s; int a=0; vvi p(s.length()); p[0].pb(0); rep(i,s.length()){ if(s[i]=='A')a++; else a--; if(a>=0)p[a].pb(i+1); } int ans=0; rep(i,p.size()){ int t=p[i].size(); if(t)ans=max(ans,p[i][t-1]-p[i][0]); } cout<