#include<bits/stdc++.h>
#include <cstring>
#include <iostream>
#define pie acos(-1)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sl(a) scanf("%lld",&a)
#define sll(a,b) scanf("%lld %lld",&a,&b)
#define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define ss(st) scanf("%s",st)
#define sch(ch) scanf("%ch",&ch)
#define ps(a) printf("%s",a)
#define newLine() printf("\n")
#define pi(a) printf("%d",a)
#define pii(a,b) printf("%d %d",a,b)
#define piii(a,b,c) printf("%d %d %d",a,b,c)
#define pl(a) printf("%lld",a)
#define pll(a,b) printf("%lld %lld",a,b)
#define plll(a,b,c) printf("%lld %lld %lld",a,b,c)
#define pd(a) printf("%lf",a)
#define pdd(a,b) printf("%lf %lf",a,b)
#define pddd(a,b,c) printf("%lf %lf %lf",a,b,c)
#define pch(c) printf("%ch",c)
#define debug1(str,a) printf("%s=%d\n",str,a)
#define debug2(str1,str2,a,b) printf("%s=%d %s=%d\n",str1,a,str2,b)
#define debug3(str1,str2,str3,a,b,c) printf("%s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c)
#define debug4(str1,str2,str3,str4,a,b,c,d) printf("%s=%d %s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c,str4,d)
#define for0(i,n) for(i=0;i<n;i++)
#define for1(i,n) for(i=1;i<=n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define forstl(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define NL puts("")
#define sd(a) scanf("%lf",&a)
#define sdd(a,b) scanf("%lf %lf",&a,&b)
#define sddd(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define SP printf(" ")
#define LL long long int
#define ULL unsigned long long int
#define N 1000007
#define MOD 100000009
#define pub(x) push_back(x)
#define pob(x) pop_back(x)
#define mem(ara,value) memset(ara,value,sizeof(ara))
#define INF INT_MAX
#define eps 1e-8
#define checkbit(n, pos) (n & (1<<pos))
#define setbit(n, pos) (n | (1<<pos))
#define para(a,b,ara)\
for(int i=a;i<=b;i++){\
    if(i!=0){printf(" ");}\
    printf("%d",ara[i]);\
}\
printf("\n");
#define pvec(vec)\
for(int i=0;i<vec.size();i++){\
    if(i!=0){printf(" ");}\
    printf("%d",vec[i]);\
}\
printf("\n");
#define ppara(n,m,ara)\
for(int i=0;i<n;i++){\
    for(int j=0;j<m;j++){\
        if(j!=0){printf(" ");}\
        printf("%d",ara[i][j]);\
    }\
    printf("\n");\
}
#define ppvec(n,vec)\
for(int i=0;i<n;i++){\
    for(int j=0;j<vec[i].size();j++){\
        if(j!=0){printf(" ");}\
        printf("%d",vec[i][j]);\
    }\
    printf("\n");\
}
#define sara(a,b,ara)\
for(int i=a;i<=b;i++){\
    scanf("%d",&ara[i]);\
}
using namespace std;
LL tree[4*2*100010];
char str[2*100010];
LL n;
vector <LL> vec[26];
LL mxIter[26],mnIter[26];
void input(){
    LL i,j;ss(str);
    n=strlen(str);
}
bool chck(){
    LL i,j,cnt=0;
    for0(i,n){
        vec[str[i]-'a'].pub(i);
    }
    for0(i,26){
        LL sz=vec[i].size();
        mnIter[i]=0;mxIter[i]=sz-1;
        if(sz%2 ==1){
            cnt++;
        }
    }
    if(cnt>1){return false;}
    return true;
}
void mrg(LL iter){
    tree[iter]=tree[2*iter+1]+tree[2*iter+2];
}
void makeTree(LL lo,LL hi,LL iter){
    if(lo==hi){
        tree[iter]=1;
        return;
    }
    else if(lo<hi){
        LL mid=(lo+hi)/2;
        tree[iter]=0;
        makeTree(lo,mid,2*iter+1);
        makeTree(mid+1,hi,2*iter+2);
        mrg(iter);
    }
}
LL query(LL lo,LL hi,LL iter,LL l,LL r){
    if(l>r){return 0;}
    if(l<=lo&&r>=hi){
        return tree[iter];
    }
    else if(l>hi||r<lo){
        return 0;
    }
    else{
        LL mid=(lo+hi)/2;
        return query(lo,mid,2*iter+1,l,r)+query(mid+1,hi,2*iter+2,l,r);
    }
}
void update(LL lo,LL hi,LL iter,LL indx){
    LL mid=(lo+hi)/2;
    if(lo==hi){
        tree[iter]=0;return;
    }
    else if(indx>=lo&&indx<=mid){
        update(lo,mid,2*iter+1,indx);
    }
    else{
        update(mid+1,hi,2*iter+2,indx);
    }
    mrg(iter);
}
void solve(){
    LL i,j,mn,s1,s2,indx,ans=0;
    if(!chck()){
        pi(-1);NL;return;
    }
    makeTree(0,n-1,0);
    for0(i,n/2){
        mn=INF;
        indx=-1;
        for0(j,26){
            if(mnIter[j]<mxIter[j]){
                s1=query(0,n-1,0,0,vec[j][mnIter[j]]-1);
                s2=query(0,n-1,0,vec[j][mxIter[j]]+1,n-1);
                if(s1+s2<mn){
                    mn=s1+s2;
                    indx=j;
                }
            }
        }
        ans+=mn;
        update(0,n-1,0,vec[indx][mnIter[indx]]);
        update(0,n-1,0,vec[indx][mxIter[indx]]);
        mnIter[indx]++;
        mxIter[indx]--;
    }
    pl(ans);NL;
}
int main(){
//    freopen("input.txt","r",stdin);
    input();
    solve();
    return 0;
}


Measured memory_bytes: 8436