//#include #include #include #include #include #include #include #include #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define pb push_back #define INF 93193111451418101 #define MIN -93193111451418101 using namespace std; typedef long long ll;//int64 typedef unsigned long long ull; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; //----------program from here---------- int a[200030]; int mx[200030]; int mn[200030]; int ans; int main(){ string s; REP(i,200020){ mn[i]=1145141919; } mn[0]=0; cin>>s; REP(i,s.length()){ if(s[i]=='A'){a[i+1]=a[i]+1;} else {a[i+1]=a[i]-1;} } REP(i,s.length()+1){ //cout<