//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp //g++ -std=c++14 -Wall -O2 -o main.exe main.cpp #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define spc " " #define MOD 1000000007 typedef long long ll; typedef long double ld; typedef pair p_ii; typedef tuple tup; bool tupComp(tup &t1, tup &t2){ return get<2>(t1) > get<2>(t2); } //------------------------------------------------------------------------------ int main(){ string s; cin >> s; int a = (s[0] == 'A' ? 1 : 0), b = (s[0] == 'B' ? 1 : 0), ans = 0, max = 0; bool flag = (s[0] == 'A' ? false : true); for(int i = 1; i < s.size(); i++){ if(s[i] == 'A'){ a = (flag ? 1 : a + 1); } else{ b = (flag ? b + 1 : 1); } ans = min(a, b) * 2; if(ans > max) max = ans; flag = (s[i] == 'A' ? 0 : 1); } cout << max << endl; return 0; }