#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }


typedef pair<int,int> pint;


typedef int VAL;
const int MAX_B = 410000;
const VAL UNITY_SUM = 0;

int SIZE_B;
struct BIT {
	VAL dat[MAX_B + 1];

	void init(int n = 1) {
		SIZE_B = n;
		for (int i = 0; i <= SIZE_B; ++i) dat[i] = UNITY_SUM;
	}

	inline void add(int a, VAL x) {
		for (int i = a; i <= SIZE_B; i += i & -i)
			dat[i] = dat[i] + x;
	}

	inline VAL sum(int a) {
		VAL res = UNITY_SUM;
		for (int i = a; i > 0; i -= i & -i)
			res = res + dat[i];
		return res;
	}

	inline VAL sum(int a, int b) {
		return sum(b - 1) - sum(a - 1);
	}

	void print() {
		for (int i = 1; i <= SIZE_B; ++i) cout << sum(i, i + 1) << ",";
		cout << endl;
	}
};

BIT bit;



string str;
map<char, deque<int> > ma;
int odd = -1;
vector<pint> pas;

long long solve() {
  ma.clear();
  for (int i = 0; i < str.size(); ++i) {
	ma[str[i]].push_back(i + 1);
  }
  pas.clear();
  odd = -1;
  for (map<char,deque<int> >::iterator it = ma.begin(); it != ma.end(); ++it) {
	deque<int> deq = it->second;
	while (deq.size() >= 2) {
	  pas.push_back(pint(deq[0], deq.back()));
	  deq.pop_front();
	  deq.pop_back();
	}
	if (deq.size() == 1) {
	  if (odd == -1) odd = deq[0];
	  else return -1;
	}
  }

  long long res = 0;

  if (odd != -1) {
	for (int i = 0; i < pas.size(); ++i) {
	  if (pas[i].first < odd && odd < pas[i].second) continue;
	  ++res;
	}
  }

  /*
  COUT(pas);
  COUT(odd);
  COUT(res);
  */
  bit.init(str.size() + 5);
  sort(pas.begin(), pas.end());

  for (int i = 0; i < pas.size(); ++i) {
	long long tmp1 = bit.sum(1, pas[i].first);
	long long tmp2 = bit.sum(1, pas[i].second);
	bit.add(pas[i].second, 1);

	res += tmp1 + tmp2;
  }
							
  return res;
}

int main() {
  while (cin >> str) {
	cout << solve() << endl;
  }
}











Measured memory_bytes: 3704