#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class BinaryIndexedTree
{
private:
    int n;
    vector<int> data;
public:
    BinaryIndexedTree(int n){ // ?????????????????????
        this->n = n;
        data.assign(n+1, 0);
    }
    void add(int k, int x){ // k?????????????´????x???????????????
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    int sum(int k){ // ??????[0,k]??????????????????
        ++ k;
        int ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    int sum(int a, int b){ // ??????[a,b]??????????????????
        return sum(b) - sum(a-1);
    }
};

int main()
{
    string s;
    cin >> s;
    int n = s.size();

    vector<vector<int> > index(128);
    for(int i=0; i<n; ++i)
        index[s[i]].push_back(i);

    vector<int> a(128);
    for(char c='a'; c<='z'; ++c){
        if(index[c].size() % 2 != 0){
            cout << -1 << endl;
            return 0;
        }
        a[c] = index[c].size() - 1;
    }

    BinaryIndexedTree bit(n);
    for(int i=0; i<n; ++i)
        bit.add(i, 1);

    long long ans = 0;
    for(int i=0; i<n; ++i){
        if(index[s[i]][a[s[i]]] < i)
            continue;
        ans += bit.sum(index[s[i]][a[s[i]]] + 1, n - 1);
        bit.add(index[s[i]][a[s[i]]], -1);
        -- a[s[i]];
    }
    cout << ans << endl;

    return 0;
}