import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	char[] s = readln.chomp.to!(char[]);
	int n = s.length.to!int;
	
	int[][char] cxs;
	foreach(int i, c; s){
		if(c !in cxs) cxs[c] = [];
		cxs[c] ~= i;
	}
	log("cxs:", cxs);
	
	S[] qs;
	char[] cs = cxs.keys;
	bool f = 0;
	int i0;
	foreach(c; cs){
		int[] xs = cxs[c];
		if(xs.length % 2){
			if(f == 0){
				f = 1;
				i0 = xs[$ / 2];
			}
			else{
				"-1".writeln;
				return;
			}
		}
		for(long i = 0; i < xs.length - 1 - i; i ++){
			qs ~= S(xs[i], xs[$ - 1 - i]);
		}
	}
	log("qs:", qs);
	
	auto seg = new SegTree!long(0, n, (long x, long y) => x + y, 0);
	seg.setValue(0, i0, 1);
	foreach(q; qs){
		seg.setValue(0, q.a, 1);
		seg.setValue(0, q.b, 1);
	}
	log("seg:", seg);
	
	long ans;
	qs.sort!"a.a<b.a"();
	foreach(q; qs){
		ans += seg.getValue(q.b);
		seg.setValue(0, q.b, -1);
		log("q:", q, "ans:", ans, "seg:", seg);
	}
	
	ans.writeln;
	
}
struct S{
	int a, b;
}

class SegTree(T){
	T delegate(T, T) apply;
	T neutral;
	int a, b; // a <= x < b を担当する
	bool isTerminal;
	SegTree left, right; // 左の子(a <= x < c)、右の子(c <= x < b)
	T value;
	this(int a, int b, T delegate(T, T) apply, T neutral = T.init){
		this.a = a, this.b = b;
		this.apply = apply;
		this.neutral = neutral;
		this.value = neutral;
		if(b - a == 1){
			this.isTerminal = 1;
		}
		else{
			int c = (a + b) / 2;
			this.left = new SegTree(a, c, apply, neutral);
			this.right = new SegTree(c, b, apply, neutral);
		}
	}
	
	// [a, b) に値を設定する ※[a, b) はこのノードの担当区間とかぶっていなくてもよい
	void setValue(int a, int b, T value){
		if(b <= this.a || this.b <= a) return;
		if(a <= this.a && this.b <= b){
			this.value = apply(this.value, value);
		}
		else{
			divideValue();
			left.setValue(a, b, value);
			right.setValue(a, b, value);
		}
	}
	
	// 自分の持っていた値を子に引き継ぐ
	void divideValue(){
		left.value = apply(left.value, this.value);
		right.value = apply(right.value, this.value);
		this.value = neutral;
	}
	
	// iにおける値 ※iは必ずこのノードの担当区間内である前提
	T getValue(int i){
		assert(a <= i && i < b);
		if(this.isTerminal) return this.value;
		else divideValue();
		if(i < left.b) return left.getValue(i);
		else return right.getValue(i);
	}
	
	// 配列に変換したもの（デバッグ用）
	T[] array(){
		T[] res;
		foreach(i; a .. b) res ~= this.value;
		return res;
	}
	
	// 文字列に変換したもの（デバッグ用）
	override string toString(){
		if(this.isTerminal) return this.array.to!string;
		else	return this.array.to!string ~ "\n" ~ left.toString ~ right.toString ~ "\n";
	}
}
