#include <bits/stdc++.h>

using namespace std;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using llint = long long;

const int N = 2e5 + 10;

char s[N];
int n;

struct Bit {
  const int BS = 5;
  int u[N];
  void clear() {
    memset(u, 0, sizeof(u));
  }
  int getsum(int x) {
    int s = 0;
    for (x += BS; x; x -= x & -x) {
      s += u[x];
    }
    return s;
  }

  void modify(int x, int v) {
    for (x += BS; x < N; x += x & -x) u[x] += v;
  }
} bit;

void run() {
  scanf("%s", s);
  n = strlen(s);
  vector <int> cnt(26, 0);
  for (int i = 0; i < n; ++i) {
    ++cnt[s[i] - 'a'];
  }
  int c = 0, who = -1;
  for (int i = 0; i < 26; ++i) {
    if (cnt[i] & 1) {
      ++c;
      who = i;
    }
  }
  if (c > 1) {
    puts("-1");
    return;
  }
  vector < pair <int, int> > half, right_half;
  vector < pair <int, int> > mid;
  vector <int> tmphalfcnt = cnt;
  for (int i = 0; i < 26; ++i) {
    tmphalfcnt[i] /= 2;
  }
  bool fl = 1;
  for (int i = 0; i < n; ++i) {
    if (tmphalfcnt[s[i] - 'a']) {
      half.emplace_back(s[i] - 'a', i);
      --tmphalfcnt[s[i] - 'a'];
    } else if (s[i] - 'a' == who && fl) {
      fl = 0;
      mid.emplace_back(s[i] - 'a', i);
    } else {
      right_half.emplace_back(s[i] - 'a', i);
    }
  }
  reverse(right_half.begin(), right_half.end());
  debug(half);
  debug(right_half);

  debug(mid);
  llint ans = 0;
  if (who != -1) {
    for (auto p : half) {
      if (p.second > mid[0].second)
        ++ans;
    }
    for (auto p : right_half) {
      if (p.second < mid[0].second)
        ++ans;
    }
  }
  debug(ans);
  vector <int> cntrightps(n, 0);
  for (auto p : right_half) {
    ++cntrightps[p.second];
  }
  for (int i = 1; i < n; ++i) {
    cntrightps[i] += cntrightps[i - 1];
  }
  debug(cntrightps);
  for (auto p : half) {
    ans += cntrightps[p.second - 1];
  }

  int hn = half.size();
  vector < queue <int> > v(26, queue <int>());
  for (int i = 0; i < hn; ++i) {
    v[half[i].first].push(i);
  }
  vector <int> ps;
  for (int i = 0; i < hn; ++i) {
    ps.push_back(v[right_half[i].first].front());
    v[right_half[i].first].pop();
  }
  debug(ps);

  bit.clear();
  for (int i = hn - 1; i >= 0; --i) {
    ans += bit.getsum(ps[i] - 1);
    bit.modify(ps[i], 1);
  }


  printf("%lld\n", ans);

}

int main() {
  run();
  return 0;
}


Measured memory_bytes: 4980