#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
#define rep(i, a, b) for (long long(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

using ll = long long;
using P = std::pair<ll, ll>;
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

//とりあえず1-indexedでつくったBIT
template <class T>
class BinaryIndexedTree {
  private:
  T n;
  std::vector<T> bit;

  public:
  BinaryIndexedTree(T i) : n(i), bit(i + 1, 0){};

  // a番目にwを加算
  void add(T a, T w) {
    for (T x = a; x <= n; x += (x & -x)) {
      bit[x] += w;
    }
  }

  //[1,a]の和
  T sum(T a) {
    T ret = 0;
    for (T x = a; x > 0; x -= (x & -x)) {
      ret += bit[x];
    }
    return ret;
  }

    //各項がすべて非負のものに対して、sum[1,a]>=keyを満たす最小のaを返す 存在しないなら-1返す
  T lower_bound(T key){
    T len=1,temp=n,now=0,value=0,flag;
    while(temp/2!=0){
      len*=2;
      temp/=2;
    }

    while(len>0){
      while(now+len>n)len/=2;

      if(value+bit[now+len]>=key){
        len/=2;
      }else{
        now+=len;
        value+=bit[now];
        len/=2;
        if(now==n){
          return -1;
        }
      }
    }

    now++;
    return now;
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::string s;
  std::cin>>s;

  ll n=s.size();

  std::vector<ll> cnt(26,0);

  rep(i,0,n)cnt[s[i]-'a']++;

  ll center=-1;
  rep(i,0,26){
    if(cnt[i]%2){
      if(center!=-1){
        std::cout<<-1;
        return 0;
      }
      center=i;
    }
  }

  ll ans=0;

  std::vector<ll> tag(n,0);
  std::vector<ll> cnt2(26,0);
  std::string left="",right="";

  rep(i,0,n){
    ll num=s[i]-'a';
    if(num==center){
      if(cnt2[num]<cnt[num]/2){
        tag[i]=-1;
      }else if(cnt2[num]>=cnt[num]/2+1){
        tag[i]=1;
      }
    }else{
      if(cnt2[num]<cnt[num]/2){
        tag[i]=-1;
      }else{
        tag[i]=1;
      }
    }
    cnt2[num]++;
  }

  rep(i,0,n){
    if(tag[i]==-1)left+=s[i];
    if(tag[i]==1)right+=s[i];
  }

  ll cntright=0,cntcen=0;

  rep(i,0,n){
    if(tag[i]==-1){
      ans+=cntright+cntcen;
    }else if(tag[i]==0){
      ans+=cntright;
      cntcen++;
    }else{
      cntright++;
    }
  }

  std::reverse(all(left));

  std::vector<std::vector<ll>> rightnum(26);

  rep(i,0,n/2){
    rightnum[right[i]-'a'].push_back(n/2-i);
  }

  cnt2=std::vector<ll>(26,0);

  std::vector<ll> bit(n/2);

  rep(i,0,n/2){
    bit[i]=rightnum[left[i]-'a'][cnt2[left[i]-'a']];
    cnt2[left[i]-'a']++;
  }

  BinaryIndexedTree<ll> seg(n/2);

  rep(i,0,n/2){
    ans+=seg.sum(bit[i]-1);
    seg.add(bit[i],1);
  }

  std::cout<<ans;

  return 0;
}



Measured memory_bytes: 5136