#include <bits/stdc++.h>

using namespace std;

int rez (string rec)
{
    int n = rec.length();

    unordered_map<char, int> broj_slova;
    unordered_map<char, int> konst;


    for (int i = 0; i < n; i++){
        broj_slova[rec[i]]++;
        konst[rec[i]]++;
    }

    /*for (auto it = broj_slova.begin(); it != broj_slova.end(); it++){
        cout << it -> first << " -> " << it -> second << endl;
    } */

    int donja_granica = 0, gornja_granica = n - 1;
    bool first_time = true; int limit; bool odma_palindrom = true;

    for (int i = 0; i < (n - 1) / 2; i++){
        if (rec[i] != rec[n - i - 1]){
            odma_palindrom = false;
            break;
        }
    }

    if (odma_palindrom){

        return 1;
    }

    for (int donja_granica; donja_granica < gornja_granica; donja_granica++){
        char slovo = rec[donja_granica];
        limit = gornja_granica - donja_granica + 1 + donja_granica;
        limit = limit / 2;
        //cout << limit << endl;
        if (slovo == rec[gornja_granica] && first_time){
            gornja_granica--;
            broj_slova[slovo] = broj_slova[slovo] - 2;
            konst[slovo] = konst[slovo] - 2;



        }

        else {
            if (donja_granica > limit){
                //cout << donja_granica << " " << gornja_granica << endl;
                return  gornja_granica - donja_granica + 1;

            }

            broj_slova[slovo]--;

            if (broj_slova[slovo] < konst[slovo] / 2.00){
                //cout << donja_granica << " " << gornja_granica << endl;
                return gornja_granica - donja_granica + 1;
            }
            first_time = false;

        }
    }

}