#K56297. Minimal Adjacent Swaps to Make Palindrome

    ID: 30167 Type: Default 1000ms 256MiB

Minimal Adjacent Swaps to Make Palindrome

Minimal Adjacent Swaps to Make Palindrome

Given a string s, determine the minimal number of adjacent swaps needed to transform s into a palindrome. If it is impossible to make the string a palindrome using any number of adjacent swaps, output -1.

Note: Two characters are considered adjacent if they are consecutive in the string. The swaps are only allowed between adjacent characters.

The solution should read the input from stdin and write the result to stdout.

It is guaranteed that the input consists of a single non-empty string of lowercase English letters.

Example:

Input:  aabb
Output: 2

inputFormat

The input consists of a single line containing the string s.

outputFormat

Output a single integer indicating the minimal number of adjacent swaps required to convert the string into a palindrome. If it is impossible, output -1.

## sample
aabb
2

</p>