import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    string s;
    s = readln.chomp;

    auto cnt = new int[](26);

    foreach (ch ; s) {
        cnt[ch - 'a']++;
    }

    int odd;

    foreach (i ; 0 .. 26) {
        if (cnt[i] & 1) odd++;
    }

    if (odd > 1) {
        writeln(-1);
        return;
    }

    auto c = new int[](26);
    auto d = new int[][](26, 0);
    auto b = new int[](s.length);
    int mae = 0;

    foreach (i, ch ; s) {
        int j = ch - 'a';

        if ((cnt[j] & 1) && c[j] == cnt[j] / 2) {
            b[i] = s.length.to!int /2;
            d[j] ~= b[i];
            c[j]++;
            continue;
        }

        if (c[j] < cnt[j] / 2) {
            b[i] = mae++;
            d[j] ~= b[i];
        }
        else {
            b[i] = s.length.to!int - 1 - d[j][cnt[j] - 1 - c[j]];
        }

        c[j]++;
    }

    debug {
        writeln(b);
    }

    auto ft = FenwickTree!(int)(s.length.to!int);
    long ans;

    foreach_reverse (bi ; b) {
        ft.add(bi, 1);
        ans += ft.sum(bi);
    }

    writeln(ans);
}

struct FenwickTree(T) {
    private {
        int _size;
        T[] _data;
    }

    this(int N) {
        _size = N;
        _data = new T[](_size + 1);
    }

    void add(int i, T x) {
        i++;
        while (i <= _size) {
            _data[i] += x;
            i += i & (-i);
        }
    }

    T sum(int r) {
        T res = 0;
        while (r > 0) {
            res += _data[r];
            r -= r & (-r);
        }
        return res;
    }
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
