#include <bits/stdc++.h>
#include<string>
#include<string>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
    ios;
    string s;
    cin>>s;
    string s1=s;
    reverse(s1.begin(),s1.end());
    if(s1==s){
        cout<<1;
        return 0;
    }
    bool ab = true;
    long long br=0;
    long long p=-1,d=-1;
    long long l=-1,de=-1;
    long long n = s.length();
    for(int i =0;i<n;i++){
        if(s[i]!='a'||s[i]!='b'){
            ab=false;
        }
        if(s[i]=='b'){
            if(p==-1)p=i;
            else {d=i;break;}
        }
    }
    if(ab){
        long long c = n-d;
        br=p-c;
        cout<<br+2;
        return 0;
    }
    double c = (double)n/2;
    long long q=0,e=0;
    for(int i =0;i<c;i++){
        q+=(int)s[i];
    }
    for(int i =c;i<n;i++){
        e+=(int)s[i];
    }
    c=(int)c;
    if(q==e){
        for(int i =0;i<c;i++){
            if(s[i]!=s[n-1-i]){
                if(l==-1){
                    l=i;
                    de=i;
                }
                else de=i;
            }
        }
    cout<<de-l+1;
    return 0;
    }
    cout<<1;
}