Codeforces Round 620 (Div. 2)
B
Longest Palindrome
Codeforces
1100
原题
← AC →
翻译中…

Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.

翻译中…

Gildong loves this concept so much, so he wants to play with it. He has $n$ distinct strings of equal length $m$. He wants to discard some of the strings (possibly none or all) and reorder the remaining strings so that the concatenation becomes a palindrome. He also wants the palindrome to be as long as possible. Please help him find one.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 50$) — the number of strings and the length of each string.

翻译中…

Next $n$ lines contain a string of length $m$ each, consisting of lowercase Latin letters only. All strings are distinct.

翻译中…

Output

翻译中…

In the first line, print the length of the longest palindrome string you made.

翻译中…

In the second line, print that palindrome. If there are multiple answers, print any one of them. If the palindrome is empty, print an empty line or don't print this line at all.

翻译中…

Note

翻译中…

In the first example, "battab" is also a valid answer.

翻译中…

In the second example, there can be 4 different valid answers including the sample output. We are not going to provide any hints for what the others are.

翻译中…

In the third example, the empty string is the only valid palindrome string.

翻译中…

样例

Input #1
3 3
tab
one
bat
Output #1
6
tabbat
InputCopy OutputCopy
Input #2
4 2
oo
ox
xo
xx
Output #2
6
oxxxxo
InputCopy OutputCopy
Input #3
3 5
hello
codef
orces
Output #3
0
InputCopy OutputCopy
Input #4
9 4
abab
baba
abcd
bcde
cdef
defg
wxyz
zyxw
ijji
Output #4
20
ababwxyzijjizyxwbaba
InputCopy OutputCopy
题目信息
题号
1304B
时间限制
1 s
内存限制
256 MB
标签
暴力
构造
贪心
模拟
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。