#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS()ios_base::sync_with_stdio(0);cin.tie(0)

template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//******************************************************************************
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
struct LazySegmentTree{
    private:
    int n;
    vector<ll> node,lazy;
    public:
    LazySegmentTree(vector<ll> v){
        int sz = (int)v.size();
        n = 1;while(n < sz)n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);

        for(int i=0;i<sz;i++)node[i+n-1] = v[i];
        for(int i=n-2;i>=0;i--)node[i]=node[2*i+1]+node[2*i+2];
    }

    void eval(int k,int l,int r){
        if(lazy[k] != 0){
            node[k] += lazy[k];

            if(r-l > 1){
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
        if(r<0)r = n;

        eval(k,l,r);
        if(b <= l || r <= a)return;

        if(a <= l && r <= b){
            lazy[k] += (r - l) * x;
            eval(k,l,r);
        }
        else{
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
    ll getsum(int a,int b,int k=0,int l=0,int r=-1){
        if(r < 0)r = n;
        eval(k,l,r);
        if(b <= l || r <= a)return 0;
        if(a <= l && r <= b)return node[k];
        ll vl = getsum(a,b,2*k+1,l,(l+r)/2);
        ll vr = getsum(a,b,2*k+2,(l+r)/2,r);
        return vl + vr;
    }
};
//LazySegmentTree seg(vector<int>(N,0));

signed main()
{
	//IOS();
	int N;
	string s;
	cin>>s;
	N = s.size();
	LazySegmentTree seg(vector<int>(N,0));
	vector<int>cnt(26,0);
	map<pair<char,int>,int>mp;
	rep(i,0,N){
		mp[{s[i],cnt[s[i]-'a']}]=i;
		cnt[s[i]-'a']++;
	}
	int flag = N&1;
	vector<int>v(26,0);
	int kaburi;
	rep(i,0,26){
		if(cnt[i]%2&&flag){
			flag--;
			kaburi = i;
		}
		else if(cnt[i]%2&&flag==0){
			cout<<"-1"<<endl;
			return 0;
		}
		v[i]=cnt[i]/2;
	}
	string t="";
	rep(i,0,N){
		if(v[s[i]-'a']){
			t+=s[i];
			v[s[i]-'a']--;
		}
	}
	string tt=t;
	reverse(all(tt));
	if(N%2)t+=kaburi+'a';
	t+=tt;

	vector<int>now(26,0);
	int ans = 0;
	rep(i,0,t.size()){
		int tmp = mp[{t[i],now[t[i]-'a']}];
		//cout<<t[i]<<" "<<now[t[i]-'a']<<" "<<tmp<<endl;
		int tmptmp=tmp+seg.getsum(tmp,tmp+1);
		ans+=max(0ll,tmptmp-i);
		now[t[i]-'a']++;
		seg.add(0,tmp,1);
		//cout<<i<<" "<<tmptmp<<" "<<ans<<endl;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 21608