#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long LL;

const int N = 200010;
int st[30][N], k[30], n;
int T[N];
bool vis[N];
char s[N];

inline void update(int k, int v){ for(; k; k -= k&-k) T[k] += v; }

inline int getsum(int k){ int ret = 0; for(; k <= n; k += k&-k) ret += T[k]; return ret; }

int main()
{
	scanf("%s", s+1); n = strlen(s+1);
	for(int i = 1; i <= n; i ++) st[s[i]-'a'][++ k[s[i]-'a']] = i;
	int cnt = 0;
	for(int i = 0; i < 26; i ++) cnt += k[i]&1;
	if(cnt > 1) { puts("-1"); return 0; }
	for(int i = 1; i <= n; i ++) update(i, 1);
	int sum = 0;
	LL ans = 0;
	for(int i = 1; i <= n; i ++) if(!vis[i]) {
		int last = st[s[i]-'a'][k[s[i]-'a'] --];
		if(last == i) {
			sum ++; ans += (n-sum)/2;
			update(i, -1); vis[i] = 1;
		} else {
			sum += 2; ans += getsum(last+1);
			update(i, -1); update(last, -1);
			vis[i] = 1; vis[last] = 1;
		}
		if(sum == n) break;
	}
	printf("%lld\n", ans);
	return 0;
}