You are given a string S consisting of lowercase English letters.
Determine whether we can turn S into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations.

-----Constraints-----
 - 1 \leq |S| \leq 2 × 10^5
 - S consists of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
S

-----Output-----
If we cannot turn S into a palindrome, print -1. Otherwise, print the minimum required number of operations.

-----Sample Input-----
eel

-----Sample Output-----
1

We can turn S into a palindrome by the following operation:
 - Swap the 2-nd and 3-rd characters. S is now ele.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'from collections import Counter\n\n\nclass fenwick_tree(object):\n    def __init__(self, n):\n        self.n = n\n        self.data = [0] * n\n\n    def __sum(self, r):\n        s = 0\n        while r > 0:\n            s += self.data[r - 1]\n            r -= r & -r\n        return s\n\n    def add(self, p, x):\n        """ a[p] += xを行う"""\n        assert 0 <= p and p < self.n\n        p += 1\n        while p <= self.n:\n            self.data[p - 1] += x\n            p += p & -p\n\n    def sum(self, l, r):\n        """a[l] + a[l+1] + .. + a[r-1]を返す"""\n        assert 0 <= l and l <= r and r <= self.n\n        return self.__sum(r) - self.__sum(l)\n\n\ndef calc_inversion(arr):\n    N = len(arr)\n    bit = fenwick_tree(N)\n    atoi = {a: i for i, a in enumerate(arr)}\n    res = 0\n    for a in reversed(range(N)):\n        i = atoi[a]\n        res += bit.sum(0, i)\n        bit.add(i, 1)\n    return res\n\n\ndef calc_inv(arr):\n    N = len(set(arr))\n    atoi = {a: i for i, a in enumerate(sorted(set(arr)))}\n    bit = fenwick_tree(N)\n    res = 0\n    for i, a in enumerate(arr):\n        res += i - bit.sum(0, atoi[a] + 1)\n        bit.add(atoi[a], 1)\n    return res\n\n\ndef main():\n    S = input()\n    N = len(S)\n    C = Counter(S)\n\n    odd = 0\n    mid = ""\n    for k, v in C.items():\n        if v & 1:\n            odd += 1\n            mid = k\n\n    if N % 2 == 0:  # 偶数\n        if odd:\n            return -1\n        half = {k: v // 2 for k, v in C.items()}\n        cnt = {k: 0 for k in C.keys()}\n        label = []\n        left = []\n        right = []\n        for i, s in enumerate(S):\n            if cnt[s] < half[s]:\n                label.append(0)\n                left.append(s)\n            else:\n                label.append(1)\n                right.append(s)\n            cnt[s] += 1\n        ans = calc_inv(label)\n\n        pos = {k: [] for k in C.keys()}\n        for i, s in enumerate(left):\n            pos[s].append(i)\n        label = []\n        for s in right:\n            label.append(pos[s].pop())\n        ans += calc_inv(label[::-1])\n        return ans\n\n    else:  # 奇数\n        if odd != 1:\n            return -1\n        half = {k: v // 2 for k, v in C.items()}\n        cnt = {k: 0 for k in C.keys()}\n        label = []\n        right = []\n        left = []\n        seen = 0\n        LL = 0  # midの右にあるL\n        RR = 0  # midの左にあるR\n\n        for i, s in enumerate(S):\n            if s == mid and cnt[s] == half[s]:\n                seen = 1\n                cnt[s] += 1\n                continue\n            if cnt[s] < half[s]:\n                label.append(0)\n                left.append(s)\n                if seen:\n                    LL += 1\n            else:\n                label.append(1)\n                right.append(s)\n                if not seen:\n                    RR += 1\n            cnt[s] += 1\n        ans = calc_inv(label)\n        ans += RR + LL\n\n        pos = {k: [] for k in C.keys()}\n        for i, s in enumerate(left):\n            pos[s].append(i)\n        label = []\n        for s in right:\n            label.append(pos[s].pop())\n        ans += calc_inv(label[::-1])\n        return ans\n\n\nprint(main())'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 19219