#arc088c. [arc088_c]Papple Sort

[arc088_c]Papple Sort

Problem Statement

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

Constraints

  • 1leqSleq2×1051 \\leq |S| \\leq 2 × 10^5
  • SS consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

SS

Output

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


Sample Input 1

eel

Sample Output 1

1

We can turn SS into a palindrome by the following operation:

  • Swap the 22-nd and 33-rd characters. SS is now ele.

Sample Input 2

ataatmma

Sample Output 2

4

We can turn SS into a palindrome by the following operation:

  • Swap the 55-th and 66-th characters. SS is now ataamtma.
  • Swap the 44-th and 55-th characters. SS is now atamatma.
  • Swap the 33-rd and 44-th characters. SS is now atmaatma.
  • Swap the 22-nd and 33-rd characters. SS is now amtaatma.

Sample Input 3

snuke

Sample Output 3

-1

We cannot turn SS into a palindrome.