#R088C. [ARC088E] Papple Sort
[ARC088E] Papple Sort
Score : points
Problem Statement
You are given a string consisting of lowercase English letters. Determine whether we can turn into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations.
Constraints
- consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
If we cannot turn into a palindrome, print -1. Otherwise, print the minimum required number of operations.
eel
1
We can turn into a palindrome by the following operation:
- Swap the -nd and -rd characters. is now
ele.
ataatmma
4
We can turn into a palindrome by the following operation:
- Swap the -th and -th characters. is now
ataamtma. - Swap the -th and -th characters. is now
atamatma. - Swap the -rd and -th characters. is now
atmaatma. - Swap the -nd and -rd characters. is now
amtaatma.
snuke
-1
We cannot turn into a palindrome.