#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();

    let mut poses = vec![VecDeque::new(); 26];
    for i in 0..s.len() {
        poses[s[i].to_digit(36).unwrap() as usize - 10].push_back(i);
    }
    let mut odd_idx = 26;
    for ci in 0..26 {
        if poses[ci].len() % 2 == 1 {
            if odd_idx != 26 {
                println!("{}", -1);
                return;
            }
            odd_idx = ci;
        }
    }

    let mut ans = 0i64;
    let mut seg = SegTree::new(s.len(), 0usize, |x, y| x + y);

    for i in 0..s.len() / 2 {
        let mut min_cost = std::usize::MAX;
        let mut min_ci = 26;
        for ci in 0..26 {
            if poses[ci].len() <= 1 {
                continue;
            }
            let cost1 = poses[ci][0] - seg.query(0, poses[ci][0]);
            let cost2 = s.len()
                - 1
                - poses[ci][poses[ci].len() - 1]
                - seg.query(poses[ci][poses[ci].len() - 1], s.len());
            let cost = cost1 + cost2;
            if cost < min_cost {
                min_cost = cost;
                min_ci = ci;
            }
        }
        if min_ci == 26 {
            break;
        }
        ans += min_cost as i64;
        let idx = poses[min_ci].pop_front().unwrap();
        seg.update(idx, 1);
        let idx = poses[min_ci].pop_back().unwrap();
        seg.update(idx, 1);
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

struct SegTree<T, F>
where
    F: Fn(T, T) -> T,
    T: std::clone::Clone + std::marker::Copy,
{
    n: usize,
    dat: Vec<T>,
    init: T,
    functor: F,
}

impl<T, F> SegTree<T, F>
where
    F: Fn(T, T) -> T,
    T: std::clone::Clone + std::marker::Copy,
{
    fn new(n: usize, init: T, f: F) -> SegTree<T, F> {
        let mut m = 1;
        // For simplicity, we use 2 ** n sized SegTree.
        while m < n {
            m *= 2;
        }
        SegTree {
            n: m,
            dat: vec![init; 2 * m - 1],
            init: init,
            functor: f,
        }
    }

    // dat[k] = a;
    fn update(&mut self, k: usize, a: T) {
        let mut k = k;
        k += self.n - 1;
        self.dat[k] = a;
        while k > 0 {
            k = (k - 1) / 2;
            self.dat[k] = (self.functor)(self.dat[k * 2 + 1], self.dat[k * 2 + 2]);
        }
    }

    fn query(&self, a: usize, b: usize) -> T {
        self.query_inner(a, b, 0, 0, self.n)
    }

    fn query_inner(&self, a: usize, b: usize, k: usize, l: usize, r: usize) -> T {
        if r <= a || b <= l {
            return self.init;
        }
        if a <= l && r <= b {
            return self.dat[k];
        }

        let vl = self.query_inner(a, b, k * 2 + 1, l, (l + r) / 2);
        let vr = self.query_inner(a, b, k * 2 + 2, (l + r) / 2, r);
        (self.functor)(vl, vr)
    }
}


Measured memory_bytes: 14100