#include #include #include #include #include #include #include #include #include #include #include #include #define vll vector #define vvvl vector #define vvl vector> #define VV(a, b, c, d) vector>(a, vector(b, c)) #define VVV(a, b, c, d) vector(a, vvl(b, vll (c, d))); #define re(c, b) for(ll c=0;c> s; ll cnt = 0; ll th = 200000; fst[th] = -1; re(i, s.size()){ if(s[i]=='A') cnt++; else cnt--; if(fst[th+cnt]==400001) fst[th+cnt] = i; else ans = max(ans, i-fst[th+cnt]); } std::cout << (ans==-10000000000?0:ans) << '\n'; return 0; }