import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
    return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
    return readInts()[0];
}
auto readLongs() {
    return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
    return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

//内部では1-based, 使うときは0-based
class BinaryIndexedTree(T, alias F = "a + b") if(is(typeof(binaryFun!F))) {
    alias f = binaryFun!F;
public:
    this(in size_t n, in T T0 = T.init) {
        t.length = n+1;
        t[] = T0;
    }

    void add(in size_t idx, in T v)
    in {
        assert(idx < t.length-1);
    }
    body {
        one_based_add(idx+1, v);
    }

    T accumulate(size_t idx) {
        return one_based_accumulate(idx+1);
    }

private:
    T[] t;

    //1-based
    void one_based_add(size_t idx, in ref T v) {
        if(idx >= t.length) {
            return;
        }
        t[idx] = f(t[idx], v);
        one_based_add(idx + (idx & (-idx)), v);
    }
    T one_based_accumulate(size_t idx) {
        if(idx == 0) {
            return t[0];
        } else {
            return f(one_based_accumulate(idx - (idx & (-idx))), t[idx]);
        }
    }
}

unittest {
    auto bit = new BinaryIndexedTree!(long)(10);
    foreach(i; iota(10)) {
        assert(bit.accumulate(i) == 0);
    }
    bit.add(5, 3);
    foreach(i; iota(5)) {
        assert(bit.accumulate(i) == 0);
    }
    foreach(i; iota(5, 10)) {
        assert(bit.accumulate(i) == 3);
    }

    bit.add(7, 2);

    foreach(i; iota(5)) {
        assert(bit.accumulate(i) == 0);
    }
    foreach(i; iota(5, 7)) {
        assert(bit.accumulate(i) == 3);
    }
    foreach(i; iota(7, 10)) {
        assert(bit.accumulate(i) == 5);
    }
}
unittest {
    auto bit = new BinaryIndexedTree!(long, "a*b")(10, 1);
    foreach(i; iota(10)) {
        assert(bit.accumulate(i) == 1);
    }
    bit.add(5, 3);
    foreach(i; iota(5)) {
        assert(bit.accumulate(i) == 1);
    }
    foreach(i; iota(5, 10)) {
        assert(bit.accumulate(i) == 3);
    }

    bit.add(7, 2);

    foreach(i; iota(5)) {
        assert(bit.accumulate(i) == 1);
    }
    foreach(i; iota(5, 7)) {
        assert(bit.accumulate(i) == 3);
    }
    foreach(i; iota(7, 10)) {
        assert(bit.accumulate(i) == 6);
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto s = readln().chomp();
    auto c = new long[](26);
    foreach(si; s) {
        ++c[si - 'a'];
    }
    if(c.count!("a % 2 == 1")() > 1) {
        writeln(-1);
        return;
    }

    auto d = new long[](26);
    auto t = new char[](s.length);
    if(s.length % 2 == 1) {
        foreach(i; iota(26)) {
            if(c[i] % 2 == 1) {
                t[s.length / 2] = (i + 'a').to!char;
                --c[i];
                break;
            }
        }
    }
    long idx;
    foreach(i; iota(s.length)) {
        if(d[s[i] - 'a'] < c[s[i] - 'a'] / 2) {
            t[idx] = s[i];
            t[s.length - 1 - idx] = s[i];
            ++idx;
        }
        ++d[s[i] - 'a'];
    }
    long[][char] m;
    foreach(i; iota(t.length)) {
        m[t[i]] ~= i;
    }
    long[] u;
    foreach(si; s) {
        u ~= m[si][0];
        m[si] = m[si][1..$];
    }

    auto bit = new BinaryIndexedTree!long(u.length);
    long ans;
    foreach(i; iota(u.length)) {
        ans += i - bit.accumulate(u[i]);
        bit.add(u[i], 1);
    }
    writeln(ans);
}



Measured memory_bytes: 10168