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.


-----Examples-----
Input
3 3
tab
one
bat

Output
6
tabbat

Input
4 2
oo
ox
xo
xx

Output
6
oxxxxo

Input
3 5
hello
codef
orces

Output
0


Input
9 4
abab
baba
abcd
bcde
cdef
defg
wxyz
zyxw
ijji

Output
20
ababwxyzijjizyxwbaba



-----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.

Difficulty: interview

Starter code:

Solutions:
n, m = map(int, input().split())

p = ''
q = []

arr = [input() for __ in range(n)]
s = set(arr)
for z in arr:
    if z == z[::-1]:
        p = z
    else:
        if z not in s: continue
        if z[::-1] in s:
            s.remove(z)
            s.remove(z[::-1])
            q += z,

res = ''.join(q)
res = res + p + res[::-1]
print(len(res))
print(res)

n,m = [int(i) for i in input().split()]
s = [input() for i in range(n)]
ans = ""
i = 0
mid = ""
while i < len(s):
    l = s.pop()
    if l[::-1] == l:
        if len(mid) < len(l):
            mid = l
    elif l[::-1] in s:
        s.remove(l[::-1])
        ans += l

print(len(ans)*2+len(mid))
print(ans+mid+ans[::-1])

from collections import defaultdict
n,m=list(map(int,input().split()))
dict=defaultdict(int)
larr=''
rarr=''
mxeq=''
mxln=0
for _ in range(n):
    s=input()
    if dict[s[::-1]]==1:
        rarr+=s
        larr=s[::-1]+larr
        del dict[s[::-1]]
    elif s==s[::-1]:
        if len(s)>mxln:
            mxln=len(s)
            mxeq=s
    else:
        dict[s]=1

farr=larr+mxeq+rarr
print(len(farr))
print(farr)




n, m = list(map(int, input().split()))
ar = []
for _ in range(n):
    ar.append(input())
ans1 = ''
ans2 = ''
kek = set()
for i in range(n):
    for j in range(i + 1, n):
        if ar[i] == ar[j][::-1]:
            ans1 += ar[i]
            ans2 = ar[j] + ans2
            kek.add(ar[i])
for i in range(n):
    if ar[i] == ar[i][::-1] and ar[i] not in kek:
        ans1 += ar[i]
        break
print(len(ans1) + len(ans2))
print(ans1 + ans2)

n, m = list(map(int, input().split()))
s = []
for i in range(n):
	s.append(input())

A, B = '', ''
M = ''
d = {}

for i in range(n):
	for j in range(i+1, n):
		if s[i][::-1] == s[j] and i not in d and j not in d:
			A = A + s[i]
			B = s[j] + B
			
			d[i] = True
			d[j] = True

for i in range(n):
	if s[i][::-1] == s[i] and i not in d:
		M = s[i]

print(len(A) + len(M) + len(B))
print(A + M + B)


from math import *

n,m = map(int,input().split())
a = []
for y in range(n):
	a.append(input())
x = [0 for i in range(n)]
t = ""
for i in range(n):
	for j in range(i+1,n):
		if(x[j] == 1 or x[i] == 1): continue
		if(a[i] == a[j][::-1]):
			t = a[i] + t + a[j]
			#print(t)
			x[i] = 1
			x[j] = 1
#print(t)
for i in range(n):
	if(x[i] == 1): continue
	if(a[i] == a[i][::-1]):
		t = t[:len(t)//2]+a[i]+t[len(t)//2:]
		break
print(len(t))
print(t)

from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
 
M = mod = 10**9 + 7
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
 
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]


n,m = li()
l = []
for i in range(n):l.append(st())
l.sort()
cnt = Counter()
for i in l:
    cnt[i] += 1
toadd = []
d1 = ''
for i in cnt:
    if cnt[i]:
        if i == i[::-1]:
            toadd.append(i*(cnt[i]//2))
            cnt[i] -= 2*(cnt[i]//2)
            if cnt[i] and len(i)>len(d1):
                d1 = i
                cnt[i] -= 1
        elif cnt[i[::-1]]:
            toadd.append(i)
            cnt[i]-=1
            cnt[i[::-1]]-=1
        elif i == i[::-1] and len(i)>len(d1):
            d1 = i
            cnt[i] -= 1
s = ''
for i in toadd:
    s += i
s = s + d1 + s[::-1]
print(len(s))
print(s)


num, n = map(int, input().split())

a = []
b = []
center = ""

for i in range(num):
    s = input()
    if s[::-1] == s:
        center = s
    if s[::-1] in a:
        b.append(s)
    else:
        a.append(s)

ans = ""

for x in b:
    ans += x

ans = ans + center + ans[::-1]

print(len(ans))
print(ans)

n,m = map(int,input().split())

pair = []
own = []
mentu = []
for _ in range(n):
    s = list(input())
    if s == s[::-1]:
        own.append(s)
    else:
        if s[::-1] in mentu:
            pair.append(s)
        else:
            mentu.append(s)
k = 1 if own else 0
print(k * m + len(pair) * 2 * m)
ans = ""
for s in pair:
    ans += "".join(s)
if own:
    for s in own[0]:
        ans += "".join(s)
for s in pair[::-1]:
    ans += "".join(s[::-1])
print(ans)

def solve(N, M, A):
    strs = set(A)
    used = set()
    forward = []
    mid = []

    for x in strs:
        rev = x[::-1]
        if x == rev:
            mid.append(x)
        elif rev in strs and x not in used:
            forward.append(x)
            used.add(x)
            used.add(rev)

    front = "".join(forward)
    back = front[::-1]
    if mid:
        ret = front + next(iter(mid)) + back
    else:
        ret = front + back
    return str(len(ret)) + "\n" + ret


def __starting_point():

    N, M = list(map(int, input().split()))
    A = []
    for i in range(N):
        S = input()
        assert len(S) == M
        A.append(S)
    ans = solve(N, M, A)
    print(ans)

__starting_point()

n,m = list(map(int,input().split()))

s = [input() for i in range(n)]

d = {}
for i in s:
	try:
		d[i] += 1
	except:
		d[i] = 1


revis = []
pal = ""

for i in d:
	revi = i[::-1]
	# print(revi,i)

	if revi == i:
		if d[i]&1:
			if len(i) > len(pal):
				pal = i
		else:
			x = d[i]//2
			for j in range(x):
				revis.append(i)
	else:
		if revi in d:
			x = min(d[i], d[revi])
			d[i] -= x
			d[revi] -= x
			for j in range(x):
				revis.append(i)

ss = ""
for i in revis:
	ss += i
ss = ss + pal + ss[::-1]

print(len(ss))
print(ss)


n, m = map(int, input().split())
K = list(set(input() for _ in range(n)))
n = len(K)

def is_pal(S):
    nonlocal m
    ret = True
    for i in range(m//2+1):
        if S[i] != S[-i-1]:
            ret = False
    return ret

ans = ""

for k in K:
    if is_pal(k):
        ans = k
        break

for i in range(n - 1):
    for j in range(i + 1, n):
        if K[i] == K[j][::-1]:
            ans = K[i] + ans + K[j]
            break

print(len(ans))
print(ans)

def palindrome(s):
    for i in range(len(s)//2):
        if s[i] != s[len(s)-1-i]:
            return False

    return True

def main():
    n,m = list(map(int,input().split()))
    strings = []
    for i in range(n):
        strings.append(input())
        
    pairs = []
    alone = []
    for i in range(n):
        found = False
        s1 = strings[i]
        for j in range(i+1,n):
            s2 = strings[j][::-1]
            #print(s1,s2)
            if s1 == s2:
                found = True
                pairs.append((s1,strings[j]))
                break
            
        if not found:
            if palindrome(s1):
                alone.append(s1)

    #print(pairs)
    s = ''
    for i in pairs:
        s += i[0]

    while len(alone) > 1:
        alone.pop()
        
    for i in alone:
        s += i

    pairs.reverse()
    for i in pairs:
        s += i[1]

    print(len(s))
    print(s)

main()


def main():
    import sys
    input = sys.stdin.readline

    N, M = list(map(int, input().split()))
    has_rev = {}
    pal = []
    for _ in range(N):
        s = input().rstrip('\n')
        s_rev = s[::-1]
        if s == s_rev:
            pal.append(s)
        else:
            if s_rev in has_rev:
                has_rev[s_rev] = 1
            else:
                has_rev[s] = 0
    ans = []
    for s in has_rev:
        if has_rev[s]:
            ans.append(s)
    if ans:
        ans = ''.join(ans)
        ans_rev = ans[::-1]
    else:
        ans = ''
        ans_rev = ''
    if pal:
        ans = ans + pal[0] + ans_rev
        print(len(ans))
        print(ans)
    else:
        ans = ans + ans_rev
        print(len(ans))
        print(ans)






def __starting_point():
    main()

__starting_point()

n,m=map(int,input().split())
ls=set()
final=""
for i in range(n):
    s=input()
    if(s[::-1] in ls):
        ls.remove(s[::-1])
        final=s+final+s[::-1]
    else:
        ls.add(s)
for s in ls:
    flag=True
    for i in range(m//2):
        if(s[i]!=s[m-i-1]):
            flag=False
    if(flag):
        final=final[0:len(final)//2]+s+final[len(final)//2:]
        break
print(len(final))    
print(final)        

n,m = map(int,input().split())
data = [input() for _ in range(n)]
data_rev = [x[::-1] for x in data]

now = ""
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if data[i] == data_rev[j]:
            now = data[i] + now + data[j]

ans = len(now)
for i in range(n):
    if data[i] == data_rev[i]:
        now2 = data[i]
        for j in range(n):
            if j == i:continue
            for k in range(j+1,n):
                if k == i:continue
                if data[j] == data_rev[k]:
                    now2 = data[j] + now2 + data[k]
        if ans < len(now2):
            now = now2
            ans = len(now2)

print(ans)
print(now)

import sys
input = sys.stdin.readline
from collections import Counter

N, M = map(int, input().split())
Ss = [input().rstrip() for _ in range(N)]

C = Counter(Ss)

ans1 = ""
only_used = ""
for S in Ss:
    Is = S[::-1]
    if S != Is:
        if Is in C and C[Is] > 0:
            C[Is] -= 1
            C[S] -= 1
            ans1 += S
    else:
        if S in C and C[Is] > 1:
            C[S] -= 2
            ans1 += S
        elif S in C and C[Is] == 1:
            C[S] = 0
            only_used = S

ans = ans1 + only_used + ans1[::-1]
print(len(ans))
print(ans)

n, m = list(map(int, input().split()))
k = set()
s = ""
ans = ""
for i in range(n):
    new_s = input()
    if new_s[::-1] in k:
        ans += new_s
    elif new_s == new_s[::-1]:
        s = new_s
    k.add(new_s)
print(2 * len(ans) + len(s))
print(ans + s + ans[::-1])


n, m = list(map(int, input().split()))
strings = []
pal = []
pairs = []

for i in range(n):
    s = input()
    r = s[::-1]
    if s == r:
        pal.append(s)
    else:
        if r in strings:
            pairs.insert(0, s)
            pairs.append(r)
            strings.remove(r)
        else:
            strings.append(s)
l = len(pairs)
ans = ''
for i in range(l // 2):
    ans += pairs[i]
if pal:
    ans += max(pal, key=lambda a: len(a))
for i in range(l // 2):
    ans += pairs[l // 2 + i]
print(len(ans))
print(ans)