#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    string rec;
    cin>>rec;
    vector<int>slovaa[26];
    bool used1[200020]={false}, used2[200020]={false};
    for(int i=0; i<rec.size(); i++){slovaa[rec[i]-'a'].push_back(i);}
    int pocetak=0, kraj=rec.size()-1;
    while(rec[pocetak]==rec[kraj] and pocetak<kraj){pocetak++; kraj--;}
    int pos1=kraj, pos2=pocetak;
    for(int i=pocetak; i<pos1; i++)
    {
        int br=rec[i]-'a';
        int l=0, r=slovaa[br].size()-1, h=pos1;
        int s=(l+r)/2;
        bool found=false;
        while(l<=r)
        {
            if(slovaa[br][s]<=i)l=s+1;
            else if(slovaa[br][s]>kraj)r=s-1;
            else if(slovaa[br][s]>i and slovaa[br][s]<=kraj and !used1[slovaa[br][s]]){h=slovaa[br][s]; found=true; l=s+1;}
            else if(slovaa[br][s]>i and slovaa[br][s]<=kraj and used1[slovaa[br][s]]){l=s+1;}
            s=(l+r)/2;
        }
        if(!found and i!=rec.size()/2){pos1=i; break;}
        pos1=min(pos1, h);
        used1[h]=true;
    }
    for(int i=kraj; i>pos2; i--)
    {
        int br=rec[i]-'a';
        int l=0, r=slovaa[br].size()-1, h=pos2;
        int s=(l+r)/2;
        bool found=false;
        while(l<=r)
        {
            if(slovaa[br][s]<pocetak)l=s+1;
            else if(slovaa[br][s]>=i)r=s-1;
            else if(slovaa[br][s]<i and slovaa[br][s]>=pocetak and !used2[slovaa[br][s]]){h=slovaa[br][s]; found=true; r=s-1;}
            else if(slovaa[br][s]<i and slovaa[br][s]>=pocetak and used2[slovaa[br][s]]){l=s+1;}
            s=(l+r)/2;
        }
        if(!found and i!=rec.size()/2){pos2=i; break;}
        pos2=max(pos2, h);
        used2[h]=true;
    }
    cout<<min(kraj-pos1+1, pos2-pocetak+1);
    return 0;
}