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 defaultdict, deque, Counter\nfrom heapq import heappush, heappop, heapify\nfrom itertools import permutations, accumulate, combinations, combinations_with_replacement\nfrom math import sqrt, ceil, floor, factorial\nfrom bisect import bisect_left, bisect_right, insort_left, insort_right\nfrom copy import deepcopy\nfrom operator import itemgetter\nfrom functools import reduce, lru_cache  # @lru_cache(None)\nfrom fractions import gcd\nimport sys\ndef input(): return sys.stdin.readline().rstrip()\ndef I(): return int(input())\ndef Is(): return (int(x) for x in input().split())\ndef LI(): return list(Is())\ndef TI(): return tuple(Is())\ndef IR(n): return [I() for _ in range(n)]\ndef LIR(n): return [LI() for _ in range(n)]\ndef TIR(n): return [TI() for _ in range(n)]\ndef S(): return input()\ndef Ss(): return input().split()\ndef LS(): return list(S())\ndef SR(n): return [S() for _ in range(n)]\ndef SsR(n): return [Ss() for _ in range(n)]\ndef LSR(n): return [LS() for _ in range(n)]\nsys.setrecursionlimit(10**6)\nMOD = 10**9+7\nINF = 10**18\n# ----------------------------------------------------------- #\n\nclass BinaryIndexedTree:\n    def __init__(self, n):\n        self.size = n\n        self.tree = [0] * (n + 1)\n\n    def sum(self, i):  # 1-index\n        s = 0\n        while i > 0:\n            s += self.tree[i]\n            i -= i & -i\n        return s\n\n    def add(self, i, x):  # 1-index\n        while i <= self.size:\n            self.tree[i] += x\n            i += i & -i\n\n    """\n    # 使用例\n    bit = BinaryIndexedTree(10)     # 要素数を与えてインスタンス化\n    bit.add(2, 10)    # a2に10を加える\n    bit.add(3, -6)    # a3に-6を加える\n    print(bit.sum(6)) # a1～a6の合計を返す\n    print(bit.sum(6) - bit.sum(3))  # a4～a6の合計を返す\n    """\n\ns = S()\nn = len(s)\ns_index = defaultdict(list)\nfor i, x in enumerate(s):\n    s_index[x].append(i)\n\nT = [0]*n  # sでi番目の文字は、最終的な回文でT[i]番目の文字となる\nflag = False  # 奇数個の文字が前にあったかフラグ(奇数個の文字が2つ以上あってはならない)\nAC = []  # 最終的な回文での前半Aと後半Cのペア\nfor x, index_list in s_index.items():\n    count = len(index_list)\n    if count % 2 == 1:\n        if flag:\n            print(-1)\n            return\n        else:\n            flag = True\n            mid = index_list[count//2]\n            T[mid] = n//2  # 回文の中心(B)\n    for i in range(count//2):\n        a = index_list[i]\n        c = index_list[-i-1]\n        AC.append((a, c))\n\nAC.sort(key=itemgetter(0))  # 前半(a)の順番でソート\nfor i, (a, c) in enumerate(AC):\n    T[a] = i  # a == i\n    T[c] = n - i - 1\n\nBIT = BinaryIndexedTree(n)\ninversion = 0\nfor i, t in enumerate(T):\n    i += 1  # 1-indexに変換\n    t += 1  # 1-indexに変換\n    BIT.add(t, 1)\n    inversion += i - BIT.sum(t)\nprint(inversion)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: