#include #include #include using namespace std; struct dta{ int n; int A,B; }; bool cmp(const dta &a,dta &b){ if(a.A==b.A){ if(a.B==b.B){ return a.n < b.n; } return a.B < b.B; } return a.A < b.A; } int nwa,nwb; int main(){ string s;cin>>s; vector A; A.push_back({-1,0,0}); for(int i = 0; s.size() > i; i++){ if(s[i] == 'A')nwa++; else nwb++; if(nwa*nwb){ nwa--; nwb--; } A.push_back({i,nwa,nwb}); } sort(A.begin(),A.end(),cmp); int nA = A[0].A; int nB = A[0].B; int nN = A[0].n; int ans = 0; for(int i = 1; A.size() > i; i++){ if(nA == A[i].A && nB == A[i].B){ cout << A[i].n << " " << nN << endl; ans = max(ans,A[i].n-nN); }else{ nA = A[i].A; nB = A[i].B; nN = A[i].n; } } cout << ans << endl; }