#include #include #include #include using namespace std; int main(){ int c,m=0; string s; cin >> s; vector a(2*s.length()+1,-2); a[s.length()] = -1; c = 0; for(int i = 0; i < (int)s.length(); i++) { if (s[i] == 'A') { c += 1; } else { c -= 1; } if (a[c + s.length()] == -2) { a[c + s.length()] = i; } else { m = max(m,i - a[c + s.length()]); } } cout << m << endl; return 0; }