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.
Input is given from Standard Input in the following format:
S
If we cannot turn S into a palindrome, print -1
. Otherwise, print the minimum required number of operations.
eel
1
We can turn S into a palindrome by the following operation:
ele
.ataatmma
4
We can turn S into a palindrome by the following operation:
ataamtma
.atamatma
.atmaatma
.amtaatma
.snuke
-1
We cannot turn S into a palindrome.
Subtask | Score |
---|---|
1 | 100 |
2 | 0 |