Longest Palindrome
면접 대비시간 제한1초메모리 제한256 MB
길이가 같은 서로 다른 문자열 n개에서 일부를 버리고 순서를 바꿔 이어 붙일 때 만들 수 있는 가장 긴 팰린드롬을 출력한다.
문제
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 distinct strings of equal length . 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.
입력
The first line contains two integers and (, ) — the number of strings and the length of each string.
Next lines contain a string of length each, consisting of lowercase Latin letters only. All strings are distinct.
출력
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.
힌트
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.