#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}

template <typename Base>
class BinaryIndexedTree
{
public:
    using T = typename Base::T;
    using AbelGroup = Base;

    BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); }
    BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity())
    {
        for (int i = 1; i <= data_num; i++) {
            value[i] = val[i - 1];
        }
        for (int x = 1; x < size; x++) {
            value[x + (x & -x)] = op(value[x + (x & -x)], value[x]);
        }
    }

    T accumulate(const int a) const
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        T sum = AbelGroup::identity();
        while (ind > 0) {
            sum = op(sum, value[ind]);
            ind &= ind - 1;
        }
        return sum;
    }
    T accumulate(const int l, const int r) const  // [l,r)
    {
        assert(0 <= l and l < r and r <= data_num);
        return op(accumulate(r - 1), op.inv(l == 0 ? AbelGroup::identity() : accumulate(l - 1)));
    }

    void add(const int a, const T& val)
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        while (ind <= size) {
            value[ind] = op(value[ind], val);
            ind += ind & (-ind);
        }
    }

    void set(const int a, const T& val)
    {
        const int v = get(a);
        add(a, op(val, op.inv(v)));
    }

    T get(const int a) const
    {
        assert(0 <= a and a < data_num);
        return accumulate(a, a + 1);
    }

    int lowerBound(T w) const
    {
        if (w <= AbelGroup::identity()) {
            return 0;
        }
        int x = 0;
        for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) {
            if (x + k <= size and value[x + k] < w) {
                w = op(w, op.inv(value[x + k]));
                x += k;
            }
        }
        return x;
    }

    int upperBound(T w) const
    {
        if (w <= AbelGroup::identity()) {
            return 0;
        }
        int x = 0;
        for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) {
            if (x + k <= size and value[x + k] <= w) {
                w = op(w, op.inv(value[x + k]));
                x += k;
            }
        }
        return min(x, data_num);
    }

private:
    const int data_num;
    const int size;
    const AbelGroup op{};
    vector<T> value;
};

template <typename T>
ostream& operator<<(ostream& os, const BinaryIndexedTree<T>& bit)
{
    os << "[";
    for (int i = 0; i < bit.data_num; i++) {
        os << bit.get(i) << ",";
    }
    os << "]" << endl;

    return os;
}
struct Sum {
    using T = ll;
    T operator()(const T& a, const T& b) const
    {
        return a + b;
    }
    T inv(const T& a) const
    {
        return -a;
    }
    static constexpr T identity()
    {
        return 0;
    }
};


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    const int N = s.size();

    vector<int> num(26, 0);
    for (const char c : s) {
        num[c - 'a']++;
    }
    int odd = -1;
    for (int i = 0; i < 26; i++) {
        if (num[i] % 2 == 1) {
            if (odd != -1) {
                cout << -1 << endl;
                return 0;
            }
            odd = i;
            num[i]--;
        }
    }
    string t;
    t.resize(N);
    if (odd != -1) {
        t[N / 2] = odd + 'a';
    }
    int pos = 0;
    for (int i = 0; i < N / 2; i++) {
        for (; pos < N; pos++) {
            if (num[s[pos] - 'a'] > 0) {
                t[i] = s[pos];
                t[N - i - 1] = s[pos];
                num[s[pos] - 'a'] -= 2;
                pos++;
                break;
            }
        }
    }
    vector<vector<int>> index(26);
    vector<int> head(26, 0);
    for (int i = 0; i < N; i++) {
        index[t[i] - 'a'].push_back(i);
    }
    vector<ll> v(N);
    for (int i = 0; i < N; i++) {
        v[i] = index[s[i] - 'a'][head[s[i] - 'a']];
        head[s[i] - 'a']++;
    }
    BinaryIndexedTree<Sum> bit(N);
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += i - bit.accumulate(v[i]);
        bit.add(v[i], 1);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5520