PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000143. Xây dựng xâu đối xứng dài nhất (Longest Palindrome)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn pairwise distinct lowercase strings of equal length mm. 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 n,mn,m. Each of the next nn lines contains one distinct lowercase string of length mm.

Output

Print the maximum length LL on the first line and the corresponding palindrome on the second line. The second line may be empty when L=0L=0.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le8; 1≤m≤51\le m\le5; all strings are distinct, lowercase, and of length mm.
  • Subtask 2 (30 points): 1≤n≤351\le n\le35; 1≤m≤181\le m\le18; all strings are distinct, lowercase, and of length mm.
  • Subtask 3 (50 points): 1≤n≤1001\le n\le100; 1≤m≤501\le m\le50; all strings are distinct, lowercase, and of length mm.

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 66. The remaining word one cannot form another pair or a center, so the maximum length is 66.