#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, lint>>>;
const lint INF = 1001001001001001LL;
const lint MOD = 1000000007LL;
const double PI = 3.1415926535897932;
int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
void possible(){ cout << "possible" << endl; }
void Possible(){ cout << "Possible" << endl; }
void POSSIBLE(){ cout << "POSSIBLE" << endl; }
void impossible(){ cout << "impossible" << endl; }
void Impossible(){ cout << "Impossible" << endl; }
void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

// quoted from beet-aizu
template <typename T, typename E, typename F, typename G>
struct SegmentTree{
    // using F = function<T(T, T)>
    // using G = function<T(T, E)>
    int n;
    F f;
    G g;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f,G g,T ti):f(f),g(g),ti(ti){}
    void init(int n_){    
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    void update(int k,const E &x){
        k += n;
        dat[k] = g(dat[k], x);
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
    }
    T operator [](int k) const { return dat[k+n]; }
    T query(int a,int b) const {
        T vl=ti,vr=ti;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,dat[l++]);
            if(r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }

    
    
    /* TODO わからない 聞く 
    template<typename C>
    int find(int a,int b,C &check,int k,int l,int r){
        if(!check(dat[k])||r<=a||b<=l) return -1;
        if(k>=n) return k-n;
        int m=(l+r)>>1;
        int vl=find(a,b,check,(k<<1)|0,l,m);
        if(~vl) return vl;
        return find(a,b,check,(k<<1)|1,m,r);
    }
    template<typename C>
    int find(int a,int b,C &check){
        return find(a,b,check,1,0,n);
    }*/
    
};


lint cntBubbleSort(vector<lint> a){
  
  lint n = a.size();
  using T = lint;  // type T
  using E = lint;  // type E
  auto f = [](T a, T b){ // return type T value
    return a + b;
  };
  auto g = [](T a, E b){ // return type T value
    return b;
  };
  T ti = 0;  // identify element
  SegmentTree<T, E, decltype(f), decltype(g)> sg(f, g, ti);  // don't change
  sg.build(vector<lint> (n, 0));   // 初期配列を代入
  

  vector<pair<lint, lint>> vp(n);
  rep(i, n) vp[i] = {a[i], i};
  sort(rall(vp));
  lint ret = 0;
  rep(i, n){
    ret += sg.query(0, vp[i].second);
    sg.update(vp[i].second, 1);
  }
  
  return ret;
}


int main(){
  
  string s; cin >> s;
  vector<int> cnt(26, 0);
  for(auto c : s) cnt[c - 'a']++; 

  int cntOdd = 0;
  rep(i, 26){
    if(cnt[i] % 2 == 1) cntOdd++;
  }

  if(cntOdd - (s.size() % 2) > 0){
    cout << -1 << endl;
    return 0;
  }
  

  // 26 * |s| の計算ステップ
  lint n = (lint)s.size();
  vector<lint> a;
  vector<bool> used(n, false);
  vector<lint> canUse(26, 0);
  rep(i, 26) canUse[i] = cnt[i] / 2;
  rep(i, n){
    if(canUse[s[i] - 'a'] > 0){
      a.push_back(i);
      canUse[s[i] - 'a']--;
      used[i] = true;
    }
  }

  // 奇数のやつがあるなら
  rep(i, n){
    if(!used[i] and cnt[s[i] - 'a'] % 2 == 1){
      a.push_back(i);
      used[i] = true;
      break;
    }
  }
  
  rep(i, n){
    if(!used[i]) a.push_back(i);
  }
  lint ans = cntBubbleSort(a);
  string x = "";
  rep(i, n) x.push_back(s[a[i]]);
  string s1 = "";
  string s2 = "";
  rep(i, n / 2){
    s1.push_back(x[i]);
    s2.push_back(x[n - 1 - i]);
  }
  vector<lint> idx(26, 0);
  vector<vector<lint>> ord(26);
  rep(i, s1.size()){
    ord[s1[i] - 'a'].push_back(i);
  }

  vector<lint> b;
  rep(i, s2.size()){
    lint idAlpha = s2[i] - 'a';
    b.push_back(ord[idAlpha][idx[idAlpha]]);
    idx[idAlpha]++;
  }
  
  ans += cntBubbleSort(b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10968