#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
   string a;
   int b1=0,b2=0,c,r;
   cin>>a;
   c=a.size();
   for(int i=0;i<c;i++)
   {
       if(a[i]=='b'&&b1!=0){b2=i;break;}
   if(a[i]=='b')b1=i;
   }
    if(c%2==0){
        if(b2<c/2)r=c/2-b2+c/2-1-b1;
        else if(b1>=c/2)r=b1-c/2+1+b2-c/2;
        else r=abs((b2-c/2)-(c/2-1-b1));
    }
    else {
        if(b2<c/2)r=c/2-b2+c/2-b1;
        else if(b1>c/2)r=b1-c/2+b2-c/2;
        else r=abs((b2-c/2)-(c/2-b1));
    }
    cout<<r+1;
    return 0;
}