#GD0000143. Xây dựng xâu đối xứng dài nhất (Longest Palindrome)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xây dựng xâu đối xứng dài nhất (Longest Palindrome)
Longest Palindrome
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given pairwise distinct lowercase strings of equal length . You may discard any of them and reorder the remaining ones, then concatenate the selected strings.
Make the longest possible palindrome. A palindrome reads the same in both directions. If no nonempty palindrome can be created, the empty string is allowed.
Input
The first line contains . Each of the next lines contains one distinct lowercase string of length .
Output
Print the maximum length on the first line and the corresponding palindrome on the second line. The second line may be empty when .
Subtasks
- Subtask 1 (20 points): ; ; all strings are distinct, lowercase, and of length .
- Subtask 2 (30 points): ; ; all strings are distinct, lowercase, and of length .
- Subtask 3 (50 points): ; ; all strings are distinct, lowercase, and of length .
Examples
Input
3 3
tab
one
bat
Output
6
tabbat
Explanation
The words tab and bat are reverses and combine into the palindrome tabbat of length . The remaining word one cannot form another pair or a center, so the maximum length is .