#C3155. Longest Palindrome Formation

    ID: 46551 Type: Default 1000ms 256MiB

Longest Palindrome Formation

Longest Palindrome Formation

Alice is a puzzle enthusiast who adores brain teasers. She has n puzzle pieces, each represented by a string consisting of lowercase English letters. Alice's challenge is to choose at most two puzzle pieces such that when concatenated in either order the resulting string is a palindrome.

A string \(s\) is a palindrome if it reads the same forward and backward, i.e., \(s = s^R\). For each puzzle piece you may use its index (1-indexed). The output should be the maximum length of a palindrome that can be formed and the indices of the puzzle pieces used. If no palindrome can be formed, output 0 and an empty list of indices.

Note: When taking two pieces, you may concatenate them in either order (first+second or second+first), and you should consider the order that gives a palindrome.

inputFormat

The input is given via standard input (stdin). The first line contains an integer n representing the number of puzzle pieces. This is followed by n lines, each containing a non-empty string that represents a puzzle piece.

outputFormat

Output via standard output (stdout) consists of two lines. The first line should contain an integer representing the maximum length of a palindrome that can be formed. The second line should contain the 1-indexed indices of the puzzle pieces used, separated by a single space. If no valid palindrome exists, print 0 on the first line and leave the second line blank.

## sample
5
madam
racecar
hello
level
world
7

2

</p>