Terrifying Palindrome
InterviewTime limit1.5sMemory limit1024 MB
Order n equal-length strings so their concatenation is a palindrome, or report -1 if no such order exists.
Statement
The children spent the whole evening going door to door and scaring passersby. At some point they got bored and went to scare Mr. X.
Everyone knows Mr. X is terribly afraid of palindromes. So the children decided to find the largest palindrome they could and show it to him. Unfortunately, by night their imagination was nearly gone. All they could do was copy the words from the banners around them and assemble a palindrome from those.
There are banners on the street, and every banner has text of the same length . The children think a palindrome is not scary enough unless it uses at least one banner text, so they want to build a palindrome by concatenating all banner texts, each exactly once, in some order.
Help the children build a scary palindrome, or report that no palindrome can be formed from these pieces, so that Mr. X can enjoy the rest of the evening in peace.
Input
The first line contains two integers and separated by a space ().
Each of the next lines contains the text of one banner. Every text has length exactly and consists only of lowercase Latin letters.
It is guaranteed that .
Output
If a scary palindrome can be built, print numbers separated by spaces. These are the banner numbers in the order they must be concatenated to form a palindrome. Each number from to must appear exactly once in the output.
If no palindrome can be built, print the single integer .