#include <bits/stdc++.h>

using namespace std;

int main(){

    string s;

    cin >> s;

    int n = s.size();

    vector<priority_queue<int, vector<int>, greater<int>>> suff(26);
    vector<priority_queue<int>> pref(26);

    for(int i = 0; i < n; ++i){
        pref[s[i]-'a'].push(i);
        suff[s[i]-'a'].push(i);
    }
    
    int i = 0, j = n-1, fL = 0, fR = n-1, ans1 = 0, ans2 = 0;
    bool setL = 0, setR = 0;

    string sCp = s;

    while(i < j){
        suff[s[i]-'a'].pop();
        if(s[i] != s[j]){
            if(!setL) fL = i;
            int ind = suff[s[j]-'a'].top();
            if(ind < j){
                if(ind > fL) ans1 += ind-fL, fL = ind;
                if(!setL) ++ans1, setL = 1;
            }else{
                if(j > fL){
                    ans1 += j-fL;
                    if(!setL) ++ans1;
                    break;
                }
            }

            suff[s[ind]-'a'].pop();
            suff[s[i]-'a'].push(ind);
            char tmp = s[i];
            s[i] = s[ind];
            s[ind] = tmp;
        }

        ++i, --j;
    }

    i = 0, j = n-1;

    s = sCp;

    while(i < j){
        pref[s[j]-'a'].pop();
        if(s[i] != s[j]){
            if(!setR) fR = j;
            int ind = pref[s[i]-'a'].top();
            if(ind != -1){
                if(ind < fR) ans2 += fR-ind, fR = ind;
                if(!setR) ++ans2, setR = 1;
            }else{
                if(i < fR){
                    ans2 += i-fR;
                    if(!setR) ++ans2;
                    break;
                }
            }

            pref[s[ind]-'a'].pop();
            pref[s[j]-'a'].push(ind);
            char tmp = s[j];
            s[j] = s[ind];
            s[ind] = tmp;
        }

        ++i, --j;
    }

    ans1 = min(ans1, ans2);

    cout << (ans1 == 0 ? 1 : ans1) << '\n';
    return 0;
}