/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.16 19:31:28
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


template < class Monoid >
struct SegmentTree {
private:
    using Func = std::function< Monoid(Monoid, Monoid) >;
    Func F;
    Monoid UNITY;
    int n;
    std::vector< Monoid > node;
public:
    SegmentTree() {}
    
    SegmentTree(int m, const Monoid &val, const Func f, const Monoid &unity) {
        F = f;
        UNITY = unity;
        n = 1;
        while (n < m) n <<= 1;
        node.resize(n * 2 - 1, UNITY);
        if (val != UNITY) {
            for (int i = 0; i < m; i++) node[i] = val;
            build();
        }
    }
    SegmentTree(const std::vector< Monoid > &v, const Func f, const Monoid &unity) {
        F = f;
        UNITY = unity;
        int sz = v.size();
        n = 1;
        while (n < sz) n <<= 1;
        node.resize(n * 2 - 1, UNITY);
        for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        build();
    }
    
    void set(int k, const Monoid &x) {
        node[n + k - 1] = x;
    }
    void build() {
        for (int i = n - 2; i >= 0; i--) node[i] = F(node[2 * i + 1], node[2 * i + 2]);
    }
    void update_query(int x, const Monoid &val) {
        if (x >= n || x < 0) return;
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) >> 1;
            node[x] = F(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    /*
    
    Monoid query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return UNITY;
        if (a <= l && r <= b) return node[k];
        Monoid vl = query(a, b, 2 * k + 1, l, (r - l) / 2 + l);
        Monoid vr = query(a, b, 2 * k + 2, (r - l) / 2 + l, r);
        return F(vl, vr);
    }
    */
    
    Monoid get_query(int a, int b) {
        Monoid L = UNITY, R = UNITY;
        if (a < 0) a = 0;
        if (b < 0) return UNITY;
        if (a >= n) return UNITY;
        if (b >= n) b = n;
        for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = F(L, node[a++ - 1]);
            if (b & 1) R = F(node[--b - 1], R);
        }
        return F(L, R);
    }
    Monoid operator[](int x) const {
        return node[n + x - 1];
    }
    int size() {
        return n;
    }
    void print() {
        for (int i = 0; i < n; i++) {
            std::cout << i << "\t: " << node[n + i - 1] << std::endl;
        }
    }
};
int main() {
    string s;cin >> s;
    vector<vector<int>> cnt(26);
    for (int i = 0; i < s.size(); i++) {
        cnt[s[i]-'a'].push_back(i);
    }
    int odd_num = -1;
    for (int i = 0; i < 26; i++) {
        if (odd_num != -1 && cnt[i].size() % 2 == 1) {
            puts("-1");
            return 0;
        }
        else if (cnt[i].size() % 2 == 1) {
            odd_num = i;
        }
    }
    vector<int> v(s.size(),-1);
    vector<int> ans(s.size(),-1);
    for (int i = 0; i < 26; i++) {
        for(int j = 0; j < cnt[i].size(); j++) {
            if (v[cnt[i][j]] != -1) break;
            
            if (cnt[i][j] == cnt[i][cnt[i].size()-j-1]) {
                ans[cnt[i][j]] = s.size() / 2;
                continue;
            }
            v[cnt[i][j]] = cnt[i][cnt[i].size()-j-1];
            v[cnt[i][cnt[i].size()-j-1]] = cnt[i][j];
        }
    }
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
        if (ans[i] != -1) continue;
        ans[i] = now;
        ans[v[i]] = s.size() - now - 1;
        now++;
    }
    ll out = 0;
    SegmentTree<int> seg(s.size(),0,[](int a,int b){return a+b;},0);
    for (int i = 0; i < s.size(); i++) {
        out += seg.get_query(ans[i],s.size());
        seg.update_query(ans[i],1);
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 8128