아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Longest Palindrome

면접 대비

시간 제한1초메모리 제한256 MB

요약
길이가 같은 서로 다른 문자열 n개에서 일부를 버리고 순서를 바꿔 이어 붙일 때 만들 수 있는 가장 긴 팰린드롬을 출력한다.
난이도

보통10점 중 5점

유형
문자열, 해시맵, 그리디
정답자
아직 제출이 없습니다

문제

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 nn distinct strings of equal length mm. 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 nn and mm (1≤n≤1001 \le n \le 100, 1≤m≤501 \le m \le 50) — the number of strings and the length of each string.

Next nn lines contain a string of length mm 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.

예제4

  1. 예제 1

    입력
    3 3
    tab
    one
    bat
    
    예상 출력
    6
    tabbat
    
  2. 예제 2

    입력
    4 2
    oo
    ox
    xo
    xx
    
    예상 출력
    6
    oxxxxo
    
  3. 예제 3

    입력
    3 5
    hello
    codef
    orces
    
    예상 출력
    0
    
  4. 예제 4

    입력
    9 4
    abab
    baba
    abcd
    bcde
    cdef
    defg
    wxyz
    zyxw
    ijji
    
    예상 출력
    20
    ababwxyzijjizyxwbaba