/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
auto fraclt = [](const pii&a,const pii&b) { return (ll)a.x * b.y < (ll)b.x * a.y; };
struct cmpfrac { bool operator()(const pii&a,const pii&b)const { return (ll)a.x * b.y < (ll)b.x * a.y; }};
template <typename T> bool in(T a, T b, T c) { return a <= b && b < c; }
ui logceil(ll x) {ui b=0;while(x){x>>=1;++b;}return b;}

namespace std {
    template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bsh(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsl(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};
template <typename T> struct bounded_priority_queue {
	inline bounded_priority_queue(ui X) : A(X), B(0) {}
	inline void push(ui L, T V) { B = max(B, L); A[L].push(V); }
	inline const T &top() const { return A[B].front(); }
	inline void pop() { A[B].pop(); while (B > 0 && A[B].empty()) --B; }
	inline bool empty() const { return A[B].empty(); }
	inline void clear() { B = 0; for (auto &a: A) a = queue<T>(); }
private:
	vector<queue<T>> A; ui B;
};


#endif


template<typename T> struct Fenwick {
	explicit Fenwick(ui N=0, T t=T()):N(1u<<logceil(N)),F(this->N,t),t(t){}
	explicit Fenwick(const vector<T>&A, T t=T()):N(1u<<logceil(A.size())),F(A),t(t){
        F.resize(N); fill(F.begin()+A.size(),F.end(),t);
		for(int i=0;i<N;i++){int j=i+lsb(i+1);if(j<N)F[j]+=F[i];}}
	void add(int i, T v){while(i<=N){F[i]+=v;i+=lsb(i+1);}}
	T sum(int i)const{T sum(t);while(i){sum+=F[i-1];i-=lsb(i);}return sum;}
	T range(int i,int j)const{j++; T s(t);while(j>i){s+=F[j-1];j-=lsb(j);}while(i>j){s-=F[i-1];i-=lsb(i);}return s;}
	T get(int i)const{return range(i,i);}
	void set(int i, T v) {add(i, v-get(i)); }
	constexpr int lsb(int i)const{return i&-i;}
    ui N;vector<T> F;T t;
};

template<typename F>struct NoCombine {
    const int NOCOMB=-2;
    void setup(ui){}void op(F&p,F n,ui,ui,ui){p=n;}F up(F l,F r,ui){return l==r?l:NOCOMB;}
    void down(F&u,F&l,F&r,ui,ui,ui){if(u!=NOCOMB){l=r=u;}u=NOCOMB;}};
template<typename F,typename Op>struct Persistent{Op o;void setup(ui){}void op(F&p,F n,ui,ui, ui){p=n;}F up(F l, F r, ui){return o(l,r);}void down(F&,F&,F&,ui,ui, ui b) {}};

template<typename F,typename SetOp,typename CombineOp,typename PowerOp>struct LazyProp{
    void setup(ui s){this->s=s;L=new F[s]();}
    void down(F&u,F&l,F&r,ui i,ui a,ui b){op(l,L[i],2*i,a,(a+b)/2);op(r,L[i],2*i+1,(a+b)/2,b);L[i]=0;}
    void op(F&p,F n,ui i,ui a,ui b){p=sop(p,pop(n,b-a));if(i<this->s)this->L[i]=sop(this->L[i],n);}
    F up(F l,F r,ui){return cop(l,r);}SetOp sop;CombineOp cop;PowerOp pop;F*L;ui s;
};

template <typename F> struct AddOp { F operator()(F a, F b) { return a+b; }};
template <typename F> struct MultOp { F operator()(F a, F b) { return a*b; }};
template <typename F> struct IdempOp { F operator()(F a, F b) { return a; }};
template <typename F> struct MinOp { F operator()(F a, F b) { return std::min(a,b); }};
template <typename F> struct MaxOp { F operator()(F a, F b) { return std::max(a,b); }};

template <typename F, typename Combine> struct SegTree {
	void setup(ui s, F def) {
		size = 1<<logceil(s);
		T = vector<F>(2*size, def);
		for (ui i = size-1; i > 0; i--) T[i] = op.up(T[2*i],T[2*i+1], i);
		op.setup(2*size);
	}

	void setup(vector<F> & data, F def = F()) {
		size = 1<<logceil(data.size());
		T = vector<F>(2*size, def);
		copy(data.begin(), data.end(), T.begin() + size);
		for (ui i = size-1; i > 0; i--) T[i] = op.up(T[2*i],T[2*i+1], i);
		op.setup(2*size);
	}

	inline void put(ui x, F n) { put(x, x, n); }
	inline void put(ui from, ui to, F n) { put2(from, to+1, n, 1, 0, size); }
	inline F get(ui x) { return get(x, x); }
	inline F get(ui from, ui to) { return get2(from, to+1, 1, 0, size); }

	void put2(ui from, ui to, F n, ui i, ui a, ui b) {
		if (from <= a && to >= b) { op.op(T[i], n, i, a, b); return; }
		if (from >= b || to <= a) { return; }
		op.down(T[i], T[2*i], T[2*i+1], i, a, b);
		put2(from, to, n, 2*i, a, (a+b)/2);
		put2(from, to, n, 2*i+1, (a+b)/2, b);
 		T[i] = op.up(T[2*i], T[2*i+1], i);
	}

	F get2(ui from, ui to, ui i, ui a, ui b) {
		if (from <= a && to >= b) { return T[i]; }
		op.down(T[i], T[2*i], T[2*i+1], i, a, b);
		if (to <= (a+b)/2) { return get2(from, to, 2*i, a, (a+b)/2); }
		else if (from >= (a+b)/2) { return get2(from, to, 2*i+1, (a+b)/2, b); }
		else return op.up(get2(from, to, 2*i, a, (a+b)/2), get2(from, to, 2*i+1, (a+b)/2, b), i);
	}

	ui size;
	vector<F> T;
	Combine op;
};

template<typename T> using SetGetTree = SegTree<T, NoCombine<T>>;
template<typename T> using AddSumTree = SegTree<T, LazyProp<T, AddOp<T>, AddOp<T>, MultOp<T>>>;
template<typename T> using AddMaxTree = SegTree<T, LazyProp<T, AddOp<T>, MaxOp<T>, IdempOp<T>>>;
template<typename T> using AddMinTree = SegTree<T, LazyProp<T, AddOp<T>, MinOp<T>, IdempOp<T>>>;
template<typename T> using AssignMinTree = SegTree<T, LazyProp<T, MinOp<T>, MinOp<T>, IdempOp<T>>>;
template<typename T> using AssignMaxTree = SegTree<T, LazyProp<T, MaxOp<T>, MaxOp<T>, IdempOp<T>>>;

template<typename T> using SetMinTree = SegTree<T, Persistent<T, MinOp<T>>>;
template<typename T> using SetMaxTree = SegTree<T, Persistent<T, MaxOp<T>>>;


class E {
public:
    void solve(istream& cin, ostream& cout) {
        string S;
        cin >> S;
        vector<int> C(26, 0);
        for (char s:S) C[s-'a']++;
        int mid = -1;
        for (int i = 0; i < 26; ++i) {
            if (C[i]%2) {
                if (mid != -1) {
                    cout << "-1\n";
                    return;
                } else {
                    mid = i;
                }
            }
        }

        int N = S.size();
        vector<int> P(N);
        vector<int> L(26, -1);
        for (int i = 0; i < N; ++i) {
            P[i] = L[S[i]-'a'];
            L[S[i]-'a'] = i;
        }

        Fenwick<int> F(N, 0);
        int done = 0;
        ll ans = 0;
        bool hasMid = false;
        for (int i = 0; done < N/2; ++i) {
            if (F.get(i) == 1) continue;

            if (C[S[i]-'a'] == 1) {
                hasMid = true;
                continue;
            }

            ans += hasMid;

            int c = S[i]-'a';
            int l = L[c];
            int o = F.range(l, N-1);
            //cerr << char(c+'a') << ' ' << l << ' ' << o << ' ';
            ans += N-l-1-o;
            F.add(l, 1);
            F.add(i, 1);
            ++done;
            C[c] -= 2;
            L[c] = P[l];
            // cerr << ans << endl;
        }
        cout << ans << endl;
    }
};


int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	E solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 2452