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: EASY
Tags: Constructive algorithms

String algorithms

Implementation

Greedy algorithms

Complete search
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
import sys
import math

def input():
	return sys.stdin.readline().strip()

def iinput():
	return [int(x) for x in sys.stdin.readline().split()]

def main():
	(n, m) = iinput()
	s = dict()
	z = []
	for i in range(n):
		a = input()
		b = a[::-1]
		if a not in s and b not in s:
			s[a] = 1
		elif a in s:
			s[a] += 1
		elif b in s:
			s[b] += 1
		if b == a:
			z += [a]
	count = 0
	data = list(s.keys())
	ans = ''
	for i in data:
		c = s[i] // 2
		ans += i * c
		count += c * 2
		s[i] %= 2
	if count == 0 and len(z) == 0:
		print(0)
	else:
		ans1 = ans[::-1]
		for i in range(len(z)):
			if s[z[i]] >= 1:
				ans += z[i]
				count += 1
				break
		print(m * count, ans + ans1, sep='\n')
	return
for ______ in range(1):
	main()


(n, m) = map(int, input().split())
lst1 = []
left = ''
right = ''
middle = ''

def pal(s):
	valid = True
	for i in range(len(s) // 2):
		if s[i] != s[~i]:
			valid = False
			break
	return valid
for i in range(n):
	a = input()
	lst1.append(a)
for i in range(n):
	for j in range(n):
		if lst1[i] != -1 and pal(lst1[i]):
			middle = lst1[i]
			lst1[i] = -1
		if i != j and lst1[i] != -1 and (lst1[j] != -1) and (lst1[i][::-1] == lst1[j]):
			left = left + lst1[i]
			right = lst1[j] + right
			lst1[i] = -1
			lst1[j] = -1
print(len(left + middle + right))
print(left + middle + right)


(m, n) = input().split()
l = []
for i in range(int(m)):
	s = input()
	l.append(s)
pallin = ''
for j in l:
	if j == j[::-1]:
		pallin = j
		l.remove(j)
		break
for k in range(len(l) - 1):
	if l[k][::-1] in l[k + 1:]:
		pallin = l[k] + pallin + l[k][::-1]
print(len(pallin))
print(pallin)


def pal(string):
	reversed_string = string[::-1]
	return string == reversed_string
(n, m) = map(int, input().split())
a = []
s = ''
s1 = ''
for _ in range(n):
	a.append(str(input()))
for i in range(len(a) - 1):
	for j in range(i + 1, len(a)):
		if a[i] == a[j][::-1]:
			s += a[i]
			s1 = str(a[j]) + s1
for i in range(len(a)):
	if pal(a[i]):
		if pal(s + a[i] + s1):
			s += a[i]
s2 = s + s1
print(len(s2))
print(s2)


from collections import defaultdict
(X, MyDict) = (list(map(int, input().split())), defaultdict(int))
for i in range(X[0]):
	Temp = input()
	MyDict[Temp if MyDict.get(Temp[::-1]) == None else Temp[::-1]] += 1
(Answer, Middle) = ('', '')
for key in MyDict.keys():
	Answer += MyDict[key] // 2 * key
	MyDict[key] %= 2
	if MyDict[key] == 1 and key[::-1] == key and (len(key) > len(Middle)):
		Middle = key
Answer = Answer + Middle + Answer[::-1]
print(len(Answer))
print(Answer)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	s = input()
	l.append(s)
a = ''
x = []
y = []
z = []
for i in l:
	if i == i[::-1]:
		x.append(i)
	elif i[::-1] in y:
		z.append(i)
	else:
		y.append(i)
mid = ''
m = 0
p = []
for i in x:
	if len(i) > m:
		m = max(len(i), m)
		p.append(i)
if len(p) > 0:
	mid = mid + p[-1]
for i in z:
	a = a + i
b = a[::-1]
a = a + mid + b
print(len(a))
print(a)


(n, m) = 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)


def pal(x):
	i = 0
	j = len(x) - 1
	f = 0
	while j > i and f == 0:
		if x[i] == x[j]:
			j = j - 1
			i = i + 1
		else:
			f = 1
			break
	return f
(n, m) = map(int, input().split())
l = []
cnt = 0
p = {}
for i in range(n):
	x = input()
	l.append(x)
	r = pal(x)
	if r == 0:
		cnt = cnt + 1
		p[x] = 1
i = 0
h = []
while i < len(l):
	j = i + 1
	f = 0
	while j < len(l) and f == 0:
		q = l[j]
		if l[i] == q[::-1]:
			h.append((l[i], q))
			if q in p:
				p[q] = 0
				cnt = cnt - 2
			f = 1
		else:
			j = j + 1
	i = i + 1
st = ''
for i in range(len(h)):
	x = h[i]
	st = st + x[0]
if cnt != 0:
	for i in p:
		if p[i] != 0:
			st = st + i
			break
h = h[::-1]
for i in range(len(h)):
	x = h[i]
	st = st + x[1]
print(len(st))
print(st)


import os
import operator
import sys
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		matrix.append(input())
	res = []
	freq = [0] * n
	for i in range(n):
		if freq[i] == 0:
			for j in range(i + 1, n):
				if freq[j] == 0:
					counter = 0
					for k in range(m):
						if matrix[i][k] != matrix[j][m - k - 1]:
							counter = 1
							break
					if counter == 0:
						res.append((matrix[i], matrix[j]))
						freq[i] = 1
						freq[j] = 1
	for i in range(n):
		if freq[i] == 0:
			pal = 0
			for k in range(m):
				if matrix[i][k] != matrix[i][m - k - 1]:
					pal = 1
					break
			if pal == 0:
				res.append((matrix[i], ''))
				break
	ans = ''
	if len(res) == 0:
		print(0)
		print('')
	else:
		for i in range(len(res)):
			ans += res[i][0]
		for i in range(len(res) - 1, -1, -1):
			ans += res[i][1]
		print(len(ans))
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


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]
			if s1 == s2:
				found = True
				pairs.append((s1, strings[j]))
				break
		if not found:
			if palindrome(s1):
				alone.append(s1)
	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()


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

def pal(s):
	return s == s[::-1]
for i in range(n):
	s = input()
	f.add(s)
center = ''
left = ''
right = ''
d = set()
for i in f:
	if i in d:
		continue
	if pal(i):
		center = i
	else:
		p = i[::-1]
		if p in f:
			left += i
			right = p + right
			d.add(i)
			d.add(p)
ans = left + center + right
print(len(ans))
print(ans)


def main():
	(n, m) = list(map(int, input().strip().split()))
	all_strings = set()
	for _ in range(n):
		s = input()
		all_strings.add(s)
	half = ''
	middle = ''
	used = set()
	for s in all_strings:
		rev = s[::-1]
		if rev in all_strings and s != rev and (s not in used) and (rev not in used):
			half += s
			used.add(s)
			used.add(rev)
		elif s == rev:
			middle = s
	res = half + middle + half[::-1]
	print(len(res))
	print(res)
main()


from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
from collections import Counter
(n, m) = rl()
ss = [stdin.readline().rstrip() for _ in range(n)]
ss = Counter(ss)
head = middle = ''
while ss:
	(s, c) = ss.popitem()
	r = ''.join(reversed(s))
	if r == s:
		head += s * (c // 2)
		if c % 2 == 1:
			middle = s
	else:
		rc = ss.pop(r, 0)
		head += s * min(c, rc)
r = head + middle + ''.join(reversed(head))
print(len(r))
print(r)


def reverse(s):
	str = ''
	for i in s:
		str = i + str
	return str
I = input
(n, m) = map(int, I().split())
a = []
b = []
c = []
d = []
sumo = 0
tc = 0
for tt in range(int(n)):
	s = I()
	a.append(s)
	t = ''
for i in range(n):
	t = reverse(a[i])
	if a[i] == t:
		if tc == 0:
			t1 = t
			b.append(a[i])
			tc += 1
		elif t1 == t:
			b.append(a[i])
for i in range(n - 1):
	for j in range(i + 1, n):
		if a[i] == reverse(a[j]):
			c.append(a[i])
			d.append(a[j])
			break
for i in range(len(c)):
	sumo = sumo + len(c[i])
for i in range(len(b)):
	sumo += len(b[i])
for i in range(len(d)):
	sumo += len(d[i])
print(sumo)
for i in range(len(c)):
	print(c[i], end='')
for i in range(len(b)):
	print(b[i], end='')
for i in range(len(d)):
	print(d[len(d) - 1 - i], end='')


def p(s):
	return s == s[::-1]
(n, m) = map(int, input().split())
l = list()
for i in range(n):
	l.append(input())
left = ''
right = ''
middle = ''
lbool = [True] * n
for i in range(len(l)):
	f = False
	for j in range(i + 1, len(l)):
		if lbool[j] and p(l[i] + l[j]):
			left = l[i] + left
			right = right + l[j]
			f = True
			lbool[j] = False
			break
		elif lbool[j] and p(l[j] + l[i]):
			left = l[j] + left
			right = right + l[i]
			lbool[j] = False
			f = True
			break
	if not f and middle == '' and p(l[i]):
		middle = l[i]
s = left + middle + right
print(len(s))
print(s)


import sys
from pprint import pprint
if not 'DEBUG' in globals():
	readline = sys.stdin.readline

def read(map_func):
	return map_func(readline().rstrip())

def reads(map_func):
	return list(map(map_func, readline().rstrip().split()))

def readn(map_func, n):
	return [map_func(readline().rstrip()) for _ in range(n)]

def readint():
	return read(int)

def readints():
	return reads(int)

def readcol(n):
	return readn(int, n)

def readmat(n):
	return [readints() for _ in range(n)]

def readmap(n):
	return readn(list, n)

def makemat(n, m, v):
	return [[v for _ in range(m)] for _ in range(n)]

def zeromat(n, m=None):
	return makemat(n, m if m else n, 0)

def listmat(n, m=None):
	return [[[] for _ in range(m if m else n)] for _ in range(n)]

def crosslist(y, x, n=None, m=None):
	return [(p, q) for (p, q) in [(y, x + 1), (y - 1, x), (y, x - 1), (y + 1, x)] if (n == None or 0 <= p < n) and (m == None or 0 <= q < m)]

def roundlist(y, x, n=None, m=None):
	return [(p, q) for (p, q) in [(y, x + 1), (y - 1, x + 1), (y - 1, x), (y - 1, x - 1), (y, x - 1), (y + 1, x - 1), (y + 1, x), (y + 1, x + 1)] if (n == None or 0 <= p < n) and (m == None or 0 <= q < m)]

def plog(obj):
	pprint(obj) if 'DEBUG' in globals() else None

def log(msg, label=None):
	print((label + ': ' if label else '') + str(msg)) if 'DEBUG' in globals() else None

def _logmat(mat, label=None):
	fmt = '{:' + str(max((max((len(str(s)) for s in m)) for m in mat))) + 'd}'
	f = lambda row: '[' + ' '.join((fmt.format(x) for x in row)) + ']'
	[log('[' + f(row), label) if i == 0 else log((' ' * (len(label) + 3) if label else ' ') + f(row) + ']', None) if i == len(mat) - 1 else log((' ' * (len(label) + 3) if label else ' ') + f(row), None) for (i, row) in enumerate(mat)]

def logmat(mat, label=None):
	_logmat(mat, label) if 'DEBUG' in globals() else None
(N, M) = readints()
W = readn(str, N)

def ispalin(s):
	l = len(s)
	if l % 2 == 0:
		return s[:l // 2] == s[l // 2:][::-1]
	else:
		return s[:l // 2] == s[l // 2 + 1:][::-1]
r = ''
P = {}
for w in W:
	if ispalin(w):
		try:
			P[w] += 1
		except:
			P[w] = 1
if P:
	A = []
	for k in P:
		A.append([P[k], k])
	t = min(A)
	if t[0] == 1:
		W.remove(t[1])
		r = t[1]
while W:
	t = W.pop()
	y = t[::-1]
	if y in W:
		W.remove(y)
		r = t + r + y
print(len(r))
print(r)


(n, m) = map(int, input().split())
s = []
r = []
l = []
for i in range(n):
	s.append(input())
d = {}
for i in range(n):
	d[s[i][::-1]] = i
p = -1
for i in range(n):
	if s[i] in d:
		if d[s[i]] != i:
			r.append(s[i])
			l.append(s[i][::-1])
			del d[s[i][::-1]]
			del d[s[i]]
		elif p == -1:
			a = 0
			k = len(s[i]) - 1
			for j in range(m // 2):
				if s[i][j] == s[i][k]:
					a += 1
				k -= 1
			if a == m // 2:
				p = i
if p == -1 and len(r) == 0:
	print(0)
elif p != -1:
	if len(r) == 0:
		print(len(s[p]), s[p], sep='\n')
	else:
		print(len(r) * m + len(l) * m + m)
		print(''.join((i for i in r)), s[p], ''.join((l[i] for i in range(len(l) - 1, -1, -1))), sep='')
else:
	print(len(r) * m + len(l) * m)
	print(''.join((i for i in r)), ''.join((l[i] for i in range(len(l) - 1, -1, -1))), sep='')


(n, m) = map(int, input().split())
x = []

def is_palindrome(string):
	acc = string
	reversed_string = string[::-1]
	return reversed_string
k = str()
pp = []
b = 0
p = str()
z = str()
c = 0
for i in range(n):
	y = input()
	x.append(y)
for i in range(0, n):
	for j in range(i + 1, n):
		b = 0
		if x[i] == is_palindrome(x[j]):
			k = k + x[i]
			pp.append(x[j])
			b = 1
	if x[i] == is_palindrome(x[i]) and b == 0:
		z = x[i]
for i in range(len(pp) - 1, -1, -1):
	p = p + pp[i]
c = len(p) + len(k) + len(z)
if c == 0:
	print(c)
else:
	print(c)
	print(k + z + p)


(n, m) = map(int, input().split())
strs = []
for _ in range(n):
	strs.append(input())
ansl = []
ansr = []
str_set = set(strs)
for s in strs:
	if s not in str_set:
		continue
	rs = s[::-1]
	if rs != s:
		if rs in str_set:
			ansl.append(s)
			ansr.append(rs)
			str_set.remove(s)
			str_set.remove(rs)
middle = ''
for s in list(str_set):
	if s == s[::-1]:
		middle = s
		break
ans = ''.join(ansl) + middle + ''.join(reversed(ansr))
print(len(ans))
print(ans)


def palindrom(s):
	for i in range(len(s)):
		if s[i] != s[-i - 1]:
			return False
	return True
(n, m) = map(int, input().split())
strings = []
for i in range(n):
	s = input()
	found = False
	for j in range(len(strings)):
		if strings[j][0] == s[::-1]:
			strings[j][1] = s
			found = True
			break
	if not found:
		strings.append([s, ''])
single = ''
dual = []
for spr in strings:
	if spr[1] != '':
		dual.append(spr)
	elif palindrom(spr[0]) and len(spr[0]) > len(single):
		single = spr[0]
ans = ''
for spr in dual:
	ans += spr[0]
ans += single
for spr in dual[::-1]:
	ans += spr[1]
print(len(ans))
print(ans)


(n, k) = map(int, input().split())
s = [input() for i in range(n)]
ls = []
j = 0
l = ''
for i in s:
	if i[::-1] in s and i != i[::-1]:
		ls.insert(j, i)
		ls.insert(len(ls) - j, i[::-1])
		s.remove(i[::-1])
		j += 1
	if i == i[::-1]:
		l = i
ls.insert(len(ls) // 2, l)
u = ''.join(ls)
print(len(u))
print(u)


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

def check_pair(s, t):
	l = len(s)
	for i in range(l):
		if s[i] != t[l - i - 1]:
			return False
	return True
(n, m) = map(int, input().split(' '))
s = []
for i in range(n):
	s.append(input())
mid = ''
left = []
used = [False for i in range(n)]
for i in range(n):
	if used[i]:
		continue
	formid = False
	if mid == '' and check(s[i]):
		formid = True
	for j in range(i + 1, n):
		if check_pair(s[i], s[j]):
			left.append(s[i])
			used[j] = True
			formid = False
			break
	if formid:
		mid = s[i]
nl = len(left)
print(m * (nl * 2 + (0 if mid == '' else 1)))
left.append(mid)
for i in range(nl):
	left.append(left[nl - i - 1][::-1])
print(''.join(left))


(n, m) = 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])


import collections
(n, m) = map(int, input().split())
s = [input() for i in range(n)]
table = collections.defaultdict(int)
for x in s:
	table[x] += 1
s_middle = []
left = []
right = []
middle = []
for x in table:
	if x == x[::-1]:
		if table[x] % 2 == 1:
			table[x] -= 1
			s_middle.append(x)
		if table[x] >= 2:
			for i in range(table[x] // 2):
				left.append(x)
				right.append(x)
			table[x] = 0
if s_middle:
	s_middle.sort(key=lambda x: len(x), reverse=True)
	middle.append(s_middle[0])
for x in table:
	if table[x] > 0:
		if x[::-1] in table and table[x[::-1]] > 0:
			for i in range(min(table[x], table[x[::-1]])):
				left.append(x)
				right.append(x[::-1])
			table[x] = 0
			table[x[::-1]] = 0
ans = left + middle + right[::-1]
ans = ''.join(ans)
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
pal = ''
m = set()
res = []
for i in range(n):
	s = input()
	rev = s[::-1]
	if s == rev:
		pal = s
	elif rev in m:
		res.append(s)
	else:
		m.add(s)
ans = ''.join(res)
ans = ''.join([ans, pal, ans[::-1]])
print(len(ans))
print(ans)


def f(s):
	return s == s[::-1]
(n, m) = map(int, input().split())
s = set()
for _ in range(n):
	s.add(input())
d = set()
mid = ''
for i in list(s):
	if i in s:
		if f(i):
			if len(i) > len(mid):
				mid = i
		else:
			v = i[::-1]
			if v in s:
				d.add((i, v))
				s.remove(v)
		s.remove(i)
(a, b) = ('', '')
for i in d:
	a += i[0]
	b = i[1] + b
ans = a + mid + b
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
l = list()
for _ in range(n):
	l.append(input())
f = [0] * n
p = [0] * n
a = [0] * n
for i in range(n):
	if l[i] == l[i][::-1]:
		p[i] = 1
	for j in range(i + 1, n):
		if f[j] == 0:
			if l[i] == l[j][::-1]:
				a[i] = 1
				a[j] = -1
				f[j] = -1
				break
s = ''
t = ''
for i in range(n):
	if a[i] == 1:
		s += l[i]
	elif p[i] == 1:
		t = l[i]
ans = s + t + s[::-1]
print(len(ans))
print(ans)


nlist = input()
list = []
rlist = []
ring = ''
rring = ''
mring = ''
(m, k) = nlist.split()
for i in range(0, int(m)):
	elelist = input()
	list.append(elelist)
	rlist.append(elelist[::-1])
for i in range(0, int(m)):
	if list[i] == rlist[i]:
		mring = list[i]
	for j in range(i + 1, int(m)):
		if list[i] == rlist[j]:
			ring = ring + list[i]
			rring = list[j] + rring
			break
tring = ring + mring + rring
print(len(tring))
print(tring)


def rev(s):
	return ''.join(reversed(list(s)))

def solve(n, m, a):
	mid = ''
	front = []
	back = []
	for i in range(n):
		s = a[i]
		if s == rev(s):
			mid = s
			continue
		for j in range(i + 1, n):
			t = a[j]
			if s == rev(t):
				front.append(s)
				back.append(t)
	return ''.join(front) + mid + ''.join(reversed(back))
(n, m) = list(map(int, input().strip().split()))
a = []
for _ in range(n):
	a.append(input().strip())
s = solve(n, m, a)
print(len(s))
print(s)


(strings_count, strings_len) = [int(i) for i in input().split()]

def is_palindrome(text):
	skipped_letters = 0
	if len(text) % 2 != 0:
		skipped_letters = 1
	first_half = text[:int(len(text) / 2)]
	second_half = text[int(len(text) / 2) + skipped_letters:]
	return first_half == second_half[::-1]
strings = {}
for i in range(strings_count):
	string = input()
	strings[string] = string[::-1]
used_strings = []
result = ''
single_palindrome = ''
for string in strings:
	if string not in used_strings:
		if string != strings[string] and strings[string] in strings:
			half = int(len(result) / 2)
			result = result[:half] + string + strings[string] + result[half:]
			used_strings.append(strings[string])
			used_strings.append(string)
		elif is_palindrome(string):
			single_palindrome = string
if single_palindrome != '':
	half = int(len(result) / 2)
	result = result[:half] + single_palindrome + result[half:]
print(len(result))
print(result)


(n, m) = list(map(int, input().split()))
a = []
for i in range(n):
	a.append(input())
pair = []
pali = []
for x in a:
	if x[::-1] in a[::-1]:
		if a[::-1].index(x) == a[::-1].index(x[::-1]):
			pali.append(x)
			continue
		pair.append(x)
		a.remove(x[::-1])
	elif x == x[::-1]:
		pali.append(x)
	else:
		pass
s = ''
try:
	s += pali[0]
except:
	pass
for x in pair:
	s = x + s + x[::-1]
print(len(s))
print(s)


(n, m) = [int(i) for i in input().split()]
(s, z) = ([], '')
for i in range(n):
	s.append(input())
	(count, res) = (0, '')
for i in range(n):
	j = i + 1
	if s[i] == s[i][::-1]:
		z = s[i]
		continue
	while j < n:
		if s[i] == s[j][::-1]:
			count += 1
			res = s[i] + res + s[j]
			break
		j += 1
res = res[:len(res) // 2] + z + res[len(res) // 2:]
print(len(res))
print(res)


a = []
r = s = ''
for _ in [0] * int(input().split()[0]):
	x = input()
	y = x[::-1]
	if y in a:
		r += x
	if x == y:
		s = x
	a += (x,)
r = r + s + r[::-1]
print(len(r), r)


import math
q = 1
for _ in range(q):
	ans = ''
	sett = set()
	(n, m) = map(int, input().split())
	for i in range(n):
		s = input()
		c = s[::-1]
		if c not in sett:
			sett.add(s)
		else:
			sett.remove(c)
			ans = s + ans + c
	for palindromes in sett:
		flag = 0
		for i in range(m // 2):
			if palindromes[i] != palindromes[m - i - 1]:
				flag = -1
		if flag == 0:
			ans = ans[0:len(ans) // 2] + palindromes + ans[len(ans) // 2:]
			break
		else:
			continue
	print(len(ans))
	print(ans)


from itertools import combinations
(n, m) = map(int, input().split())
l = [input() for _ in range(n)]
pn = combinations(l, 2)
ans = []
for q in l:
	if all([i == j for (i, j) in zip(q, q[::-1])]):
		ans.append(q)
		break
for (q, r) in pn:
	if all([i == j for (i, j) in zip(q, r[::-1])]):
		ans.append(q)
		ans = [r] + ans
st = ''.join(ans)
print(len(st))
print(st)


(n, l) = map(int, input().split())
d = {}
p_ = ''
k = {}
k1 = {}
for i in range(n):
	flag = 0
	s = input()
	if s[::-1] in d:
		d[s[::-1]] = d[s[::-1]] + 1
	else:
		d[s] = 1
	for j in s:
		if j != s[0]:
			flag = 1
			break
	if flag == 0:
		if s not in k:
			k[s] = 1
		else:
			k[s] = k[s] + 1
	elif s == s[::-1]:
		k1[s] = 1
ans = ''
for i in d:
	ans = ans + i * (d[i] // 2)
s1 = ''
z = float('-inf')
for i in k:
	if d[i] > z:
		s1 = i * k[i]
	z = max(z, d[i])
s2 = ''
if len(k1):
	for i in k1:
		s2 = i
if s1 == '':
	ans = ans + s2 + ans[::-1]
else:
	ans = ans + s1 + ans[::-1]
print(len(ans))
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
st = set()
considered = set()
for i in range(n):
	st.add(input())
ans = []
ans2 = []
longest = 0
ll = ''
for each in st:
	if each in considered:
		continue
	strev = each[::-1]
	if strev in st and strev != each:
		ans += [each]
		ans2 += [strev]
		considered.add(strev)
	elif strev == each:
		if len(each) > longest:
			longest = len(each)
			ll = each
a = ''.join(ans) + ll + ''.join(ans2[::-1])
print(len(a))
print(a)


def palindrome(queries):
	d = {}
	max_ = 0
	s = ''
	ele = ''
	for e in queries:
		if d.get(e[::-1]):
			s += e
		elif e == e[::-1]:
			if max_ < len(e):
				if ele:
					d[ele] = True
				max_ = len(e)
				ele = e
		else:
			d[e] = True
	string = s[::-1] + ele + s
	return (len(string), string)
(n, m) = map(int, input().split())
queries = []
for i in range(n):
	queries.append(input())
(a, b) = palindrome(queries)
print(a)
print(b)


(n, m) = map(int, input().split())
strs = [list(input()) for i in range(n)]
ans = [''] * n
num = 0
ind = -1
for i in range(n):
	try:
		temp = list(reversed(strs[i]))
		temp2 = strs.index(temp)
		if temp2 > i:
			ans[num] = ''.join(strs[i])
			ans[n - num - 1] = ''.join(temp)
			num += 1
		elif temp2 == i:
			ans[n // 2] = ''.join(strs[i])
	except:
		continue
ans = ''.join(ans)
print(len(ans))
print(ans)


import collections

def longestPal(words):
	words = set(words)
	pair = collections.defaultdict(str)
	pal = collections.defaultdict(int)
	for word in words:
		if word == word[::-1]:
			pal[word] += 1
		elif word[::-1] in words:
			pair[word] = word[::-1]
	used = set()
	ans = collections.deque()
	(count, currPal) = (0, '')
	for word in pal:
		if pal[word] > count:
			(count, currPal) = (pal[word], word)
	if count:
		ans.append(count * currPal)
	for word in pair:
		if word not in used and pair[word] not in used:
			ans.append(word)
			ans.appendleft(pair[word])
			used.add(word)
			used.add(pair[word])
	return ''.join(ans)
(n, m) = map(int, input().split())
words = []
for _ in range(n):
	words.append(input())
word = longestPal(words)
print(len(word))
print(word)


(a, b) = map(int, input().split())
c = []
p = ' '
f = []
for i in range(a):
	c += [input()]
d = c.copy()
for i in range(a):
	z = c[i]
	z1 = c[i][::-1]
	if z == z1 and (c.count(z) == 1 or d.count(z) == 1):
		f += [z]
	elif z in c and z1 in c:
		if z in d and z1 in d:
			p = z + p + z1
			d[d.index(z)] = 0
			d[d.index(z1)] = 0
try:
	p = p.replace(' ', sorted(f)[-1])
	print(len(p))
	print(p)
except:
	p = p.replace(' ', '')
	print(len(p))
	print(p)


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def solve():
	pass
(n, m) = rinput()
s = defaultdict(int)
for _ in range(n):
	s[input()] += 1
left = ''
right = ''
ans = 0
store = ''
for i in s:
	rev = i[::-1]
	if rev in s:
		if rev == i:
			continue
		if s[rev] <= 0:
			continue
		s[i] -= 1
		s[rev] -= 1
		ans += 2
		left += i
		right = rev + right
for i in s:
	if i == i[::-1] and s[i] > 0:
		store = i
		ans += 1
		break
print(ans * m)
print(left + store + right)


def pal(i):
	if len(i) % 2 == 0:
		sub1 = i[0:len(i) // 2]
		sub2 = i[len(i) // 2:len(i)]
	else:
		sub1 = i[0:len(i) // 2]
		sub2 = i[len(i) // 2 + 1:len(i)]
	sub2 = sub2[::-1]
	if sub1 == sub2:
		return True
	else:
		return False
temp = input()
temp = temp.split(' ')
n = int(temp[0])
l = int(temp[1])
s = []
for x in range(0, n):
	s.append(input())
f = []
r = []
remain = []
i = 0
while True:
	if len(s) == 0:
		break
	temp = s[0]
	s.remove(temp)
	if temp[::-1] in s:
		r.append(temp[::-1])
		s.remove(temp[::-1])
		f.append(temp)
	else:
		remain.append(temp)
for x in remain:
	if pal(x):
		f.append(x)
		break
r.reverse()
res = ''
for x in f:
	res = res + x
for x in r:
	res += x
print(len(res))
print(res)


(n, m) = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append(input())
d = {}
visited = {}
for i in arr:
	d[i] = i[-1::-1]
	visited[i] = False
t1 = []
t2 = []
rem = []
for i in d:
	if d[i] in arr:
		if visited[i] == False and visited[d[i]] == False and (i != d[i]):
			t1.append(i)
			t2.append(d[i])
			visited[i] = True
			visited[d[i]] = True
		else:
			rem.append(i)
	else:
		rem.append(i)
temp = []
for i in rem:
	if i == i[-1::-1]:
		temp.append(i)
rem = temp[:]
f = 0
if len(rem) >= 1:
	f = 1
	m = len(rem[0])
	s = rem[0]
	for i in range(1, len(rem)):
		if len(rem[i]) > m:
			m = len(rem[i])
			s = rem[i]
t2 = t2[-1::-1]
ans = ''
for i in t1:
	ans += i
if f == 1:
	ans += s
for i in t2:
	ans += i
print(len(ans))
print(ans)


from collections import defaultdict
(n, m) = map(int, input().split())
is_in_w = defaultdict(lambda : False)
has_reverse = defaultdict(lambda : 0)
is_a_pal = ['']
for i in range(n):
	w = input()
	if w == w[::-1]:
		is_a_pal.append(w)
		continue
	is_in_w[w] = True
	if is_in_w[w[::-1]]:
		has_reverse[w] += 1
		is_in_w[w[::-1]] = False
		is_in_w[w] = False
use = []
pal = max(is_a_pal, key=len)
for i in has_reverse:
	for _ in range(has_reverse[i]):
		use.append(i)
if pal:
	f = -2
else:
	f = -1
use.append(pal)
for i in range(len(use) + f, -1, -1):
	use.append(use[i][::-1])
r = ''.join(use)
print(len(r))
print(r)


(m, n) = map(int, input().split())
a = ['0'] * m
pali = list()
aseh = list()
r = list()
r1 = ''
aseh1 = ''
pc = 0
for i in range(m):
	a[i] = input()
for i in range(m):
	s = ''
	s = a[i]
	if s == s[n::-1]:
		if str(s) in pali:
			pc += 1
		pali.append(a[i])
	elif s[n::-1] in a:
		if s[n::-1] in a[i + 1:]:
			r.append(a[i])
			aseh.append(s[n::-1])
print(2 * (len(r) * n) + (n if len(pali) > 0 else 0))
for i in r:
	r1 += i
for i in range(len(aseh) - 1, -1, -1):
	aseh1 += aseh[i]
print(r1, end='')
for i in range(1 if len(pali) > 0 else 0):
	print(pali[i], end='')
print(aseh1)


(n, m) = map(int, input().split())
lst = []
for _ in range(n):
	lst.append(input())
d = {}
for i in lst:
	if i not in d.keys():
		d[i] = 1
	else:
		d[i] += 1
ans = []
op = []
for i in lst:
	rev = i[::-1]
	if i == rev and d[i] > 1:
		ans.append([i, rev])
		d[i] -= 2
	elif i != rev and d[i] > 0 and (rev in d.keys()) and (d[rev] > 0):
		ans.append([i, rev])
		d[i] -= 1
		d[rev] -= 1
	elif d[i] > 0 and i == rev:
		d[i] -= 1
		op.append(i)
res = ''
for i in ans:
	res += i[0]
if len(op) > 0:
	res += op[0]
for i in ans[::-1]:
	res += i[1]
print(len(res), res, sep='\n', end='')


(n, m) = map(int, input().split())
a = []
ans = []
for _ in range(n):
	a.append(str(input()))
for i in range(n):
	f = 1
	for j in range(m // 2):
		if a[i][j] != a[i][-j - 1]:
			f = 0
			break
	if f:
		ans.append(a[i])
		break
for i in range(n):
	for j in range(i + 1, n):
		flag = 1
		for k in range(m):
			if a[i][k] != a[j][-1 - k]:
				flag = 0
				break
		if flag:
			ans.append(a[j])
			ans.insert(0, a[i])
str = ''.join(ans)
print(len(str))
print(str)


def check(k):
	s = k[::-1]
	return s
arr = []
d = {}
(n, m) = map(int, input().split())
for i in range(n):
	s = input()
	d[s] = d.get(s, 0) + 1
	arr.append(s)
s1 = ''
s2 = ''
s = ''
for i in arr:
	if d[i] > 0:
		p = check(i)
		if d.get(p, 0) > 0 and p != i:
			s1 += i
			d[i] -= 1
			d[p] -= 1
		elif d.get(p, 0) > 0 and p == i:
			s = i
			d[i] -= 1
print(2 * len(s1) + len(s))
print(s1 + s + s1[::-1])


from collections import defaultdict as dc
from heapq import *
import math
import bisect
import sys
from collections import deque as dq

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p

def check(n, d, x):
	if x < 0:
		return 0
	return n >= x + math.ceil(d / (x + 1))

def form(a, b):
	q = a | b
	q = q - b
	print(a, b, a | b, q)
	return q

def ans(a, n):
	z = form(a[0], a[1])
	for i in range(2, n):
		z = form(z, a[i])
	return z
(n, m) = line()
p = dc(int)
lt = []
for _ in range(n):
	s = str(input())
	lt.append(s)
	p[s] += 1
ans1 = ''
ans2 = ''
mid = ''
for i in range(n):
	x = lt[i]
	y = x[::-1]
	if x == y:
		if len(x) > len(mid):
			mid = x
		p[x] -= 1
	elif p[y]:
		ans1 += x
		ans2 = y + ans2
		p[x] -= 1
		p[y] -= 1
if len(ans1) == 0 and len(ans2) == 0 and (len(mid) == 0):
	print(0)
else:
	ans = ans1 + mid + ans2
	print(len(ans))
	print(ans)


(n, length) = [int(i) for i in input().split()]
words = []
palindromes = []
mirror = ''
final = ''
for i in range(n):
	words.append(input())
for word in words:
	if word == word[::-1]:
		if len(word) > len(mirror):
			mirror = word
	elif word[::-1] in words and word not in palindromes and (word[::-1] not in palindromes):
		palindromes.append(word)
for word in palindromes:
	final += word
final += mirror + final[::-1]
print(len(final))
print(final)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	s = input()
	l.append(s)
p = 1
e = []
f = []
g = []
for i in l:
	c = 0
	d = i[::-1]
	for j in range(p, n):
		if d == l[j]:
			c = 1
			e.append(i)
			f.append(d)
	if c == 0:
		if i == i[::-1]:
			g.append(i)
	p = p + 1
if len(g) != 0:
	e.append(g[0])
s = ''
for i in e:
	s = s + i
v2 = f[::-1]
for i in v2:
	s = s + i
print(len(s))
print(s)


(n, m) = map(int, input().split())
list1 = []
orig = []
rep = []
used = [0 for i in range(n)]
for i in range(n):
	str1 = input()
	list1.append(str1)
for i in range(n):
	temp = list1[i][::-1]
	for j in range(n):
		if i != j and temp == list1[j] and (used[i] == 0):
			used[i] = 1
			used[j] = 1
			orig.append(list1[i])
			rep.append(list1[j])
for i in range(n):
	if list1[i][::-1] == list1[i] and used[i] == 0:
		orig.append(list1[i])
		break
result = ''
for items in orig:
	result += items
for items in rep[::-1]:
	result += items
print(len(result))
print(result)


def is_pali(x):
	return x == x[::-1]

def cnt_pali(x, c):
	cnt = 0
	for i in c:
		if i == x:
			cnt += 1
	return cnt
(n, m) = [int(i) for i in input().split(' ')]
cont = []
for i in range(n):
	cont.append(input())
cont_cp = [i for i in cont]
res = []
pali = ''
out = ''
for i in cont:
	if i[::-1] in cont_cp:
		if not is_pali(i):
			res.append(i)
			cont_cp.remove(i[::-1])
			cont_cp.remove(i)
		elif cnt_pali(i, cont_cp) > 1:
			res.append(i)
			cont_cp.remove(i)
			cont_cp.remove(i)
for i in cont_cp:
	if is_pali(i):
		pali += i
		break
for i in res:
	out += i
out += pali
for i in res[::-1]:
	out += i[::-1]
print(len(out))
print(out)


def solve(n, a):
	used = []
	pair = []
	for i in range(n):
		if i in used:
			continue
		for j in range(i + 1, n):
			if j in used:
				continue
			if a[i] == a[j][::-1]:
				pair.append([i, j])
				used.append(i)
				used.append(j)
				break
	ans = ''
	for i in range(n):
		if i not in used and a[i] == a[i][::-1]:
			ans += a[i]
			break
	for (x, y) in pair:
		ans = a[x] + ans + a[y]
	print(len(ans))
	print(ans)

def main():
	(n, _) = [int(x) for x in input().split()]
	a = [input() for _ in range(n)]
	solve(n, a)
main()


(n, m) = [int(x) for x in input().split()]
tot = 0
lis = []
for i in range(n):
	s = input()
	lis.append(s)
ans = ''
for i in range(n):
	for j in range(i):
		if lis[j] == ''.join(reversed(lis[i])):
			ans = lis[i] + ans + lis[j]
l = len(ans)
for i in range(n):
	if lis[i] == ''.join(reversed(lis[i])):
		ans = ans[:l // 2] + lis[i] + ans[l // 2:]
		break
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(input())
hash_a = {}
for i in range(n):
	hash_a[arr[i]] = 1
temp = []
for i in arr:
	rev = i[::-1]
	if rev in arr:
		temp.append(i)
tup = []
visited = [0 for i in range(len(temp))]
i = 0
flag = False
x = []
for i in range(len(temp)):
	s = temp[i]
	rev = s[::-1]
	ind = temp.index(rev)
	if i != ind and visited[i] == 0 and (visited[ind] == 0):
		tup.append([s, rev])
		visited[i] = 1
		visited[ind] = 1
	elif visited[i] == 0 and (not flag):
		x = [s, '*']
		visited[i] = 1
		flag = True
if len(x) > 0:
	tup.append(x)
if len(tup) == 0:
	print(0)
else:
	l = 0
	for i in range(len(tup)):
		if tup[i][1] != '*':
			l += 2 * m
		else:
			l += m
	ans = ''
	for i in range(len(tup)):
		ans += tup[i][0]
	start = -1
	if tup[-1][1] == '*':
		start = len(tup) - 2
	else:
		start = len(tup) - 1
	for j in range(start, -1, -1):
		ans += tup[j][1]
	print(l)
	print(ans)


def solver(s):
	word_pairs = []
	for (idx, wi) in enumerate(s):
		for wj in s[idx + 1:]:
			if wi == wj:
				continue
			word_pairs.append([wi, wj])
	successful_words = {}
	palindromes = []
	for word_pair in word_pairs:
		try:
			successful_words[word_pair[0]]
		except KeyError:
			try:
				successful_words[word_pair[1]]
			except KeyError:
				if check_palindrome_concat(word_pair[0], word_pair[1]):
					successful_words[word_pair[0]] = 1
					successful_words[word_pair[1]] = 1
					palindromes.append(word_pair[0])
	for word in s:
		try:
			successful_words[word]
		except KeyError:
			if check_palindrome(word):
				return ''.join(palindromes) + word + ''.join(palindromes)[::-1]
	return ''.join(palindromes) + ''.join(palindromes)[::-1]

def check_palindrome_concat(a, b):
	test = []
	for c in a:
		test.append(c)
	for c in b:
		if test.pop() != c:
			return False
	return True

def check_palindrome(a):
	if len(a) == 1:
		return True
	test = []
	rev_a = ''
	for c in a:
		test.append(c)
		rev_a = c + rev_a
	for c in rev_a:
		if test.pop(0) != c:
			return False
	return True
nm = list(map(lambda x: int(x), input().split(' ')))
n = nm[0]
m = nm[1]
s = []
for _ in range(n):
	s.append(input())
result = solver(s)
print(len(result))
print(result)


try:

	def reverse(s):
		s1 = ''
		for i in s:
			s1 = i + s1
		return s1

	def Palindrome(s):
		if s == reverse(s):
			return True
		else:
			return False
	nm = list(map(int, input().split()))
	n = nm[0]
	m = nm[1]
	given_list = [input() for i in range(n)]
	S = ''
	for i in given_list:
		if Palindrome(i):
			S = i
			break
	for i in range(len(given_list)):
		for j in range(i + 1, len(given_list)):
			if given_list[j] == reverse(given_list[i]):
				S = given_list[i] + S + given_list[j]
				break
	print(len(S))
	print(S)
except:
	pass


lst = []
ans = []
(n, m) = [int(x) for x in input().split()]
for i in range(n):
	lst.append(input())
flag = 0
temp = ''
while len(lst) > 0:
	st = lst[0]
	lst.remove(lst[0])
	if st[::-1] in lst:
		ans.insert(0, st)
		ans.append(st[::-1])
		lst.remove(st[::-1])
	elif st == st[::-1] and flag == 0:
		temp = st
		falg = 1
if temp != '':
	ans.insert(len(ans) // 2, temp)
if len(ans) > 0:
	print(len(''.join(ans)))
	print(''.join(ans))
else:
	print(0)


import sys
(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
used = [-1 for i in range(n)]
count = 0
for i in range(n):
	for j in range(i + 1, n):
		if used[i] == -1 and used[j] == -1 and (s[i] == s[j][::-1]):
			used[i] = j
			used[j] = i
			count += 2
beginning = ''
end = ''
middle = ''
for i in range(n):
	x = used[i]
	if x != -1:
		if x > i:
			beginning += s[i]
			end = s[x] + end
if count < n:
	best_i = -1
	best = -1
	for i in range(n):
		if used[i] == -1 and s[i] == s[i][::-1] and (len(s[i]) > best):
			best_i = i
			best = len(s[i])
	if best != -1:
		middle = s[best_i]
result = beginning + middle + end
print(len(result))
print(result)


(n, m) = map(int, input().split())
a = []
b = []
f = []
x = 101
for _ in range(n):
	a.append(input())
for i in range(n - 1):
	for j in range(i + 1, n):
		l = m - 1
		c = 0
		for k in range(m):
			if a[i][k] != a[j][l]:
				c = 1
				break
			l = l - 1
		if c == 0:
			if [i, j] not in b:
				b.append([i, j])
			break
for i in range(len(b)):
	f.append(b[i][0])
for i in range(len(b) - 1, -1, -1):
	f.append(b[i][1])
for i in range(n):
	if a[i] == a[i][::-1]:
		if i not in f:
			x = i
			break
string = ''
for i in range(len(b)):
	string = string + a[f[i]]
if x != 101:
	string += a[x]
for i in range(len(b), len(f)):
	string += a[f[i]]
if len(string) == 0:
	print('0')
else:
	print(len(string))
	print(string)


line1 = list(map(lambda x: int(x), input().split()))
n = line1[0]
m = line1[0]
start = ''
end = ''
mid = ''
str_set = set()
for i in range(0, n):
	st = input()
	if st[::-1] in str_set:
		str_set.remove(st[::-1])
		start += st[::-1]
		end = st + end
	else:
		str_set.add(st)
for s in str_set:
	if s == s[::-1]:
		mid = s
		break
ans = start + mid + end
print(len(ans))
print(ans)


from sys import stdin, stdout
from collections import deque
M = 1000000007

def reverse(s):
	str = ''
	for i in s:
		str = i + str
	return str
(n, m) = map(int, stdin.readline().split())
l = []
for i in range(n):
	l.append(stdin.readline()[:-1])
count1 = 0
count2 = 0
ans1 = ''
ans2 = ''
ans3 = ''
l.sort()
while len(l) > 0:
	i = l[0]
	if i == reverse(i):
		if len(l) > 1 and l[1] == i:
			count2 += 1
			ans1 = ans1 + i
			ans2 = reverse(i) + ans2
			l.remove(i)
			l.remove(reverse(i))
		else:
			ans3 = i
			count1 = 1
			l.remove(i)
	elif reverse(i) in l:
		count2 += 1
		ans1 = ans1 + i
		ans2 = reverse(i) + ans2
		l.remove(i)
		l.remove(reverse(i))
	else:
		l.remove(i)
print((count1 + count2 * 2) * m)
print(ans1 + ans3 + ans2)


from sys import stdin, stdout
from math import factorial as f
inp = stdin.readline
op = stdout.write
(n, l) = list(map(int, inp().split()))
a = [input() for i in range(n)]
ans = []
st = []
d = {}
for i in range(n):
	for j in range(n):
		if a[i] == a[j][::-1] and (not i == j) and (d.get(i) == d.get(j) == None):
			d[i] = 1
			d[j] = 1
			ans.append(a[i])
			st.append(a[j])
			break
for i in range(n):
	if a[i] == a[i][::-1] and d.get(i) == None:
		ans.append(a[i])
		break
st = st[::-1]
n = len(list(''.join(ans) + ''.join(st)))
op(str(n) + '\n')
op(''.join(ans) + ''.join(st))


from collections import defaultdict
(n, _) = map(int, input().split())
usedFlag = list()
words = defaultdict(list)
for i in range(n):
	word = input()
	words[word].append(i)
TopHalfPalindrome = []
for word in words:
	if word[::-1] not in words:
		continue
	for location in words[word]:
		for reversed_location in words[word[::-1]]:
			if reversed_location == location:
				continue
			if location in usedFlag:
				continue
			if reversed_location in usedFlag:
				continue
			TopHalfPalindrome.append(word)
			usedFlag.append(location)
			usedFlag.append(reversed_location)
MiddlePalindrom = ''
for word in words:
	for location in words[word]:
		if location in usedFlag:
			continue
		if word == word[::-1]:
			MiddlePalindrom = word
palindrom = ''.join(TopHalfPalindrome) + MiddlePalindrom + ''.join(TopHalfPalindrome)[::-1]
print(len(palindrom))
print(palindrom)


(n, m) = map(int, input().split())
l = []
p3 = []
p1 = []
p2 = []
ans = 0
c = 0
for i in range(n):
	f = 0
	s = input()
	if s in l:
		p1.append(s)
		p2.append(s[::-1])
		f = 1
		ans += 2
		l.remove(s)
	else:
		l.append(s[::-1])
	if f == 0:
		if m % 2 == 0 and s[:m // 2] == s[m // 2:][::-1]:
			if c == 0:
				p3.append(s)
			c += 1
			if c == 1:
				ans += 1
		elif m % 2 == 1 and s[:m // 2] == s[m // 2 + 1:][::-1]:
			if c == 0:
				p3.append(s)
			c += 1
			if c == 1:
				ans += 1
print(m * ans)
anss = ''
for i in p2:
	anss += i
for i in p3:
	anss += i
for i in p1[::-1]:
	anss += i
print(anss)


(n, m) = [int(i) for i in input().split()]
A = [input() for i in range(n)]

def check_palindrome(x):
	return x == x[::-1]
used = [False for i in range(n)]
palindrome = [check_palindrome(i) for i in A]
constructed_string = ''
backward_string = ''
for i in range(n):
	if not used[i]:
		for j in range(i + 1, n):
			if A[i][::-1] == A[j]:
				constructed_string += A[i]
				backward_string = A[j] + backward_string
				used[i] = True
				used[j] = True
				break
middle_string = ''
for i in range(n):
	if palindrome[i] and (not used[i]):
		middle_string = A[i]
		break
ans = constructed_string + middle_string + backward_string
print(len(ans))
print(ans)


def isPalindrome(s):
	L = len(s)
	for i in range(0, L):
		if s[i] != s[L - i - 1]:
			return -1
	return L
(n, m) = map(int, input().split())
L = []
pal_left = ''
pal_center = ''
len_pal_center = 0
pal_right = ''
for i in range(n):
	L.append(input())
used = [0] * n
for i in range(n):
	b = L[i][::-1]
	for j in range(i + 1, n):
		if b == L[j] and used[j] == 0:
			used[j] = 1
			used[i] = 1
			pal_left = pal_left + L[i]
			pal_right = L[j] + pal_right
for i in range(n):
	if used[i] == 0 and isPalindrome(L[i]) > len_pal_center:
		len_pal_center = len(L[i])
		pal_center = L[i]
palindrome = pal_left + pal_center + pal_right
print(len(palindrome))
print(palindrome)


(n, m) = map(int, input().split())
s1ls = list()
s2ls = list()
for i in range(n):
	s = input()
	s1ls.append(s)
	s2ls.append(''.join(list(reversed(s))))
ansidx = []
used = []
for i in range(n):
	for j in reversed(range(i, n)):
		if s1ls[i] == s2ls[j] and (not i in used) and (not j in used):
			ansidx.append((i, j))
			used.append(j)
			break
ans1 = ''
ans2 = ''
ans3 = ''
for (i, j) in ansidx:
	if i != j:
		ans1 += s1ls[i]
		ans3 = s1ls[j] + ans3
	elif ans2 == '':
		ans2 += s1ls[i]
print(len(ans1 + ans2 + ans3))
print(ans1 + ans2 + ans3)


import math
from collections import deque
from collections import defaultdict
(n, m) = map(int, input().strip().split(' '))
mp = {}
ans = []
md = ''
for i in range(n):
	s = input().strip()
	mp[s] = 1
for i in mp:
	j = i[::-1]
	mp[i] = 0
	if mp.get(j) is not None and mp[j] == 1:
		ans.append([i, j])
		mp[j] = 0
	elif md == '':
		fq = {}
		for k in range(len(i)):
			fq[i[k]] = fq.get(i[k], 0) + 1
		if len(fq) == 1:
			md = i
		else:
			j = i[::-1]
			if j == i:
				md = i
fans = ''
for i in ans:
	fans += i[0]
fans += md
ans = ans[::-1]
for i in ans:
	fans += i[1]
print(len(fans))
print(fans)


from copy import copy
from math import *

def arr_float_inp():
	return [float(s) for s in input().split()]

def arr_int_inp():
	return [int(s) for s in input().split()]

def int_inp():
	return int(input())

def float_inp():
	return float(input())

def comp(a):
	return a[0]

def gcd(a, b):
	if b != 0:
		return gcd(b, a % b)
	else:
		return a

def lcm(a, b):
	a / gcd(a, b) * b
(n, m) = arr_int_inp()
strings = []
polindromes = []
pairs = []
for _ in range(n):
	string = input()
	flag = False
	for i in range(len(strings)):
		if string == strings[i][::-1]:
			pairs.append(string)
			del strings[i]
			flag = True
			break
	if flag:
		continue
	if string == string[::-1]:
		polindromes.append(string)
	else:
		strings.append(string)
out = ''
for str in pairs:
	out += str
if len(polindromes) > 0:
	out += polindromes[0]
second_out = ''
for str in pairs:
	second_out = str[::-1] + second_out
out += second_out
if out == '':
	print(0)
else:
	print(len(out))
	print(out)


(n, s) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
s1 = ''
f = 0
st = ''
d = dict()
for i in l:
	d[i] = 0
for i in l:
	s3 = i[::-1]
	if s3 == i:
		st = i
	elif d[i] == 0:
		if s3 in d and d[s3] == 0:
			d[s3] = 1
			d[i] = 2
			s1 += i
ans = s1 + st + s1[::-1]
le = len(ans)
print(le)
print(ans)


def rev(s):
	return s[::-1]
(a, b) = map(int, input().split())
s = []
for i in range(a):
	ss = str(input())
	s.append(ss)
left = ''
pal = ''
right = ''
for i in range(a):
	if rev(s[i]) == s[i] and pal == '':
		pal = s[i]
	chk = s[i]
	for j in range(i + 1, a):
		if rev(chk) == s[j]:
			left = chk + left
			break
ans = left + pal + rev(left)
print(len(ans))
print(ans)


import pdb

def rev(s):
	r = ''
	for ch in s:
		r = ch + r
	return r
wl = []
rl = []
p = rp = 0
pw = ''
(n, m) = tuple([int(i) for i in input().split()])
for i in range(n):
	wl.append(input())
while len(wl) > 0:
	w = wl[0]
	if rev(w) == w:
		p += 1
		pw = w
	elif rev(w) in wl:
		rp += 1
		rl.append(w)
		wl.remove(rev(w))
	wl.remove(w)
print((min(1, p) + rp * 2) * m)
print(''.join(rl) + pw + rev(''.join(rl)))


import sys
import keyword
N = int(1000.0 + 5)
mp = [0] * N
(n, m) = map(int, input().split())
a = []
b = []
c = []
mid = ''
for i in range(n):
	tmp = input()
	a.append(tmp)
for i in range(n):
	tmp = a[i]
	str = ''.join(reversed(tmp))
	for j in range(i + 1, n):
		if a[j] == str and mp[j] != 1:
			b.append(a[i])
			c.append(a[j])
			mp[i] = mp[j] = 1
	if mp[i] != 1 and tmp == str:
		mid = tmp
num = len(b) * m * 2 + len(mid)
print(num)
for i in b:
	print(i, end='')
print(mid, end='')
c.reverse()
for i in c:
	print(i, end='')
print('')


(n, m) = map(int, input().split())
record = set()
sl = sc = ''
for _ in range(n):
	s = input()
	if s[::-1] in record:
		sl += s
	if s == s[::-1]:
		sc = s
	record.add(s)
print(len(sl) * 2 + len(sc))
print(sl + sc + sl[::-1])


(words, palin) = (set(), set())
ans = anss = ansrev = ''
(n, m) = map(int, input().split())
while n:
	n -= 1
	s = input()
	rev = s[::-1]
	if rev in words:
		ansrev = rev + ansrev
		anss = anss + s
		words.remove(rev)
		if rev in palin:
			palin.remove(rev)
	else:
		words.add(s)
	if rev == s:
		palin.add(s)
if not len(palin) == 0:
	ans = ansrev + list(palin)[0] + anss
else:
	ans = ansrev + anss
l = len(ans)
print(l)
if not l == 0:
	print(ans)


(n, m) = map(int, input().split())
S0 = set()
S1 = set()
S2 = set()
for i in range(n):
	s = str(input())
	s_ = ''.join(list(reversed(s)))
	if s == s_:
		S0.add(s)
	S1.add(s)
	S2.add(s_)
ans = ''
if len(S0) == 0:
	used = set()
	for c in S1:
		if c in S2 and c not in used:
			c_ = ''.join(list(reversed(c)))
			ans = c + ans + c_
			used.add(c_)
else:
	S0 = list(S0)
	ans += S0[0]
	used = set()
	S0 = set(S0)
	for c in S1:
		if c in S2 and c not in used and (c not in S0):
			c_ = ''.join(list(reversed(c)))
			ans = c + ans + c_
			used.add(c_)
if len(ans) != 0:
	print(len(ans))
	print(ans)
else:
	print(len(ans))


def add(i, s):
	if s == '':
		return s + i
	else:
		half = len(s) // 2
		return s[:half] + i + s[half:]

def valid(i):
	p1 = 0
	p2 = len(i) - 1
	while p1 <= p2:
		if i[p1] != i[p2]:
			return False
		p1 += 1
		p2 -= 1
	return True

def largepalin(d, m):
	le = 0
	string = ''
	t = True
	for i in d.keys():
		if d[i]:
			if valid(i):
				if t:
					le += m
					string = add(i, string)
				t = False
			else:
				rev = i[::-1]
				if rev in d:
					if d[rev]:
						le += 2 * m
						string = i + string + rev
						d[rev] = False
			d[i] = False
	return (le, string)
(n, m) = (int(x) for x in input().split())
dic = {}
for i in range(n):
	st = input()
	dic[st] = True
(a, b) = largepalin(dic, m)
print(a, b, sep='\n')


def will_be_palindrome(s1, s2):
	i = 0
	n = len(s1) - 1
	while i <= n:
		if s1[i] != s2[n - i]:
			return False
		i += 1
	return True

def is_palindrome(s):
	i = 0
	n = len(s) - 1
	while i <= n:
		if s[i] != s[n - i]:
			return False
		i += 1
	return True

def main(strings):
	used = set()
	p_start = []
	p_end = []
	pal = ''
	for s1 in strings:
		if not pal and is_palindrome(s1):
			pal = s1
		for s2 in strings:
			if s1 == s2 or s1 in used or s2 in used:
				continue
			if will_be_palindrome(s1, s2):
				p_start.append(s1)
				p_end.append(s2)
				used.add(s1)
				used.add(s2)
				break
	return ''.join(p_start + [pal] + list(reversed(p_end)))
(n, m) = input().split()
r = main([input() for _ in range(int(n))])
print(len(r))
print(r)


(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
i = 0
lst = []
while i < n:
	lst.append(input())
	i += 1
lst.append('')
pair = []
pal = []
for i in range(0, n):
	for j in range(i + 1, n + 1):
		if lst[i] == lst[j][::-1]:
			pair.append(lst[i])
			pair.append(lst[j])
		elif lst[i] == lst[i][::-1]:
			pal.append(lst[i])
ans = ''
for i in range(0, len(pair), 2):
	ans += pair[i]
if len(pal) > 0:
	ans += pal[0]
for i in range(len(pair) - 1, 0, -2):
	ans += pair[i]
print(len(ans))
if len(ans) > 0:
	print(ans)


(n, m) = map(int, input().split())
strings = []
for i in range(n):
	strings.append(input())
pals = []
pal_pairs = set()
for s in strings:
	if s[::-1] in strings and s != s[::-1]:
		pal_pairs.add(tuple(sorted([s, s[::-1]])))
	elif s == s[::-1]:
		pals.append(s)
pal_pairs = list(pal_pairs)
ans = []
for (l, r) in pal_pairs:
	ans.append(l)
if len(pals) > 0:
	ans.append(pals[0])
for (l, r) in pal_pairs[::-1]:
	ans.append(r)
ans = ''.join(ans)
print(len(ans))
print(ans)


(n, m) = list(map(int, input().split()))
d = dict()
for i in range(n):
	temp = input()
	if temp in d:
		d[temp] += 1
	else:
		d[temp] = 1
ans = []
for i in d:
	j = i[::-1]
	if i == j:
		for _ in range(d[i] // 2):
			ans.insert(0, i)
			ans.append(j)
			d[i] -= 1
			d[j] -= 1
	elif d[i] > 0 and j in d and (d[j] > 0):
		count = min(d[i], d[j])
		for _ in range(count):
			ans.insert(0, i)
			ans.append(j)
			d[i] -= 1
			d[j] -= 1
for i in d:
	j = i[::-1]
	if d[i] > 0 and i == j:
		ans.insert(len(ans) // 2, i)
		break
x = ''.join(ans)
print(len(x))
print(x)


(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])


(n_strings, length) = input().split()
length = int(length)
strings = [input().strip() for i in range(int(n_strings))]

def is_palindrome(string):
	(i, j) = (0, len(string) - 1)
	while i < j:
		if string[i] != string[j]:
			return False
		i += 1
		j -= 1
	return True

def solve(strings):
	longest_palindrome = ''
	seen = set()
	palindromes = []
	for string in strings:
		if is_palindrome(string):
			longest_palindrome = string
		elif string in seen:
			palindromes.append(string)
		elif string[::-1] in seen:
			palindromes.append(string[::-1])
		seen.add(string)
		seen.add(string[::-1])
	start_palindrome = ''.join(palindromes)
	palindrome = start_palindrome + longest_palindrome + start_palindrome[::-1]
	print(len(palindrome))
	print(palindrome)
	return
solve(strings)


[test, l] = [int(i) for i in input().split()]
words = set()
lis = []
for t in range(test):
	temp = input()
	words.add(temp)
	lis.append(temp)
(left, right) = ([], [])
mid = []
for i in lis:
	temp = i[::-1]
	if temp == i:
		mid.append(temp)
	elif temp in words:
		left.append(i)
		right.insert(0, temp)
		words.remove(i)
m = ''
for i in mid:
	if len(i) > len(m):
		m = i
ans = ''.join(left) + m + ''.join(right)
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
c = 0
d1 = {}
d2 = {}
p = []
for i in range(n):
	s = input()
	c += 1
	if s == s[::-1]:
		p.append(s)
		continue
	d1[s] = c
	d2[s[::-1]] = c
	c += 1
l1 = []
l2 = []
for i in d2:
	if i in d1 and d1[i] != 0:
		l1.append(i[::-1])
		l2.append(i)
		d1[i[::-1]] = 0
		d1[i] = 0
s = ''
for i in l1:
	s += i
if len(p) != 0:
	s += p[0]
l2 = l2[::-1]
for i in l2:
	s += i
print(len(s))
print(s)


(n, m) = map(int, input().split())
all = []
(mid, res) = (0, 0)
middle = 0
ans = []
gg = ''
for _ in range(n):
	s = input()
	if s == s[::-1] and len(s) > mid:
		mid = len(s)
		middle = s
	elif s[::-1] in all:
		res += 2 * len(s)
		ans.append(s)
	else:
		all.append(s)
res += mid
print(res)
for i in ans:
	gg += i
gg += middle if middle else ''
for i in ans[::-1]:
	gg += i[::-1]
print(gg)


(n, m) = map(int, input().split())
s = list()
for i in range(n):
	k = input()
	s.append(k)
k = ''
k1 = ''
res = ''
for i in range(len(s)):
	if s[i] == s[i][::-1]:
		k = s[i]
for i in range(len(s)):
	for j in range(i, len(s)):
		if s[i][::-1] == s[j] and s[i] != s[i][::-1]:
			k1 += s[i]
res = k1 + k + k1[::-1]
print(len(res))
print(res)


(n, m) = map(int, input().split(' '))
a = set((input()[:m] for _ in range(n)))
ps = []
mds = []
while len(a) > 0:
	i = a.pop()
	if i[::-1] in a:
		ps.append((i, i[::-1]))
		a.remove(i[::-1])
	elif m & 1:
		if i[:m // 2] == i[m // 2 + 1:][::-1]:
			mds.append(i)
	elif i[:m // 2] == i[m // 2:][::-1]:
		mds.append(i)
fs = ''
ts = ''
for (a, b) in ps:
	fs += a
	ts = b + ts
if len(mds) >= 1:
	s = fs + mds[0] + ts
	print(len(s))
	print(s)
else:
	s = fs + ts
	print(len(s))
	print(s)


(n, m) = map(int, input().split())
dp = [0] * n
for i in range(n):
	s = input()
	dp[i] = s
dpp = []
dpop = []
for i in range(n):
	if dp[i] == dp[i][::-1]:
		dpp.append(dp[i])
	elif dp[i][::-1] in dp:
		if dp[i][::-1] not in dpop:
			dpop.append(dp[i])
			dpop.append(dp[i][::-1])
s = ''
if dpp:
	s = dpp[0]
while dpop:
	a = dpop.pop(0)
	b = dpop.pop(0)
	s = a + s + b
print(len(s))
print(s)


import sys
(n, m) = map(int, sys.stdin.readline().split())
words = list()
ans = ''
for _ in range(n):
	raw = sys.stdin.readline().rstrip()
	if raw == raw[::-1]:
		ans = raw
	else:
		words.append(raw)
check = list()
for i in range(len(words)):
	tmp = words[i]
	for j in range(i + 1, len(words)):
		if tmp[::-1] == words[j]:
			check.append([tmp, tmp[::-1]])
for x in check:
	ans = x[0] + ans + x[1]
print(len(ans))
print(ans)


(n, m) = [int(i) for i in input().split()]
s = []
mid = ''
for i in range(n):
	s.append(input())
	if s[-1] == s[-1][::-1]:
		n -= 1
		mid = s[-1]
		s = s[:-1]
ans = ''
for i in range(n):
	for j in range(i + 1, n):
		if s[i] == s[j][::-1]:
			ans += s[i]
ans = ans + mid + ans[::-1]
print(len(ans))
print(ans, end='')


from collections import defaultdict
(n, m) = [int(i) for i in input().split()]
Dict = defaultdict(int)
lis_strings = []
for _ in range(n):
	lis_strings.append(input())
possible = []
pali = []
for i in lis_strings:
	if Dict[i] == 0:
		if i == i[::-1]:
			pali.append(i)
		Dict[i] = 1
		Dict[i[::-1]] = 1
	else:
		possible.append(i)
s1 = ''
s2 = ''
if len(pali) > 0:
	s2 = pali[0]
for i in possible:
	s1 += i
s1 = s1 + s2 + s1[::-1]
print(len(s1))
print(s1)


def pal(s):
	s2 = s[::-1]
	if s2 == s:
		return 1
	else:
		return 0

def rev(s):
	return s[::-1]
lista = []
dob = []
un = []
a = input().split()
a1 = int(a[0])
a2 = int(a[1])
for i in range(a1):
	lista.append(input())
for i in range(a1):
	for j in range(a1):
		if lista[i] == '':
			break
		if lista[i] == rev(lista[j]) and i != j:
			dob.append(lista[i])
			lista[i] = ''
			lista[j] = ''
			break
	if pal(lista[i]) and lista[i] != '':
		un.append(lista[i])
s = ''
for i in range(len(dob)):
	s += dob[i]
sr = rev(s)
if len(un) > 0:
	s += un[0]
s += sr
print(len(s))
print(s)


number = lambda : int(input())
string = lambda : input()
numbers = lambda : map(int, input().split())
lst = lambda : list(map(int, input().split()))

def isPalindrome(s):
	return s == s[::-1]

def main():
	(n, m) = numbers()
	arr = [''] * n
	s = set()
	x = ''
	plaindromes = ['']
	for i in range(n):
		arr[i] = string()
		if arr[i][::-1] in s:
			x += arr[i]
		elif isPalindrome(arr[i]):
			plaindromes.append(arr[i])
		else:
			s.add(arr[i])
	res = x[::-1] + max(plaindromes, key=len) + x
	print(len(res))
	print(res)
main()


from queue import LifoQueue

def reverse(s):
	return s[::-1]

def isPalindrome(s):
	rev = reverse(s)
	if s == rev:
		return True
	return False

def find(l, j, s):
	for i in range(j, len(l)):
		if l[i] == s:
			return True
	return False
nm = input().split()
n = int(nm[0])
m = int(nm[1])
l = []
nl = [0] * n
tp = n
while tp > 0:
	tp -= 1
	s = input()
	l.append(s)
x = 1
spec = ''
for i in range(n):
	ns = l[i][::-1]
	if find(l, i + 1, ns):
		for j in range(i + 1, n):
			if l[j] == ns:
				nl[j] = x
				nl[i] = x
				x += 1
				break
	elif isPalindrome(l[i]):
		spec = l[i]
ns = ''
stack = LifoQueue(maxsize=n)
for i in range(n):
	if nl[i] != 0:
		for j in range(i + 1, n):
			if nl[i] == nl[j]:
				stack.put(l[j])
				ns += l[i]
				break
ns += spec
while not stack.empty():
	ns += stack.get()
print(len(ns))
print(ns)


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(N, M, A):
	al = []
	ar = []
	cand = Counter(A)
	done = set()
	p = ''
	for k in cand.keys():
		rk = ''.join(k[::-1])
		if k not in done and rk in cand:
			if k == rk:
				n = cand[k] // 2
				al.append(k * n)
				ar.append(rk * n)
				done.add(k)
				done.add(rk)
				if cand[k] % 2 == 1:
					p = k
			else:
				n = min(cand[k], cand[rk])
				al.append(k * n)
				ar.append(rk * n)
				done.add(k)
				done.add(rk)
	ans = ''.join(al) + p + ''.join(reversed(ar))
	print(len(ans))
	print(ans)

def main():
	(N, M) = read_int_n()
	A = [read_str() for _ in range(N)]
	slv(N, M, A)
main()


(n, l) = [int(x) for x in input().split()]
arr = []
for _ in range(int(n)):
	arr.append(input().strip())
pals = []
sing_pal = ''
i = 0
while i < len(arr):
	if arr[i][::-1] in arr and arr[i][::-1] != arr[i]:
		temp = arr[i]
		pals.insert(0, temp)
		pals.append(arr[i][::-1])
		arr.remove(temp)
		arr.remove(temp[::-1])
		i -= 1
	elif arr[i][::-1] == arr[i]:
		sing_pal = arr[i]
	i += 1
if sing_pal != '':
	pals.insert(int(len(pals) / 2), sing_pal)
a = ''.join(pals)
print(len(a))
print(a)


import collections
(n, m) = list(map(int, input().split()))
a = list((input() for i in range(n)))
dic = {}
for w in a:
	dic[w] = dic.get(w, 0) + 1
(l, r) = ('', '')
for i in range(n):
	for j in range(i + 1, n):
		if a[i] == a[j][::-1] and dic[a[i]] and dic[a[j]]:
			l += a[i]
			r = a[j] + r
			dic[a[i]] -= 1
			dic[a[j]] -= 1
c = ''
for (k, v) in dic.items():
	if v and k == k[::-1]:
		if c and c[-m] == k or not c:
			c += k
print(f'{len(l) + len(c) + len(r)}\n{l + c + r}')


(n, m) = map(int, input().split())
(a, ans) = ([], [])
mid = ''
for _ in range(n):
	x = input()
	if x == x[::-1]:
		mid = x
	elif x[::-1] in a:
		ans += x
	else:
		a.append(x)
print(len(ans) * 2 + len(mid))
print(*ans, mid, *reversed(ans), sep='')


from collections import deque
(n, m) = [int(i) for i in input().split(' ')]
pals = {}
center = None
pal = deque([])
for i in range(n):
	w = input()
	rw = w[::-1]
	pw = pals.get(w)
	if w == rw:
		center = w
		continue
	if not pw:
		pals[rw] = w
	else:
		pal.appendleft(rw)
		pal.append(w)
if center:
	pal.insert(len(pal) // 2, center)
pal = ''.join(pal)
print(len(pal))
print(pal)


(n, m) = map(int, input().split())
l1 = []
l2 = []
flag = []
for i in range(100):
	flag.append(0)
for i in range(n):
	s = input()
	l1.append(s)
	t = s[::-1]
	l2.append(t)
a1 = ''
a2 = ''
for i in range(len(l1)):
	for j in range(len(l2)):
		if l2[j] == l1[i] and i != j and (flag[i] == 0) and (flag[j] == 0):
			a1 = a1 + l1[i]
			a2 = a2 + l2[j]
			flag[i] = 1
			flag[j] = 1
for i in range(len(l1)):
	if flag[i] == 0:
		a = l1[i]
		if a == a[::-1]:
			a1 = a1 + a
			break
a2 = a2[::-1]
if len(a1) == 0 and len(a2) == 0:
	print('0')
else:
	print(len(a1) + len(a2))
	print(a1 + a2)


from collections import deque as de

def isp(s):
	return s == s[::-1]
(n, m) = map(int, input().split())
di = {}
c = 0
ad = ''
for i in range(n):
	s = input()
	if (isp(s) or len(set(s)) == 1) and c == 0:
		ad = s
		c = 1
	elif s[::-1] in di:
		di[s[::-1]] = s
	else:
		di[s] = 'loda'
res = de([])
for (k, v) in di.items():
	if v != 'loda':
		res.append(k)
		res.appendleft(v)
if ad != '':
	res.insert(len(res) // 2, ad)
print(len(res) * m)
print(*res, sep='')


INF = 10 ** 10

def main():
	print = out.append
	(n, m) = get_list()
	strings = [input() for _ in range(n)]
	(p1, p2) = ([], [])
	taken = [False] * n
	for i in range(n - 1):
		if taken[i]:
			continue
		for j in range(i + 1, n):
			if taken[j]:
				continue
			if strings[i] == strings[j][::-1]:
				p1.append(strings[i])
				p2.append(strings[j])
				taken[i] = True
				taken[j] = True
				break
	p2.reverse()
	pal = ''
	for (i, ele) in enumerate(strings):
		if not taken[i] and ele == ele[::-1]:
			pal = ele
			break
	res = ''.join(p1) + pal + ''.join(p2)
	print(len(res))
	print(res)
import sys
from collections import defaultdict, Counter
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()
print(*out, sep='\n')


(n, m) = map(int, input().split(' '))
l = []
l2 = []
l3 = []
for i in range(n):
	l.append(input())
for j in range(n):
	if l[j] == 1:
		continue
	try:
		t = l.index(l[j][::-1])
	except ValueError:
		t = -1
	if t != -1:
		if t != j:
			l2.append(l[j])
		else:
			l3.append(l[j])
		l[j] = 1
		l[t] = 1
if len(l3) == 0:
	print(2 * len(l2) * m)
else:
	print(2 * len(l2) * m + m)
for i in l2:
	print(i, end='')
if len(l3) != 0:
	print(l3[0], end='')
for i in range(len(l2) - 1, -1, -1):
	print(l2[i][::-1], end='')


(n, m) = map(int, input().split())
a = []
ans = ''
subans = ''
count = 0
for i in range(n):
	s = input()
	if s[::-1] in a:
		ans += s
		count += 2
		del a[a.index(s[::-1])]
	else:
		a.append(s)
for x in a:
	if x == x[::-1]:
		count += 1
		subans = x
		break
print(count * m)
print(ans + subans + ans[::-1])


tandc = input()
l1 = tandc.split(' ')
t = int(l1[0])
c = int(l1[1])
l2 = []
lent = 0
strans = ''
str4 = ''
for x in range(0, t):
	strng = input()
	l2.append(strng)
for y in range(0, t):
	rev = l2[y][::-1]
	same = str(l2[y])
	if rev in l2 and rev != same:
		strans = strans[0:int(lent / 2)] + l2[y] + rev + strans[int(lent / 2):]
		l2.remove(rev)
		l2.append('boy')
	elif rev == str(l2[y]):
		str4 = l2[y]
	lent = len(strans)
strans = strans[0:int(lent / 2)] + str4 + strans[int(lent / 2):]
x = len(strans)
print(x)
print(strans)


(n, m) = list(map(int, input().split()))
dc = {}
arr = []
for i in range(n):
	s = input()
	dc[s] = 1
	arr += [s]
norm = 0
cent = ''
first = []
for i in range(n):
	if dc[arr[i]] != -1:
		rev = arr[i][::-1]
		if arr[i] != rev:
			if dc.get(rev, -1) != -1:
				norm += 1
				first += [arr[i]]
				dc[arr[i]] = -1
				dc[rev] = -1
		else:
			cent = arr[i]
print(norm * m * 2 + len(cent))
print(''.join(first) + cent + ''.join(first)[::-1])


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
(n, m) = map(int, readline().split())
dic2 = dict()
dic1 = dict()
for i in range(n):
	s = readline().rstrip().decode('utf-8')
	flag = 0
	for j in range(len(s) // 2):
		if s[j] != s[-(j + 1)]:
			flag = 1
			break
	if not flag:
		if s in dic2:
			dic2[s] += 1
		else:
			dic2[s] = 1
	if s in dic1:
		dic1[s] += 1
	else:
		dic1[s] = 1
dic3 = dict()
for i in dic1:
	if i[::-1] in dic3:
		dic3[i] = min(dic1[i], dic1[i[::-1]])
	else:
		dic3[i] = 0
ans = ''
for i in dic2:
	if dic2[i] == 1:
		ans = i
		break
for i in dic3:
	if dic3[i]:
		for k in range(dic3[i]):
			ans = i + ans
			ans = ans + i[::-1]
if len(ans) == 0:
	print(0)
else:
	print(len(ans))
	print(ans)


import sys, math
sys.setrecursionlimit(10 ** 8)
(n, m) = map(int, input().split())
a = []
first = ''
mid = None
for _ in range(n):
	s = input()
	a.append(s)
for i in a:
	pal = i[::-1]
	if pal != i and pal in a:
		first += i
		a[a.index(i)] = ''
		a[a.index(pal)] = ''
	elif pal == i and pal != '':
		mid = i
		a[a.index(pal)] = ''
if mid == None:
	ans = first + first[::-1]
else:
	ans = first + mid + first[::-1]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
ll = []
lr = []
for i in range(n):
	for j in range(i + 1, n):
		if l[i] == l[j][::-1]:
			ll.append(i)
			lr.append(j)
if len(ll) == 0:
	c = 0
	r = ''
	for i in l:
		if len(set(i)) == 1 or i == i[::-1]:
			if len(i) > c:
				r = i
	if r:
		print(len(r))
		print(r)
	else:
		print(0)
else:
	r = ''
	for i in range(len(ll)):
		r += l[ll[i]]
	res = ''
	c = 0
	for i in l:
		if len(set(i)) == 1 or i == i[::-1]:
			if len(i) > c:
				res = i
	r += res
	for i in range(len(lr) - 1, -1, -1):
		r += l[lr[i]]
	print(len(r))
	print(r)


(n, m) = list(map(int, input().split()))
a = [input() for i in range(n)]
fl = 1
save = ''
ans = ''
while a:
	s = a[0]
	rev_s = s[::-1]
	a.pop(0)
	if rev_s == s and fl == 1:
		save = s
		fl = 0
	if rev_s in a:
		ans += s
		a.remove(rev_s)
ans = ans + save + ans[::-1]
print(len(ans))
print(ans)


T = 0
n = 0
g = list(input().split())
T = g[0]
n = g[1]
T = int(T)
s = []
a = ''
temp = ''
ans = 0
for k in range(int(T)):
	temp = input()
	s.append(temp)
n = int(n)
hash = [0] * T
mid = []
aa = []
for i in range(0, T):
	flag = 0
	for j in range(i + 1, T):
		if s[i] == s[j][::-1] and hash[j] == 0:
			hash[j] = 1
			aa.append(s[i])
			aa.append(s[j])
			flag = 1
	if flag == 0:
		if s[i] == s[i][::-1]:
			mid.append(s[i])
			hash[i] = 1
			continue
mix = ''
s1 = ''
s2 = ''
for v in mid:
	if len(v) > ans:
		ans = len(v)
		mix = v
for i in range(0, len(aa), 2):
	if i != len(aa) - 1:
		s1 += aa[i]
		s2 = aa[i + 1] + s2
print(len(s1) * 2 + len(mix))
print(s1 + mix + s2)


(n, m) = map(int, input().split())
lst = []
pre = ''
for _ in range(n):
	s = input()
	r = s[::-1]
	try:
		idx = lst.index(r)
		lst.pop(idx)
		pre += s
	except ValueError:
		lst.append(s)
ans = pre
for s in lst:
	if s == s[::-1]:
		ans += s
		break
ans += pre[::-1]
print(len(ans))
print(ans)


import sys
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
(n, m) = read()
a = []
for i in range(n):
	a.append(input())

def checkpal(a, b):
	for i in range(len(a)):
		if a[i] != b[len(b) - 1 - i]:
			return False
	return True

def check(a):
	for i in range(len(a) // 2):
		if a[i] != a[len(a) - 1 - i]:
			return False
	return True
an = []
single = []
mark = [0] * n
for i in range(n - 1):
	if mark[i] == 1:
		continue
	for j in range(i + 1, n):
		if mark[i] == 1:
			continue
		ans = checkpal(a[i], a[j])
		if ans:
			an.append(a[i])
			an.append(a[j])
			mark[i] = 1
			mark[j] = 1
for i in range(n):
	if mark[i] == 0:
		if check(a[i]):
			mark[i] = 1
			single.append(a[i])
if len(an) == 0 and len(single) == 0:
	print(0)
else:
	l = len(an) * m
	if len(single) > 0:
		l += m
	print(l)
	for i in range(0, len(an), 2):
		print(an[i], end='')
	if len(single) > 0:
		for i in range(1):
			print(single[i], end='')
	for i in range(len(an) - 1, -1, -2):
		print(an[i], end='')
	print()


def ispalindrome(Str):
	n = len(Str)
	for i in range(len(Str)):
		if Str[i] != Str[n - i - 1]:
			return False
	return True
li = list(map(int, input().split()))
n = li[0]
m = li[1]
li = []
d = {}
for _ in range(n):
	Str = input()
	li.append(Str)
li2 = li.copy()
a = 0
k = 0
for j in range(len(li2)):
	i = li[k]
	k = k + 1
	if i[::-1] in li and li.index(i[::-1]) != li.index(i):
		h = 0
	elif ispalindrome(i) and a == 0:
		a = 1
	else:
		li.remove(i)
		k = k - 1
new_li = [0 for i in range(len(li))]
if len(li) == 0:
	print('0')
else:
	len_li = len(li)
	ans1 = len_li * m
	for i in li:
		if i[::-1] in li and li.index(i) == li.index(i[::-1]):
			s1 = i
			new_li[int(len_li / 2)] = s1
			li.remove(s1)
			break
		if (i[::-1] in li) != True:
			s1 = i
			new_li[int(len_li / 2)] = s1
			li.remove(s1)
			break
	for i in range(int(len_li / 2)):
		s1 = li[0]
		if s1[::-1] in li:
			s2 = s1[::-1]
			new_li[i] = s1
			new_li[len_li - i - 1] = s2
			li.remove(s1)
			li.remove(s2)
	ans2 = ''.join(new_li)
	print(ans1)
	print(ans2)


(n, k) = map(int, input().split())
st = set()
ans = ''
for _ in range(n):
	s = input()
	rev = ''.join(reversed(s))
	if rev in st:
		st.remove(rev)
		ans += s
	else:
		st.add(s)
for v in st:
	if v == ''.join(reversed(v)):
		print(len(ans) * 2 + k)
		print(ans + v + ''.join(reversed(ans)))
		exit()
print(len(ans) * 2)
print(ans + ''.join(reversed(ans)))


(n, m) = map(int, input().split())
st = []
arr = []
arr1 = ''
arr2 = ''
arr3 = ''
for _ in range(0, n):
	arr.append(0)
for i in range(0, n):
	s = input()
	st.append(s)
	if s == s[::-1]:
		arr[i] = 1
for i in range(0, n):
	for j in range(i + 1, n):
		if st[i] == st[j][::-1] and len(st[i]) != 0:
			arr2 += st[i]
			arr[i] = 0
			arr[j] = 0
			st[j] = ''
zz = 0
if len(arr3) // m % 2 == 0 and arr.count(1) != 0:
	CH = 0
	xyz = 0
	while CH != 1:
		CH = arr[xyz]
		xyz += 1
	zz = 1
if zz == 1:
	arr3 = st[xyz - 1]
arr1 = arr2 + arr3 + arr2[::-1]
print(len(arr1))
print(arr1)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
d = {}
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
c = 0
pa = ''
s = ''
for i in a:
	r = i[::-1]
	if i == r:
		if pa == '':
			c += m
		pa = i
		continue
	if r in d and d[r] != 0 and (d[i] != 0):
		c += 2 * m
		d[r] -= 1
		d[i] -= 1
		s += i
ans = s + pa + s[::-1]
print(c)
print(ans)


from collections import Counter
dic = Counter()
(n, lenn) = map(int, input().split())
mas = [input() for i in range(n)]
maxPol = ['']
c = dict()

def ggg(st):
	if len(maxPol[0]) < len(st):
		maxPol[0] = st
for i in Counter(mas + [i[::-1] for i in mas]).most_common():
	if i[1] > 1:
		if i[0][::-1] not in c:
			c[i[0]] = (i[1] // 4, ggg(i[0]))[0] if i[0] == i[0][::-1] and i[1] % 4 == 2 else i[1] // 2
polpol = ''.join([i * j for (i, j) in c.items()])
polpol = polpol + maxPol[0] + polpol[::-1]
print(len(polpol))
print(polpol)


import math
from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(int)
z = []
for i in range(n):
	z.append(input())
for i in range(n):
	d[z[i]] += 1
s = ''
for i in z:
	if i != i[::-1]:
		if d[i] and d[i[::-1]]:
			d[i] -= 1
			d[i[::-1]] -= 1
			s += i
	elif d[i] > 1:
		d[i] -= 2
		s += i
longest = ''
for i in z:
	if i == i[::-1]:
		if d[i]:
			if len(longest) < len(i):
				longest = i
print(len(s) * 2 + len(longest))
print(s + longest + s[::-1])


(t, l) = (int(i) for i in input().split(' '))
s = []
for ti in range(t):
	s.append(input())
a1 = []
a2 = []
marked = [False for i in range(t)]
singlestr = ''
sinflg = 1
for (idx, i) in enumerate(s):
	if marked[idx]:
		continue
	for jdx in range(idx + 1, len(s)):
		if marked[jdx]:
			continue
		if i[::-1] == s[jdx]:
			a1.append(i)
			a2.append(s[jdx])
			marked[idx] = True
			marked[jdx] = True
for (jdx, i) in enumerate(s):
	if marked[jdx]:
		continue
	if sinflg:
		if s[jdx][::-1] == s[jdx]:
			sinflg = 0
			singlestr = s[jdx]
	else:
		break
a2.reverse()
ans = ''
for i in a1:
	ans += i
ans += singlestr
for i in a2:
	ans += i
print(len(ans))
print(ans)


from collections import deque
from itertools import combinations
(n, m) = map(int, input().split())
s = [input() for i in range(n)]
ans1 = []
ans2 = deque()
center = []
used = [0 for i in range(n)]
for (i, j) in combinations(range(n), 2):
	if s[i] == s[j][::-1]:
		ans1.append(s[i])
		ans2.appendleft(s[j])
		used[i] = 1
		used[j] = 1
for i in range(n):
	if used[i] == 0:
		if s[i] == s[i][::-1]:
			center.append(s[i])
print((len(ans1) + (center != []) + len(ans2)) * m)
if ans1 or center:
	if center:
		print(*ans1, center[0], *ans2, sep='')
	else:
		print(*ans1, *ans2, sep='')


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():
	(n, m) = map(int, input().split())
	ss = []
	ssr = []
	centre = ''
	for _ in range(n):
		ss.append(input())
		ssr.append(ss[-1][::-1])
		if ss[-1] == ssr[-1]:
			centre = ss[-1]
	rset = set(ssr)
	beg = ''
	used = set()
	for s in ss:
		if s in rset and s not in used and (s != s[::-1]):
			beg += s
			used.add(s[::-1])
	res = beg + centre + beg[::-1]
	print(len(res))
	print(res)
main()


(n, t) = map(int, input().split())
d = {}
arr = []
for i in range(n):
	st = input()
	arr.append(st)
	d[st] = 1
strb = ''
strf = ''
middle = ''
for i in arr:
	o = ''.join(reversed(i))
	if o == i:
		middle = o
	elif o in d.keys():
		if d[o] > 0 and d[i] > 0:
			strb = strb + i
			strf = o + strf
			d[o] = d[o] - 1
			d[i] = d[i] - 1
qq = strb + middle + strf
print(len(qq))
print(qq)


from sys import stdin
r = stdin.readline

def is_pali(x):
	(n, ans) = (len(x), True)
	for i in range(n // 2):
		if x[i] != x[n - i - 1]:
			ans = False
			break
	return ans

def solve(A):
	(i, j, mid) = (0, 1, '')
	(seq, words) = ([], 0)
	for x in A:
		rev = x[::-1]
		pali = is_pali(x)
		if not pali and rev in A and (rev not in seq):
			words += 1
			seq.append(x)
		elif pali:
			mid = x
	n = 2 * words
	if mid != '':
		n += 1
	ans = ['' for _ in range(n)]
	for i in range(len(seq)):
		ans[i] = seq[i]
		ans[n - i - 1] = seq[i][::-1]
	for i in range(n):
		if ans[i] == '':
			ans[i] = mid
	ans2 = ''
	for x in ans:
		ans2 += x
	return ans2

def main():
	(n, sz) = map(int, r().strip().split())
	A = set()
	for i in range(n):
		A.add(r().strip())
	ans = solve(A)
	print(len(ans))
	print(ans)
main()


from collections import *
(n, m) = map(int, input().split())
arr = [input() for i in range(n)]
(mem, ans, pal) = (Counter(arr), 0, deque())
for i in range(n):
	r = ''.join(list(reversed(arr[i])))
	if arr[i].count(arr[i][0]) == m or r == arr[i]:
		if not pal:
			pal.append(arr[i])
			ans += m
		mem[arr[i]] -= 1
for i in range(n):
	r = ''.join(list(reversed(arr[i])))
	if mem[arr[i]] and mem[r] and (arr[i] != r):
		mem[arr[i]] -= 1
		mem[r] -= 1
		ans += m * 2
		pal.append(r)
		pal.appendleft(arr[i])
print(ans)
print(''.join(pal))


(n, _) = input().split()
lines = []
for _ in range(int(n)):
	lines.append(input())
length = 0
pall = []

def reverse(s):
	return ''.join(list(reversed(s)))
center = ''
for i in lines:
	if i == reverse(i):
		if lines.count(i) == 1:
			center = i
			continue
		for _ in range(int(lines.count(i) / 2)):
			pall.append(i)
	if reverse(i) in lines:
		if not i in pall and (not reverse(i) in pall):
			pall.append(i)
pall = ''.join(pall)
pall += center + reverse(pall)
print(len(pall), pall, sep='\n')


(n, m) = list(map(int, input().split()))
strings = set((input() for _ in range(n)))
backwards = set()
mid = ''
for w in strings:
	reverse = w[::-1]
	if reverse == w:
		mid = reverse
	elif reverse in strings:
		backwards.add(tuple(sorted([w, reverse])))
(forw, back) = ([], [])
for (f, b) in backwards:
	forw.insert(0, f)
	back.append(b)
word = ''.join(forw) + mid + ''.join(back)
print(len(word))
print(word)


def call(s, m):
	i = 0
	j = m - 1
	while i <= j:
		if s[i] == s[j]:
			i += 1
			j -= 1
		else:
			return False
	return True
(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(input())
ans = ''
for s in l:
	if call(s, m):
		ans = s
		break
d = {}
for i in range(len(l)):
	d[l[i]] = i
for i in d:
	x = i
	y = i[-1::-1]
	if x in d and y in d and (d[x] != -1) and (d[y] != -1) and (d[x] != d[y]):
		ans = x + ans + y
		d[x] = -1
		d[y] = -1
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
p = []
d = {}
for _ in range(n):
	s = input()
	p.append(s)
	d[s] = True
ans = ''
palindroms = []
for x in p:
	rev = x[::-1]
	d[x] = False
	if d.get(rev):
		ans += x
		d[rev] = False
	elif rev == x:
		palindroms.append(x)
size = 0
pal = ''
for x in palindroms:
	length = len(x)
	if length > size:
		pal = x
		size = length
ans = ans + pal + ans[::-1]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
l = list()
ls = list()
lc = list()
lm = list()
for i in range(n):
	x = input()
	l.append(x)
i = 0
j = 1
if l == []:
	print('')
else:
	while True:
		if i == n - 1:
			if l[i] == l[i][::-1]:
				lm.append(l[i])
			break
		if j == n:
			i += 1
			j = i + 1
			continue
		if l[i][::-1] == l[j]:
			ls.append(l[i])
			lc.append(l[j])
			j += 1
		elif l[i][::-1] == l[i]:
			lm.append(l[i])
			i += 1
			j = i + 1
		else:
			j += 1
counts = dict()
for i in lm:
	counts[i] = counts.get(i, 0) + 1
if bool(counts):
	max_ = max(counts.keys())
	s = max(counts.values())
	lm = [max_] * s
x = ''.join(ls)
y = ''.join(reversed(lc))
z = ''.join(lm)
ans = x + z + y
print(len(ans))
print(x + z + y)


def reverse_string(x):
	return x[::-1]
(n, m) = map(int, input().split())
l = []
save = ''
same = []
rest = []
more = []
for i in range(n):
	l.append(input())
	x = set(l[i])
	if len(x) == 1:
		same.append(l[i])
	else:
		rest.append(l[i])
dict = {}
dict_1 = {}
for (e, f) in enumerate(rest):
	x = reverse_string(f)
	if x not in dict:
		dict[x] = [e]
	if f in dict:
		dict[f].append(e)
for e in dict.items():
	if len(e[1]) != 1 and e[1].count(e[1][0]) != len(e[1]):
		dict_1[e[0]] = e[1]
	elif len(e[1]) != 1 and e[1].count(e[1][0]) == len(e[1]):
		save = e[0]
new = {}
for (e, f) in dict_1.items():
	if len(f) % 2 == 0:
		new[e] = len(f)
	else:
		new[e] = len(f) - 1
left = []
right = []
for (e, f) in new.items():
	x = reverse_string(e)
	left.append(e * (f // 2))
	right.append(x * (f // 2))
same_dict = {}
for e in same:
	if e not in same_dict:
		same_dict[e] = 1
	else:
		same_dict[e] = same_dict[e] + 1
more_new = {}
i = 0
for (e, f) in same_dict.items():
	if f % 2 == 0:
		more_new[e] = f
	else:
		more_new[e] = f - 1
	if f == 1 and i == 0:
		save = e
		i = 1
for (e, f) in more_new.items():
	if f != 0:
		left.append(e * (f // 2))
		right.append(e * (f // 2))
s = ''
if len(save) > 0:
	left.append(save)
for i in range(len(left)):
	s += left[i]
zx = len(right)
for i in range(1, len(right) + 1):
	s += right[zx - i]
print(len(s))
print(s)


import sys
import math
import bisect

def main():
	(n, m) = map(int, input().split())
	d = dict()
	center = None
	A = []
	for _ in range(n):
		s = input()
		t = s[::-1]
		if t in d:
			d[t] -= 1
			if d[t] == 0:
				del d[t]
			A.append(s)
		else:
			if s not in d:
				d[s] = 0
			d[s] += 1
	for k in d:
		if k == k[::-1]:
			center = k
			break
	s = ''.join(A)
	if center:
		ans = s + center + s[::-1]
	else:
		ans = s + s[::-1]
	print(len(ans))
	print(ans)
main()


line = input().split(' ')
N = int(line[0])
M = int(line[1])
strings = set([])
for i in range(N):
	strings.add(input())
deleted_strings = set([])
palindrome = ''
put_in_middle = False
longest_palindromic_string = ''
for string in strings:
	if string == ''.join(list(reversed(string))):
		if len(string) > len(longest_palindromic_string):
			longest_palindromic_string = string
for string in strings:
	if string == ''.join(list(reversed(string))):
		continue
	elif ''.join(list(reversed(string))) in strings and string not in deleted_strings:
		deleted_strings.add(''.join(list(reversed(string))))
		palindrome = string + palindrome
		palindrome = palindrome + ''.join(list(reversed(string)))
palindrome = palindrome[0:len(palindrome) // 2] + longest_palindromic_string + palindrome[len(palindrome) // 2:]
print(len(palindrome))
print(palindrome)


(n, m) = map(int, input().split())
a = []
b = []
d = []
e = 0
for i in range(n):
	s = input()
	s = list(s)
	a.append(s)
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		if a[i] == a[j][::-1]:
			if len(b) == 0:
				b.insert(0, ''.join(map(str, a[i])))
				b.insert(1, ''.join(map(str, a[j])))
			else:
				b.insert(0, ''.join(map(str, a[i])))
				b.insert(len(b), ''.join(map(str, a[j])))
	if len(a[i]) % 2 == 0:
		if a[i][:len(a[i]) // 2] == a[i][len(a[i]) // 2:][::-1]:
			e = 1
			if len(d) == 0:
				b.insert(len(b) // 2, ''.join(map(str, a[i])))
				d.append(''.join(map(str, a[i])))
	elif a[i][:len(a[i]) // 2 + 1] == a[i][len(a[i]) // 2:][::-1]:
		e = 1
		if len(d) == 0:
			b.insert(len(b) // 2, ''.join(map(str, a[i])))
			d.append(''.join(map(str, a[i])))
print(len(''.join(map(str, b))))
print(''.join(map(str, b)))


l = []
(n, m) = map(int, input().split())
for i in range(n):
	l.append(input())
marque = [False] * n
ans = []
for i in range(n):
	if not marque[i]:
		for j in range(i + 1, n):
			if l[i] == l[j][::-1]:
				ans.append(l[i])
				marque[j] == True
mil = ''
for i in range(n):
	if not marque[i] and l[i] == l[i][::-1]:
		mil = l[i]
		break
print(2 * m * len(ans) + len(mil))
for x in ans:
	print(x, end='')
print(mil, end='')
for x in ans[::-1]:
	print(x[::-1], end='')


(n, m) = (int(i) for i in input().split())
a = []
for x in range(n):
	a.append(input())
(pal1, pal2, r) = ([], [], '')
while len(a) > 0:
	y = a.pop(0)
	if y[::-1] in a:
		pal1.append(y)
		pal2.insert(0, a.pop(a.index(y[::-1])))
	elif y == y[::-1]:
		r = y
pal = ''.join(pal1) + r + ''.join(pal2)
print(len(pal))
print(pal)


def pal(s):
	return s == s[::-1]
from collections import deque
n_m = list(map(int, input().split(' ')))
(n, m) = n_m
set1 = deque()
set2 = deque()
dic = {}
for i in range(n):
	s = input()
	if s[::-1] == s:
		if s in dic:
			dic[s] += 1
		else:
			dic[s] = 1
	elif s[::-1] in set1:
		set2.append(s)
	else:
		set1.append(s)
ans_str1 = ''
ans_str2 = ''
ans_str3 = ''
if set2 or dic:
	for i in set2:
		ans_str1 += i
	for i in dic:
		ans_str2 += i * (dic[i] // 2)
		dic[i] = dic[i] % 2
	for i in dic:
		if dic[i] == 1:
			ans_str3 = i
			break
	ans = ans_str1 + ans_str2 + ans_str3 + ans_str2[::-1] + ans_str1[::-1]
	print(len(ans))
	print(ans)
else:
	print(0)


def checkPal(s):
	return s == s[::-1]

def palindromes():
	flag = True
	pal = ''
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(input().strip('\r'))
		if flag & checkPal(arr[i]):
			pal = arr[i]
			flag = False
	retval = ''
	for j in range(n):
		if arr[j][::-1] in arr[j + 1:n]:
			retval += arr[j]
	oput = retval + pal + retval[::-1]
	print(len(oput))
	print(oput)
palindromes()


s = []
(n, l) = map(int, input().split())
for i in range(n):
	s.append(input())
left = []
right = []
middle = ''
for i in range(n):
	added = False
	for j in range(i + 1, n):
		if s[i][-1] == s[j][0] and s[i] == s[j][::-1]:
			left.append(s[i])
			right.append(s[j])
			added = True
			break
	if not added and s[i] == s[i][::-1] and (len(s[i]) > len(middle)):
		middle = s[i]
right.reverse()
lp = ''.join(left) + middle + ''.join(right)
if lp:
	print(len(lp))
	print(lp)
else:
	print(0)


(x, y) = [int(z) for z in input().split()]
u = {}
a = []
for i in range(x):
	s = input()
	a.append(s)
	if s in u:
		u[s] += 1
	else:
		u[s] = 1
forw = []
back = []
final = ''
middle = ''
for i in range(x):
	s = a[i]
	if s not in u or u[s] < 1:
		continue
	r = s[::-1]
	if s == r:
		if len(middle) < len(s):
			middle = s
	elif r in u and u[r] > 0:
		forw.append(s)
		back.append(r)
		u[s] -= 1
		u[r] -= 1
for temp in forw:
	final += temp
final += middle
for temp in reversed(back):
	final += temp
print(len(final))
print(final)


from sys import stdin
(n, m) = [int(i) for i in stdin.readline().split(' ')]
s = []
for i in range(n):
	s.append(stdin.readline().strip())
t1 = ''
t2 = ''
temp = ''
for i in range(n):
	rev = s[i][::-1]
	for j in range(i + 1, n):
		if rev == s[j]:
			if s[i] != rev:
				t1 = t1 + s[i]
				t2 = rev + t2
	if s[i] == rev and s.count(s[i]) > 1:
		t1 = t1 + s[i]
		t2 = rev + t2
	elif s[i] == rev and s.count(s[i]) == 1:
		temp = rev
f = t1 + temp + t2
print(len(f))
print(f)


(n, m) = list(map(int, input().split()))
strings = [input() for i in range(n)]
from collections import defaultdict
store = defaultdict(int)
palins = []
for i in strings:
	if i == i[::-1]:
		palins.append(i)
	else:
		store[i] += 1
		store[i[::-1]] += 1
for i in store.keys():
	store[i] //= 2
ans = ''
if palins:
	ans = palins[0]
for i in store.keys():
	if store[i] > 0:
		ans = i * store[i] + ans + i[::-1] * store[i]
		store[i] = 0
		store[i[::-1]] = 0
print(len(ans))
print(ans)


import sys
input = sys.stdin.readline

def f(c, al):
	for i in al:
		if c != i:
			return False
	return True

def pal(a):
	m = len(a)
	for i in range(m):
		if a[i] != a[m - 1 - i]:
			return False
	return True

def main():
	(n, m) = map(int, input().split())
	al = []
	for i in range(n):
		cur = list(input())
		cur.pop()
		cur = ''.join((str(x) for x in cur))
		al.append(cur)
	beg = ''
	end = ''
	used = [False] * n
	for i in range(n):
		if used[i] == True:
			continue
		for j in range(i):
			if used[j] == True:
				continue
			cur = al[j][::-1]
			if al[i] == cur:
				used[i] = used[j] = True
				beg += al[i]
				end = al[j] + end
	best = ''
	for i in range(n):
		if used[i] == True:
			continue
		mid = ''
		if f(al[i][0], al[i]):
			mid += al[i]
			c = al[i][0]
			for j in range(i):
				if used[i] == True:
					continue
				if f(c, al[j]):
					mid += al[j]
			if len(mid) > len(best):
				best = mid
	if len(best) == 0:
		for i in range(n):
			if used[i] == True:
				continue
			if pal(al[i]):
				best = al[i]
				break
	beg += best
	beg += end
	print(len(beg))
	if len(beg) > 0:
		print(beg)
main()


import sys
import math
from collections import defaultdict as dd
mod = 1000000007
T = 1
for _ in range(T):
	(n, m) = map(int, input().split())
	l = []
	d = dd(int)
	m = 0
	q = ''
	for i in range(n):
		s = input()
		l.append(s)
		d[s] += 1
		if len(s) > m:
			if s == s[::-1]:
				q = s
	a = q
	for i in range(n):
		x = l[i][::-1]
		s = l[i]
		if x != s and d[x]:
			a += s[::-1]
			a = s + a
			d[s] = 0
			d[x] = 0
	print(len(a))
	print(a)


(n, m) = map(int, input().split())
z = dict()
l = []
for i in range(int(n)):
	temp = input()
	l.append(temp)
hash = [0] * n
ans = []
mid = []
for i in range(0, n):
	flag = 0
	for j in range(i + 1, n):
		if l[i] == l[j][::-1] and hash[j] == 0:
			hash[j] = 1
			ans.append(l[i])
			ans.append(l[j])
			flag = 1
	if flag == 0:
		if l[i] == l[i][::-1]:
			mid.append(l[i])
			hash[i] = 1
			continue
(front, back) = ('', '')
mix = ''
maxx = 0
for i in mid:
	if len(i) > maxx:
		maxx = len(i)
		mix = i
for i in range(0, len(ans), 2):
	if i != len(ans) - 1:
		front += ans[i]
		back = ans[i + 1] + back
print(len(front) * 2 + len(mix))
print(front + mix + back)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = list(map(int, input().split()))
li = []
str1 = ''
str2 = ''
mid = ''
for i in range(n):
	li.append(input())
for i in range(n):
	if li[i] == ''.join(reversed(li[i])):
		mid = li[i]
	for j in range(i + 1, n):
		if ''.join(reversed(li[i])) == li[j]:
			str1 = li[i] + str1
			str2 = str2 + li[j]
print(len(str1) + len(str2) + len(mid))
print(str1 + mid + str2)


(n, m) = map(int, input().split())
S = []
S1 = ''
S3 = ''
S2 = []
s1 = ''
for _ in range(n):
	x = input()
	S.append(x)
i = 0
while i < len(S):
	z = S[i][::-1]
	if S[i] == z:
		p = S[i]
		S.remove(p)
		if z in S:
			S1 = S1 + p
			S2.append(z)
			S.remove(z)
		elif len(S3) == 0:
			S3 = S3 + p
	elif z in S:
		S1 = S1 + S[i]
		S.remove(S[i])
		S2.append(z)
		S.remove(z)
	else:
		i = i + 1
s1 = s1.join(reversed(S2))
if len(S1 + S3 + s1) > 0:
	print(len(S1 + S3 + s1))
	print(S1 + S3 + s1)
else:
	print('0')


def get_palindrome(word):
	string = ''.join(reversed(word))
	return string

def palindrome(word):
	i = 0
	j = len(word) - 1
	while i <= j:
		if word[i] != word[j]:
			return False
		i += 1
		j -= 1
	return True
input_ = list(map(int, input().split()))
n = input_[0]
size = input_[1]
words = []
for i in range(n):
	words.append(input())
result = {}
mid = -1
max_len = -1
count = 0
for i in range(len(words)):
	word = words[i]
	if word not in result.values():
		pal = get_palindrome(word)
		if pal in words:
			if words.index(pal) != i:
				count += 1
				result[count] = word
				result[-count] = pal
			elif palindrome(word):
				if len(word) > max_len:
					mid = i
					max_len = len(word)
		elif palindrome(word):
			if len(word) > max_len:
				mid = i
				max_len = len(word)
new_res = []
for i in range(1, count + 1):
	new_res.append(result[i])
if mid != -1:
	new_res.append(words[mid])
for i in range(-count, 0):
	new_res.append(result[i])
latest = ''.join(new_res)
print(len(latest))
print(latest)


def main():

	def pal(s):
		for i in range(len(s) // 2):
			if s[i] != s[-1 * i - 1]:
				return False
		return True
	(n, m) = map(int, input().split())
	brick = {}
	var = []
	for i in range(n):
		s = input()
		if s in brick:
			brick[s] += 1
			brick[s[::-1]] += 1
		else:
			brick[s] = 1
			brick[s[::-1]] = 1
			var.append(s)
	part1 = ''
	central = ''
	Lc = 0
	for s in var:
		if brick[s] % 2 == 0:
			part1 += s * (brick[s] // 2)
		else:
			part1 += s * (brick[s] // 2)
			if pal(s) and len(s) > Lc:
				Lc = len(s)
				central = s
	ans = part1 + central + part1[::-1]
	print(len(ans))
	print(ans)
main()


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l += [input()]
st = ''
for i in range(n):
	if l[i] == l[i][::-1]:
		pali = l[i]
		continue
	for j in range(i + 1, n):
		if l[i] == l[j][::-1]:
			st += l[i]
			st = l[j] + st
try:
	st = st[:len(st) // 2] + pali + st[len(st) // 2:]
	print(len(st))
	print(st)
except:
	print(len(st))
	print(st)


(n, m) = map(int, input().split())
lst = []
first = ''
mid = ''
end = ''
for i in range(n):
	s = input()
	lst.append(s)
	e = s[::-1]
	if e in lst and e != s:
		first = first + s
		end = e + end
	elif e == s:
		mid = s
ans = first + mid + end
print(len(ans))
print(ans)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
(n, m) = MAP()
g = []
ans = ''
for i in range(n):
	s = input()
	if s == s[::-1]:
		if len(ans) == 0:
			ans = s
	else:
		g.append(s)
r1 = ''
r2 = ''
for i in range(len(g)):
	x = g.pop()
	y = x[::-1]
	if y in g:
		r1 = x + r1
		r2 += y
v = len(r1) + len(r2) + len(ans)
print(v)
v2 = r1 + ans + r2
print(r1 + ans + r2)


(n, m) = map(int, input().split(' '))
ar = []
s = ''
for i in range(n):
	s1 = input()
	ar.append(s1)
	if s1 == s1[::-1]:
		s = s1
		ar[i] = ''
for i in range(n):
	if ar[i][::-1] in ar:
		s = ar[i] + s
		s = s + ar[i][::-1]
		ar[i] = ''
print(len(s))
print(s)


(n, m) = map(int, input().split())
s = [input() for i in range(n)]
ans = 0
res = ''
i = 0
fl = 0
while i < len(s):
	if s[i] == s[i][::-1] and s.count(s[i]) == 1:
		if fl:
			i += 1
			continue
		res = res[:ans // 2] + s[i] + res[ans // 2:]
		ans += m
		i += 1
		fl = 1
		continue
	if s[i][::-1] in s:
		ans += 2 * m
		res = s[i] + res + s[i][::-1]
		ind = s.index(s[i][::-1])
		s.pop(ind)
		s.pop(i)
		continue
	i += 1
print(ans)
print(res)


import itertools
(n, m) = map(int, input().split())
words = [input() for _ in range(n)]
assert all((len(x) == m for x in words))
for w in words:
	if w == w[::-1]:
		output = w
		break
else:
	output = ''
for (a, b) in itertools.combinations(words, 2):
	if a == b[::-1]:
		output = a + output + b
print(len(output))
print(output)


import sys
from collections import defaultdict
input = sys.stdin.readline
(n, m) = list(map(int, input().strip().split()))
dic = defaultdict(int)
for _ in range(n):
	dic[input().strip()] += 1
(f, b, p) = ('', '', [])
done = set()
for x in dic:
	rev = x[::-1]
	if x not in done and rev not in done:
		if rev == x:
			p.append(rev * dic[rev])
			done.add(rev)
		elif rev in dic:
			mi = min(dic[x], dic[rev])
			f += x * mi
			b = rev * mi + b
			done.add(x)
			done.add(rev)
p.sort(key=lambda el: len(el), reverse=True)
if len(p) > 0:
	ans = f + p[0] + b
	if len(ans) > 0:
		print(len(ans))
		print(ans)
	else:
		print(0)
else:
	ans = f + b
	if len(ans) > 0:
		print(len(ans))
		print(ans)
	else:
		print(0)


(n, m) = map(int, input().split())
d = {}
s1 = ''
s2 = ''
pln = ''
flag = 1
for t in range(n):
	s = input()
	d[s] = 1
	if flag and s == s[::-1]:
		flag = 0
		pln = s
	elif d.get(s[::-1], 0) == 1 and s != s[::-1]:
		s1 += s
		s2 = s[::-1] + s2
print(len(s1 + pln + s2))
print(s1 + pln + s2)


(n, k) = map(int, input().split())
b = []
c = []
d = []
e = []
f = []
s = ''
for i in range(n):
	b.append(input())
	c.append(b[i][::-1])
for i in range(n):
	if b[i] == c[i]:
		f.append(b[i])
	else:
		for j in range(i + 1, n):
			if b[i] == '':
				break
			if b[i] == c[j]:
				d.append(b[i])
				e.append(c[i])
				b[i] = ''
				c[j] = ''
for i in range(len(d)):
	s = s + d[i]
if len(f) >= 1:
	s = s + f[0]
for i in range(len(e)):
	s = s + e[len(e) - i - 1]
print(len(s))
print(s)


def isPalindrome(s):
	rev = ''.join(reversed(s))
	if s == rev:
		return True
	return False
(n, l) = map(int, input().strip().split())
arr = []
for i in range(n):
	arr.append(input())
raj = list()
visited = [0] * n
for i in range(n):
	s = arr[i][::-1]
	for j in range(n):
		if arr[j] == s and visited[j] == 0 and (visited[i] == 0) and (j != i):
			raj.append((i, j))
			visited[i] = 1
			visited[j] = 1
			break
x = -1
for i in range(n):
	if visited[i] == 0:
		if isPalindrome(arr[i]):
			x = i
			break
front = ''
rear = []
for i in raj:
	front += arr[i[0]]
	rear.append(arr[i[1]])
rear = rear[::-1]
rear = ''.join(rear)
if len(raj) == 0 and x == -1:
	print(0)
elif len(raj) == 0 and x != -1:
	print(len(arr[x]))
	print(arr[x])
elif x == -1:
	andro = front + rear
	print(len(andro))
	print(andro)
else:
	andro = front + arr[x] + rear
	print(len(andro))
	print(andro)


(n, m) = map(int, input().split())
s = set()
ss = []
for i in range(n):
	t = input()
	s.add(t)
	ss.append(t)
pal = ''
ans = ''
for st in ss:
	if st not in s:
		continue
	rs = st[::-1]
	if st == rs:
		pal = st
	elif rs in s:
		ans += st
		s.remove(st)
		s.remove(rs)
ans = ans + pal + ans[::-1]
print(len(ans))
print(ans)


from sys import stdin, stdout

def ok1(a, b):
	return a == b[::-1] or a[::-1] == b

def ok2(a):
	return a == a[::-1]
t = 1
for case in range(t):
	(n, m) = map(int, stdin.readline().split())
	xx = [stdin.readline().strip() for i in range(n)]
	pair = []
	taken = [False] * n
	for i in range(n):
		for j in range(i + 1, n):
			if not taken[i] and (not taken[j]) and ok1(xx[i], xx[j]):
				pair.append((i, j))
				taken[i] = True
				taken[j] = True
	ans = ''
	for p in pair:
		ans = ans + xx[p[0]]
	mid = ''
	for i in range(n):
		if not taken[i] and ok2(xx[i]) and (len(mid) < len(xx[i])):
			mid = xx[i]
	ans = ans + mid
	for p in pair[::-1]:
		ans = ans + xx[p[1]]
	stdout.write('{}\n{}'.format(len(ans), ans))


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
x = ''
y = ''
c = ''
b = []
while a != []:
	z = a.pop()
	w = z[::-1]
	if w in a:
		x = x + z
		y = w + y
		a.remove(w)
	elif z[:m // 2] == z[m // 2:][::-1] and m % 2 == 0:
		c = z
	elif z[:m // 2] == z[m // 2 + 1:][::-1] and m % 2 != 0:
		c = z
ans = x + c + y
print(len(ans))
print(ans)


(t, n) = map(int, input().split())
a = []

def isPalindrome(s):
	if s == s[::-1]:
		return True
	return False
res = ''
flag = 0
for i in range(t):
	s = input()
	a.append(s)
	if isPalindrome(s):
		if flag != 1:
			temp = len(res) // 2
			res = res[:temp] + s + res[temp:]
			flag = 1
			a.remove(s)
	elif s[::-1] in a:
		res = s + res + s[::-1]
		temp = s[::-1]
		a.remove(s)
		a.remove(temp)
print(len(res))
print(res)


def isPalindrome(s):
	for i in range(len(s) // 2):
		if s[i] != s[len(s) - 1 - i]:
			return False
	return True
(n, m) = [int(i) for i in input().strip().split()]
l = []
d = {}
for i in range(n):
	l.append(input().strip())
	d[l[i]] = 1
lp = ''
added = {}
for i in range(n):
	if added.get(l[i], -1) == -1:
		if isPalindrome(l[i]):
			if len(l[i]) > len(lp):
				lp = l[i]
		elif d.get(l[i][::-1], -1) == 1:
			added[l[i][::-1]] = 1
l = list(added.keys())
result = ''.join([i for i in l]) + lp + ''.join([l[i][::-1] for i in range(len(l) - 1, -1, -1)])
print(len(result))
print(result)


(n, m) = map(int, input().split())
(nonpals, pals) = ({}, {})
for _ in range(n):
	s = input()
	if s == s[::-1]:
		pals[s] = pals.get(s, 0) + 1
	else:
		nonpals[s] = nonpals.get(s, 0) + 1
result = center = ''
for (s, c) in nonpals.items():
	rs = s[::-1]
	if s < rs:
		for _ in range(min(c, nonpals.get(rs, 0))):
			result += s
for (s, c) in pals.items():
	for _ in range(c >> 1):
		result += s
	if c % 2 == 1 and (not center):
		center = s
result = result + center + result[::-1]
print(len(result))
print(result)


import sys
import bisect
from collections import deque

def no():
	print('NO')

def dist(z, c):
	return (z[0] - c[0]) * (z[0] - c[0]) + (z[1] - c[1]) * (z[1] - c[1])

def vec(z, c):
	return z[0] * c[1] - z[1] * c[0]

def pro(z, c):
	return [z[0] - c[0], z[1] - c[1]]

def main():

	def pro(s):
		chars = list(s)
		for i in range(len(s) // 2):
			tmp = chars[i]
			chars[i] = chars[len(s) - i - 1]
			chars[len(s) - i - 1] = tmp
		return ''.join(chars)
	q = []
	res = ''
	ans = ''
	for i in range(n):
		q.append(sys.stdin.readline())
	w = []
	for i in range(n):
		for o in range(i + 1, n):
			if q[i] not in w and q[o] not in w:
				fl = 0
				for k in range(m):
					if fl:
						break
					if q[i][k] != q[o][m - k - 1]:
						fl = 1
				if fl == 0:
					res += str(q[i][:-1])
					w.append(q[i])
					w.append(q[o])
	for i in range(n):
		fl = 1
		if q[i] not in w:
			for o in range(m):
				if q[i][o] != q[i][m - 1 - o]:
					fl = 0
			if fl == 1:
				ans = q[i][:-1]
				break
	print(2 * len(res) + len(ans))
	print(res + ans + pro(res), end='')
(n, m) = [int(i) for i in sys.stdin.readline().split()]
for i in range(1):
	main()


import sys, itertools, math
(n, m) = [int(i) for i in sys.stdin.readline().strip().split(' ')]
S = set()
p = ''
for _ in range(n):
	s = sys.stdin.readline().strip()
	S.add(s)
	if s == s[::-1] and p == '':
		p = s
while S:
	s = S.pop()
	if s[::-1] in S:
		p = s + p + s[::-1]
		S.remove(s[::-1])
print(len(p))
print(p)


(n, m) = [int(x) for x in input().split()]
s = []
for i in range(n):
	s.append(input())
first = []
second = []
p = []
ans = ''
for i in range(n):
	if s[i] != '$':
		if s[i] == s[i][::-1]:
			p.append(s[i])
			s[i] = '$'
			continue
		for j in range(i + 1, n):
			if s[j] != '$' and s[i] == s[j][::-1]:
				ans = s[i] + ans + s[j]
				s[i] = '$'
				s[j] = '$'
				break
if len(p) > 0:
	ans = ans[:len(ans) // 2] + p[0] + ans[len(ans) // 2:]
if len(ans):
	print(len(ans))
	print(ans)
else:
	print(0)


(n, m) = map(int, input().split())
s = [0] * n
ans = []
pal = ''
for i in range(n):
	s[i] = input()
for i in range(n):
	if s[i][::-1] in s[i + 1:]:
		ans.append(s[i])
	elif pal == '' and s[i] == s[i][::-1]:
		pal = s[i]
print(2 * m * len(ans) + len(pal))
print(''.join(ans) + pal + ''.join(map(lambda x: x[::-1], reversed(ans))))


from collections import defaultdict
inp = lambda : map(int, input().split(' '))
(n, m) = inp()
strings = []
d = defaultdict(bool)
for i in range(n):
	strings.append(input())
	d[strings[i]] = True
is_pal = lambda x: x[:len(x) // 2] == x[::-1][:len(x) // 2]
final_string_first = ''
final_string_second = ''
middle_pal = ''
for s in strings:
	reverse_string = s[::-1]
	if d[reverse_string] and s != reverse_string:
		final_string_first += s
		final_string_second += reverse_string
		d[s] = False
	elif is_pal(s):
		middle_pal = s
ret = ''.join([final_string_second[i * m:i * m + m] for i in range(0, len(final_string_second) // m)[::-1]])
res = final_string_first + middle_pal + ret
print(str(len(res)) + '\n' + res)


(n, m) = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
	s = input()
	a.append(s)
for i in range(n):
	k = a[i]
	o = len(b)
	for j in range(n):
		p = a[j]
		p = p[::-1]
		if p == k and j != i:
			b.append(p)
			a[j] = ''
			break
	if len(b) > o:
		a[i] = ''
for i in range(n):
	if a[i] != '':
		p = a[i]
		q = p[::-1]
		if p == q:
			c.append(p)
			break
s = ''
for i in range(len(b)):
	f = b[i]
	s += f
d = s[::-1]
if len(c) > 0:
	s += c[0]
s += d
print(len(s))
print(s)


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)
		elif 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()


def solve(words):
	(res1, res2) = ([], [])
	mid_w = ''
	while words:
		w1 = words.pop(0)
		w2 = w1[::-1]
		if w2 in words:
			words.remove(w2)
			res1.append(w1)
			res2.append(w2)
		elif w1 == w2:
			mid_w = w1
	res = ''.join(res1 + [mid_w] + res2[::-1])
	print(len(res))
	print(res)
(m, n) = map(int, input().split())
words = []
for _ in range(m):
	words.append(input())
solve(words)


(n, m) = map(int, input().split())
included = [False] * n
pl = 0
d = []
special = ''
specFound = False
strs = [''] * n
for i in range(n):
	strs[i] = input()
for i in range(n):
	for j in range(n):
		if strs[j] == strs[i][::-1] and i != j and (not included[i]) and (not included[j]):
			pl += 2 * m
			included[i] = included[j] = True
			d.append(strs[i])
			break
		if not specFound and strs[j] == strs[i][::-1] and (i == j):
			specFound = True
			special = strs[j]
			pl += m
			break
print(pl)
if pl > 0:
	for i in d:
		print(i, end='')
	if specFound:
		print(special, end='')
	for i in d[::-1]:
		print(i[::-1], end='')
print()


(a, b) = map(int, input().split())
l = []
l1 = []
l2 = []
l3 = []
for i in range(a):
	x = input()
	l.append(x)
for i in range(a):
	rev = l[i][::-1]
	if rev == l[i]:
		l3.append(rev)
	elif rev in l:
		if rev in l1 or rev in l2:
			continue
		else:
			l1.append(l[i])
			l2.append(rev)
x = len(l1)
y = len(l3)
if y == 0:
	print((x + x) * b)
else:
	print(2 * x * b + b)
if x != 0 or y != 0:
	for i in range(x):
		print(l1[i], end='')
	if y != 0:
		print(l3[0], end='')
	while x:
		print(l2[x - 1], end='')
		x -= 1


(n, m) = 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]
	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)
	elif 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)


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
	elif 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)


from sys import stdin, stdout
(n, m) = map(int, input().split())
strs = []
in_str = [False for i in range(n)]
un_pal = False

def pal(a, b, size):
	for j in range(size):
		if a[j] != b[size - j - 1]:
			return False
	return True
result = 0
palindrome_left = ''
palindrome_right = ''
middle = ''
for i in range(n):
	strs.append(stdin.readline()[:-1])
for i in range(n):
	if not in_str[i]:
		coupled = False
		for j in range(i + 1, n):
			if not in_str[j]:
				if pal(strs[i], strs[j], m):
					in_str[i] = True
					in_str[j] = True
					palindrome_left = strs[i] + palindrome_left
					palindrome_right = palindrome_right + strs[j]
					coupled = True
					result += 2 * m
					break
		if not coupled and (not un_pal) and pal(strs[i][:int(m / 2)], strs[i][int((m + 1) / 2):], int(m / 2)):
			un_pal = True
			middle = strs[i]
			result += m
print(result)
print(palindrome_left + middle + palindrome_right)


(n, m) = map(int, input().split())
s = []
for i in range(int(n)):
	s.append(str(input()))
palindrom = ''
for i in range(len(s)):
	if s[i] == s[i][::-1]:
		palindrom = s[i]
		s[i] = ''
for i in range(len(s)):
	for j in range(len(s)):
		if s[i] == s[j][::-1]:
			palindrom = s[i] + palindrom + s[j]
			s[i] = ''
			s[j] = ''
print(len(palindrom))
print(palindrom)


(n, m) = map(int, input().split())
a = [''] * n
for i in range(n):
	a[i] = input()
s = ''
z = ''
p = set()
for i in range(n):
	for j in range(i, n):
		if i != j and i not in p and (j not in p):
			if a[i] == a[j][::-1]:
				s += a[i]
				p.add(i)
				p.add(j)
for i in range(n):
	if i not in p and a[i] == a[i][::-1]:
		z = a[i]
		break
print(len(s) * 2 + len(z))
print(s + z + s[::-1])


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	a.append(input())
b = []
c = []
d = []
for i in range(n - 1):
	for j in range(i + 1, n):
		if a[j][::-1] == a[i]:
			b.append(a[i])
			c.append(a[j])
		elif a[i] == a[i][::-1]:
			d.append(a[i])
if a[-1] == a[-1][::-1]:
	d.append(a[-1])
if len(b) == 0:
	if len(d) == 0:
		print(0)
	else:
		print(len(d[0]))
		print(d[0])
else:
	z = ''
	for i in range(len(b)):
		z += b[i]
	if len(d) != 0:
		z += d[0]
	for i in range(len(c) - 1, -1, -1):
		z += c[i]
	print(len(z))
	print(z)


(n, m) = map(int, input().split())
strSet = set()
l = []
r = []
longPal = ''
for _ in range(n):
	s = input()
	t = s[::-1]
	if s == t and len(s) > len(longPal):
		longPal = s
	if t in strSet:
		l.append(s)
		r.append(t)
		strSet.remove(t)
	else:
		strSet.add(s)
r.reverse()
ls = ''.join(l)
rs = ''.join(r)
ans = ''.join([ls, longPal, rs])
print(len(ans))
print(ans)


import math
(n, m) = map(int, input().split())
strs = []
for i in range(n):
	strs.append(input().replace('\r', ''))
dic = {}
for i in strs:
	dic[i] = 1
ans = ''
ex = ''
for i in strs:
	if dic[i] > 0 and i[::-1] in dic and (i[::-1] != i):
		ans += i
		dic[i[::-1]] -= 1
	elif i[::-1] == i and ex == '':
		ex = i
fin = ans + ex + ans[::-1]
print(len(fin))
if len(fin) != 0:
	for i in fin:
		print(i, end='')


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
(n, m) = sp()
a2 = ''
arr = list()
palin = ''
for i in range(n):
	temp = data()
	if temp[::-1] in arr:
		a2 = temp + a2 + temp[::-1]
		arr.remove(temp[::-1])
	else:
		arr.append(temp)
for i in arr:
	if i[::-1] == i:
		palin = i
a2 = a2[:len(a2) // 2] + palin + a2[len(a2) // 2:]
print(len(a2))
print(a2)


(s, n) = map(int, input().split())
l = []
for i in range(s):
	l.append(input())
j = 0
front = []
end = []
mid = ''
while len(l) != 0:
	k = l[j]
	if k == k[::-1]:
		mid = k
		l.remove(k)
	if j > len(l):
		j = j % len(l)
	else:
		p = k[::-1]
		if p in l and k in l:
			front.append(k)
			end.append(p)
			l.remove(k)
			l.remove(p)
		elif p not in l and k in l:
			l.remove(k)
y = len(front) + len(end) + 1
r = ['0'] * y
(k1, h) = (0, -1)
while len(front) > 0 and len(end) > 0 and (k1 < len(front)):
	r[k1] = front[k1]
	r[h] = end[k1]
	h -= 1
	k1 += 1
if mid != '':
	e = len(r) // 2
	r[e] = mid
p1 = [i for i in r if i != '0']
print(len(p1) * n)
print(''.join(p1))


a = []
b = []
c = []
(n, m) = map(int, input().split())
lst = []
for j in range(n):
	lst.append(input())
for k in range(len(lst)):
	temp = lst[k][::-1]
	try:
		if temp in lst[k + 1:]:
			a.append(lst[k])
			b.append(temp)
		elif lst[k] == temp:
			c.append(temp)
	except:
		if lst[k] == temp:
			c.append(temp)
b.reverse()
if len(c):
	result = ''.join(a) + ''.join(c[0]) + ''.join(b)
else:
	result = ''.join(a) + ''.join(b)
print(len(result))
print(result)


from collections import Counter, defaultdict

def check(a, b):
	n = len(a)
	for i in range(n):
		if a[i] != b[n - i - 1]:
			return False
	return True

def ispallin(a):
	n = len(a)
	for i in range(n):
		if a[i] != a[n - i - 1]:
			return False
	return True
(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(input())
a1 = []
a2 = []
for i in range(n - 1):
	for j in range(i + 1, n):
		if check(l[i], l[j]) == True:
			a1.append(l[i])
			a2.append(l[j])
a3 = []
for i in range(n):
	if len(set(l[i])) == 1 or ispallin(l[i]):
		a3.append(l[i])
ans = ''
for i in range(len(a1)):
	ans += a1[i]
if len(a3) > 1:
	ans += a3[0]
else:
	for i in range(len(a3)):
		ans += a3[i]
for i in range(len(a2) - 1, -1, -1):
	ans += a2[i]
if len(ans) == 0:
	print(0)
	print()
else:
	print(len(ans))
	print(ans)


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
gg1 = 0
gg2 = 0
x1 = ''
x2 = ''
x3 = ''
for i in range(n):
	if a[i] == a[i][::-1] and gg1 == 0:
		gg1 = 1
		x2 += a[i]
	else:
		for j in range(i + 1, n):
			if a[i] == a[j][::-1]:
				gg2 += 1
				x1 += a[i]
				x3 += a[j][::-1]
				break
x3 = x3[::-1]
if 0:
	print(2 * m * gg2)
	print(x1 + x3)
else:
	print((2 * gg2 + gg1) * m)
	print(x1 + x2 + x3)


def main():
	(n, m) = map(int, input().split())
	pal = []
	npal = {}
	for x in range(n):
		s = input()
		if s[::-1] == s:
			pal.append(s)
		elif s[::-1] in npal:
			npal[s[::-1]] += 1
		else:
			npal[s] = 1
	end = []
	start = ''
	for item in npal:
		if npal[item] == 2:
			start += item
			end.append(item[::-1])
	to = ''
	end = end[::-1]
	for item in end:
		to += item
	end = to
	n = len(start) + len(end)
	if len(pal) > 0:
		n += len(pal[0])
		print(n)
		print(start + pal[0] + end)
	else:
		print(len(start) + len(end))
		if n > 0:
			print(start + end)
		else:
			print()
main()


(n, m) = map(int, input().split())
a = []
b = []
for _ in range(n):
	s = input()
	t = ''
	for i in range(m)[::-1]:
		t += s[i]
	a.append(s)
	b.append(t)
cnt = [0 for _ in range(n)]
c = []
d = []
e = []
for i in range(n):
	for j in range(i + 1, n):
		if a[i] == b[j]:
			c.append(a[i])
			d.append(b[i])
	if a[i] == b[i]:
		e.append(a[i])
print((len(c) * 2 + int(e != [])) * m)
ans = ''
d.reverse()
for x in c:
	ans += x
if e != []:
	ans += e[0]
for x in d:
	ans += x
print(ans)


def main():
	(n, m) = map(int, input().split())
	d = {}
	arr = []
	temp = [True] * n
	l = 0
	p1 = ''
	s1 = ''
	s2 = []
	for i in range(0, n):
		string = input()
		arr.append(string)
		d[string] = i
	for i in range(0, n):
		if arr[i] == arr[i][::-1] and temp[i] == True:
			if len(p1) == 0:
				l += m
				p1 += arr[i]
			del d[arr[i]]
			temp[i] = False
		elif arr[i][::-1] in d:
			if temp[i] == True and temp[d[arr[i][::-1]]] == True:
				l += 2 * m
				s1 += arr[i]
				s2.append(arr[i][::-1])
				temp[i] = False
				temp[d[arr[i][::-1]]] = False
				del d[arr[i]]
				del d[arr[i][::-1]]
		elif temp[i] == True:
			temp[i] = False
			del d[arr[i]]
	r2 = ''
	while len(s2) > 0:
		r2 += s2.pop()
	res = s1 + p1 + r2
	if len(res) == 0:
		print(0)
	else:
		print(len(res))
		print(res)
main()


(n, m) = map(int, input().split())
words = [input() for _ in range(n)]
s = set(words)
doubles = []
ones = []
for word in words:
	if word[::-1] in s:
		if word[::-1] == word:
			ones.append(word)
			s.remove(word)
		else:
			doubles.append(word)
			s.remove(word)
			s.remove(word[::-1])
center = ''
if len(ones) > 0:
	center = ones[0]
result = ''.join(doubles) + center + ''.join(doubles)[::-1]
print(len(result))
print(result)


(n, m) = map(int, input().split())
s = []
was = set()
for i in range(n):
	s.append(input())
answ1 = []
answ2 = []
for i in range(n):
	for j in range(n):
		if i not in was and j not in was and (i != j) and (s[i] == s[j][::-1]):
			was.add(j)
			was.add(i)
			answ1.append(s[i])
			answ2.append(s[j])
			break
for i in range(n):
	if i not in was and s[i] == s[i][::-1]:
		answ1.append(s[i])
		break
answ = ''.join(answ1) + ''.join(answ2[::-1])
print(len(answ))
print(answ)


from typing import List
import collections
import bisect
import itertools
import functools
from collections import defaultdict
import collections
from fractions import gcd
import heapq
from math import ceil, sqrt
import sys
sys.setrecursionlimit(50000)
from collections import defaultdict
(n, m) = list(map(int, input().split()))
words = []
for _ in range(n):
	s = input()
	words.append(s)
counter = collections.Counter(words)
rev_counts = {}
palindrome_counts = defaultdict(int)
seen = set()
for (s, count) in counter.items():
	rev = s[::-1]
	if rev == s:
		palindrome_counts[s] = count
	elif s not in seen and rev in counter:
		rev_counts[s] = min(counter[rev], count)
		seen.add(s)
		seen.add(rev)
ret = collections.deque()
for (s, count) in palindrome_counts.items():
	if not ret and count % 2 == 1:
		ret.append(s)
for (s, count) in palindrome_counts.items():
	for _ in range(count // 2):
		ret.appendleft(s)
		ret.append(s)
for (s, count) in rev_counts.items():
	for _ in range(count):
		ret.appendleft(s)
		ret.append(s[::-1])
result = ''.join(ret)
print(len(result))
print(result)


(n, m) = map(int, input().split())
dic = {}
for _ in range(n):
	s = input()
	if s[::-1] in dic.keys():
		dic[s[::-1]] += 1
	elif s in dic.keys():
		dic[s] += 1
	else:
		dic[s] = 1
s1 = ''
s2 = ''
maxs = ''
for key in dic.keys():
	s1 += key * (dic[key] // 2)
	s2 = key[::-1] * (dic[key] // 2) + s2
	if dic[key] % 2 != 0 and key == key[::-1] and (len(key) > len(maxs)):
		maxs = key
print(len(s1) + len(s2) + len(maxs))
print(s1 + maxs + s2)


(n, l) = map(int, input().split())
arr = []
for z in range(n):
	arr.append(input())
own = []
for i in arr:
	if i == i[::-1]:
		own.append(i)
max = ''
for i in own:
	if len(i) > len(max):
		max = i
double = []
for i in range(len(arr)):
	f = arr[i]
	for j in range(i + 1, len(arr)):
		s = arr[j]
		if f == s[::-1]:
			double.append(f)
ans = ''
for i in double:
	ans += i
secondhalf = ans[::-1]
ans += max
ans += secondhalf
print(len(ans))
print(ans)


from collections import defaultdict
(n, m) = map(int, input().split())
l1 = []
for i in range(n):
	l1.append([i for i in input()])
l2 = l1[:]
reverse = []
for j in l1:
	l = []
	for i in reversed(j):
		l.append(i)
	reverse.append(l)
counter = 0
same = 0
(a, b, c) = ([], [], [])
for j in range(len(reverse)):
	for i in range(len(l1)):
		if l1[i] == reverse[j]:
			l3 = l1[i][:]
			l3.reverse()
			if l1[i] == l3:
				if same == 0:
					same += 1
					c.append(''.join(l1[i]))
					l1[i] = 0
					break
			else:
				b.append(''.join(l1[i]))
				l1[i] = 0
				a.append(''.join(l2[j]))
				break
output = [0] * (len(a) + len(c))
sq = 0
dict1 = defaultdict(list)
for ij in range(len(a)):
	if b[ij] not in dict1:
		dict1[b[ij]] = 1
	if a[ij] != b[ij] and a[ij] not in dict1:
		output[sq] = a[ij]
		output[-sq - 1] = b[ij]
		sq += 1
if same == 1:
	output[len(output) // 2] = c[0]
if len(output) > 0:
	print(len(output) * m)
	print(''.join(output))
else:
	print(0)


(n, m) = map(int, input().split())
a = []
b = []
cnt = 0
ok = 0
for i in range(n):
	tmp = input()
	if tmp[::-1] in a:
		b.append(2)
		cnt += 2
	elif tmp == tmp[::-1]:
		b.append(1)
		ok = 1
	else:
		b.append(0)
	a.append(tmp)
cnt += ok
s = ['' for i in range(cnt)]
j = 0
for i in range(n):
	if b[i] == 1 and ok:
		ok = 0
		s[cnt // 2] = a[i]
	elif b[i] == 2:
		s[j] = a[i]
		s[cnt - 1 - j] = a[i][::-1]
		j += 1
s = ''.join(s)
print(len(s))
print(s)


(n, m) = map(int, input().split())
array = []
for i in range(n):
	s = input()
	array.append(s)
a = []
b = []
r = []
for i in range(n):
	if array[i][::-1] == array[i]:
		r.append(array[i])
		continue
	for k in range(i + 1, n):
		if array[i][::-1] == array[k]:
			a.append(array[i])
			b.append(array[k])
			break
s = ''
for i in range(len(a)):
	s += a[i]
if len(r) != 0:
	s += r[0]
for i in range(len(b) - 1, -1, -1):
	s += b[i]
print(len(s))
print(s)


(n, m) = map(int, input().split())
strings = {input() for _ in range(n)}
pali = ''
left = []
used = set()
for s in strings:
	if s == s[::-1]:
		pali = s
	elif s not in used and s[::-1] in strings:
		left.append(s)
		used.add(s)
		used.add(s[::-1])
left = ''.join(left)
ans = left + pali + left[::-1]
print(len(ans))
print(ans)


def isPalindromic(s):
	if s == ''.join(reversed(s)):
		return 1
	return 0
(n, m) = map(int, input().split())
ans = 0
l = [input() for i in range(n)]
f = [0] * n
front = ''
back = ''
mid = ''
for i in range(n):
	found = 0
	for j in range(i + 1, n):
		if f[j] == 0:
			if ''.join(reversed(l[j])) == l[i]:
				f[j] = 1
				ans += 2 * m
				front += l[i]
				back = l[j] + back
				found = 1
				break
	if found == 0:
		if isPalindromic(l[i]):
			mid = l[i]
print(ans + len(mid))
print(front + mid + back)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
m = []
r = []
t = []
f = 0
c = 0
for j in range(len(l)):
	s = l[j]
	for k in range(len(l)):
		if j == k:
			if s[::-1] == l[k] and f == 0:
				t = [l[k], '']
				c = c + len(s)
				f = 1
		elif j not in r and k not in r:
			if s[::-1] == l[k]:
				m.append([s, l[k]])
				c = c + 2 * len(s)
				r.append(j)
				r.append(k)
f = []
s = []
if len(t) != 0:
	m.append(t)
for j in range(len(m)):
	f.append(m[j][0])
	s.append(m[j][1])
y = ''
for j in range(len(s) - 1, -1, -1):
	y = y + s[j]
print(c)
print(''.join(f) + y)


(n, m) = list(map(int, input().split()))
words = []
for _ in range(n):
	s = input()
	words.append(s)
mid = []
pal = []
d = {}
for word in words:
	if word not in d:
		d[word] = 0
	d[word] += 1
for word in words:
	if word == word[::-1]:
		mid.append(word)
	elif word[::-1] in words:
		pal.append(word)
start = []
end = []
for item in pal:
	if d[item] > 0 and d[item[::-1]] > 0:
		start.append(item)
		end.append(item[::-1])
		d[item] -= 1
		d[item[::-1]] -= 1
if len(mid) != 0:
	mid = sorted(mid, key=lambda m: d[m], reverse=True)
	mid = [mid[0] * mid.count(mid[0])]
end.reverse()
res = start + mid + end
res = ''.join(res)
print(len(res))
print(res)


from sys import stdin
input = lambda : stdin.readline().strip()
from collections import deque as d

def palin(x):
	if x == x[::-1]:
		return True
(n, m) = map(int, input().split())
a = d([])
p = d([])
s = ''
for _ in range(n):
	x = input()
	if x[::-1] in a:
		s += x
	elif palin(x) and x not in a:
		p.append(x)
	else:
		a.append(x)
if p:
	s += p[0] + s[::-1]
else:
	s += s[::-1]
print(len(s))
print(s)


(t, b) = map(int, input().split())
l = []
l_1 = ''
l_t = ''
ty = 0
flag = 0
for _ in range(t):
	s = input()
	s_t = s[::-1]
	if s_t in l:
		l_1 += s
		ty += b + b
	if s == s_t and (not flag):
		l_t = s
		ty += b
		flag += 1
	l.append(s)
print(ty)
print(l_1 + l_t + l_1[::-1])


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
from io import BytesIO, IOBase

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = mi()
res = ''
pal = ''
l = ['' for i in range(n)]
for i in range(n):
	l[i] = input()
for i in range(n - 1):
	if l[i] == l[i][::-1]:
		pal = l[i]
		continue
	for j in range(i + 1, n):
		if l[j][::-1] == l[i]:
			res = l[i] + res + l[j]
if l[-1] == l[-1][::-1]:
	pal = l[-1]
res1 = res[:len(res) // 2] + pal + res[len(res) // 2:]
print(len(res1))
print(res1)


def isPalindrom(s):
	l = len(s)
	for i in range(l // 2):
		if s[i] != s[l - 1 - i]:
			return False
	return True
(n, length) = [int(i) for i in input().split(' ')]
strs = dict()
for i in range(n):
	strs[input()] = False
longest = []
middle = False
for s in strs:
	if isPalindrom(s):
		if not middle:
			middle = True
			longest.insert(len(longest) // 2, s)
	elif not strs[s] and s[::-1] in strs:
		longest.insert(0, s)
		longest.append(s[::-1])
		strs[s] = True
		strs[s[::-1]] = True
out = ''
for s in longest:
	out += s
print(len(out))
print(out)


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	s = input()
	if s in d:
		d[s] += 1
	else:
		d[s] = 1
lis = []
c = 0
for i in d:
	k = i[::-1]
	if k in d:
		if i != k:
			mi = min(d[i], d[k])
			d[i] -= mi
			d[k] -= mi
			for j in range(mi):
				lis.insert(0, i)
				lis.append(k)
		else:
			while d[i] >= 2:
				d[i] -= 2
				lis.insert(0, i)
				lis.append(i)
			if d[i] == 1 and c == 0:
				lis.insert(len(lis) // 2, i)
				c += 1
aaa = ''.join(lis)
print(len(aaa))
print(aaa)


(n, m) = map(int, input().split())
a = []
cen = ''
b = ''
for i in range(n):
	s = input()
	r = s[::-1]
	ss = list(s)
	if len(ss) != len(set(ss)) and len(set(ss)) == 1:
		cen = s
	if s == s[::-1]:
		cen = s
	if r in a:
		p = s + r
		b = b[:len(b) // 2] + p + b[len(b) // 2:]
	else:
		a.append(s)
if cen != '':
	b = b[:len(b) // 2] + cen + b[len(b) // 2:]
print(len(b))
print(b)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))
mo = 1000000007
(n, m) = value()
pair = defaultdict(int)
single1 = defaultdict(int)
single2 = defaultdict(int)
for i in range(n):
	s = input()
	r = ''.join(reversed(s))
	if s == r:
		if len(s) % 2 == 0:
			single2[s] += 1
		else:
			single1[s] += 1
	else:
		pair[s] += 1
ans = ''
ln = len(single1.keys())
temp1 = ''
if ln > 0:
	for i in single1:
		val = single1[i] // 2
		if single1[i] % 2 != 0 and len(i) > len(temp1):
			temp1 = i
		ans = i * val + ans + i * val
ln = len(single2.keys())
temp2 = ''
if ln > 0:
	for i in single2:
		val = single2[i] // 2
		if single2[i] % 2 != 0 and len(i) > len(temp2):
			temp2 = i
		ans = i * val + ans + i * val
ln = len(pair.keys())
if ln > 0:
	for i in pair:
		r = ''.join(reversed(i))
		if r in pair:
			mn = min(pair[i], pair[r])
			ans = i * mn + ans + r * mn
			pair[i] -= mn
			pair[r] -= mn
lc = len(ans)
if lc % 2 == 0:
	lc = lc // 2 - 1
else:
	lc = lc // 2
if len(temp1) > len(temp2):
	ans = ans[:lc + 1] + temp1 + ans[lc + 1:]
else:
	ans = ans[:lc + 1] + temp2 + ans[lc + 1:]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
A = []
res = []
center = ''
for i in range(n):
	curr = input()
	check = False
	for j in range(len(A) - 1, -1, -1):
		if curr == A[j][::-1]:
			if center == A[j]:
				center = ''
			res.append(A.pop(j))
			check = True
			break
	if not check:
		A.append(curr)
		for j in range(int(m / 2) + 1):
			if curr[j] != curr[-j - 1]:
				check = True
	if not check:
		center = curr
for item in res:
	center = item + center + item[::-1]
print(len(center))
print(center)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	string = input()
	l.append(string)
cnt = 0
check = []
temp = []
aaa = []
bbb = []
for i in l:
	if i not in check:
		if i[::-1] in l:
			if i != i[::-1]:
				cnt += len(i) * 2
				check.append(i)
				check.append(i[::-1])
				aaa.append(i)
				bbb.append(i[::-1])
			elif len(temp) == 0:
				temp.append(i)
				cnt += len(i)
			elif len(i) > len(temp[0]):
				cnt -= len(temp[0])
				temp = []
				temp.append(i)
				cnt += len(i)
bbb.reverse()
print(cnt)
for i in aaa:
	print(i, end='')
if len(temp) != 0:
	print(temp[0], end='')
for i in bbb:
	print(i, end='')


import sys
words = sys.stdin.read().split()
(N, L) = map(int, words[:2])
words = words[2:]
isPal = ''
vis = []
left = ''
right = ''
for i in words:
	if i == i[::-1]:
		isPal = i
	elif i not in vis and i[::-1] in words:
		left += i
		right = i[::-1] + right
		vis.append(i[::-1])
print(len(left + isPal + right))
print(left + isPal + right)


(n, m) = map(int, input().split())
arr = []
res = ''
for i in range(n):
	s = input()
	arr.append(s)
q = [0] * n
for i in range(n):
	a = str(arr[i])
	for j in range(i + 1, n):
		if a == str(arr[j])[::-1]:
			res += a
			q[i] = 1
			q[j] = 1
			break
ans = ''
for i in range(n):
	if str(arr[i]) == str(arr[i][::-1]) and q[i] != 1:
		ans += str(arr[i])
		break
if len(res) != 0 or len(ans) != 0:
	print(2 * len(res) + len(ans))
	print(res + ans + res[::-1])
else:
	print(0)


def xaudao(st):
	ch = []
	n = len(st)
	for i in range(n - 1, -1, -1):
		ch.append(st[i])
	delim = ''
	return delim.join(ch)
mydict = {}
s = input()
b = s.split(' ')
n = int(b[0])
m = int(b[1])
a = []
dau = []
cuoi = []
d = []
id = 0
giua = ''
for i in range(0, n):
	d.append(0)
for i in range(0, n):
	st = input()
	a.append(st)
	mydict[st] = i
for i in range(0, n):
	if d[i] == 0:
		s = xaudao(a[i])
		if s in a:
			if mydict[s] != i:
				dau.append(i)
				cuoi.append(mydict[s])
				d[i] = 1
				d[mydict[s]] = 1
			else:
				giua = s
				d[i] = 1
				id = 1
print(m * 2 * len(dau) + id * m)
kq = []
for i in dau:
	kq.append(a[i])
if id == 1:
	kq.append(giua)
for i in range(len(cuoi) - 1, -1, -1):
	kq.append(a[cuoi[i]])
delim = ''
print(delim.join(kq))


line = input().split(' ')
n = int(line[0])
length = int(line[1])
l = []
single = ''
d = []
for i in range(n):
	l.append(input())
	if l[i] == l[i][::-1]:
		single = l[i]
i = 0
while i < n:
	j = i + 1
	while j < n:
		if l[i] == l[j][::-1]:
			d.append(l[i])
		j = j + 1
	i = i + 1
if single == '' and len(d) == 0:
	print('0')
if single != '' and len(d) == 0:
	print(str(length))
	print(single)
if single == '' and len(d) != 0:
	ans = ''.join(d) + ''.join(d)[::-1]
	print(len(ans))
	print(ans)
if single != '' and len(d) != 0:
	ans = ''.join(d) + single + ''.join(d)[::-1]
	print(len(ans))
	print(ans)


(n, m) = map(int, input().split())
l = []
x = []
pa = ''
for i in range(n):
	s = input()
	if s == s[::-1] and len(s) > len(pa):
		pa += s
	elif s[::-1] in l:
		l.remove(s[::-1])
		x.append(s)
	else:
		l.append(s)
for i in x:
	pa = i + pa + i[::-1]
print(len(pa))
print(pa)


for _mind_control in range(1):

	def reverse1(s):
		c = list(s)
		for i in range(len(s) // 2):
			t = c[i]
			c[i] = c[len(s) - i - 1]
			c[len(s) - i - 1] = t
		return ''.join(c)
	arr = []
	res = ''
	ans = ''
	(n, m) = map(int, input().split())
	for i in range(n):
		arr.append(input())
	q = []
	for i in range(n):
		for o in range(i + 1, n):
			if arr[i] not in q and arr[o] not in q:
				flag = 0
				for k in range(m):
					if flag:
						break
					if arr[i][k] != arr[o][m - k - 1]:
						flag = 1
				if flag == 0:
					res += str(arr[i])
					q.append(arr[i])
					q.append(arr[o])
	for i in range(n):
		flag = 1
		if arr[i] not in q:
			for o in range(m):
				if arr[i][o] != arr[i][m - 1 - o]:
					flag = 0
			if flag == 1:
				ans = arr[i]
				break
	print(2 * len(res) + len(ans))
	print(res + ans + reverse1(res), end='')


def reverse(s):
	st = str()
	for i in s:
		st = i + st
	return st
(n, m) = map(int, input().split())
s = []
d = {}
for _ in range(n):
	st = input()
	s.append(st)
	if d.get(st) == None:
		d[st] = 0
	d[st] += 1
ans = str()
r = []
l = []
mid = str()
for i in s:
	if d[i] > 0:
		rev = reverse(i)
		if d.get(rev) != None and d[rev] > 0 and (rev != i):
			r.append(i)
			l.append(rev)
			d[i] -= 1
			d[rev] -= 1
		elif i == rev:
			if len(mid) < len(i):
				mid = i
				d[i] -= 1
for i in range(len(r) - 1, -1, -1):
	mid = r[i] + mid
for i in range(len(l) - 1, -1, -1):
	mid = mid + l[i]
print(len(mid))
print(mid)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
(n, m) = mi()
pool = dd()
res = []
mid = ''
for _ in range(n):
	s = input()
	revs = s[::-1]
	if revs in pool:
		res.append(revs)
		pool[revs] -= 1
		continue
	if s == revs:
		mid = s
	pool[s] += 1
pref = ''.join(res)
print(2 * len(pref) + len(mid))
print(pref + mid + pref[::-1])


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
(left, mid, right) = ('', '', '')
used = [0] * n
for i in range(n):
	if used[i]:
		continue
	done = 0
	for j in range(i + 1, n):
		if used[j] or done:
			continue
		if a[i] == a[j][::-1]:
			left += a[i]
			right = a[j] + right
			used[i] = used[j] = 1
			done = 1
	if not done and a[i] == a[i][::-1] and (mid == ''):
		mid = a[i]
		used[i] = 1
res = left + mid + right
print(len(res))
print(res)


(n, m) = map(int, input().split())
mid = []
left = []
right = []
arr = []
lock = 0
for _ in range(n):
	s = input()
	arr.append(s)
for i in range(n):
	if arr[i] != '-1':
		done = 0
		for j in range(i + 1, n):
			if arr[i] == arr[j][::-1]:
				left.append(arr[i])
				right.append(arr[j])
				arr[j] = '-1'
				done = 1
				break
		if done == 0 and lock == 0:
			if arr[i] == arr[i][::-1]:
				mid.append(arr[i])
				lock = 1
s = ''
for i in left:
	s += i
for i in mid:
	s += i
for i in right[::-1]:
	s += i
print(len(s))
print(s)


def obr(s):
	s1 = ''
	for i in range(len(s)):
		s1 = s[i] + s1
	return s1

def prv(s):
	pr = 1
	for i in range(len(s) // 2):
		if s[i] != s[len(s) - i - 1]:
			pr = 0
			break
	if pr:
		return True
	else:
		return False
(n, m) = [int(i) for i in input().split()]
M = set()
sr = ''
for i in range(n):
	i = str(input())
	if obr(i) in M:
		sr = i + sr + obr(i)
		M.remove(obr(i))
	else:
		M.add(i)
mx = 0
for i in M:
	if prv(i):
		if len(i) > mx:
			mx = len(i)
			ms = i
if mx:
	sr = sr[:len(sr) // 2] + ms + sr[len(sr) // 2:]
print(len(sr))
if len(sr):
	print(sr)


(n, m) = map(int, input().split())
alll = []
for i in range(n):
	alll.append(input())
anz = ''
mid = ''
while n:
	n -= 1
	i = alll[0]
	alll.remove(i)
	if i[::-1] in alll:
		anz += i
	elif mid == '' and i == i[::-1]:
		mid = i
anz = anz + mid + anz[::-1]
print(len(anz))
print(anz)


(n, m) = map(int, input().split())
s = [input() for _ in range(n)]
start = ''
end = ''
mid = ''
seen = set()
for x in s:
	if x in seen:
		continue
	seen.add(x)
	if x[::-1] == x:
		if not mid:
			mid = x
	elif x[::-1] in s:
		start += x
		end = x[::-1] + end
		seen.add(x[::-1])
print(len(start + mid + end))
print(start + mid + end)


def solve(strings):
	front = ''
	middle = []
	back = ''
	while len(strings) > 0:
		string = strings[0]
		reverse = string[::-1]
		if reverse in strings:
			if reverse == string:
				middle.append(string)
			else:
				front += string
				strings.remove(reverse)
		strings.remove(string)
	longest_middle = ''
	for s in middle:
		if len(s) > len(longest_middle):
			longest_middle = s
	return front + longest_middle + front[::-1]
(n, m) = map(int, input().split())
strings = [input() for x in range(n)]
result = solve(strings)
print(len(result))
print(result)


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

def is_p(st):
	fl = True
	mh = -1
	for h in range(len(st) // 2):
		if st[h] != st[mh]:
			fl = False
			break
		mh -= 1
	return fl
if m == 1:
	print(1)
	print(A[0])
elif n == 1:
	if is_p(A[0]):
		print(m)
		print(A[0])
	else:
		print(0)
else:
	middle = True
	mid = ''
	B = []
	for j in range(n):
		if is_p(A[j]):
			if middle:
				mid = A[j]
				middle = False
		else:
			B.append(A[j])
	Bs = set(B)
	Rs = set()
	for k in Bs:
		g = list(k)
		g.reverse()
		kx = ''.join(g)
		Rs.add(kx)
	r1 = len(mid)
	r2 = 0
	s1 = ''
	s2 = ''
	X = Bs & Rs
	xh = len(X)
	r2 += xh * m
	Y = set()
	for ky in X:
		g = list(ky)
		g.reverse()
		kx = ''.join(g)
		if kx not in Y:
			Y.add(ky)
	for y in Y:
		s1 = s1 + y
		g = list(y)
		g.reverse()
		s2 = ''.join(g) + s2
	print(r1 + r2)
	print(s1 + mid + s2)


(t, m) = (int(x) for x in input().strip().split(' '))
from collections import defaultdict
L = []
for _ in range(t):
	L.append(input())
d = defaultdict(int)
left = ''
right = ''
mid = ''
vis = set()
for x in L:
	d[x] += 1
for (x, v) in d.items():
	if x == x[::-1] and m * v >= len(mid):
		mid = x * v
	elif x not in vis and x[::-1] in d.keys():
		e = min(d[x], d[x[::-1]])
		left = left + x * e
		right = e * x[::-1] + right
	vis.add(x[::-1])
ans = left + mid + right
print(len(ans))
if len(ans):
	print(ans)


import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1 / 0

def write(*args, sep='\n'):
	for i in args:
		sys.stdout.write('{}{}'.format(i, sep))
INF = float('inf')
MOD = int(1000000000.0 + 7)
YES = 'YES'
NO = 'NO'
for _ in range(1):
	try:
		(n, m) = read()
		arr = [input() for i in range(n)]
		ans = deque()
		d = defaultdict(bool)
		temp = []
		for i in arr:
			if i[::-1] == i:
				temp.append(i)
			else:
				d[i] = True
		for i in arr:
			if d[i] and d[i[::-1]]:
				d[i] = False
				d[i[::-1]] = False
				ans.append(i)
				ans.appendleft(i[::-1])
		if not temp:
			print(sum([len(i) for i in ans]))
			print(*ans, sep='')
		else:
			s = sorted(temp, key=lambda x: len(x))[-1]
			print(sum([len(i) for i in ans]) + len(s))
			for i in range(len(ans) // 2):
				print(ans[i], end='')
			print(s, end='')
			for i in range(len(ans) // 2, len(ans)):
				print(ans[i], end='')
	except ZeroDivisionError:
		continue
	except Exception as e:
		print(e)
		continue


(n, m) = map(int, input().split())
dic = {}
l = []
self = []
s = ''
e = ''
for i in range(n):
	l.append(str(input()))
	dic[l[-1]] = 0
for i in range(len(l)):
	dic[l[i]] = dic[l[i]] + 1
for i in range(len(l)):
	if l[i] == l[i][::-1]:
		self.append([l[i], dic[l[i]]])
	elif l[i][::-1] in l[i + 1:]:
		k = min(dic[l[i]], dic[l[i][::-1]])
		s = s + l[i] * k
		e = l[i][::-1] * k + e
self = sorted(self, key=lambda x: x[1], reverse=True)
if len(self) > 0:
	ans = s + self[0][0] * self[0][1] + e
else:
	ans = s + e
print(len(ans))
print(ans)


line = input()
(n, m) = [int(x) for x in line.split()]
lines = []
length = 0
middle = ''
start = ''
for i in range(n):
	line = input()
	lines.append(line.rstrip())
for i in range(n):
	line = lines[i]
	if length % 2 == 0 and line == ''.join(reversed(line)):
		length += 1
		middle = line
	for line2 in lines[i + 1:]:
		if line == ''.join(reversed(line2)):
			length += 2
			start += line
answer = start + middle + ''.join(reversed(start))
print(length * m)
print(answer)


from sys import *
input = stdin.readline
listInput = lambda : list(map(int, input().strip().split()))
lineInput = lambda : map(int, input().strip().split())
sJoin = lambda a, sep: f'{sep}'.join(a)
arrJoin = lambda a, sep: f'{sep}'.join(map(str, a))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(math.sqrt(n) + 1), 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def main():
	(n, m) = lineInput()
	arr = [input().strip() for i in range(n)]
	ans = ''
	special = ''
	for i in range(n):
		if arr[i] == '':
			continue
		if arr[i] == arr[i][::-1]:
			special = arr[i]
			continue
		rV = arr[i][::-1]
		for j in range(i + 1, n):
			if arr[j] == '':
				continue
			if rV == arr[j] and arr[j] != '':
				ans += arr[i]
				arr[j] = ''
				arr[i] = ''
				break
	ans += special + ans[::-1]
	print(f'{len(ans)}\n{ans}')
main()


I = input
pr = print
str = "if ar[i]!='' and ar[i]==ar[i][::-1]:b=ar[i];f=0;str=''"
(t, l) = map(int, I().split())
ar = []
a = b = ''
exec(t * 'ar.append(I());')
for i in range(t):
	if ar[i] == '':
		continue
	for j in range(i + 1, t):
		if ar[i] == ar[j][::-1]:
			a += ar[i]
			ar[i] = ar[j] = ''
			break
	exec(str)
print(2 * len(a) + len(b))
pr(a + b + a[::-1])


(n, m) = map(int, input().split())
list_a = list()
for x in range(n):
	a = input()
	list_a.append(a)
result = ''
for z in range(n):
	t = list_a[z]
	if t == t[::-1]:
		result = t
temp = ''
for x in range(n - 1):
	for y in range(x + 1, n):
		temp = list_a[y]
		temp = temp[::-1]
		if list_a[x] == temp:
			result = list_a[x] + result + list_a[y]
print(len(result))
print(result)


(n, m) = list(map(int, input().split()))
l = []
for i in range(n):
	l.append(input())
used = [0] * n
s = ''
e = ''
for i in range(n):
	for j in range(i + 1, n):
		if l[i] == l[j][::-1] and used[i] != 1 and (used[j] != 1):
			s += l[i]
			e = l[j] + e
			(used[i], used[j]) = (1, 1)
final = s
for i in range(n):
	if used[i] != 1 and l[i] == l[i][::-1]:
		final += l[i]
		break
final += e
print(len(final))
print(final)


(n, m) = map(int, input().split())
arr = []
s = ''
sss = ''
for _ in range(n):
	arr.append(input())
	for i in range(_):
		if arr[_][::-1] == arr[i]:
			s += arr[_]
			arr[_] = ''
			arr[i] = ''
	if arr[-1] != '' and arr[-1] == arr[-1][::-1]:
		sss = arr[-1]
s = s + sss + s[::-1]
print(len(s))
print(s)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d

def isPalindrome(s):
	return s == s[::-1]

def check(s1, s2):
	return s1 == s2[::-1]
(n, m) = inputnums()
a = []
for i in range(n):
	s = input()
	a.append(s)
front = ''
back = ''
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		if check(a[i], a[j]):
			front = a[i] + front
			back = back + a[j]
			a[i] = '.,'
			a[j] = '.,'
			break
mid = ''
for i in range(len(a)):
	if isPalindrome(a[i]):
		mid = a[i]
		break
rtn = front + mid + back
print(len(rtn))
print(rtn)


from sys import stdin

def inp():
	return (ss.rstrip() for ss in stdin).__next__()

def itg():
	return int(inp())

def mpint():
	return map(int, inp().split())
(n, m) = mpint()
data = set()
pair = []
palindrome = ''
for case in range(n):
	s = inp()
	rs = s[::-1]
	if s == rs and len(s) > len(palindrome):
		palindrome = s
	elif rs in data:
		pair.append(s)
		data.remove(rs)
	else:
		data.add(s)
ans = ''.join(pair)
ans = ans + palindrome + ans[::-1]
print(len(ans))
print(ans)


(q, l) = map(int, input().split())
(arr, pal) = ([], [])
palindrom = ''
for i in range(q):
	tmp = str(input())
	arr.append(tmp)
	if arr[i] == arr[i][::-1]:
		pal.append(arr[i])
	for j in range(i + 1):
		if i != j and arr[i] == arr[j][::-1]:
			palindrom = arr[i] + palindrom + arr[j]
if pal != []:
	l = int((len(palindrom) + 1) / 2)
	palindrom = palindrom[0:l] + pal[0] + palindrom[l:]
if palindrom == '':
	print(0)
else:
	print(len(palindrom))
	print(palindrom)


import sys
from math import *
(n, l) = map(int, sys.stdin.readline().split())
pal = [sys.stdin.readline().replace('\n', '') for i in range(n)]
check = [0] * n
middle = ''
listea = list()
listeb = list()
for i in range(n):
	for s in range(l):
		if pal[i][s] != pal[i][l - s - 1]:
			check[i] = -1
			break
	if check[i] == -1:
		for i1 in range(i + 1, n):
			check[i] = 1
			for s in range(l):
				if pal[i][s] != pal[i1][l - s - 1]:
					check[i] = -1
					break
			if check[i] == 1:
				listea.append(pal[i])
				listeb.append(pal[i1])
				break
	else:
		middle = pal[i]
word = ''
for i in range(len(listea)):
	word += listea[i]
word += middle
for i in range(len(listea) - 1, -1, -1):
	word += listeb[i]
print(len(word))
print(word)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def main():
	[n, m] = inlt()
	hashm = {}
	middle = ''
	out = ''
	for i in range(n):
		s = insr()
		hashm[s] = 1
		r_s = ''.join(reversed(s))
		if r_s in hashm and r_s != s:
			out = r_s + out + s
		if r_s == s and len(r_s) > len(middle):
			middle = r_s
	if len(middle) != 0:
		out = out[0:int(len(out) / 2)] + middle + out[int(len(out) / 2):len(out)]
	print(len(out))
	print(out)
	return out
main()


(n, l) = map(int, input().split())
sl = [''] * n
tmp1 = set()
tmp2 = set()
for i in range(n):
	sl[i] = input()
	if sl[i] == sl[i][::-1]:
		tmp1.add(sl[i])
for i in range(n):
	if sl[i][::-1] in sl:
		tmp2.add(sl[i])
		if sl[i][::-1] in tmp2:
			tmp2.remove(sl[i][::-1])
k = 0
target = ''
for a in tmp1:
	if k <= len(a):
		k = len(a)
		target = a
for a in tmp2:
	target = a + target + a[::-1]
print(len(target))
print(target)


def isPalindrome(s):
	for i in range(s.__len__()):
		if s[i] != s[s.__len__() - 1 - i]:
			return False
	return True

def newTest(arr):
	result = ''
	pairs = []
	for i in range(len(arr) - 1):
		for j in range(i + 1, len(arr)):
			if isPalindrome(arr[i] + arr[j]):
				pairs.append([arr[i], arr[j]])
	for i in arr:
		if isPalindrome(i):
			result = i
			break
	while len(pairs) != 0:
		result = pairs[0][0] + result + pairs[0][1]
		pairs.pop(0)
	return result
lines = int(input().split()[0])
strings = []
for a in range(lines):
	strings.append(input())
result = newTest(strings)
print(len(result))
print(result)


(n, m) = map(int, input().split())
strings = []
for i in range(n):
	strings.append(input())
is_pal = []
for s in strings:
	if s == s[::-1]:
		is_pal.append(True)
	else:
		is_pal.append(False)
used = [False] * n
erg = ''
for i in range(n):
	if used[i]:
		continue
	rev = strings[i][::-1]
	for j in range(i + 1, n):
		if used[j]:
			continue
		if rev == strings[j]:
			erg += strings[j]
			used[j] = True
			used[i] = True
middle = ''
for i in range(n):
	if not used[i] and is_pal[i]:
		middle = strings[i]
print(2 * len(erg) + len(middle))
print(erg + middle + erg[::-1])


import math

def fact(n):
	ans = 1
	for i in range(2, n + 1):
		ans *= i
	return ans

def comb(n, c):
	return fact(n) // (fact(n - c) * c)
(n, m) = map(int, input().split())
s = []
found = False
ans = ''
for i in range(n):
	temp = list(str(input()))
	if not found:
		if len(list(dict.fromkeys(temp))) == 1 or temp == temp[::-1]:
			ans = ''.join(temp)
			found = True
	s.append(''.join(temp))
for i in range(n):
	for f in range(i + 1, n):
		if s[i] == s[f][::-1]:
			ans = s[i] + ans + s[f]
print(len(ans))
print(ans)


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

def isOppos(s, t):
	l = len(s)
	for i in range(l):
		if s[i] != t[l - i - 1]:
			return False
	return True
s = input()
(n, m) = (int(s.split(' ')[0]), int(s.split(' ')[1]))
lst = []
for i in range(n):
	lst.append(input())
l = len(lst)
flag = [False for i in range(l)]
final = ''
middle = False
for i in range(l):
	if flag[i]:
		continue
	if middle == False:
		if isPal(lst[i]):
			flag[i] = True
			middle = lst[i]
			continue
	for j in range(i + 1, l):
		if flag[j]:
			continue
		if isOppos(lst[i], lst[j]):
			flag[i] = True
			flag[j] = True
			final = lst[i] + final + lst[j]
lenF = len(final)
if middle != False:
	final = final[0:int(lenF / 2)] + middle + final[int(lenF / 2):lenF]
sum = 0
for f in flag:
	if f:
		sum += m
print(sum)
print(final)


(n, m) = map(int, input().split())
s = []
res = []
t = 0
for i in range(n):
	a = list(input())
	s.append(a)
y = s.copy()
for j in y:
	copy = j.copy()
	copy.reverse()
	if copy in s and j in s:
		if j != copy or s.count(j) > 1:
			res.insert(0, j)
			res.append(copy)
			s.remove(j)
			if j == copy:
				s.remove(j)
		elif j == copy and s.count(j) == 1 and (not t):
			q = len(res) // 2
			res.insert(q, j)
			s.remove(j)
			t = 1
if len(res):
	print(len(res) * m)
	for i in res:
		for j in i:
			print(j, end='')
else:
	print(0)
	print('\n')


(n, k) = map(int, input().split())
a = []
f = []
l = []
m = []
for i in range(n):
	a.append(input())
for i in range(n):
	if a == []:
		break
	v = a.pop()
	t = v[::-1]
	if t in a:
		f.append(v)
		l.append(t)
		a.remove(t)
	elif v == t:
		m.append(v)
print(len(f) * k * 2 + min(len(m), 1) * k)
print(''.join(f) + (m[0] if m != [] else '') + ''.join(l[::-1]))


(n, m) = map(int, input().split())
a = []
s = []
flag = 0
for _ in range(n):
	k = input()
	a.append(k)
c = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if a[i] == a[j][-1:-m - 1:-1]:
			s.append(a[i])
			c += len(a[i])
k = []
c = c * 2
for i in a:
	if i == i[-1:-m - 1:-1]:
		k.append(i)
		c += len(i)
		break
print(c)
for i in range(len(s)):
	print(s[i], end='')
if len(k) == 1:
	print(k[0], end='')
for i in range(len(s) - 1, -1, -1):
	h = s[i]
	print(h[-1:-m - 1:-1], end='')


(n, m) = list(map(int, input().split()))
memo = [input() for _ in range(n)]
first = []
middle = []
last = []
for i in range(n):
	if memo[i] == memo[i][::-1]:
		middle.append(memo[i])
	else:
		for j in range(i + 1, n):
			if memo[i] == memo[j][::-1]:
				first.insert(0, memo[i])
				last.append(memo[j])
result = ''.join(first)
if middle:
	result += middle[0]
result += ''.join(last)
print(len(result))
if len(result):
	print(result)
else:
	print()


def main():
	(n, l) = input().split()
	(n, l) = (int(n), int(l))
	L = [input() for _ in range(n)]
	sp = ''
	sm = ''
	L2 = []
	for s in L:
		si = s[::-1]
		if not si in L2 and (not s in L2):
			L2.append(s)
			L2.append(si)
			if si == s:
				sm = s
			elif si in L:
				sp += s
	print(2 * len(sp) + len(sm))
	print(sp + sm + sp[::-1])
main()


(n, m) = map(int, input().split())
sis = [input() for _ in range(n)]
(pl, pr) = ([], [])
left = [s for s in sis]
for s in sis:
	rev = s[::-1]
	if s != rev and rev in left:
		left.remove(s)
		left.remove(rev)
		pl.append(s)
		pr.append(rev)
pal = ''
for s in left:
	ispal = all([s[i] == s[m - 1 - i] for i in range(m)])
	if ispal:
		pal = s
		break
ans = len(pal) + len(pl) * m * 2
print(ans)
if ans:
	s = ''.join(pl)
	s += pal
	pr.reverse()
	s += ''.join(pr)
	print(s)


from collections import defaultdict
(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input().strip())
pairs = []
s1 = defaultdict(set)
for i in range(n):
	s1[s[i][::-1]].add(i)
res = ''
for i in range(n):
	if s[i] in s1 and i in s1[s[i]]:
		res += s[i]
		s1[s[i]].remove(i)
		break
for i in range(n):
	if s[i] in s1 and i not in s1[s[i]]:
		if len(s1[s[i]]) > 0:
			v = s1[s[i]].pop()
			s1[s[v]].remove(i)
			res = s[i] + res
			res = res + s[i][::-1]
if len(res):
	print(len(res))
	print(res)
else:
	print(0)
	print()


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
t = []
s = ''
for i in range(n):
	if l[i] == l[i][::-1]:
		t.append(l[i])
	for j in range(i + 1, n):
		if l[i] == l[j][::-1]:
			s = l[i] + s + l[j]
			break
if len(t) >= 1:
	s = s[0:len(s) // 2] + t[0] + s[len(s) // 2:]
print(len(s))
print(s)


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
sa = set(map(lambda x: x[::-1], a))
used = set()
st = []
(c, cl) = ('', 0)
for i in a:
	if not i in used:
		if i in sa:
			i1 = i[::-1]
			if i1 == i:
				if len(i) > cl:
					cl = len(i)
					c = i
			else:
				st.append(i)
			used.add(i)
			used.add(i[::-1])
jst = ''.join(st)
print(len(jst) * 2 + cl)
print(jst + c + jst[::-1])


(n, m) = map(int, input().split())
lst1 = []
lst2 = []
lst3 = []
word3 = ''
for _ in range(n):
	s = input()
	if s[::-1] in lst1:
		lst2.append(s)
	elif s[::-1] == s:
		word3 = s
	else:
		lst1.append(s)
lst2.sort()
lst3 = [word[::-1] for word in lst2[::-1]]
k = ''.join(lst3) + word3 + ''.join(lst2)
print(len(k))
print(k)


(n, m) = map(int, input().split())
li = []
l = []
r = []
mid = False
for i in range(n):
	li.append(input())
j = 0
while j < len(li):
	temp = list(li[j])
	temp.reverse()
	temp = ''.join(temp)
	if temp == li[j]:
		mid = li[j]
		li.remove(li[j])
	elif temp in li:
		l.append(li[j])
		r.append(temp)
		li.remove(temp)
		li.remove(li[j])
	else:
		j += 1
r.reverse()
if mid:
	s = ''.join(l) + mid + ''.join(r)
else:
	s = ''.join(l) + ''.join(r)
print(len(s))
print(s)


lst = []
palindrome = ''
temp = ''
(n, m) = map(int, input().split(' '))
for i in range(n):
	str = input()
	lst.append(str)
for value in lst:
	if value != '0':
		x = value[::-1]
		if x in lst:
			index1 = lst.index(value)
			index2 = lst.index(x)
			if index1 == index2:
				temp = value
				lst[index2] = '0'
			else:
				palindrome = value + palindrome + x
				lst[index2] = '0'
				lst[index1] = '0'
y = int(len(palindrome) / 2)
palindrome = palindrome[:y] + temp + palindrome[y:]
print(len(palindrome))
print(palindrome)


(n, m) = map(int, input().split())
x = []
ans = ''
y = ''
f = 0
st = []
en = []
for _ in range(n):
	s = input()
	x.append(s)
	if s[::-1] == s and f == 0:
		f = 1
		y += s
for i in range(n - 1):
	for j in range(i + 1, n):
		k = x[j]
		if x[i] == k[::-1]:
			st.append(x[i])
			en.insert(0, k)
m = len(ans) // 2
st = ''.join(st)
en = ''.join(en)
ans += st + y + en
print(len(ans))
print(ans)


(n, l) = map(int, input().split())
word = [input() for i in range(n)]
word.sort()
pals = []
powt = []
for i in range(n):
	if word[i][::-1] in word:
		if word[i] != word[i][::-1]:
			if word[i] not in powt:
				powt.append(word[i])
				powt.append(word[i][::-1])
for i in range(n):
	if word[i][::-1] == word[i] and word[i] not in powt:
		pals.append(word[i])
orde1 = []
orde2 = []
i = 0
while i < len(powt):
	orde1.append(powt[i])
	i += 2
i = 1
while i < len(powt):
	orde2.append(powt[i])
	i += 2
orde2.reverse()
bestie = ''
if len(pals) > 0:
	for i in pals:
		if len(i) > len(bestie):
			bestie = i
slowo = orde1 + [bestie] + orde2
dupa = ''.join(slowo)
print(len(dupa))
print(dupa)


def isPalindromeOfEachOther(a, b):
	s = a + b
	if isPalindrome(s):
		return 1
	return 0

def isPalindrome(s):
	c = 0
	for i in range(0, len(s) // 2):
		if s[i] == s[len(s) - i - 1]:
			continue
		else:
			c = 1
			break
	if c == 0:
		return 1
	return 0
(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
palstart = []
palend = []
for i in range(n):
	word = s[i]
	for j in range(i + 1, n):
		if isPalindromeOfEachOther(word, s[j]):
			palstart.append(word)
			palend.append(s[j])
onepalindrome = ''
for i in s:
	if i not in palstart and i not in palend:
		if isPalindrome(i):
			onepalindrome = i
			break
longestPalindrome = ''
for i in palstart:
	longestPalindrome += i
longestPalindrome += onepalindrome
for i in range(len(palend) - 1, -1, -1):
	longestPalindrome += palend[i]
print(len(longestPalindrome))
print(longestPalindrome)


(n, k) = map(int, input().split())
arr = []
ans = ''
arr2 = []
arr1 = []
ann = ''
for _ in range(n):
	a = input()
	arr.append(a)
for i in arr:
	if i[::-1] in arr and i != i[::-1]:
		if i[::-1] not in arr1:
			arr1.append(i)
			ans += i
	elif i == i[::-1]:
		ann = i
	else:
		pass
partial = ans[::-1]
ans = ans + ann + partial
if len(ans) > 0:
	print(len(ans))
	print(ans)
else:
	print('0')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
ar = []
for i in a:
	ar.append(i[::-1])
i = 0
ans = []
while i < n:
	j = i + 1
	while j < n:
		if a[i] == ar[j]:
			n -= 2
			ans.append(a[i])
			a.pop(j)
			ar.pop(j)
			a.pop(i)
			ar.pop(i)
			i -= 1
			break
		j += 1
	i += 1
ansp = ''
for i in a:
	if i == i[::-1] and len(ansp) < len(i):
		ansp = i
		break
q = ''
for i in ans:
	q += i
q += ansp
for i in ans[::-1]:
	q += i[::-1]
print(len(q))
print(q)


(t, n) = map(int, input().split())
l = []
for _ in range(t):
	l.append(input())
(c, c1) = ([], [])
k = n // 2
(l1, l2) = ([], [])
for i in range(t - 1):
	s1 = l[i][:k]
	s2 = l[i][k:n]
	if n % 2 == 0:
		if s1 == s2[::-1]:
			c1.append(l[i])
	else:
		s2 = s2[1:]
		if s1 == s2[::-1]:
			c1.append(l[i])
	for j in range(i + 1, t):
		if l[i] == l[j][::-1]:
			l1.append(l[i])
			l2.append(l[j])
s1 = l[-1][:k]
s2 = l[-1][k:n]
if n % 2 == 0:
	if s1 == s2[::-1]:
		c1.append(l[-1])
else:
	s2 = s2[1:]
	if s1 == s2[::-1]:
		c1.append(l[-1])
if len(l1) != 0:
	l2 = l2[::-1]
	if len(c1) == 0:
		print(2 * len(l1) * n)
	else:
		print(2 * len(l1) * n + n)
	for i in l1:
		print(i, end='')
	if len(c1) != 0:
		print(c1[0], end='')
	for i in l2:
		print(i, end='')
elif len(l1) == 0 and len(c1) != 0:
	print(n)
	print(c1[0])
else:
	print(0)


(N, M) = map(int, input().split())
L = []
for i in range(N):
	L.append(input())
Z = ''
FLAG = 0
for i in range(N):
	if L[i] == L[i][::-1]:
		Z = Z + L[i]
		L[i] = -1
		FLAG = 1
		break
if FLAG == 0:
	for i in range(N):
		for j in range(N):
			if L[i][::-1] != L[j]:
				X = L[i] + L[j]
				if X == X[::-1] and FLAG == 0:
					Z = Z + X
					FLAG = 1
					L[i] = -1
					L[j] = -1
					break
		if FLAG == 1:
			break
for i in range(N):
	if L[i] != -1:
		X = L[i][::-1]
		for j in range(N):
			if i != j:
				if X == L[j]:
					Z = L[i] + Z + L[j]
					L[i] = -1
					L[j] = -1
					break
print(len(Z))
print(Z)


(n, m) = [int(i) for i in input().split()]
word_set = set()
cool_word_len = 0
cool_word = ''
first_half = ''
second_half = ''
for i in range(n):
	word = input()
	word_set.add(word)
	if word == word[::-1] and len(word) > cool_word_len:
		cool_word_len = len(word)
		cool_word = word
	elif word != word[::-1] and word[::-1] in word_set:
		first_half = word + first_half
		second_half += word[::-1]
palindrome = first_half + cool_word + second_half
print(len(palindrome))
print(palindrome)


import os
from io import BytesIO, IOBase
import sys
import math
from math import ceil
from collections import Counter

def main():
	(n, m) = map(int, input().split())
	a = []
	b = set()
	for i in range(n):
		a.append(input().rstrip())
		b.add(a[-1])
	f = []
	r = []
	t = ''
	for i in range(n):
		z = a[i][::-1]
		b.discard(a[i])
		if z == a[i]:
			t = a[i]
		if z in b:
			f.append(a[i])
			r.append(z)
			b.discard(z)
	r.reverse()
	print(m * (len(f) + len(r)) + len(t))
	print(''.join(f), end='')
	print(t, end='')
	print(''.join(r))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
s = []
d = dict()
for i in range(n):
	temp = input()
	s.append(temp)
	if temp not in d:
		d[temp] = 1
	else:
		d[temp] += 1
reslen = 0
s1 = []
s2 = []
res = []
for i in d:
	if d[i] != 0:
		temp = i[::-1]
		if i == temp:
			if d[i] == 1:
				s1.append(i)
			else:
				for j in range(d[i] // 2):
					s2.insert(0, i)
					s2.append(i)
					reslen += 2 * m
				if d[i] % 2 != 0:
					s1.append(i)
		elif temp in d:
			co = min(d[i], d[temp])
			for j in range(co):
				s2.insert(0, i)
				s2.append(temp)
				reslen += 2 * m
			d[temp] = 0
res += s2[:len(s2) // 2]
if s1:
	res += s1[0]
	reslen += m
res += s2[len(s2) // 2:]
print(reslen)
print(''.join(res))


(n, m) = map(int, input().split())
a = []
for i in range(n):
	g = list(input())
	a.append(g)
b = []
c = []
d = [0] * n
cnt1 = 0
cnt2 = 0
for i in range(n):
	for j in range(i + 1, n):
		if a[i] == a[j][::-1] and d[j] == 0 and (d[i] == 0):
			b.append(a[i])
			c.append(a[j])
			d[j] = 1
			d[i] = 1
			cnt1 += 1
			cnt2 += 1
			break
k = []
for i in range(n):
	f = 0
	for j in range(m):
		if d[i] == 0:
			if a[i][j] == a[i][m - j - 1]:
				f += 1
	if f == m:
		b.append(a[i])
		cnt1 += 1
		break
ans1 = []
ans2 = []
for i in range(cnt1):
	for j in range(m):
		ans1.append(b[i][j])
for i in range(cnt2):
	for j in range(m):
		ans2.append(c[i][m - j - 1])
ans2 = ans2[::-1]
ans = ans1 + ans2
print(len(ans))
print(*ans, sep='')


(n, m) = map(int, input().split())
dic = {}
dic2 = {}
for i in range(n):
	s = input()
	temp = list(s)
	temp.reverse()
	rev = ''.join(temp)
	if s == rev:
		if s not in dic2:
			dic2[s] = 0
		dic2[s] += 1
	elif s < rev:
		if s not in dic:
			dic[s] = [0, 0]
		dic[s][0] += 1
	else:
		if rev not in dic:
			dic[rev] = [0, 0]
		dic[rev][1] += 1
lis = []
bis = []
for s in dic:
	temp = list(s)
	temp.reverse()
	rev = ''.join(temp)
	for i in range(min(dic[s])):
		lis.append(s)
		bis.append(rev)
sub = ''
for s in dic2:
	if dic2[s] % 2 == 1:
		sub = s
	for i in range(dic2[s] // 2):
		lis.append(s)
		bis.append(s)
bis.reverse()
ans = ''.join(lis) + sub + ''.join(bis)
print(len(ans))
print(ans)


def isPalindrome(string):
	return string == string[::-1]

def solver(strings, len_str):
	seen = set()
	solution = ''
	hasPalindrome = False
	palindrome = ''
	for string in strings:
		if isPalindrome(string):
			if not hasPalindrome:
				palindrome = string
				hasPalindrome = True
		else:
			if string[::-1] in seen:
				solution += string
			seen.add(string)
	solution = solution + palindrome + solution[::-1]
	print(len(solution))
	print(solution)
(count_str, len_str) = (int(x) for x in input().split())
strings = []
for i in range(int(count_str)):
	strings.append(input())
solver(strings, len_str)


(a, b) = [int(h) for h in input().strip().split(' ')]
arr = []
palin = ''
pal = ''
odd = True
for i in range(a):
	inp = input().strip()
	if inp[::-1] in arr:
		palin = palin + inp
	elif inp == inp[::-1]:
		if odd:
			pal = pal + inp
			odd = False
	else:
		arr.append(inp)
print(len(palin) * 2 + len(pal))
print(palin + pal + palin[::-1])


(n, m) = map(int, input().split())
all = []
for _ in range(n):
	all.append(input())
palins = ''
have_palins = []
for i in all:
	if i == i[::-1] and len(i) > len(palins):
		palins = i
	elif i[::-1] in all and (not i[::-1] in have_palins) and (i != i[::-1]):
		have_palins += [i]
x = ''.join(have_palins)
a = x + palins + x[::-1]
print(len(a))
print(a)


(n, m) = map(int, input().split())
A = []
st = ''
e = ''
f = 0
ans = 0
temp = ''
for i in range(n):
	s = input()
	A.append(s)
	if s[::-1] in A and s != s[::-1]:
		st += s
		e = s[::-1] + e
		ans += 2 * m
	elif f == 0 and s == s[::-1]:
		temp += s
		ans += m
		f = 1
print(ans)
print(st + temp + e)


(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)


(n, m) = [int(i) for i in input().strip().split(' ')]
a = {}
ans = ''
mid = ''
for i in range(n):
	s = input().strip()
	t = ''.join(list(s)[::-1])
	if a.get(t) != None:
		ans += s
		a[t] = a[t] - 1
		if a[t] == 0:
			t = a.pop(t)
	else:
		a[s] = a.get(s, 0) + 1
for string in a.keys():
	temp = ''.join(list(string)[::-1])
	if temp == string:
		if len(temp) > len(mid):
			mid = temp
ans = ans + mid + ''.join(list(ans)[::-1])
print(len(ans))
print(ans)


from sys import stdin
inp = lambda : stdin.readline().strip()
(n, m) = [int(x) for x in inp().split()]
d = {}
for i in range(n):
	s = inp()
	if d.get(s, 0):
		d[s] += 1
	else:
		d[s] = 1
left = []
right = []
middle = ''
for i in d.keys():
	minExist = min(d[i], d.get(i[::-1], 0))
	if minExist > 0:
		if i == i[::-1]:
			left.extend([i] * (minExist // 2))
			right.extend([i] * (minExist // 2))
		else:
			left.extend([i] * minExist)
			right.extend([i[::-1]] * minExist)
			d[i] -= minExist
			d[i[::-1]] -= minExist
for i in d.keys():
	if i == i[::-1] and len(i) > len(middle) and (d[i] > 0):
		middle = i
ans = ''.join(left) + middle + ''.join(right[::-1])
if len(ans) == 0:
	print(0)
else:
	print(len(ans))
	print(''.join(ans))


from sys import stdin, stdout
from os import path
from dataclasses import dataclass
if path.exists('inp.txt'):
	stdin = open('inp.txt', 'r')
s = [None for i in range(105)]
q = []
p = []
r = []
(n, m) = map(int, stdin.readline().split())
for i in range(n):
	k = stdin.readline().split()
	s[i] = k[0]
for i in range(n):
	if s[i] != None:
		t = s[i][::-1]
		for id in range(n):
			if id != i and t == s[id]:
				q.append(s[i])
				r.append(t)
				s[i] = s[id] = None
				break
		if s[i] == t:
			p.append(s[i])
			s[i] = None
if len(p) > 0:
	print(m * len(q) * 2 + m)
else:
	print(m * len(q) * 2)
for v in q:
	print(v, end='')
if len(p) > 0:
	print(p[0], end='')
r.reverse()
for v in r:
	print(v, end='')


import sys
from collections import deque, Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
(N, M) = MAP()
C = Counter()
que = deque()
for i in range(N):
	s = input()
	rev = s[::-1]
	if C[rev] > 0:
		C[rev] -= 1
		que.appendleft(s)
		que.append(rev)
	else:
		C[s] += 1
mx = 0
add = ''
for (k, v) in C.items():
	if v > 0 and k == k[::-1]:
		if len(k) > mx:
			mx = len(k)
			add = k
ans = list(que)
ans = ans[:len(ans) // 2] + [add] + ans[len(ans) // 2:]
ans = ''.join(ans)
print(len(ans))
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()

def par(c):
	for i in range(len(c) // 2):
		if c[i] != c[-(1 + i)]:
			return False
	return True
(n, m) = map(int, input().split())
mas = []
ans = ''
mid = ''
for i in range(n):
	s = input()
	if par(s) == True:
		mid = s
	elif s[::-1] in mas:
		ans += s
		del mas[mas.index(s[::-1])]
	else:
		mas.append(s)
print(len(ans[::-1] + mid + ans))
print(ans[::-1] + mid + ans)


(n, m) = input().split()
n = int(n)
m = int(m)
arr = []
mystr = ''
ans = ''
while n:
	n -= 1
	st = input()
	if st == st[::-1] and len(mystr) == 0:
		mystr = st
	if st[::-1] in arr:
		ans = st + ans + st[::-1]
		arr.remove(st[::-1])
		continue
	arr.append(st)
if len(mystr):
	l = len(ans)
	ans = ans[0:int(l / 2)] + mystr + ans[int(l / 2):l]
print(len(ans))
print(ans)


(n, m) = [int(i) for i in input().split()]
st = set()
cen_st = set()
for i in range(n):
	s = input()
	if s == s[::-1]:
		cen_st.add(s)
	else:
		st.add(s)
arr = set()
for i in st:
	temp = i[::-1]
	if temp in st and temp not in arr:
		arr.add(i)
cen = ''
for i in cen_st:
	if len(cen) < len(i):
		cen = i
arr = [i for i in arr]
ans = ''.join(arr) + cen + ''.join(arr)[::-1]
print(len(ans))
print(ans)


from collections import Counter, defaultdict, deque
from math import *
import sys
input = sys.stdin.readline

def solve():
	(n, m) = [int(x) for x in input().split()]

	def pal(s):
		return s == s[::-1]
	arr = []
	for i in range(n):
		arr.append(input().strip())
	ans = ''
	mid = 1
	while len(arr):
		cur = arr.pop(0)
		rev = cur[::-1]
		if rev in arr:
			ans = cur + ans + rev
			arr.remove(rev)
		elif mid and pal(cur):
			l = len(ans) // 2
			ans = ans[:l] + cur + ans[l:]
			mid = 0
	print(len(ans))
	print(ans)
tt = 1
for test in range(tt):
	solve()


def main():
	(n, m) = map(int, input().split())
	s = set()
	t = {}
	for __ in range(n):
		temp = input()
		s.add(temp)
		t[temp] = False
	left = []
	right = []
	mid = ''
	for i in s:
		if not t[i]:
			temp = i[::-1]
			if temp == i:
				mid = i
			elif temp in s:
				left.append(i)
				right.insert(0, temp)
				t[i] = True
				t[temp] = True
	print(len(left) * m + len(right) * m + len(mid))
	print(''.join(left), end='')
	print(mid, end='')
	print(''.join(right))
main()


def palindrom(v):
	y = v[::-1]
	return y
(n, m) = map(int, input().split())
a = []
res = ''
for i in range(n):
	s = input()
	k = palindrom(s)
	if k == s:
		res = s
	else:
		a.append(s)
for i in range(len(a)):
	q = palindrom(a[i])
	for j in range(i, len(a)):
		if a[j] == q:
			res = a[i] + res + a[j]
print(len(res))
print(res)


(n, m) = map(int, input().split())
ar = [input() for i in range(n)]
prs = []
alone = []
pairs = 0
pitself = 0
for i in range(n):
	if ar[i] == ar[i][::-1]:
		alone.append(ar[i])
	for j in range(i + 1, n):
		if ar[i] == ar[j][::-1]:
			prs.append((ar[i], ar[j]))
			pairs += 1
alone = list(set(alone))
for i in alone:
	for j in prs:
		if i == j[0]:
			alone.remove(i)
if len(alone):
	pitself = 1
print(m * 2 * pairs + pitself * m)
string = ''
for i in prs:
	string += i[0]
if len(alone):
	string += alone[0]
for i in prs[::-1]:
	string += i[1]
print(string)


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr += [input()]
s = set({})
ans = []
for i in range(n):
	a = arr[i]
	b = a[::-1]
	if b in arr and a not in s and (a != b):
		ans += [[b, a]]
		s.add(a)
		s.add(b)
ma = -1
for i in range(n):
	a = arr[i]
	b = a[::-1]
	if a == b and len(a) > ma:
		ma = len(a)
		aa = a[:]
one = ''
two = ''
for i in range(len(ans)):
	one += ans[i][0]
	two += ans[len(ans) - i - 1][1]
if ma != -1:
	one += aa + two
else:
	one += two
print(len(one))
print(one)


(n, m) = list(map(int, input().split()))
a = []
ma = ''
b = []
check = set()
for i in range(n):
	a.append(input())
for i in range(n):
	f = True
	for j in range(n):
		if i == j:
			continue
		x = a[i]
		y = a[j][::-1]
		if x == y and (i, j) not in check:
			f = False
			b.append([x, y[::-1]])
			check.add((i, j))
			check.add((j, i))
	if f:
		ff = True
		for r in range(len(a[i]) // 2):
			if a[i][r] != a[i][-1 - r]:
				ff = False
		if ff:
			if len(a[i]) > len(ma):
				ma = a[i]
s = ''
s2 = ''
for i in b:
	s += i[0]
	s2 = i[1] + s2
s3 = s + ma + s2
print(len(s3))
print(s3)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	s = input()
	a.append(s)
b = []
d = []
visited = [False for i in range(n)]
for i in range(n):
	if visited[i] == False:
		for p in range(n - 1, i - 1, -1):
			(j, k, flag) = (0, m - 1, 0)
			while j < m:
				if a[i][j] != a[p][k]:
					flag = -1
					break
				j += 1
				k -= 1
			if flag == 0 and i == p:
				d.append(a[i])
				break
			elif flag == 0:
				visited[p] = True
				b.append(a[i])
				break
c = []
e = []
count = 0
for i in b:
	for j in i:
		count += 1
		c.append(j)
z = 0
if len(d) > 0:
	for i in range(m):
		e.append(d[0][i])
	z = m
print(len(b) * 2 * m + z)
for i in range(count):
	print(c[i], end='')
for i in e:
	print(i, end='')
for i in range(count - 1, -1, -1):
	print(c[i], end='')


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, m) = I()
d = dd(int)
for i in range(n):
	s = input()
	d[s] += 1
s = []
check = ''
for i in d:
	if i == i[::-1]:
		check = i
	if i[::-1] in d and i != i[::-1]:
		if i[::-1] not in s and i not in s:
			s.append(i)
ans = ''
for i in s:
	ans += i
ans += check
for i in s[::-1]:
	ans += i[::-1]
print(len(ans))
print(ans)


(n, m) = map(int, input().split(' '))
d = dict()
ans = 0
for i in range(n):
	s = input()
	d[s] = True

def cp(s):
	if s == s[::-1]:
		return True
	return False
ans = ''
for i in list(d.keys()):
	if cp(i):
		ans += i
		d[i] = False
		break
for s in list(d.keys()):
	try:
		if d[s] and (not cp(s)):
			rs = s[::-1]
			if d[rs]:
				ans = s + ans + rs
				d[rs] = False
			d[s] = False
	except:
		pass
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
d = {}
p = set()
for i in range(n):
	s = input()
	s1 = s[::-1]
	if d.get(s) == None:
		if d.get(s1) == None:
			d[s] = 1
		else:
			d[s1] += 1
	else:
		d[s] += 1
	if s == s1:
		p.add(s)
ans = ''
m = 0
ind = -1
for i in d:
	if d[i] % 2 != 0 and i in p:
		if len(i) > m:
			m = len(i)
			ind = i
if ind != -1:
	ans = ind
for i in d:
	if d[i] >= 2:
		ans = i * (d[i] // 2) + ans + i[::-1] * (d[i] // 2)
print(len(ans))
print(ans)


import sys

def is_palindrome(str):
	if str == str[::-1]:
		return True
	else:
		return False

def build_huge_palindrome(tests):
	result = ''
	marked_tests = [(test, 'new') for test in tests]
	for i in range(0, len(marked_tests)):
		if marked_tests[i][1] != 'removed':
			j = i + 1
			while j < len(marked_tests):
				if marked_tests[j][1] != 'removed':
					if marked_tests[i][0] == marked_tests[j][0][::-1]:
						result = marked_tests[i][0] + result + marked_tests[j][0]
						marked_tests[i] = (marked_tests[i][0], 'deleted')
						marked_tests[j] = (marked_tests[j][0], 'deleted')
						break
				j += 1
	for word in marked_tests:
		if word[1] != 'deleted' and is_palindrome(word[0]):
			result = result[:len(result) // 2] + word[0] + result[len(result) // 2:]
			break
	return result
[n, m] = [int(number) for number in input().split(' ')]
tests = []
for line in sys.stdin:
	tests.append(line.strip())
tests = tests[0:n]
answer = build_huge_palindrome(tests)
print(len(answer))
print(answer)


(n, m) = map(int, input().split())
s = []
for i in range(n):
	x = input()
	s.append(x)
d = {}
ans = ''
cnt = 0
for i in s:
	if i[::-1] in d:
		cnt = cnt + 2 * m
		if ans == '':
			ans = i + i[::-1]
		else:
			l = len(ans) // 2
			ans = ans[0:l] + i + i[::-1] + ans[l:]
	else:
		d[i] = i
for i in s:
	if i[::-1] == i:
		l = len(ans) // 2
		ans = ans[0:l] + i + ans[l:]
		cnt = cnt + m
		break
if cnt == 0:
	print(0)
else:
	print(cnt)
	print(ans)


def main(n, xs):
	rs = []
	insert_index = 0
	for (i, x) in enumerate(xs):
		match = False
		for (j, r) in enumerate(rs):
			if rs[j][1] == '':
				if rs[j][0] == x[::-1]:
					rs[j][1] = x
					match = True
		if not match:
			rs.append([x, ''])
	palindrome = ''
	for r in rs:
		if r[1] == '':
			if r[0] == r[0][::-1]:
				palindrome = r[0]
				break
	for r in rs:
		if r[1] != '':
			palindrome = r[0] + palindrome + r[1]
	print(len(palindrome))
	print(palindrome)
(n, m) = [int(x) for x in input().split()]
xs = [''] * n
for i in range(n):
	xs[i] = input()
main(n, xs)


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
(N, M) = 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)


(n, m) = list(map(int, input().rstrip().split()))
strs = []
num_l = [0] * n
num = 1
mid = False
mids = ''
fronts = ''
backs = ''
plstr = ''
for i in range(n):
	a = input()
	strs.append(a)
for i in range(n):
	if num_l[i] != 1:
		num_l[i] = 1
		a = strs[i]
		a = list(a)
		a.reverse()
		b = ''
		b = b.join(a)
		a.reverse()
		a = ''.join(a)
		if strs[i] == b:
			if mid == False:
				mid = True
				mids = strs[i]
		else:
			for j in range(n):
				if b == strs[j]:
					num_l[j] = 1
					fronts = a + fronts
					backs = backs + b
plstr = fronts + mids + backs
print(len(plstr))
print(plstr)


def examA():
	t = I()
	ans = []
	for _ in range(t):
		(x, y, a, b) = LI()
		if (y - x) % (a + b) != 0:
			cur = -1
		else:
			cur = (y - x) // (a + b)
		ans.append(cur)
	for v in ans:
		print(v)
	return

def examB():
	(N, M) = LI()
	S = [SI() for _ in range(N)]
	d = defaultdict(int)
	ok_1 = []
	ok_2 = []
	for i in range(N):
		cur = S[i]
		if d[S[i][::-1]] > 0:
			ok_2.append([d[S[i][::-1]], i + 1])
		flag = True
		for j in range(M // 2):
			if cur[j] != cur[M - 1 - j]:
				flag = False
				break
		if flag:
			ok_1.append(i + 1)
		d[cur] = i + 1
	ans = ''
	for i in range(len(ok_2)):
		ans += S[ok_2[i][0] - 1]
	if ok_1:
		ans += S[ok_1[0] - 1]
	for i in range(len(ok_2) - 1, -1, -1):
		ans += S[ok_2[i][1] - 1]
	print(len(ans))
	print(ans)
	return

def examC():
	ans = 0
	print(ans)
	return

def examD():
	ans = 0
	print(ans)
	return

def examE():
	ans = 0
	print(ans)
	return

def examF():
	ans = 0
	print(ans)
	return
import sys, copy, bisect, itertools, heapq, math, random
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = 10 ** (-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
examB()


(n, m) = map(int, input().split())
a = []
r = s = ''
for _ in range(n):
	x = input()
	y = ''.join(reversed(x))
	if y in a:
		r += x
	a.append(x)
	if x == y:
		s = x
r = r + s + ''.join(reversed(r))
print(len(r), r)


(n, m) = map(int, input().split())
w = [input() for _ in range(n)]
selfp = [x for x in w if x == x[-1::-1]]
notp = [x for x in w if x != x[-1::-1]]
posp = []
while len(notp) > 0:
	word = notp.pop()
	if word[-1::-1] in notp:
		posp.append(word)
		notp.remove(word[-1::-1])
print((int(len(selfp) > 0) + 2 * len(posp)) * m)
k = ''.join(posp)
print(k + (selfp[0] if len(selfp) > 0 else '') + k[-1::-1])


def is_palindrome(word, n):
	for i in range(n):
		if word[i] != word[n - i - 1]:
			return False
	return True

def are_palindromes(word_a, word_b, n):
	for i in range(n):
		if word_a[i] != word_b[n - i - 1]:
			return False
	return True
result = 0
(t, n) = map(int, input().split())
middle_word = ''
words = list()
remove_list = list()
for _ in range(t):
	words.append(input())
for i in words:
	if is_palindrome(i, n):
		result += n
		remove_list.append(i)
		middle_word = i
		break
[words.remove(x) for x in remove_list]
first_words = list()
final_words = list()
remove_list = list()
for i in words:
	for j in words:
		if are_palindromes(i, j, n) and j not in remove_list and (j != i):
			first_words.append(i)
			final_words.append(j)
			result += 2 * n
			remove_list.append(i)
			break
[words.remove(x) for x in remove_list]

def get_resutl(first_words, middle_word, final_words):
	r = ''
	for i in first_words:
		r += i
	r += middle_word
	n = len(final_words)
	for j in range(n):
		r += final_words[n - j - 1]
	return r
print(result)
print(get_resutl(first_words, middle_word, final_words))


(nb_strings, lens) = [int(x) for x in input().split()]
has = [input() for _ in range(nb_strings)]
mids = ''
(left, rite, paired) = ([], [], [])
for i in has:
	if i == i[::-1]:
		mids = i
	elif i not in paired:
		if i[::-1] in has:
			left.append(i)
			rev = i[::-1]
			rite.append(rev)
			paired.append(rev)
answer = ''.join(left)
answer += mids
answer += ''.join(rite[::-1])
lens = len(answer)
print(lens)
if lens:
	print(answer)


def main():
	given_list = list()
	(n, l) = map(int, input().split(' '))
	for _ in range(n):
		given_list.append(input())
	start_string = str()
	end_string = str()
	self_palindrome = str()
	while given_list:
		i = given_list[0]
		given_list.remove(i)
		if i[::-1] in given_list:
			start_string += i
			end_string = i[::-1] + end_string
			given_list.remove(i[::-1])
		elif l % 2 == 0:
			if i[:l // 2] == i[l // 2:l][::-1] and self_palindrome == '':
				self_palindrome += i
		elif i[:l // 2] == i[l // 2 + 1:l][::-1] and self_palindrome == '':
			self_palindrome += i
	ans = start_string + self_palindrome + end_string
	print(len(ans))
	print(ans)
	print()
main()


(n, m) = map(int, input().split())
l = []
p = ''
b = ''
f = 0
for i in range(n):
	s = input()
	if s == s[::-1]:
		if f == 0:
			b = b + s
			f = 1
	elif s[::-1] in l:
		p = p + s
	l.append(s)
a = p + b + p[::-1]
print(len(a))
print(a)


import sys
(n, m) = map(int, sys.stdin.readline().split())
arr = [sys.stdin.readline().rstrip() for _ in range(n)]
front = []
back = []
itself = dict()
for i in range(n):
	if arr[i] == arr[i][::-1]:
		if arr[i] not in itself:
			itself[arr[i]] = 1
		else:
			itself[arr[i]] += 1
	else:
		for j in range(i + 1, n):
			if arr[j] == arr[i][::-1]:
				front.append(arr[i])
				back.append(arr[j])
ans = ''
for i in front:
	ans += i
val = 0
key = ''
for i in itself:
	if val < itself[i]:
		val = itself[i]
		key = i
ans += key * val
for i in back[::-1]:
	ans += i
print(len(ans))
print(ans if len(ans) else '')


(n, m) = [int(x) for x in input().split()]
sd = {}
for si in range(n):
	s = input()
	if not s in sd:
		if not s[::-1] in sd:
			sd[s] = -1
		else:
			sd[s[::-1]] = s
sdl = sd.items()
ans = []
single = []
for sdi in sdl:
	if sdi[1] != -1:
		ans.append(sdi[0])
	elif sdi[0] == sdi[0][::-1]:
		single.append(sdi[0])
if single:
	ans.append(single[0])
for ari in range(len(ans) - 1 * int(single != []) - 1, -1, -1):
	ans.append(sd[ans[ari]])
ans = ''.join(ans)
print(len(ans))
print(ans)


import sys
import math
from itertools import combinations
from collections import defaultdict
from collections import Counter
(n, m) = map(int, input().split())
a = []
p = []
s = []
d = {}
for i in range(n):
	t = input()
	if t not in d:
		if t.count(t[0]) == len(t):
			s.append(t)
		elif t == t[::-1]:
			p.append(t)
		else:
			a.append(t)
		d[t] = 1
	else:
		d[t] += 1
y = ''
f = 0
y1 = ''
t1 = 0
for x in s:
	if f == 0 and d[x] == 1:
		y += x
		f = 1
	if t1 < d[x] and d[x] != 1:
		t1 = d[x]
		y1 = x
y1 = y1 * t1
if t1 == 0:
	y1 = y
y = ''
if len(s) == 0:
	for x in p:
		if d[x] == 1:
			y1 = x
			break
for x in p:
	if d[x] % 2 == 0:
		y = x * int(d[x] / 2) + y
for x in a:
	if x[::-1] in d:
		y = x * min(d[x], d[x[::-1]]) + y
		d[x] = 0
print(len(y + y1 + y))
if len(y + y1 + y) > 0:
	print(y + y1 + y[::-1])


(n, m) = map(int, input().split())
a = []
pel = ''
ans = ''

def palindron(s):
	if s == s[::-1]:
		return 'yes'
	else:
		return 'no'
for i in range(0, n):
	s = input()
	a.append(s)
flag = 0
while len(a) != 0:
	s = a[0]
	if s[::-1] in a[1:]:
		ans = ans + s
	elif palindron(s) == 'yes' and flag == 0:
		pel = pel + s
		flag = 1
	a = a[1:]
final = ans + pel + ans[::-1]
if len(final) == 0:
	print(0)
	print()
else:
	print(len(final))
	print(final)


def pal(s, n):
	for i in range(n // 2):
		if s[i] != s[n - 1 - i]:
			return 0
	return 1
(n, m) = map(int, input().split())
l = []
fg = 0
s = ''
temp = ''
pp = 0
for i in range(n):
	l.append(input())
i = 0
while i < n:
	if pal(l[i], m):
		pp += 1
		if fg == 0:
			temp = l[i]
			fg = 1
	else:
		t1 = l[i]
		t1 = t1[::-1]
		if t1 in l:
			l.remove(t1)
			n = n - 1
			s += l[i]
	i += 1
s += s[::-1]
w = len(s) // 2
if fg == 1:
	s = s[:w] + temp + s[w:]
else:
	s = s[:w] + s[w:]
if s != '':
	print(len(s))
	print(s)
else:
	print(0)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline().strip())
pt = lambda x: sys.stdout.write(str(x))
from random import random

def reverse(s):
	return s[::-1]

def isPalindrome(s):
	rev = reverse(s)
	if s == rev:
		return True
	return False
(n, m) = get_int_list()
strig_list = [0] * n
rev_string_list = [0] * n
for i in range(n):
	s = get_string()
	strig_list[i] = s
	rev_string_list[i] = reverse(s)
left = []
right = []
pallindrome = []
for i in range(n):
	for j in range(n):
		if i != j:
			if strig_list[i] != '~' and rev_string_list[j] != '~':
				if strig_list[i] == rev_string_list[j]:
					left.append(strig_list[i])
					right.append(strig_list[j])
					rev_string_list[j] = '~'
					rev_string_list[i] = '~'
					strig_list[i] = '~'
					strig_list[j] = '~'
					break
	if isPalindrome(strig_list[i]) and strig_list[i] != '~' and (len(pallindrome) == 0):
		pallindrome.append(strig_list[i])
		strig_list[i] = '~'
		rev_string_list[i] = '~'
s = ''
for i in left:
	s += i
for i in pallindrome:
	s += i
for i in right[::-1]:
	s += i
if isPalindrome(s):
	print(len(s))
	print(s)
else:
	print(0)
	print('')


(n, m) = tuple(map(int, input().split()))
l = []
k = 0
ans1 = []
ans2 = []
for i in range(n):
	l.append(input())
for i in range(n):
	for j in range(i + 1, n):
		if l[i] == l[j][::-1]:
			ans1.append(l[i])
	if m % 2 == 0:
		if l[i][:int(len(l[i]) / 2)] == l[i][int(len(l[i]) / 2):][::-1]:
			ans2.append(l[i][:int(len(l[i]) / 2)])
	elif l[i][:int(len(l[i]) / 2)] == l[i][int(len(l[i]) / 2) + 1:][::-1]:
		k += 1
		ans2.append(l[i][:int(len(l[i]) / 2) + 1])
if len(ans2) != 0:
	s = ''.join(ans1) + ans2[0]
else:
	s = ''.join(ans1)
if k == 0:
	print(len(s) * 2)
	print(s + s[::-1])
else:
	print(len(s) * 2 - 1)
	print(s + s[::-1][1:])


def longest_palindrome(seq):
	palindrome = []
	two_part = []
	for x in seq:
		if x[::-1] == x:
			palindrome.append(x)
		elif x[::-1] in two_part:
			pass
		elif x[::-1] in seq:
			two_part.append(x)
	ans = ''.join(two_part)
	if len(palindrome) > 0:
		ans += palindrome[0]
	for x in reversed(two_part):
		ans += x[::-1]
	return ans
(n, m) = list(map(int, input().split()))
seq = []
for x in range(n):
	seq.append(input())
ans = longest_palindrome(seq)
print(len(ans), ans, sep='\n')


(n, m) = [int(x) for x in input().split(' ')]
lines = []
revs = []
palindrom = ''
results = []
for i in range(n):
	s = input()
	try:
		revs.remove(s)
		results.append(s)
	except:
		revs.append(s[::-1])
for rev in revs:
	if rev == rev[::-1]:
		palindrom = rev
		break
answer = ''.join(results) + palindrom + ''.join([x[::-1] for x in results[::-1]])
print(len(answer))
print(answer)


(t, n) = [int(i) for i in input().split()]
str_s = []
for i in range(t):
	str_s.append(input())
firstPart = ''
secPart = ''
palins = []
for str_ in str_s:
	str_i = str_[::-1]
	tempList = str_s.copy()
	tempList.remove(str_)
	if str_i in tempList:
		firstPart += str_
		secPart = str_i + secPart
		str_s.remove(str_i)
	elif str_ == str_i:
		palins.append(str_)
if len(palins) > 0:
	ans = firstPart + palins[0] + secPart
else:
	ans = firstPart + secPart
print(len(ans))
print(ans)


(t, n) = map(int, input().split())
l = []
ol1 = []
ol2 = []
ol3 = []
dic = {}
for _ in range(t):
	s = input()
	l.append(s)
	dic[s] = 0
for i in range(t):
	st = l[i]
	if st == st[::-1] and dic[st] == 0:
		dic[st] = 1
		ol3.append(st)
	elif st[::-1] in l and dic[st] == 0:
		dic[st] = 1
		dic[st[::-1]] = 1
		ol1.append(st)
		ol2.append(st[::-1])
res = ''
res1 = ''
res2 = ''
res3 = ''
if len(ol1) != 0:
	for i in ol1:
		res1 = res1 + i
if len(ol2) != 0:
	for i in range(len(ol2) - 1, -1, -1):
		res2 = res2 + ol2[i]
if len(ol3) != 0:
	res3 = res3 + ol3[0]
res = res1 + res3 + res2
print(len(res))
print(res)


(n, m) = map(int, input().split())
a = []
e = []
c = []
d = []
for _ in range(n):
	a.append(str(input()))
dict = {}
for _ in range(len(a)):
	if a[_] == a[_][::-1]:
		if a[_] not in e:
			e.append(a[_])
	for i in range(_ + 1, len(a)):
		if a[_] == a[i][::-1]:
			c.append(a[_])
			d.append(a[i])
ans = list(c + e + d[::-1])
x = 0
for _ in range(len(ans)):
	if ans[_] == ans[_][::-1] and ans.count(ans[_]) < 2:
		if x >= 1:
			ans[_] = '-1'
		x += 1
anss = ''
for _ in range(len(ans)):
	if ans[_] != '-1':
		anss += ans[_]
print(len(anss))
print(anss)


(n, m) = map(int, input().split())
li = []
ans = []
pal = ''
for x in range(n):
	s = input()
	flag2 = 0
	for j in li:
		if j[::-1] == s:
			s = s[::-1]
			ans.append(s)
			li.remove(s)
			flag2 = 1
	if flag2 == 0:
		li.append(s)
for x in li:
	flag = 0
	for i in range((m - 1) // 2 + 1):
		if x[i] != x[m - 1 - i]:
			flag = 1
			break
	if flag == 0:
		pal = x
ansstr = ''
for i in ans:
	ansstr += i
ansstr += pal
for i in ans[::-1]:
	ansstr += i[::-1]
print(len(ansstr))
print(ansstr)


(n, m) = map(int, input().split())
strSet = set()
l = []
r = []
mid = ''
for _ in range(n):
	s = input()
	t = s[::-1]
	if s == t:
		mid = s
	elif t in strSet:
		l.append(s)
		r.append(t)
		strSet.remove(t)
	else:
		strSet.add(s)
r.reverse()
ans = ''.join(l + [mid] + r)
print(len(ans))
print(ans)


(n, m) = list(map(int, input().split(' ')))
s = []
for _ in range(n):
	s.append(input())
ready_one = []
ready_two = []
b = []
for elem in s:
	if elem == '':
		break
	if elem in b:
		ready_two.append(elem)
		b.remove(elem)
	else:
		b.append(elem[::-1])
center = ''
for elem in b:
	if elem == elem[::-1]:
		center = elem
		break
new_str = center if center else ''
for elem in ready_two:
	new_str = elem + new_str + elem[::-1]
print(len(new_str))
print(new_str)


def ispalindrome(x):
	return x == x[::-1]
(n, m) = map(int, input().split())
strs = [input() for _ in range(n)]
middle = ''
left = ''
right = ''
for i in range(n):
	curr = strs[i]
	if curr is None:
		continue
	revs = curr[::-1]
	if curr == revs:
		middle = curr
		continue
	for j in range(i + 1, n):
		oth = strs[j]
		if oth is None:
			continue
		if oth == revs:
			left = curr + left
			right = right + oth
			strs[j] = None
			break
res = left + middle + right
print(len(res))
print(res)


(n, m) = [int(x) for x in input().split()]
L = []
for i in range(n):
	ch = input()
	L.append(ch)
ph = ''
s = set()
for k in L:
	if k == k[::-1]:
		ph += k
		s.add(k)
		break
for k in L:
	if k[::-1] in L and k[::-1] != k and (k[::-1] not in s):
		ph = k + ph + k[::-1]
		s.add(k)
	else:
		pass
print(len(ph))
if ph != '':
	print(ph)


(n, m) = map(int, input().split())
a = []
b = a
for i in range(n):
	a.append(input())
start = ''
kon = ''
polidrom = ''
for item_a in a:
	for item_b in b:
		if item_a == item_b[::-1] and item_a != item_b:
			start = start + item_a
			kon = item_a[::-1] + kon
			b.remove(item_b)
		elif item_a == item_b[::-1]:
			polidrom = item_a
print(len(start + polidrom + kon))
print(start + polidrom + kon)


n = []
ans = ''
(a, b) = map(int, input().split())
cash = {}
for i in range(a):
	a = input()
	if a[::-1] in n:
		n.remove(a[::-1])
		ans += a
	elif a == a[::-1]:
		if a in cash:
			cash[a] += 1
		else:
			cash[a] = 1
	else:
		n.append(a)
ans2 = ans[::-1]
ans3 = ''
(mx, wmx) = (0, '')
for i in cash:
	if cash[i] % 2:
		if cash[i] > mx:
			mx = cash[i]
			wmx = i
	else:
		ans3 += i * (cash[i] // 2)
ans = ans + ans3 + wmx * mx + ans3[::-1] + ans2
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
a = []
s1 = []
p = []
s2 = []
for i in range(n):
	a.append(input())
while len(a) != 0:
	f = a[0]
	x = list(a[0])
	del a[0]
	x.reverse()
	y = ''.join(x)
	if y in a:
		s1.append(f)
		s2.append(y)
		a.remove(y)
	elif f == y:
		p = [f]
s2.reverse()
S = s1 + p + s2
hh = ''.join(S)
print(len(hh))
print(hh)


def chkpal(x):
	return x == x[::-1]
(m, n) = list(map(int, input().split()))
st = []
flg = 1
for _ in range(m):
	st.append(input())
l = {}
for i in st:
	try:
		if l[i] >= 1:
			l[i] += 1
	except:
		l[i] = 1
x = {}
cpo = 0
po = '-1'
for i in l:
	if chkpal(i):
		if l[i] % 2 == 0:
			x[i] = [1, l[i]]
		elif po == '-1':
			cpo = l[i]
			po = i
			x[po] = [1, l[po]]
		elif l[i] > cpo:
			x.pop(po)
			po = i
			x[po] = [1, l[po]]
			cpo = l[po]
	else:
		try:
			if l[i[::-1]] > 0:
				x[i[::-1]] = [0, l[i[::-1]]]
		except:
			pass
pall = []
palr = []
palmid = []
otl = []
otr = []
for i in x:
	if not x[i][0]:
		(u, v) = (x[i][1], x[i[::-1]][1])
		w = min(u, v)
		if u > w:
			x[i][1] = w
		else:
			x[i[::-1]][1] = w
for i in x:
	if not x[i][0]:
		for _ in range(x[i][1]):
			otl.append(i)
			otr.append(i)
		x[i[::-1]][1] = 0
	elif x[i][1] % 2 == 0:
		for _ in range(x[i][1] // 2):
			pall.append(i)
			palr.append(i)
	else:
		palmid.append(i)
p = ''.join(otl)
q = ''.join(pall)
r = ''.join(palmid)
s = ''.join(palr)
t = ''.join(otr)
res = p + q + r + s[::-1] + t[::-1]
print(len(res))
if len(res):
	print(res)


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	s = input().strip()
	arr.append(s)
d = {}
for i in range(len(arr)):
	d[arr[i]] = i
visited = [0] * n
start = ''
end = ''
for i in range(len(arr)):
	if visited[i] == 0:
		temp = arr[i]
		temp = temp[::-1]
		if temp in d and d[temp] != i:
			start += arr[i]
			end = arr[d[temp]] + end
			visited[i] = 1
			visited[d[temp]] = 1
flag = False
for i in range(len(arr)):
	if visited[i] == 0:
		temp = arr[i]
		temp = temp[::-1]
		if temp == arr[i]:
			start += temp
			ans = start + end
			print(len(ans))
			print(start + end)
			flag = True
			break
if not flag:
	print(len(start + end))
	print(start + end)


s = {input() for _ in [0] * int(input().split()[0])}
r = ''.join((x for x in s if x < x[::-1] and x[::-1] in s))
r = r + max('', '', *(x for x in s if x == x[::-1]), key=len) + r[::-1]
print(len(r), r)


from collections import defaultdict

def int_as_array(num):
	return list(map(int, [y for y in str(num)]))

def array_as_int(arr):
	return int(''.join(map(str, arr)))

def read_int():
	return int(input())

def read_int_array():
	return list(map(int, input().split(' ')))

def int_array_to_string(arr, sep=' '):
	return sep.join(map(str, arr))

def solve(array):
	single_pals = set()
	pair_pals = defaultdict(lambda : {'D': [], 'A': []})
	for word in array:
		reverse = word[::-1]
		key = min(word, reverse)
		if word == key:
			pair_pals[key]['A'].append(word)
		else:
			pair_pals[key]['D'].append(word)
		if reverse == word:
			single_pals.add(word)
	center = ''
	for word in single_pals:
		all_words = pair_pals[word]['A']
		if len(all_words) % 2 == 1:
			center = ''.join(all_words)
			del pair_pals[word]
			break
	longest = [center]
	for (key, words) in pair_pals.items():
		asc = words['A']
		desc = words['D']
		total = len(asc) + len(desc)
		if total > 1:
			if key in single_pals:
				_total = total if total % 2 == 0 else total - 1
				all_words = asc
			else:
				sub_len = min(len(asc), len(desc))
				_total = sub_len * 2
				all_words = asc[:sub_len] + desc[:sub_len]
			mid = len(all_words) // 2
			longest = all_words[:mid] + longest + all_words[mid:_total]
	ans = ''.join(longest)
	print(len(ans))
	print(ans)
(N, M) = read_int_array()
words = []
for i in range(N):
	words.append(input())
solve(words)


(n, m) = map(int, input().split())
data = [input() for _ in range(n)]
state = [-1] * n
for (i, elem1) in enumerate(data):
	for (j, elem2) in enumerate(data):
		if elem1 == elem2[::-1] and i != j:
			state[i] = j
			state[j] = i
			break
	else:
		if elem1 == elem1[::-1]:
			state[i] = i
		else:
			data[i] = ''
res = ''
for (i, elem) in enumerate(data):
	if state[i] != -1 and state[i] != i:
		res += elem
		state[state[i]] = -1
		state[i] = -1
for i in range(n):
	if state[i] != -1:
		print(len(res + data[i] + res[::-1]))
		print(res + data[i] + res[::-1])
		exit()
print(len(res + res))
print(res + res[::-1])


(n, m) = input().split(' ')
n = int(n)
m = int(m)
s_map = {}
for _ in range(n):
	s_map[input()] = ''
mm = {}
p = {}
for s in s_map:
	if s[::-1] in s_map and s != s[::-1]:
		mm[tuple(sorted((s, s[::-1])))] = 1
	elif not p:
		if s == s[::-1]:
			p[s] = s
ans = ''
if p:
	ans = list(p.keys())[0]
for (s, s1) in mm:
	ans = s + ans + s1
print(len(ans))
print(ans)


palin = []
specialpalin = []
lst = []
count = 0
specialcount = 0

def reverse(string, N):
	temp = []
	temp = [0 for i in range(N)]
	for i in range(N):
		temp[N - 1 - i] = string[i]
	str1 = ''.join((str(e) for e in temp))
	return str1
(T, N) = map(int, input().split())
for test in range(T):
	word = input()
	if word == reverse(word, N):
		specialpalin.append(word)
		specialcount += 1
	elif reverse(word, N) in lst:
		palin.append(word)
		count += 2
	else:
		lst.append(word)
print((min(specialcount, 1) + count) * N)
for i in range(int(count / 2)):
	print(palin[i], end='')
for i in range(min(specialcount, 1)):
	print(specialpalin[i], end='')
for i in range(int(count / 2)):
	print(reverse(palin[int(count / 2) - 1 - i], N), end='')


(n, m) = list(map(int, input().split()))
occs = {}
a = []
revs = {}
for i in range(n):
	s = input()
	a.append(s)
	revs[s] = s[::-1]
	if s in occs.keys():
		occs[s] += 1
	else:
		occs[s] = 1
start = ''
end = ''
middle = ''
for i in range(n):
	if a[i] in occs.keys():
		n1 = occs[a[i]]
		n2 = 0
		del occs[a[i]]
		if revs[a[i]] in occs.keys():
			n2 = occs[revs[a[i]]]
			ss = min(n1, n2)
			start += a[i] * ss
			end = revs[a[i]] * ss + end
			del occs[revs[a[i]]]
		if a[i] == revs[a[i]] and (min(n1, n2) < n1 or min(n1, n2) < n2) and (middle == ''):
			middle = a[i]
ans = start + middle + end
print(len(ans))
print(ans)


import sys
inp = sys.stdin.readline
input = lambda : inp().strip()
flush = sys.stdout.flush

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	(n, m) = lin()
	a = [input() for i in range(n)]
	sa = set(a)
	pairs = []
	for i in a:
		if i not in sa:
			continue
		rv = ''.join(list(i)[::-1])
		if rv in sa and rv != i:
			pairs.append([rv, i])
			sa.remove(rv)
			sa.remove(i)

	def checkPalindrom(a):
		l = len(a)
		for i in range(l // 2):
			if a[i] != a[-i - 1]:
				return False
		return True
	ans = []
	(l, r) = ([], [])
	for i in sa:
		if checkPalindrom(i):
			ans.append(i)
			break
	for (i, j) in pairs:
		l.append(i)
		r.append(j)
	r = r[::-1]
	ans = l + ans + r
	print(len(ans) * m)
	print(''.join(ans))
main()


f = [int(x) for x in input().split()]
r = []
for i in range(f[0]):
	r.append(input())
t = []
for i in range(f[0]):
	for j in range(i + 1, f[0]):
		ok = True
		for k in range(f[1]):
			if r[i][k] != r[j][f[1] - 1 - k]:
				ok = False
				break
		if ok == True:
			t.append([i, j])
u = []
for i in range(f[0]):
	ok = True
	for k in range(f[1]):
		if r[i][k] != r[i][f[1] - k - 1]:
			ok = False
			break
	if ok == True:
		u.append(i)
if len(u) > 0:
	print(f[1] * (2 * len(t) + 1))
	for i in range(len(t)):
		print(r[t[i][0]], end='')
	print(r[u[0]], end='')
	for i in range(len(t)):
		print(r[t[len(t) - i - 1][1]], end='')
else:
	print(f[1] * (2 * len(t)))
	for i in range(len(t)):
		print(r[t[i][0]], end='')
	for i in range(len(t)):
		print(r[t[len(t) - i - 1][1]], end='')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	s = input()
	a.append(s)
f = []
l = []
m = []
for i in range(n - 1):
	k = a[i][::-1]
	if a[i] != k:
		for j in range(i + 1, n):
			if a[j] == k:
				f.append(a[i])
				l.append(a[j])
for i in range(n):
	k = a[i][::-1]
	if k == a[i]:
		m.append(a[i])
l.reverse()
if len(m) > 0:
	f.append(m[0])
for i in range(len(l)):
	f.append(l[i])
length = 0
for i in f:
	length += len(i)
print(length)
for i in f:
	print(i, end='')


def find(arr, s, i):
	rev = s[::-1]
	for j in range(i + 1, len(arr)):
		if arr[j] == rev:
			return j
	return -1
(m, n) = [int(s) for s in input().split()]
arr = [''] * m
for i in range(m):
	arr[i] = input()
dp = [-1] * m
for i in range(len(arr)):
	if dp[i] == -1:
		dp[i] = find(arr, arr[i], i)
	if dp[i] != -1:
		dp[dp[i]] = i
flag = False
for i in range(len(arr)):
	if dp[i] == -1:
		if arr[i][::-1] == arr[i]:
			flag = True
			dp[i] = i
			break
count = 0
for i in range(len(arr)):
	if dp[i] != -1:
		count += 1
print(count * n)
flag_arr = [0] * m
for i in range(len(arr)):
	if dp[i] != -1:
		if flag_arr[i] == 0:
			flag_arr[i] = 1
			flag_arr[dp[i]] = -1
		if dp[i] == i:
			flag_arr[i] = 2
last = ''
c = 0
middle = ''
for i in range(len(arr)):
	if flag_arr[i] == 1:
		print(arr[i], end='')
		last += arr[i]
	elif flag_arr[i] == 2:
		middle = arr[i]
print(middle, end='')
print(last[::-1])


(m, n) = input().split()
m = int(m)
n = int(n)
li = []
lirev1 = []
lirev2 = []
mid = []
num = []
for i in range(0, m):
	s = input()
	li.append(s)
for i in range(0, m):
	l = 0
	if i in num:
		continue
	for j in range(i + 1, m):
		if li[i] == li[j][n::-1]:
			num.append(i)
			num.append(j)
			lirev1.append(li[i])
			lirev2.append(li[j])
			l = 1
			break
	if l == 1:
		continue
	if n % 2 == 0:
		if li[i][0:n // 2] == li[i][n // 2:n][n // 2::-1]:
			mid.append(li[i])
	elif li[i][0:n // 2] == li[i][n // 2 + 1:n][n // 2::-1]:
		mid.append(li[i])
s = ''
for i in lirev1:
	s = s + i
for i in mid[0:1]:
	s = s + i
for i in lirev2[len(lirev2)::-1]:
	s = s + i
print(len(s))
print(s)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
slist = [stdin.readline().strip() for _ in range(n)]
sset = set(slist)
(out, last) = ([], '')
while sset:
	s1 = sset.pop()
	for s2 in slist:
		palin = False
		if s1 != s2:
			palin = True
			for i in range(m):
				if s1[i] != s2[-i - 1]:
					palin = False
					break
		if palin:
			out.append(s1)
			sset.remove(s2)
		elif not last:
			palin = True
			for i in range(m // 2):
				if s1[i] != s1[-i - 1]:
					palin = False
					break
			if palin:
				last = s1
cnt = len(out) * 2 * m + (m if last else 0)
out = ''.join(out)
stdout.write('{}\n{}{}{}'.format(cnt, out, last, out[::-1]))


def isPalindrome(s):
	rev = ''.join(reversed(s))
	if s == rev:
		return True
	return False
(n, m) = map(int, input().split())
q = []
d = set()
for i in range(n):
	q.append(input())
for i in q:
	d.add(''.join(reversed(i)))
r = ''
s = ''
f = 0
for i in range(n):
	if isPalindrome(q[i]):
		if f == 0:
			s = s + q[i]
			f = 1
	elif q[i] in d:
		(a, b) = (r[:len(r) // 2], r[len(r) // 2:])
		r = a + q[i] + ''.join(reversed(q[i])) + b
		d.remove(q[i])
		d.remove(''.join(reversed(q[i])))
if s == '' and r == '':
	print(0)
	print()
else:
	(a, b) = (r[:len(r) // 2], r[len(r) // 2:])
	w = a + s + b
	print(len(w))
	print(w)


(n, m) = map(int, input().split())
vis = [0] * n
L = []
for _ in range(n):
	L.append(input())
ans = ''
t = ''
for i in L:
	if i == i[::-1]:
		t = i
for i in range(len(L)):
	s = L[i][::-1]
	for j in range(len(L)):
		if not vis[j] and L[j] == s and (i != j):
			vis[j] = 1
			ans = ans + L[j]
			vis[i] = 1
print(len(ans + t + ans[::-1]))
print(ans + t + ans[::-1])


(n, m) = map(int, input().split())
l = []
for i in range(n):
	x = input()
	l.append(x)
li = []
x = 0
y = 0
lis = ''
for i in l:
	if i[::-1] == i:
		y = m
		lis = i
	elif i[::-1] in l and i[::-1] not in li:
		x += m * 2
		li.append(i)
print(x + y)
print(''.join(li) + lis + ''.join(li)[::-1])


(n, m) = map(int, input().split())
xs = [input() for _ in range(n)]
rxs = [x[::-1] for x in xs]
oans = ''
for x in xs:
	if x == x[::-1]:
		oans = x
		break
ans = []
rans = []
for (i, x) in enumerate(xs):
	for rx in rxs[i + 1:]:
		if x == rx:
			ans.append(x)
			rans.append(x[::-1])
if not ans:
	ans = oans
elif oans and oans not in ans:
	ans = ''.join(ans + [oans] + rans[::-1])
else:
	ans = ''.join(ans + rans[::-1])
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
words = [input() for _ in range(n)]
start = []
lost = []
end = []
i = 0
while words:
	word = words.pop()
	i += 1
	found = False
	for j in range(len(words)):
		if word == words[j][::-1]:
			start.append(word)
			end.append(words.pop(j))
			i += 1
			found = True
			break
	if not found:
		lost.append(word)
middle = ''
while lost:
	word = lost.pop()
	if word[::-1] == word:
		middle = word
		break
answer = ''.join(start) + middle + ''.join(end[::-1])
print(len(answer))
print(answer)


(n, m) = map(int, input().split())
cnt = 0
ans = []
ans2 = []
st = []
for _ in range(n):
	st.append(input())
for i in range(n):
	if st[i] == st[i][::-1]:
		cnt += len(st[i])
		ans2.append(st[i])
	else:
		for j in range(i + 1, n):
			if st[i] == st[j][::-1]:
				cnt += 2 * len(st[i])
				ans.append([st[i], st[j]])
if len(ans2) > 0:
	maximum = max(ans2, key=lambda x: len(x))
else:
	maximum = ''
string = maximum
for item in ans:
	string = item[0] + string + item[1]
print(len(string))
print(string)


(n, m) = map(int, input().split())
s = []
prd = []
pal = ''
ls = ''
solo = []
for i in range(n):
	tmp = input()
	s.append(tmp)
dit = {}
for i in range(len(s)):
	rev = s[i][::-1]
	if rev in dit:
		pal = s[i] + pal + rev
		prd.append(i)
		prd.append(dit[rev])
		del dit[rev]
	else:
		dit[s[i]] = i
for i in range(len(s)):
	if i in prd:
		continue
	else:
		rev = s[i][::-1]
		if rev == s[i]:
			ls = s[i]
tmp = pal[:len(pal) // 2] + ls + pal[len(pal) // 2:len(pal)]
print(len(tmp))
print(tmp)


(n, m) = list(map(int, input().split()))
sents = list()
for _ in range(n):
	sents.append(input())
pals = dict()
for val in sents:
	if val[::-1] in sents:
		if val not in pals.values():
			pals[val] = val[::-1]
(keys, values) = (pals.keys(), pals.values())
for (key, val) in zip(keys, values):
	if key == val:
		pals[key] = 0
	else:
		pals[key] = 1
start = ''
mid = ''
end = ''
for (key, val) in pals.items():
	if val == 1:
		start += key
		end = key[::-1] + end
	elif val == 0:
		mid = key
print(len(start + mid + end))
print(start + mid + end)


def solve(s):
	if s == '':
		return True
	if s[0] != s[-1]:
		return False
	s = s[1:-1]
	return solve(s)
(n, m) = input().split()
n = int(n)
m = int(m)
store = [input() for i in range(n)]
pel = 0
ans = 0
ans_word = ''
pel_word = ''
dict_word = dict()
for key in store:
	if key[::-1] in store and (not solve(key)):
		ans += len(key)
		if not key in dict_word:
			ans_word += key
			dict_word[key] = 1
			dict_word[key[::-1]] = 1
	if solve(key):
		pel = max(pel, len(key))
		if pel == len(key):
			pel_word = key
ans += pel
ans_word = ans_word + pel_word + ans_word[::-1]
print(ans)
print(ans_word)


(a, b) = map(int, input().split())
l = []
for i in range(a):
	l.append(input())
l1 = []
l2 = []
s = ''
for i in l:
	try:
		if l.index(i[::-1]) >= 0 and i != i[::-1] and (i[::-1] not in l1):
			s += i
			l1.append(i)
	except ValueError:
		continue
sr = s[::-1]
s2 = ''
for i in l:
	if i == i[::-1] and i not in l1:
		s2 += i
		break
s += s2
s += sr
print(len(s))
print(s)


def reverse(s):
	t = ''
	i = len(s) - 1
	while i >= 0:
		t += s[i]
		i += -1
	return t
(m1, n) = input().split()
m = int(m1)
a = []
for i in range(m):
	a.append(input())
l = []
j = 0
p = ''
for i in a:
	if reverse(i) in a and i != reverse(i):
		l.insert(j, i)
		l.insert(len(l) - j, reverse(i))
		a.remove(reverse(i))
		j += 1
	if i == reverse(i):
		p = i
l.insert(len(l) // 2, p)
t = ''
for i in l:
	t += i
print(len(t))
print(t)


(n, m) = list(map(int, input().split()))
palin = ''
d = dict()
for i in range(n):
	tmp = input()
	p = True
	if palin == '':
		k = m - 1
		for j in range(int(m / 2)):
			if tmp[j] != tmp[k]:
				p = False
			k -= 1
		if p:
			palin = tmp
	if tmp not in d.keys():
		aux = tmp[::-1]
		if aux in d.keys():
			d[aux] += 1
		else:
			d[tmp] = 1
resp = palin
for key in d:
	if d[key] == 2:
		resp = key + resp + key[::-1]
print(len(resp))
print(resp)


(n, m) = map(int, input().split())
mass = []
ans = ''
ansm = []
ans1 = ''
reverse = ''
for i in range(n):
	mass.append(input())
for i in range(n):
	for j in range(n):
		if mass[i] == mass[j][::-1] and i != j:
			ansm.append(mass[i])
			ansm.append(mass[j])
			mass[i] = '01'
			mass[j] = '01'
		if mass[i] == mass[i][::-1]:
			reverse = mass[i]
for i in range(0, len(ansm), 2):
	ans1 += ansm[i]
ans += ans1
ans += reverse
ans += ans1[::-1]
print(len(ans))
print(ans)


def test(ch1, ch2):
	for i in range(len(ch1)):
		if ch1[i] != ch2[len(ch1) - i - 1]:
			return False
	return True

def test2(ch):
	for i in range(len(ch)):
		if ch[i] != ch[len(ch) - i - 1]:
			return False
	return True
ch = input()
L = [int(i) for i in ch.split()]
n = L[0]
m = L[1]
L = []
s = ''
s2 = ''
t = 0
for i in range(n):
	ch = input()
	if test2(ch) and t == 0:
		s2 += ch
		t = 1
	else:
		for j in L:
			if test(j, ch):
				s = s + j
				s = ch + s
				L.remove(j)
				break
	L.append(ch)
s3 = ''
for i in range(len(s) // 2):
	s3 += s[i]
for i in s2:
	s3 += i
for i in range(len(s) // 2, len(s)):
	s3 += s[i]
print(len(s3))
print(s3)


(n, m) = map(int, input().split())
s = []
c1 = ''
c2 = ''
for i in range(n):
	s.append(input())
lp = ''
while s:
	if s[0] == s[0][::-1]:
		if len(s[0]) > len(lp):
			lp = s[0]
	else:
		try:
			ind = s.index(s[0][::-1])
			c1 += s[0]
			c2 = s[ind] + c2
			s.pop(ind)
		except:
			pass
	try:
		s.pop(0)
	except:
		pass
print(len(c1) * 2 + len(lp))
print(c1 + lp + c2)


n_m = list(map(int, input().split()))
string1 = ''
string2 = ''
string3 = ''
a = []
for i in range(n_m[0]):
	a.append(input())
for i in range(n_m[0]):
	flag = 0
	for j in range(int(n_m[1] / 2)):
		if a[i][j] != a[i][n_m[1] - j - 1]:
			flag = 1
			break
	if flag == 0:
		string3 += a[i]
		break
for i in range(n_m[0] - 1):
	for j in range(i + 1, n_m[0]):
		flag = 0
		for k in range(n_m[1]):
			if a[i][k] != a[j][n_m[1] - k - 1]:
				flag = 1
				break
		if flag == 0:
			string1 += a[i]
if len(string1) == 0 and len(string3) != 0:
	print(len(string3))
	print(string3)
elif len(string1) != 0 and len(string3) != 0 or (len(string1) != 0 and len(string3) == 0):
	for j in range(len(string1)):
		string2 += string1[len(string1) - 1 - j]
	string = string1 + string3 + string2
	print(len(string))
	print(string)
else:
	print(0)


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]
			x[i] = 1
			x[j] = 1
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)


(n, m) = map(int, input().split())
matrix = [[0 for y in range(0, n)] for x in range(0, 2)]
sum1 = []
sum2 = []
sum3 = []
ans = 0
sample1 = 0
sample2 = 0
for i in range(0, n):
	matrix[0][i] = input()
for i in range(0, n):
	for j in range(i, n):
		if matrix[1][i] == 0:
			for k in range(0, m):
				if matrix[0][i][k] == matrix[0][i][m - k - 1]:
					sample1 += 1
				if matrix[0][i][k] == matrix[0][j][m - k - 1] and i != j:
					sample2 += 1
			if sample2 == m:
				sum1.append(matrix[0][i])
				sum2.append(matrix[0][j])
				matrix[1][i] = 1
				matrix[1][j] = -1
				ans += 1
			elif sample1 == m and len(sum3) != 1:
				sum3.append(matrix[0][i])
				matrix[1][i] = 1
				ans += 1
			sample1 = 0
			sample2 = 0
victory = 0
if ans == 0:
	print(0)
else:
	victory = (len(sum1) + len(sum2) + len(sum3)) * m
	print(victory)
	for i in range(len(sum1)):
		print(sum1[i], end='')
	for i in range(len(sum3)):
		print(sum3[i], end='')
	for i in range(len(sum2)):
		print(sum2[len(sum2) - i - 1], end='')


(n, m) = map(int, input().split())
l = []
for i in range(n):
	s = input()
	l.append(s)
res = ''
c = 0
for i in l:
	p = ''.join(reversed(i))
	if p == i:
		res = p
		c += 1
if c > 1:
	res = res[:m]
j = len(l)
while j > 0:
	for i in l:
		p = ''.join(reversed(i))
		if p in l and p != i:
			res = res + i
			res = p + res
			if p in l:
				l.remove(p)
			if i in l:
				l.remove(i)
		elif i in l:
			l.remove(i)
	j = len(l)
print(len(res))
print(res)


def Input():
	tem = input().split()
	ans = []
	for it in tem:
		ans.append(int(it))
	return ans
s = []
ma = {}
ans1 = []
ans2 = []
ans3 = ''
(n, m) = Input()

def pal(s):
	k = len(s)
	for i in range(k // 2):
		if s[i] != s[k - 1 - i]:
			return False
	return True
for i in range(n):
	s.append(input())
	if s[-1] not in ma:
		ma[s[-1]] = 1
	else:
		ma[s[-1]] += 1
for i in range(n):
	if s[i] in ma:
		ma[s[i]] -= 1
		if ma[s[i]] == 0:
			del ma[s[i]]
	else:
		continue
	res = s[i][::-1]
	if res in ma:
		ma[res] -= 1
		if ma[res] == 0:
			del ma[res]
		ans1.append(s[i])
		ans2.append(res)
	elif pal(s[i]):
		ans3 = s[i]
if len(ans1) == 0 and len(ans3) == 0:
	print(0)
else:
	total = len(ans1) * 2 * m
	if len(ans3) > 0:
		total += m
	print(total)
	for i in range(len(ans1)):
		print(ans1[i], end='')
	if len(ans3) > 0:
		print(ans3, end='')
	for i in range(len(ans2) - 1, -1, -1):
		print(ans2[i], end='')
	print()


(m, n) = map(int, input().split())
List = []
for i in range(m):
	List.append(input())
reqstr = ''
palstr = ''
flag = 0
for x in List:
	if x == x[-1::-1] and flag == 0:
		palstr += x
		List.remove(x)
		flag = 1
		continue
	if x == x[-1::-1] and flag == 1:
		continue
	if x[-1::-1] in List:
		reqstr += x
		List.remove(x[-1::-1])
		continue
revans = reqstr[-1::-1]
reqstr = reqstr + palstr + revans
print(len(reqstr))
print(reqstr)


(n, m) = list(map(int, input().split()))
strs = []
ans = ''
for _ in range(n):
	strs.append(input())
for i in strs:
	if i == i[::-1]:
		ans += i
		strs.remove(i)
		break
for i in range(len(strs)):
	now = strs[i]
	if now[::-1] in strs[i + 1:]:
		ans = now + ans + now[::-1]
	else:
		pass
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
(p, q) = ('', '')
o = ''
for i in range(n):
	if a[i]:
		for j in range(i + 1, n):
			if a[j][::-1] == a[i]:
				p += a[i]
				q = a[j] + q
				a[j] = ''
				break
		else:
			if a[i] == a[i][::-1]:
				o = a[i]
t = p + o + q
print(len(t))
print(t)


(x, y) = map(int, input().split())
mid = ''
ans = ''
set1 = set()
for i in range(x):
	a = input()
	if a == a[::-1]:
		mid = a
	if a[::-1] in set1:
		ans += a
	else:
		set1.add(a)
ans = ans + mid + ans[::-1]
print(len(ans))
print(ans)


def solve():
	(n, m) = map(int, input().split())
	strings = []
	res = ''
	for _ in range(n):
		s = input()
		if s[::-1] in strings:
			res = s + res + s[::-1]
			strings.remove(s[::-1])
		else:
			strings.append(s)
	for s in strings:
		if s == s[::-1]:
			res = res[:len(res) // 2] + s + res[len(res) // 2:]
			break
	print(len(res))
	print(res)
solve()


(n, m) = map(int, input().split())
d = {}
f = []
a = []
used = [False] * n
for i in range(n):
	s = input()
	if s[::-1] in d:
		used[i] = True
		used[d[s[::-1]]] = True
		f = [s] + f + [s[::-1]]
		del d[s[::-1]]
	else:
		d[s] = i
	a.append(s)
if len(f) % 2:
	print(len(f) * m)
	print(''.join(f))
else:
	for i in range(n):
		if not used[i] and a[i] == a[i][::-1]:
			f = f[:len(f) // 2] + [a[i]] + f[len(f) // 2:]
			break
	print(len(f) * m)
	print(''.join(f))


li = list(input().split())
try:
	x = int(li[0])
	y = int(li[1])
except:
	y = int(li[0])
	x = 1
li = [0] * x
for i in range(x):
	li[i] = input()
count = 0
li1 = []
str1 = ''
b = True
for i in range(0, x):
	for j in range(i + 1, x):
		if j not in li1 and li[i] == li[j][::-1]:
			count += 2 * y
			li1.append(j)
			str1 = li[i] + str1 + li[j]
			break
	else:
		if b:
			if li[i] == li[i][::-1]:
				count += y
				str1 = str1[:len(str1) // 2] + li[i] + str1[len(str1) // 2:]
				b = False
print(count)
print(str1)


(n_word, word_len) = map(int, input().split())
palindrome_word = ''
enclosing_words = list()
visited_words = set()
for i in range(n_word):
	word = input()
	rev_word = word[::-1]
	if palindrome_word == '' and word == rev_word:
		palindrome_word = word
		continue
	if rev_word in visited_words:
		enclosing_words.append(word)
	visited_words.add(word)
for e_word in enclosing_words:
	palindrome_word = e_word + palindrome_word + e_word[::-1]
print(len(palindrome_word))
print(palindrome_word)


l = input()
l = l.split()
n = int(l[0])
m = int(l[1])
all = []
s = ''
for i in range(n):
	x = input()
	all.append(x)
for i in range(n):
	no = True
	for j in range(i + 1, n):
		if all[i] == all[j][::-1]:
			no = False
	if no:
		if all[i] == all[i][::-1]:
			s = all[i]
			break
for i in range(n):
	for j in range(i + 1, n):
		if all[i] == all[j][::-1]:
			s = all[i] + s
			s += all[j]
print(len(s))
print(s)


[n, m] = list(map(int, input().split()))
l = []
d = {}
res = ''
mid = ''
for i in range(n):
	s = input()
	d[s] = 1
	if s[::-1] == s:
		mid = s
	elif d.get(s[::-1], 0) == 1:
		res += s
res = res + mid + res[::-1]
print(len(res))
print(res)


lis = []
pair = []
aatam = []
faltu = []
(a, b) = map(int, input().split())
for i in range(a):
	lis.append(input())
while lis != []:
	if lis[0][::-1] in lis[1:]:
		pair.append(lis.pop(0))
	elif lis[0][::-1] == lis[0]:
		aatam.append(lis.pop(0))
	else:
		faltu.append(lis.pop(0))
first = ''
second = ''
third = ''
first = first + ''.join(pair)
if aatam != []:
	second = second + aatam[0]
third = third + first[::-1]
final = first + second + third
print(len(final))
print(final)


def palindrome(s):
	for i in range(len(s) // 2):
		if s[i] != s[-i - 1]:
			return False
	return True
(n, m) = map(int, input().split())
strings = []
ok = dict()
for i in range(n):
	strings.append(input())
	ok[strings[i]] = True
ans = ''
temp = ''
for i in strings:
	if palindrome(i):
		ans = i
		ok[i] = False
		break
for i in range(len(strings) - 1):
	if ok[strings[i]]:
		for j in range(i + 1, len(strings)):
			if ok[strings[j]]:
				s = strings[i] + strings[j]
				if palindrome(s):
					ans = strings[i] + ans + strings[j]
					ok[strings[i]] = False
					ok[strings[j]] = False
					j = len(strings)
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(input())
sol = []
sol_m = []
while len(l) > 0:
	if l[-1][::-1] in l:
		if l[-1][::-1] != l[-1]:
			sol.append(l[-1])
		else:
			sol_m.append(l[-1])
	del l[-1]
ss = ''.join(sol)
if len(sol_m) > 0:
	res = ss + sol_m[0] + ss[::-1]
else:
	res = ss + ss[::-1]
print(len(res))
print(res)


(n, m) = map(int, input().split())
strings = [input() for s in range(n)]
selfpalis = []
palis = []
already = set([])
for a in range(len(strings)):
	if not a in already:
		pali = False
		for b in range(len(strings)):
			if a != b and (not b in already):
				if strings[a][::-1] == strings[b]:
					already.add(b)
					already.add(a)
					palis.append(strings[a])
					pali = True
			elif a == b and strings[a][::-1] == strings[a]:
				if pali == False:
					selfpalis.append(strings[a])
					already.add(a)
			if pali == True:
				break
p1 = ''
mid = ''
for s in range(len(palis)):
	p1 += palis[s]
if len(selfpalis) >= 1:
	mid += selfpalis[0]
if len(p1) + len(mid) == 0:
	print(0)
else:
	print(2 * len(p1) + len(mid))
	print(p1 + mid + p1[::-1])


import sys
INF = 10 ** 18
MOD = 10 ** 9 + 7

def input():
	return sys.stdin.readline().rstrip()

def main():
	(n, m) = map(int, input().split())
	s = set()
	ans1 = ''
	ans2 = ''
	for _ in range(n):
		a = input()
		b = ''.join(list(reversed(a)))
		if a == b:
			ans2 = a
		if b in s:
			ans1 += a
		s.add(a)
	ans3 = ''.join(list(reversed(ans1)))
	ans = ans1 + ans2 + ans3
	print(len(ans))
	print(ans)
main()


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)
length = len(Ss)
middle = ''
aa = ['' for _ in range(length)]
maa = ['' for _ in range(length)]
for (i, S) in enumerate(Ss):
	mirrorS = S[::-1]
	if S != mirrorS:
		if mirrorS in C:
			if C[mirrorS] > 0:
				C[S] -= 1
				aa[i] = S
				C[mirrorS] -= 1
				maa[i] = mirrorS
	elif C[S] > 0:
		if C[S] > 1:
			C[S] -= 2
			aa[i] = S
			maa[i] = S
		else:
			C[S] -= 1
			middle = S
answer = ''.join(aa) + middle + ''.join(maa[::-1])
print(len(answer))
print(answer)


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
v = [False for i in range(n)]
center = ''
ans = ''

def pnp(ts):
	for i in range(m // 2):
		if ts[i] != ts[m - i - 1]:
			return False
	return True

def psnp(s1, s2):
	for i in range(m):
		if s1[i] != s2[m - i - 1]:
			return False
	return True
for i in range(n):
	if v[i]:
		continue
	for j in range(n):
		if j == i or v[j]:
			continue
		if psnp(a[i], a[j]):
			(v[i], v[j]) = (True, True)
			ans += a[i]
	if pnp(a[i]):
		if v[i]:
			continue
		v[i] = True
		center = a[i]
ans = ans + center + ans[::-1]
print(len(ans))
print(ans)


a = input()
a = a.split()
(n, m) = [int(i) for i in a]
li = []
p = []
for i in range(n):
	x = input()
	if x == x[::-1]:
		p.append(x)
	else:
		li.append(x)
result = []
s = ''
l = ''
for j in li:
	if j[::-1] in li:
		s = s + j
		l = j[::-1] + l
		li.pop(li.index(j[::-1]))
if len(p):
	print(len(s + p[0] + l))
	print(s + p[0] + l)
else:
	print(len(s + l))
	print(s + l)


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) = map(int, input().split())
q1 = []
ans = []
val = ''
used = [0 for i in range(n)]
for i in range(n):
	s = input()
	q1.append(s)
for i in range(n):
	for j in range(i + 1, n):
		if q1[i] == q1[j][::-1] and used[i] == 0 and (used[j] == 0):
			ans.append(q1[i])
			used[i] = 1
			used[j] = 1
for i in range(n):
	if not used[i]:
		f = 1
		for j in range(m):
			if q1[i][j] != q1[i][m - 1 - j]:
				f = 0
				break
		if f:
			val = q1[i]
			break
if val == '':
	print(len(ans) * 2 * m)
else:
	print((len(ans) * 2 + 1) * m)
for qw in ans:
	print(qw, end='')
print(val, end='')
for i in range(len(ans) - 1, -1, -1):
	print(ans[i][::-1], end='')


from collections import deque
(t, n) = map(int, input().split())
ans = deque()
(v, self, q) = ([], [0] * (t + 1), [])
for i2 in range(t):
	s = str(input())
	v.append(s)
	li = []
	for i in range(n - 1, -1, -1):
		li.append(s[i])
	s1 = ''.join(li)
	if s == s1:
		self[i2] = 1
	for i in range(len(q) + 1):
		if i == len(q):
			q.append([s, i2])
		elif q[i][0] == s1:
			ans.append(q[i][1])
			ans.appendleft(i2)
			self[i2] = 0
			self[q[i][1]] = 0
			del q[i]
			break
for i in range(t):
	if self[i] == 1:
		ans.insert(len(ans) // 2, i)
		break
if len(ans) == 0:
	print(0)
else:
	print(len(ans) * n)
	for i in range(len(ans)):
		print(v[ans[i]], end='')


(N, M) = map(int, input().split())
S = [input() for _ in range(N)]
ans = ''
pairs = 0
used = set()
rev_sento = set()
for i in range(N):
	if i in used:
		continue
	for j in range(i + 1, N):
		if j in used:
			continue
		if ''.join(S[i][::-1]) == S[j]:
			pairs += 1
			used.add(i)
			used.add(j)
			rev_sento.add(S[i])

def isPalindrome(s):
	return all((a == b for (a, b) in zip(s, reversed(s))))
for s in rev_sento:
	ans += s
if any((i not in used and isPalindrome(a) for (i, a) in enumerate(S))):
	print((pairs * 2 + 1) * M)
	for s in S:
		if isPalindrome(s):
			print(ans + s + ans[::-1])
			break
else:
	print(pairs * 2 * M)
	print(ans + ans[::-1])


def main():
	(n, m) = map(int, input().split())
	words = []
	(mid, start, end) = ('', '', '')
	for i in range(n):
		w = input()
		rw = w[::-1]
		if rw == w:
			mid = rw
		elif rw in words:
			end = end + rw
			start = w + start
		words.append(w)
	ans = start + mid + end
	print(len(ans))
	print(ans)
main()


def isPalindrome(a, b):
	flag = True
	for i in range(len(a)):
		if a[i] != b[len(a) - i - 1]:
			flag = False
			break
	return flag
(n, m) = map(int, input().split())
s = []
startList = []
endList = []
selfList = []
for i in range(n):
	s.append(input().strip())
for i in range(len(s)):
	for j in range(i + 1, len(s)):
		if isPalindrome(s[i], s[j]):
			startList.append(s[i])
			endList.append(s[j])
for i in range(len(s)):
	if isPalindrome(s[i], s[i]):
		selfList.append(s[i])
result = ''
for ele in startList:
	result += ele
for ele in selfList:
	result += ele
	break
for i in range(len(endList) - 1, -1, -1):
	result += endList[i]
print(len(result))
print(result)


def revd(s):
	return ''.join(reversed(s))

def check_Palindrome(s):
	return s == s[::-1]

def condition(s, llr):
	if s in llr:
		return True
	else:
		return False
s = []
(n, m) = map(int, input().split())
lp = ''
llr = s.copy()
ll = s.copy()
lr = s.copy()
i = 0
flag = 0
le = 0
while i < n:
	s = input()
	if check_Palindrome(s):
		if flag == 0:
			lp = s
			le += len(s)
			flag = 1
	elif condition(s, llr):
		lr.append(s)
		ll.insert(0, revd(s))
		le += 2 * len(s)
	else:
		llr.append(revd(s))
	i += 1
print(le)
for el in ll:
	print(el, end='')
print(lp, end='')
for el in lr:
	print(el, end='')


(n, m) = list(map(int, input().split()))
l = []
max_pal = ''
esq = ''
dir = ''
for i in range(n):
	l.append(input())
while len(l) > 0:
	if l[0] == l[0][::-1]:
		if len(l[0]) >= len(max_pal):
			max_pal = l[0]
	elif l[0][::-1] in l:
		esq += l[0]
		dir = l[0][::-1] + dir
		l.remove(l[0][::-1])
	l.pop(0)
resp = esq + max_pal + dir
print(len(resp))
print(resp)


def reverse(s):
	return s[::-1]
(n, m) = map(int, input().split())
a = list()
b = list()
c = ''
for i in range(0, n):
	temp = input()
	a.append(temp)
	t = reverse(temp)
	if t == temp:
		c = temp
for i in range(0, len(a)):
	s = reverse(a[i])
	for j in range(i + 1, len(a)):
		if s == a[j]:
			b.append(a[i])
if len(b) == 0:
	if c == '':
		print(0)
	else:
		print(len(c))
		print(c)
else:
	g = ''
	tp = ''
	tp1 = ''
	for i in b:
		g = g + i
	tp = reverse(g)
	tp1 = g + c + tp
	print(len(tp1))
	print(tp1)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
d = {}
check = {}
mid = ''
midlength = 0
for i in range(n):
	flag = 0
	if l[i] not in check:
		for j in range(i + 1, n):
			if l[i] == l[j][::-1]:
				d[l[i]] = l[j]
				check[l[i]] = 1
				check[l[j]] = 1
				flag = 1
		if flag == 0:
			if l[i] == l[i][::-1]:
				if len(l[i]) > midlength:
					midlength = len(l[i])
					mid = l[i]
p1 = ''
p2 = ''
count = 0
for i in d:
	p1 += i
	count += len(i)
print(count * 2 + midlength)
print(p1 + mid + p1[::-1])


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
(n, m) = invr()
a = []
for _ in range(n):
	a.append(input())
count = defaultdict(lambda : 0)
found = ''
for i in a:
	count[i] += 1
	rev = i[::-1]
	if rev == i:
		found = rev
	else:
		count[rev] += 1
for k in count:
	if count[k] == 2:
		rev = k[::-1]
		found = k + found + rev
		count[k] = -1
		count[rev] = -1
print(len(found))
print(found)


(n, m) = map(int, input().split())
arr = []
pal = ''
rev = ''
for i in range(n):
	temp = input()
	arr.append(temp)
	if temp == temp[::-1]:
		rev = temp
	for j in range(i):
		if arr[i] == arr[j][::-1]:
			pal = arr[i] + pal + arr[j]
if rev != '':
	l = int((len(pal) + 1) / 2)
	pal = pal[0:l] + rev + pal[l:]
if pal == '':
	print(0)
else:
	print(len(pal))
	print(pal)


(n, m) = map(int, input().split())
L = []
L1 = ''
L3 = ''
L2 = []
s1 = ''
for _ in range(n):
	x = input()
	L.append(x)
i = 0
while i < len(L):
	z = L[i][::-1]
	if L[i] == z:
		p = L[i]
		L.remove(p)
		if z in L:
			L1 = L1 + p
			L2.append(z)
			L.remove(z)
		elif len(L3) == 0:
			L3 = L3 + p
	elif z in L:
		L1 = L1 + L[i]
		L.remove(L[i])
		L2.append(z)
		L.remove(z)
	else:
		i = i + 1
s1 = s1.join(reversed(L2))
if len(L1 + L3 + s1) > 0:
	print(len(L1 + L3 + s1))
	print(L1 + L3 + s1)
else:
	print('0')


(a, b) = map(int, input().split())
words = []
pal1 = ''
pal2 = ''
pals = ''
for i in range(a):
	words.append(input().strip())
for i in range(a):
	temp = words[i]
	if temp == temp[::-1]:
		pals = temp if len(temp) >= len(pals) else pals
	else:
		try:
			q = words[i:].index(temp[::-1])
			pal1 += words[i]
		except:
			continue
sr = pal1 + pals + pal1[::-1]
print(len(sr))
print(sr)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = 1
	rr = []
	for _ in range(t):
		(n, m) = LI()
		sa = [S() for _ in range(n)]
		ta = [s[::-1] for s in sa]
		a = []
		b = []
		for i in range(n):
			if i in b:
				continue
			s = sa[i]
			for j in range(i + 1, n):
				if j not in b and s == ta[j]:
					a.append(s)
					b.append(ta[j])
		k = -1
		for i in range(n):
			if i in a or i in b:
				continue
			if sa[i] == ta[i]:
				k = i
				break
		r = JA(a, '')
		if k >= 0:
			r += sa[k] + r[::-1]
		else:
			r += r[::-1]
		rr.append(len(r))
		rr.append(r)
	return JA(rr, '\n')
print(main())


def ii():
	return int(input())

def ai():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())
(n, l) = mi()
strings = []
for i in range(n):
	strings.append(input())
palindrome = ''
lar_pal = ''
for s in strings:
	if s == s[::-1]:
		if len(lar_pal) < len(s):
			palindrome = s
for i in range(n):
	s = strings[i]
	if s[::-1] in strings[i + 1:]:
		palindrome = s + palindrome + s[::-1]
print(len(palindrome))
print(palindrome)


(n, m) = map(int, input().split())
strings = []
pal = []
pairs = []
for i in range(n):
	s = input()
	r = s[::-1]
	if s == r:
		pal.append(s)
	elif 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)


(n, m) = map(int, input().split())
line_list = []
line_dict = {}
for _ in range(n):
	line = input()
	line_list.append(line)
	line_dict[line] = line_dict.get(line, 0) + 1
head = []
body = ''
for line in line_dict.keys():
	if line_dict.get(line, 0) <= 0:
		continue
	line_rev = line[::-1]
	if line == line_rev:
		body = line
		continue
	if line_dict.get(line_rev, 0) > 0:
		head.append(line)
		line_dict[line_rev] = line_dict[line_rev] - 1
		line_dict[line] = line_dict[line] - 1
answer = ''.join(head) + body + ''.join(head)[::-1]
print(len(answer))
print(answer)


(x, y) = map(int, input().split())
dictpp = {}
dictsp = {}
l = []
p = []
for i in range(x):
	k = input()
	if k == k[::-1]:
		if k in dictpp.keys():
			dictpp[k] += 1
		else:
			p.append(k)
			dictpp[k] = 1
	elif k[::-1] in dictsp.keys():
		l.append([k[::-1], k])
		dictsp.pop(k[::-1])
	else:
		dictsp[k] = ''
left = ''
right = ''
middle = ''
f = 0
for i in p:
	if dictpp[i] == 1 and f == 0:
		middle = i
		f = 1
	else:
		left += dictpp[i] // 2 * i
		right = dictpp[i] // 2 * i + right
for i in range(len(l)):
	left += l[i][0]
	right = l[i][1] + right
j = left + middle + right
print(len(j))
print(j)


def give(s, t):
	for i in range(len(s)):
		if s[i] != t[len(s) - i - 1]:
			return False
	return True

def pali(s):
	i = 0
	j = len(s) - 1
	while i <= j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True
l = list(map(int, input().split()))
n = l[0]
g = []
h = []
for i in range(n):
	s = input()
	if pali(s) and len(h) == 0:
		h.append(s)
	else:
		g.append(s)
for i in range(len(g) - 1):
	for j in range(i + 1, len(g)):
		if give(g[i], g[j]):
			h.insert(0, g[i])
			h.append(g[j])
			break
c1 = 0
d = ''
for i in range(len(h)):
	c1 += len(h[i])
	d += h[i]
print(c1)
print(d)


(n, m) = map(int, input().split())
s = []
is_p = [True for i in range(n)]
for i in range(n):
	s.append(input())
for i in range(n):
	flag = True
	for j in range(m // 2):
		if s[i][j] != s[i][m - 1 - j]:
			flag = False
			break
	if not flag:
		is_p[i] = False
used = [False for i in range(n)]
ans_l = []
ans_r = []
for i in range(n):
	if used[i]:
		continue
	for j in range(i + 1, n):
		if not used[j] and s[i][::-1] == s[j]:
			ans_l.append(s[i])
			ans_r.append(s[j])
			used[i] = True
			used[j] = True
			break
ans_r.reverse()
for i in range(n):
	if not used[i] and is_p[i]:
		ans_l.append(s[i])
		break
ans = ''
for i in ans_l:
	ans += i
for i in ans_r:
	ans += i
print(len(ans))
print(ans, end='\n')


def palin(st):
	if st == st[::-1]:
		return 1
	else:
		return 0
(n, m) = map(int, input().split())
strngs = []
checks = []
reals = []
palins = []
rever = []
flag = 0
for _ in range(n):
	i = input()
	checks.append([i, palin(i)])
for i in range(len(checks)):
	if checks[i][1] == 1:
		if flag == 0:
			palins.append(checks[i][0])
			flag = 1
	else:
		strngs.append(checks[i][0])
for i in range(len(strngs)):
	if strngs[i][::-1] in strngs and strngs[i][::-1] not in reals:
		reals.append(strngs[i])
		rever.append(strngs[i][::-1])
length = (len(reals) + len(palins) + len(rever)) * m
rever.reverse()
stri = ''.join(reals) + ''.join(palins) + ''.join(rever)
print(length)
print(stri)


I = lambda : map(int, input().split())
(n, m) = I()
S = [input() for _ in range(n)]
T = set(S)
done = [False] * n
lft = ''
mid = ''
for (i, s) in enumerate(S):
	if done[i]:
		continue
	if s == s[::-1]:
		mid = s
	elif s[::-1] in T:
		done[i] = True
		done[S.index(s[::-1])] = True
		lft += s
ans = lft + mid + lft[::-1]
print(len(ans), ans, sep='\n')


(n, m) = [int(x) for x in input().split(' ')]
a = []
result = []
center = ''
for i in range(n):
	a.append(input())
for x in range(len(a)):
	if center == '':
		for y in range((m + 1) // 2):
			if a[x][y] != a[x][m - 1 - y]:
				break
			elif y + 1 == (m + 1) // 2:
				center = a[x]
	for y in a[x + 1:]:
		if a[x] == y[::-1]:
			result.append(y)
			result.insert(0, a[x])
if center != '' and result != []:
	result.insert(int(len(result) / 2), center)
elif center != '':
	result.append(center)
text = ''.join(result)
print(len(text))
print(text)


def reverse(s):
	return s[::-1]

def isPalindrome(s):
	rev = reverse(s)
	if s == rev:
		return True
	return False
(num, n) = map(int, input().split())
l = []
l2 = []
for i in range(num):
	l.append(input())
pals = ''
rests = ''
for x in l:
	if isPalindrome(x):
		pals = x
		l2.append(x)
	rex = reverse(x)
	if rex in l and rex not in l2:
		rests += x
		l2.append(x)
		l2.append(rex)
print(len(pals) + 2 * len(rests))
print(rests + pals + reverse(rests))


def palindrome(s):
	if s == s[-1::-1]:
		return 1
	else:
		return 0

def reverse(s):
	return s[-1::-1]
l = []
(n, m) = list(map(int, input().split()))
for i in range(n):
	s = input()
	l.append(s)
pair = []
palin = []
for i in range(n - 1):
	for j in range(i + 1, n):
		if l[i] == reverse(l[j]):
			pair.append([l[i], l[j]])
	if palindrome(l[i]) == 1:
		palin.append(l[i])
if palindrome(l[-1]) == 1:
	palin.append(l[-1])
ANSWER = ''
for i in range(len(pair)):
	ANSWER += pair[i][0]
temp = ANSWER
if len(palin) > 0:
	ANSWER += palin[0]
ANSWER += temp[-1::-1]
if len(ANSWER) == 0:
	print(0)
else:
	print(len(ANSWER))
	print(ANSWER)


(n, m) = map(int, input().split(' '))
A = []
front = ''
end = ''
mid = ''
for i in range(n):
	s = input()
	A.append(s)
	r = s[::-1]
	if r in A and r != s:
		front += r
		end = s + end
	elif r == s:
		mid = s
fins = front + mid + end
print(len(fins))
print(fins)


def is_palindrome(str1, str2):
	ret = True
	for i in range(0, len(str1)):
		if str1[i] is not str2[len(str2) - i - 1]:
			ret = False
	return ret

def is_pal_one_word(str1):
	ret = True
	for i in range(0, len(str1) // 2):
		if str1[i] is not str1[len(str1) - i - 1]:
			ret = False
	return ret
(num_str, len_str) = map(int, input().split())
words = []
words_cp = []
semi_res = []
for i in range(0, num_str):
	words.append(input())
for it in words:
	words_cp.append(it)
for i in range(0, num_str - 1):
	for j in range(i + 1, num_str):
		if is_palindrome(words[i], words[j]):
			words_cp[i] = words_cp[j] = ''
			semi_res.append(words[i])
			semi_res.append(words[j])
max_middle = ''
for it in words_cp:
	if it is not '' and len(it) > len(max_middle) and is_pal_one_word(it):
		max_middle = it
res = []
res.append(max_middle)
for i in range(0, len(semi_res)):
	if not i % 2:
		res.insert(0, semi_res[i])
	else:
		res.append(semi_res[i])
final_res = ''
for it in res:
	final_res += it
print(len(final_res))
print(final_res)


(Test, length) = [int(x) for x in input().split()]
Words = []
ind = 0
Reverk = []
for i in range(Test):
	temp = input()
	if temp == temp[::-1]:
		Reverk.append(temp)
	Words.append([temp, -1, ind])
	ind = ind + 1
szavak = []
for i in Words:
	if i[1] == -1:
		for j in Words:
			temp = j[0]
			if i[0] == temp[::-1] and i[2] != j[2]:
				i[1] = j[2]
				j[1] = i[2]
				szavak.append(i[0])
szo = ''
if len(Reverk) > 0:
	for i in szavak:
		szo += i
	szo += Reverk[0]
	for i in szavak[::-1]:
		szo += i[::-1]
else:
	for i in szavak:
		szo += i
	for i in szavak[::-1]:
		szo += i[::-1]
print(len(szo))
print(szo, end='')


(n, m) = map(int, input().split())
a = []
e = []
for _ in range(n):
	f = input()
	if f == f[::-1]:
		e.append(f)
	else:
		a.append(f)
b = []
t = []
f = len(a)
k = 0
for i in range(f - 1):
	for j in range(i + 1, f):
		if a[i] == a[j][::-1]:
			b.append(a[i])
			t.append(a[j])
			break
if len(e) != 0:
	b.append(e[0])
t.reverse()
b = b + t
d = ''.join(map(str, b))
print(len(d))
print(d)


(n, m) = map(int, input().split())
d = {}
l = []
for i in range(n):
	l.append(input())
	d[l[-1]] = 0
(d1, d2) = ({}, {})
for i in range(n):
	if l[i][::-1] in d.keys() and l[i] != l[i][::-1]:
		if l[i] not in d1.keys() and l[i] not in d1.values():
			d1[l[i]] = l[i][::-1]
	elif l[i] == l[i][::-1]:
		d2[l[i]] = 0
(g, h, ans) = ('', '', '')
for i in d1:
	g += i
h += g[::-1]
t = 0
for i in d2:
	if t == 0:
		g += i
		t += 1
	else:
		break
ans += g + h
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
a = []
s = []
b = []
l = 0
z = ''
for i in range(n):
	x = input()
	if x.count(x[0]) == m or x == x[::-1]:
		b.append(x)
	else:
		a.append(x)
for i in range(len(a)):
	if a[i][::-1] in a:
		if a[i][::-1] not in s:
			s.append(a[i])
for i in s:
	z = z + i
p = z
if len(b) > 0:
	z += b[0]
z += p[::-1]
print(len(z))
print(z)


(a, b) = map(int, input().split(' '))
A = []
f = ''
end = ''
mid = ''
for i in range(0, a):
	a = input()
	A.append(a)
	e = a[::-1]
	if e in A and e != a:
		f += a
		end = e + end
	elif e == a:
		mid = e
ans = f + mid + end
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
words = []
for _ in range(n):
	words.append(input())
d = {}
res = []
for w in words:
	r = w[::-1]
	if r in d and d[r] != 0:
		d[r] -= 1
		res.append(w)
	else:
		d[w] = d.get(w, 0) + 1
c = 0
for w in d:
	if d[w] > 0 and w == w[::-1]:
		res.append(w)
		c -= 1
		break
for i in range(len(res) + c - 1, -1, -1):
	res.append(res[i][::-1])
print(sum(map(len, res)))
print(''.join(res))


(n, m) = map(int, input().split())
b = [input().rstrip() for _ in range(n)]
c = set(b)
(l, r) = ([], [])
x = ''
for p in b:
	q = p[::-1]
	if p in c:
		if p == q:
			if len(p) > len(x):
				x = p
		elif q in c:
			l.append(p)
			r.append(q)
			c.remove(q)
		c.remove(p)
a = ''.join(l) + x + ''.join(reversed(r))
print(len(a))
print(a)


(n, m) = map(int, input().split())
a = [input() for x in range(n)]
z = []
p = []
for x in range(n):
	for y in range(x + 1, n):
		if a[x] == a[y][::-1]:
			z.append((x, y))
		if a[x] == a[x][::-1]:
			p.append(x)
	if x == n - 1:
		if a[x] == a[x][::-1]:
			p.append(x)
ans = ''
for x in z:
	ans += a[x[0]]
if len(p) > 0:
	ans += a[p[0]]
for x in z[::-1]:
	ans += a[x[1]]
print(len(ans))
print(ans)


def run():
	import sys
	sys.stdin = open('/home/punit/Documents/Cpp Programs/input.txt', 'r')
	sys.stdout = open('/home/punit/Documents/Cpp Programs/output.txt', 'w')
	from math import ceil, sqrt, floor
(n, m) = map(int, input().split())
ans = [0] * (n * m)
d = dict()
for i in range(n):
	x = input()
	y = x[::-1]
	if y in d.keys():
		d[y] += 1
	else:
		d[x] = 1
k = 0
j = n * m - 1

def check(st):
	i = 0
	j = len(st) - 1
	while i <= j:
		if st[i] != st[j]:
			return False
		i += 1
		j -= 1
	return True
for (i, v) in d.items():
	if v == 2:
		ans[k] = i
		ans[j] = i[::-1]
		k += 1
		j -= 1
for (i, v) in d.items():
	if v == 1:
		if check(i):
			ans[n // 2] = i
			break
p = ''
for i in ans:
	if i != 0:
		p += i
print(len(p))
print(p)


(nb_strings, lens) = [int(x) for x in input().split()]
has = [input() for _ in range(nb_strings)]
ones = []
pairs = []
paired = []
for i in has:
	if i == i[::-1]:
		ones.append(i)
	elif i not in paired:
		if i[::-1] in has:
			pairs.append([i, i[::-1]])
			paired.append(i[::-1])
answer = ''
for i in pairs:
	answer += i[0]
if ones:
	answer += ones[0]
for i in pairs[::-1]:
	answer += i[1]
print(len(answer))
if len(answer) > 0:
	print(answer)


def palin(st):
	for i in range(len(st) // 2):
		if not st[i] == st[len(st) - i - 1]:
			return False
	return True
f = []
used = []
notusls = ''
ans = ''
zap = ''
(n, m) = map(int, input().split())
for i in range(n):
	a = input()
	f.append(a)
for j in range(len(f)):
	for t in range(len(f)):
		if palin(f[j] + f[t]) and j != t and (j not in used) and (t not in used):
			notusls = f[j] + notusls + f[t]
			used.append(j)
			used.append(t)
for i in range(len(f)):
	if palin(f[i]) and i not in used:
		zap = f[i]
		break
if len(notusls) > 0:
	for i in range(len(notusls)):
		if i == len(notusls) // 2:
			ans += zap
		ans += notusls[i]
else:
	ans += zap
print(len(ans))
print(ans)


import string

def main():
	(n, m) = map(int, input().split())
	dct = dict()
	for i in range(n):
		line = input()
		if line in dct:
			dct[line] += 1
		else:
			dct[line] = 1
	total = 0
	beggining = ''
	ending = ''
	middle = ''
	for line in dct:
		st = line[::-1]
		if line == st:
			a = dct[line] // 2
			total += a
			if dct[line] % 2 == 1:
				middle = st
			for i in range(a):
				beggining += line
				ending += line
		elif st in dct:
			a = min(dct[line], dct[st])
			total += a
			for i in range(a):
				beggining += line
				ending = st + ending
		dct[line] = 0
	print(len(beggining) + len(middle) + len(ending))
	print(beggining + middle + ending)
t = 1
for i in range(t):
	main()


(n, m) = map(int, input().split())
A = list()
Ar = list()
Ap = list()
for i in range(0, n):
	x = input()
	A.append(x)
	Ar.append(x[::-1])
	if x == x[::-1]:
		Ap.append(x)
B = list()
for i in range(0, n):
	for j in range(i + 1, n):
		if Ar[i] == A[j]:
			B.append(A[j])
s = ''
for x in B:
	s += x
if len(Ap) > 0:
	s += Ap[0]
for x in range(len(B) - 1, -1, -1):
	s += B[x][::-1]
print(len(s))
print(s)


(n, m) = map(int, input().split())
s = set()
arr = []
ceven = 0
codd = 1
for i in range(n):
	a = input()
	arr.append(a)
	s.add(a)
f = 0
ans = ''
c = 0
last = ''
for i in range(n):
	rev = arr[i][::-1]
	if rev == arr[i] and (not f):
		f = 1
		last = arr[i]
		c += m
	elif rev != arr[i]:
		if rev in s:
			ans += arr[i]
			c += 2 * m
			s.remove(rev)
			s.remove(arr[i])
n = len(ans)
rev = ans[::-1]
ans += last
ans += rev
print(c)
print(ans)


(n, m) = map(int, input().split())
a = []
nonpal = pal = ''
for _ in [0] * n:
	x = input()
	y = x[::-1]
	nonpal += x * (y in a)
	a += (x,)
	if x == y:
		pal = x
nonpal = nonpal + pal + nonpal[::-1]
print(len(nonpal), nonpal)


(n, m) = map(int, input().split())
a = set()
b = []
for i in range(n):
	b.append(input())
	a.add(b[-1])
s = set()
mid = ''
for i in a:
	r = i[::-1]
	if i != r and r in a and (r not in s):
		s.add(i)
	elif r == i and len(i) > len(mid):
		mid = i
s = ''.join(list(s))
ans = s + mid + s[::-1]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
s = set()
r = ''
p = ''
for _ in range(n):
	c = input()
	if c[::-1] == c:
		p = c
	if c[::-1] in s:
		r += c
	else:
		s.add(c)
r = r + p + r[::-1]
print(len(r))
print(r)


(n, m) = [int(j) for j in input().split()]
l = [1] * n
for i in range(n):
	s = input()
	l[i] = s
visited = [0] * n
pairs = []
indi = ''

def pal(s1, s2):
	n = len(s1)
	if s1 == s2[::-1]:
		return True
	elif s1 == s2:
		return True
	else:
		return False

def ispal(s1):
	n = len(s1)
	for i in range(n // 2 + 1):
		if s1[i] != s1[n - i - 1]:
			return False
	return True
for i in range(n):
	if visited[i] == 0:
		visited[i] = 1
		for j in range(i + 1, n):
			if visited[j] == 0:
				if pal(l[i], l[j]):
					pairs.append((i, j))
					visited[j] = 1
					break
		else:
			if ispal(l[i]) and indi == '':
				indi = l[i]
ans = indi
for pair in pairs:
	ans = l[pair[0]] + ans + l[pair[1]]
print(len(ans))
print(ans)


l = []
x = []
pal = ''
f = 0
(n, k) = map(int, input().split())
for _ in range(n):
	s = input()
	if s[::-1] in l:
		x.append(s)
		l.remove(s[::-1])
	elif s[::-1] == s and f == 0:
		f = 1
		pal += s
	else:
		l.append(s)
for i in x:
	pal = i + pal + i[::-1]
print(len(pal), pal, sep='\n')


t = 1
while t:
	d = {}
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		s = input()
		l.append(s)
	index = {}
	prev = [0] * (n + 1)
	for i in range(n):
		for j in range(i + 1, n):
			if prev[i] == 0 and prev[j] == 0:
				k1 = 0
				ch = 0
				for k in range(m - 1, -1, -1):
					if l[i][k] == l[j][k1]:
						ch += 1
					k1 += 1
				if ch == m:
					d[i] = []
					prev[j] = 1
					prev[i] = 1
					d[i].append(l[i])
					d[i].append(l[j])
	s1 = ''
	lmax = 0
	for i in range(n):
		if prev[i] == 0:
			ch = 0
			k = 0
			ch1 = max(len(l[i]) // 2, 1)
			ind = 0
			for j in range(m - 1, -1, -1):
				if l[i][j] == l[i][k]:
					ch += 1
				ind += 1
				k += 1
				if ind == ch1:
					if ch == ind and lmax < len(l[i]):
						lmax = len(l[i])
						s1 = l[i]
					break
	lmax += len(d) * m * 2
	d1 = []
	print(lmax)
	for i in d:
		print(d[i][0], end='')
		d1.append(i)
	print(s1, end='')
	for i in range(len(d1) - 1, -1, -1):
		print(d[d1[i]][1], end='')
	print()
	t -= 1


(n, m) = map(int, input().split())
to_find_pair = set()
pairs_count = 0
palindromes = []
palindromes_count = {}
for i in range(n):
	a = input()
	if a[::-1] in to_find_pair:
		pairs_count += 1
		palindromes.append(a)
		to_find_pair.remove(a[::-1])
	else:
		to_find_pair.add(a)
	if a == a[::-1]:
		if a in palindromes_count:
			palindromes_count[a] += 1
		else:
			palindromes_count[a] = 1
flag_center = False
center = ''
ans_len = pairs_count * 2 * m
for item in palindromes_count:
	if palindromes_count[item] % 2 == 1:
		ans_len += m
		flag_center = True
		center = item
		break
ans_string = [0 for i in range(ans_len)]
for i in range(pairs_count):
	item = palindromes[i]
	for j in range(m):
		ans_string[i * m + j] = item[j]
		ans_string[-1 - i * m - j] = item[j]
if flag_center:
	for j in range(m):
		ans_string[m * pairs_count + j] = center[j]
print(ans_len)
print(''.join([str(item) for item in ans_string]))


(n, m) = [int(x) for x in input().strip().split()]
strings = []
for _ in range(n):
	s = input()
	strings.append(s)
s_p = []
n = len(strings)
for i in range(n):
	if strings[i] == strings[i][::-1]:
		s_p.append(i)
pair = []
for i in range(n - 1):
	for j in range(i + 1, n):
		if strings[i] == strings[j][::-1]:
			pair.append((i, j))
res = ''
for p in pair:
	res += strings[p[0]]
res1 = res[::-1]
p_set = set([])
for p in pair:
	if p[0] not in p_set:
		p_set.add(p[0])
	if p[1] not in p_set:
		p_set.add(p[1])
mid = ''
for ind in s_p:
	if ind not in p_set:
		mid = strings[ind]
ans = res + mid + res1
print(len(ans))
print(ans)


L = list(map(int, input().split()))
spis = []
s = []
s1 = []
temp = ''
temp2 = ''
for _ in range(L[0]):
	spis.append(input())
for i in range(len(spis)):
	if spis[i] == spis[i][::-1]:
		temp = spis[i]
		spis[i] = ''
for i in range(len(spis)):
	if spis[i][::-1] in spis:
		s.append(spis[i])
		s1.append(spis[i][::-1])
		spis[i] = ''
for i in range(len(s)):
	temp2 += s[i]
temp2 += temp
for i in range(len(s1) - 1, -1, -1):
	temp2 += s1[i]
print(len(temp2))
print(temp2)


t = [int(x) for x in input().split(' ')]
(n, m) = t
sset1 = []
sset2 = []
pl_p = []
pl_pair_b = []
pl_pair_a = []
for i in range(n):
	a = input()
	sset1.append(a)
	sset2.append(a[::-1])
i = 0
res = ''
while len(sset1) > 0 and i < len(sset1):
	s = sset1[i]
	if s in sset2:
		if s == s[::-1]:
			res = s
			sset1.remove(s)
		else:
			pl_pair_b.append(s)
			pl_pair_b.append(s[::-1])
			sset1.remove(s)
			sset1.remove(s[::-1])
		i = 0
	else:
		i += 1
for i in range(0, int(len(pl_pair_b)), 2):
	res = pl_pair_b[i] + res + pl_pair_b[i + 1]
print(len(res))
print(res)


tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())

def longestPal(stringsSet):
	res = {'pairs': set(), 'singles': set()}
	for s in stringsSet:
		if s[::-1] in stringsSet - {s} and s[::-1] not in res['pairs']:
			res['pairs'].add(s)
		elif s == s[::-1]:
			res['singles'].add(s)
	if res['singles']:
		res['singles'] = sorted(list(res['singles']), key=len)[-1]
	else:
		res['singles'] = ''
	return res
n = nextInt()
m = nextInt()
s = [next_str() for _ in range(n)]
res = longestPal(frozenset(s))
res = ''.join(res['pairs']) + res['singles'] + ''.join(res['pairs'])[::-1]
print(len(res))
print(res)


def is_palindrome(string):
	return string == string[::-1]

def long_palin(l, array):
	array_c = array[:]
	s = 0
	p = 0
	answer_s = ''
	palindromes = ''
	for string in array:
		if string in array_c:
			array_c.remove(string)
			if string[::-1] in array_c:
				array_c.remove(string[::-1])
				answer_s = string + answer_s + string[::-1]
				s += 2
			elif is_palindrome(string):
				p += 1
				palindromes += string
	if p != 0:
		answer = s * l + l
		answer_s = answer_s[:s * l // 2] + palindromes[:l] + answer_s[s * l // 2:]
		print(answer)
		print(answer_s)
	else:
		answer = s * l
		print(answer)
		print(answer_s)
(n, m) = list(map(int, input().split(' ')))
array = []
for i in range(n):
	array.append(input())
long_palin(m, array)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
(n, m) = map(int, input().split())
strings = set()
for _ in range(n):
	strings.add(input())
used = set()
pick = []
pal = ''
for s in strings:
	if s in used:
		continue
	s_rev = s[::-1]
	if s == s_rev:
		pal = s
	elif s_rev in strings:
		used.add(s)
		used.add(s_rev)
		pick.append(s)
half = ''.join(pick)
ans = half + pal + half[::-1]
print(len(ans))
print(ans)


temp = list(map(int, input().rstrip().split()))
n = temp[0]
m = temp[1]
result = list()
result2 = list()
values = set()
for i in range(n):
	temp = input().rstrip()
	result.append(temp)
	result2.append(temp)
first = str()
second = str()
mid = str()
for i in result:
	reverse = i[::-1]
	if i in result2 and reverse in result2 and (reverse != i):
		first += i
		second = reverse + second
		result2.remove(i)
		result2.remove(reverse)
	elif reverse == i:
		temp = mid
		temp += i
		if temp == temp[::-1]:
			mid += i
first += mid + second
print(len(first))
if first != '':
	print(first)


(n, m) = map(int, input().split())
L = []
for i in range(n):
	L.append(input())
L1 = []
c = 0
for i in range(len(L)):
	flag = True
	for k in range(len(L1)):
		if L1[k][0] == L[i] or L1[k][1] == L[i]:
			flag = False
	if L[i] == L[i][::-1]:
		if c < 1:
			L1.append([L[i], ''])
			c += 1
	if flag == True:
		for j in range(i + 1, len(L)):
			flag1 = True
			for k in range(len(L1)):
				if L1[k][0] == L[j] or L1[k][1] == L[j]:
					flag1 = False
			if flag1 == True:
				if L[j] == L[i][::-1]:
					L1.append([L[i], L[j]])
				elif L[j] == L[j][::-1]:
					if c < 1:
						L1.append([L[j], ''])
						c += 1
s = ''
i = 0
p = []
while i < len(L1):
	if L1[i][1] == '':
		p = L1.pop(i)
		i = i
	else:
		i = i + 1
for i in range(len(L1)):
	s = s + L1[i][0]
if len(p) != 0:
	s = s + p[0]
for i in range(len(L1)):
	s = s + L1[len(L1) - i - 1][1]
if len(s) == 0:
	print(0)
else:
	print(len(s))
	print(s)


def pali(a, b):
	for i in range(len(a)):
		if a[i] != b[len(b) - 1 - i]:
			return 0
	return 1

def palisol(a):
	for i in range(len(a) // 2):
		if a[i] != a[len(a) - 1 - i]:
			return 0
	return 1
(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
res = []
fmid = -1
res = ''
bo = [int(-1) for i in range(n)]
for i in range(n):
	if bo[i] != -1:
		continue
	for j in range(i + 1, n):
		if bo[j] != -1:
			continue
		if pali(s[i], s[j]) == 1:
			bo[j] = i
			bo[i] = j
	if bo[i] == -1 and fmid == -1:
		if palisol(s[i]) == 1:
			fmid = i
			bo[i] = -2
			res = s[i]
k = 0
for i in range(len(s)):
	if bo[i] != -1:
		k += 1
print(k * m)
for i in range(len(s)):
	if bo[i] > -1 and bo[i] > i:
		res = s[i] + res + s[bo[i]]
print(res)


(n, m) = map(int, input().strip().split())
v = {input().strip(): 0 for i in range(n)}
o = ''
m = ''
for i in v:
	if v[i]:
		continue
	if i != i[::-1] and i[::-1] in v:
		v[i] = v[i[::-1]] = 1
		o += i
	elif not m and i == i[::-1]:
		m = i
t = o + m + o[::-1]
print(len(t))
print(t)


l = input().split()
(n, m) = (int(l[0]), int(l[1]))
s = []
for i in range(n):
	s.append(input())
l1 = ''
l2 = ''
l3 = ''
j = 0
for i in range(len(s)):
	if s[i] == s[i][::-1]:
		l3 += s[i]
	elif s.count(s[i][::-1]) != 0:
		l1 += s[i]
		l2 = s[i][::-1] + l2
		s[i] = '1'
l1 = l1 + l3[0:m] + l2
print(len(l1))
print(l1)


def reverse(string):
	string = string[::-1]
	return string
(n, m) = map(int, input().split())
s = [''] * n
for i in range(n):
	s[i] = input()
count = [0] * n
for i in range(n):
	for j in range(i + 1, n):
		if s[i] == reverse(s[j]):
			count[i] = count[i] + 1
c1 = 0
c2 = 0
ans = ''
size = 0
for i in range(n):
	if s[i] == reverse(s[i]):
		ans = ans + s[i]
		c1 = 1
		size = size + m
		break
for i in range(n):
	if count[i] + 1 >= 2:
		x = (count[i] + 1) // 2
		ans = s[i] * x + ans + reverse(s[i]) * x
		size = size + m * (2 * x)
print(size)
print(ans)


(n, m) = map(int, input().split())
d = {}
isPal = {}
for _ in range(n):
	x = input()
	xReverse = x[::-1]
	if x == xReverse:
		isPal[x] = 0
	x = min(x, xReverse)
	if x in d:
		d[x] += 1
	else:
		d[x] = 1
result = []
for k in d:
	oc = d[k]
	pair = oc // 2
	if pair > 0:
		result += [k] * pair
	if oc == pair * 2:
		if k in isPal:
			del isPal[k]
c = ''
if isPal:
	for x in isPal:
		c = x
		break
r = ''.join(result)
result = r + c + r[::-1]
print(len(result))
print(result)


def read_ints():
	return [int(i) for i in input().strip().split()]

def solve():
	pass

def main():
	(n, m) = read_ints()
	s = []
	palin = False
	count = 0
	left = []
	right = []
	palin_str = ''
	for _ in range(n):
		x = input()
		if not palin and x == x[::-1]:
			palin = True
			palin_str = x
		elif x[::-1] in s:
			s.remove(x[::-1])
			left.append(x)
			right.insert(0, x[::-1])
			count += 2
		else:
			s.append(x)
	if palin:
		palin = 1
	else:
		palin = 0
	ans = palin + count
	if ans == 0:
		print(0)
		print('')
	else:
		print(ans * m)
		print(''.join(left) + palin_str + ''.join(right))
main()


(n, m) = map(int, input().split())
x = []

def is_palind(string):
	acc = string
	reversed_string = string[::-1]
	return reversed_string
kon = str()
pp = []
bt = 0
p = str()
zz = str()
c = 0
for i in range(n):
	y = input()
	x.append(y)
for i in range(0, n):
	for j in range(i + 1, n):
		bt = 0
		if x[i] == is_palind(x[j]):
			kon = kon + x[i]
			pp.append(x[j])
			bt = 1
	if x[i] == is_palind(x[i]) and bt == 0:
		zz = x[i]
for i in range(len(pp) - 1, -1, -1):
	p = p + pp[i]
c = len(p) + len(kon) + len(zz)
if c == 0:
	print(c)
else:
	print(c)
	print(kon + zz + p)


from collections import Counter

def longest_palindrome(arr):
	counter = Counter(arr)
	left = ''
	right = ''
	middle = ''
	for string in arr:
		rev = string[::-1]
		counter[string] -= 1
		if counter[string] <= 0:
			counter.pop(string)
		if rev in counter:
			left += string
			right = rev + right
			counter[rev] -= 1
			if counter[rev] <= 0:
				counter.pop(rev)
			continue
		if string == string[::-1]:
			middle = string if len(string) > len(middle) else middle
	print(len(left + middle + right))
	if left + middle + right:
		print(left + middle + right)
(n, m) = list(map(int, input().strip().split()))
lookup = [input().strip() for _ in range(n)]
longest_palindrome(lookup)


(n, m) = map(int, input().split())
given = []
given.append(input())
(forward, back) = ([], [])
taken = [True] * n
for i in range(1, n):
	given.append(input())
	for j in range(i):
		if taken[j]:
			if given[i] == given[j][::-1]:
				forward.append(given[j])
				back.append(given[i])
				(taken[i], taken[j]) = (False, False)
for i in range(n):
	if taken[i] == True:
		temp = given[i]
		if given[i] == temp[::-1]:
			forward.append(given[i])
			break
ans = ''
for i in range(len(forward)):
	ans = ans + forward[i]
j = len(back)
for i in range(j):
	ans = ans + back[j - i - 1]
print(len(ans))
print(ans)


(a, b) = map(int, input().split())
(l, lst, s, r, f) = ([], [], [], '', 0)
for i in range(a):
	lst.append(input())
for (k, j) in enumerate(lst):
	if j[::-1] in lst[k + 1:]:
		l.append(j)
		for x in range(k + 1, a):
			if lst[x] == j[::-1]:
				lst[x] = ''
				break
	elif j != '' and j == j[::-1] and (f == 0):
		r = j
		f = 1
l = ''.join(map(str, l))
p = l + r + l[::-1]
print(len(p))
print(p)


def pa(s1, s2):
	for i in range(0, len(s1)):
		if s1[i] != s2[len(s1) - i - 1]:
			return 0
	return 1
(n, m) = list(map(int, input().split()))
a = []
for i in range(0, n):
	a.append(input())
arr1 = []
arr2 = []
for i in range(0, n):
	if pa(a[i], a[i]):
		arr1.append(a[i])
		continue
	for j in range(i, n):
		if pa(a[i], a[j]):
			arr2.append([i, j])
os = ''
if len(arr1) != 0:
	arr1.sort()
	os = arr1[-1]
s2 = ''
for i in range(0, len(arr2)):
	s2 += a[arr2[i][0]]
s2 += os
for i in range(len(arr2) - 1, -1, -1):
	s2 += a[arr2[i][1]]
print(len(s2))
print(s2)


import sys
import math
import itertools
import functools
import collections
import operator

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def p(s):
	if s == s[::-1]:
		return True
	else:
		return False
(n, m) = mi()
s = []
for i in range(n):
	s.append(input())
d = collections.Counter(s)
dk = d.keys()
ls = ''
rs = ''
mid = ''
max_ = 0
used = set()
for t in dk:
	if p(t):
		if d[t] > max_:
			mid = t * d[t]
			max_ = d[t]
	elif not t[::-1] in used:
		for u in dk:
			if t == u[::-1]:
				ls += t * min(d[t], d[u])
				rs = u * min(d[t], d[u]) + rs
	used.add(t)
print(len(ls + mid + rs))
print(ls + mid + rs)


def strrev(s):
	rs = s[::-1]
	return rs

def ispal(s):
	if s == strrev(s) or s == '':
		return True
	else:
		return False
l = list(map(int, input().split()))
n = l[0]
m = l[1]
sl = []
start = ''
end = ''
middle = ''
for i in range(0, n):
	sl.append(input())
for i in range(0, n):
	if ispal(sl[i]):
		middle = sl[i]
		sl[i] = ''
for i in range(0, n):
	if sl[i] == '':
		continue
	for j in range(0, n):
		if i == j:
			continue
		if sl[i] == '':
			continue
		if strrev(sl[j]) == sl[i]:
			start = start + sl[i]
			end = sl[j] + end
			sl[i] = ''
			sl[j] = ''
string = start + middle + end
length = len(string)
print(length)
print(string)


s = [input() for i in range(int(input().split()[0]))]
lprt = ''
for i in range(len(s)):
	if s[i] != None:
		if s[i][::-1] in s and s[i] != s[i][::-1]:
			lprt += s[i]
			k = i
			for j in range(len(s)):
				if s[j] == s[i][::-1]:
					s[i] = None
					s[j] = None
					break
mid = ''
for i in s:
	if i != None:
		if i == i[::-1]:
			mid = i
			break
lprt = lprt + mid + lprt[::-1]
print(len(lprt))
print(lprt)


(n, m) = input().split()
n = int(n)
l = []
for i in range(n):
	l.append(input())
k = []
ans = ''
flag = 0
for i in range(len(l)):
	if l[i][::-1] in l[i + 1:]:
		k.append(l[i])
	elif flag == 0 and l[i] == l[i][::-1]:
		ans = ans[:int(len(ans) / 2)] + l[i] + ans[int(len(ans) / 2):]
		flag = 1
for i in k:
	ans = i + ans + i[::-1]
print(len(ans))
print(ans)


from collections import defaultdict
(n, m) = tuple(map(int, input().split()))
startswith = defaultdict(list)
endswith = defaultdict(list)
alls = []
for i in range(n):
	s = input()
	alls.append(s)
	startswith[s[0]].append((s, i))
	endswith[s[-1]].append((s, i))
pairs = []
used = [0] * n
for s in startswith.keys():
	for (first, idx1) in startswith[s]:
		for (rev, idx2) in endswith[s]:
			if idx1 != idx2 and used[idx1] == 0 and (used[idx2] == 0):
				if first == rev[::-1]:
					used[idx1] = 1
					used[idx2] = 1
					pairs.append((first, rev))
single_pals = []
for i in range(n):
	if used[i] == 0 and alls[i] == alls[i][::-1]:
		single_pals.append(alls[i])
if len(pairs) == 0 and len(single_pals) == 0:
	print(0)
else:
	(init, ends) = ([], [])
	for (x, y) in pairs:
		init.append(x)
		ends.insert(0, y)
	final = ''.join(init + single_pals[0:1] + ends)
	print(len(final))
	print(final)


from collections import deque
(n, m) = map(int, input().split())
pairs = []
words = []
for i in range(n):
	zz = input()
	words.append(zz)
paired = [0 for i in range(n)]
for i in range(n):
	if paired[i]:
		continue
	word = words[i]
	rev = word[::-1]
	for j in range(i + 1, n):
		word1 = words[j]
		if paired[j]:
			continue
		if word1 == rev:
			paired[j] = 1
			paired[i] = 1
			pairs.append((word, word1))
maxlen = 0
mid = ''
for i in range(n):
	if paired[i]:
		continue
	word = words[i]
	if word == word[::-1] and len(word) > maxlen:
		maxlen = len(word)
		mid = word
dq = deque([mid])
for (a, b) in pairs:
	dq.appendleft(a)
	dq.append(b)
print(len(''.join(dq)))
print(''.join(dq))


(n, m) = map(int, input().split())
s = [str(input()) for i in range(n)]
pair = []
for i in range(n - 1):
	p = s[i]
	p = p[::-1]
	for j in range(i + 1, n):
		if s[j] == p:
			pair.append(s[i])
			break
palindrom = ''
for i in range(n):
	if s[i] == s[i][::-1]:
		palindrom = s[i]
print(len(pair) * 2 * m + len(palindrom))
for i in range(len(pair)):
	print(pair[i], end='')
print(palindrom, end='')
for i in range(len(pair) - 1, -1, -1):
	print(pair[i][::-1], end='')


from collections import defaultdict
fre = defaultdict(int)
fre1 = defaultdict(int)
(n, m) = [int(x) for x in input().split(' ')]
for i in range(n):
	temp = input()
	if temp[::-1] not in fre:
		fre[temp] = 1
	else:
		fre[temp[::-1]] += 1
	if temp == temp[::-1]:
		fre1[temp] = 1
ans = ''
for i in fre:
	if fre[i] >= 2:
		ans += i
		fre[i] -= 2
ma = -1
mi = ''
for i in fre1:
	if len(i) > ma:
		ma = len(i)
		mi = i
pal = ans + mi + ans[::-1]
if len(pal) == 0:
	print(0)
	print()
else:
	print(len(pal))
	print(pal)


from collections import defaultdict as d
(n, x) = map(int, input().split())

def reverse(string):
	string = ''.join(reversed(string))
	return string
m1 = d(int)
a = []
for _ in range(n):
	a.append(input())
for i in range(n):
	m1[a[i]] += 1
first = []
last = []
pal = []
for i in range(n):
	if reverse(a[i]) == a[i]:
		pal.append(a[i])
		m1[a[i]] -= 1
	elif m1[reverse(a[i])] > 0:
		m1[reverse(a[i])] -= 1
		m1[a[i]] -= 1
		first.append(a[i])
		last.append(reverse(a[i]))
res = ''.join(first)
if len(pal) > 0:
	res += pal[0]
last.reverse()
res += ''.join(last)
print(len(res))
print(res)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
mod = 1000000007
(n, m) = li()
a = []
p = ''
q = ''
r = ''
for i in range(n):
	a.append(S())
c = defaultdict(int)
for i in a:
	c[i] += 1
f = 0
l = 0
for i in range(n):
	k = a[i]
	if a[i][::-1] in c and c[k[::-1]] > 0 and (c[a[i]] > 0) and (k != k[::-1]):
		p = p + k
		c[a[i]] -= 1
		c[k[::-1]] -= 1
	elif k == k[::-1] and c[k] >= 2:
		p = p + k
		c[k] -= 2
	elif k == k[::-1] and len(k) > l:
		l = len(k)
		q = k
print(len(p + q + p[::-1]))
print(p + q + p[::-1])


import os, sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	lst = [input().strip() for _ in range(n)]
	visi = [0] * n
	xxx = 1
	for i in range(n):
		for j in range(i + 1, n):
			if not visi[j]:
				if lst[i] == lst[j][::-1]:
					visi[i] = xxx
					visi[j] = xxx
					xxx += 1
					break
		if not visi[i]:
			if lst[i] == lst[i][::-1]:
				visi[i] = 'mid'
	xx = (n - visi.count(0) - visi.count('mid')) // 2
	ans = [0] * xx
	ans1 = [0] * xx
	for (i, val) in enumerate(visi):
		if val != 'mid' and val:
			if not ans[val - 1]:
				ans[val - 1] = lst[i]
			else:
				ans1[val - 1] = lst[i]
	if 'mid' in visi:
		tt = lst[visi.index('mid')]
		kk = ans + [tt] + ans1[::-1]
	else:
		kk = ans + ans1[::-1]
	kk = ''.join(kk)
	print(len(kk))
	print(kk)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	from collections import deque

	def is_palindrome(a):
		n = len(a)
		for i in range(n):
			if a[i] != a[n - 1 - i]:
				return False
		return True
	(n, m) = map(int, input().split())
	used = dict()
	for _ in range(n):
		used[input()] = False
	left = deque()
	right = deque()
	center = []
	for a in used:
		if used[a]:
			continue
		if is_palindrome(a):
			if len(center) == 0:
				center.append(a)
				used[a] = True
		else:
			r = a[::-1]
			if r in used and (not used[r]):
				left.appendleft(a)
				right.append(r)
				used[a] = used[r] = True
	ans = ''.join(left) + ''.join(center) + ''.join(right)
	print(len(ans))
	print(ans)
main()


(N, M) = map(int, input().split())
S = [input() for _ in range(N)]
ans_parindrome = ''
ans_length = 0
used = set()
for i in range(N):
	for j in range(i + 1, N):
		if i not in used and j not in used and (''.join(S[i][::-1]) == S[j]):
			ans_length += 2 * M
			ans_parindrome += S[i]
			used.add(i)
			used.add(j)

def isPalindrome(s):
	return all((a == b for (a, b) in zip(s, reversed(s))))
for s in S:
	if isPalindrome(s):
		ans_length += M
		ans_parindrome = ans_parindrome + s + ans_parindrome[::-1]
		break
else:
	ans_parindrome += ans_parindrome[::-1]
print(ans_length)
print(ans_parindrome)


(n, m) = map(int, input().split())
(a, b) = ([], [])
cp = ''
for i in range(n):
	s = input()
	if s[::-1] == s:
		cp = s
	if s[::-1] in a:
		b.append(s)
	else:
		a.append(s)
ans = ''
for i in b:
	ans += i
ans = ans + cp + ans[::-1]
print(len(ans))
print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
ABCD = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
months = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
MOD = 1000000007
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def check_palin(st):
	if st == st[::-1]:
		return True
	return False
(n, k) = map(int, input().split(' '))
pal = False
s = set()
for i in range(n):
	s.add(input())
ex = ''
a = ''
b = ''
used = set()
for i in s:
	if i[::-1] in s and i not in used and (not check_palin(i)):
		a += i
		b += i
		used.add(i)
		used.add(i[::-1])
	elif not pal:
		if check_palin(i):
			ex = i
			pal = True
print(len(a) * 2 + len(ex))
print(a + ex + b[::-1])


(a, b) = map(int, input().split())
f = []
pt2 = ''
pos = 0
res = ''
for i in range(a):
	s = input()
	if s == s[::-1]:
		res = s
	else:
		f.append(s)
for i in range(len(f)):
	p = f[i][::-1]
	if (p in f) == True:
		res = f[i] + res + p
		pos = f.index(p)
		f[pos] = '-1'
print(len(res))
print(res)


(n, m) = map(int, input().split())
t = []
ans = ans1 = ''
for i in range(n):
	s = input()
	r = s[::-1]
	if r in t:
		ans += r
	elif s == r:
		ans1 = s
	t.append(s)
anss = ans + ans1 + ans[::-1]
print(len(anss), anss, end='')


(n, m) = map(int, input().split())
(l, li, r, rc) = ([], [], [], [])
for i in range(n):
	s = input()
	if s[::-1] in l:
		li.append(s)
		li.append(s[::-1])
		if s in r:
			rc.pop(r.index(s))
			r.remove(s)
		if s[::-1] in r:
			rc.pop(r.index(s[::-1]))
			r.remove(s[::-1])
	elif s == s[::-1]:
		r.append(s)
		rc.append(len(s))
	l.append(s)
s = ''
for i in range(0, len(li), 2):
	s += li[i]
if len(r) > 0:
	s += r[rc.index(max(rc))]
if (len(li) - 1) % 2 == 0:
	j = len(li) - 2
else:
	j = len(li) - 1
for i in range(j, -1, -2):
	s += li[i]
print(len(s))
print(s)


gi = lambda : list(map(int, input().split()))
(n, m) = gi()
s = {}
l = []
for k in range(n):
	t = input()
	s[t] = 1 if t not in s else s[t] + 1
	l.append(t)
ans = []
for t in l:
	if t[::-1] in s and s[t[::-1]]:
		if t != t[::-1]:
			ans.append(t)
			s[t] -= 1
			s[t[::-1]] -= 1
		elif s[t[::-1]] > 1:
			ans.append(t)
			s[t] -= 1
			s[t[::-1]] -= 1
mid = ''
for t in s:
	if s[t] and t[::-1] == t:
		mid = t
print(sum([len(t) for t in ans]) * 2 + len(mid))
print(''.join(ans), end='')
print(mid, end='')
ans = [t[::-1] for t in ans][::-1]
print(''.join(ans))


s = {input() for _ in [0] * int(input().split()[0])}
p = max('', '', *(x for x in s if x == x[::-1]), key=len)
t = [x for x in s if x[::-1] in s and x < x[::-1]]
print(len(p) + 2 * sum(map(len, t)), ''.join(t) + p + ''.join((x[::-1] for x in t[::-1])))


(n, m) = map(int, input().split())
array = []
fin = []
finfin = ''
for _ in range(n):
	array.append(input())
for i in range(n - 1):
	if array[i] == '':
		continue
	for j in range(i + 1, n):
		if array[j] == '':
			continue
		if array[i] == array[j][::-1]:
			fin.append(array[i])
			array[i] = ''
			array[j] = ''
			break
length = len(fin)
if m % 2 == 0:
	adj = 1
else:
	adj = 0
for i in range(n):
	if array[i] == '':
		continue
	if array[i][0:m // 2] == array[i][:m // 2 - adj:-1]:
		fin.append(array[i])
		break
for i in range(length - 1, -1, -1):
	fin.append(fin[i][::-1])
print(len(''.join(fin)))
print(''.join(fin))


def daotu(a):
	b = ''
	for i in range(len(a) - 1, -1, -1):
		b += a[i]
	return b

def isvalid(a):
	return daotu(a) != a
temp = input()
temp = temp.split(' ')
n = int(temp[0])
m = int(temp[1])
a = list()
b = ''
spec = list()
for i in range(n):
	a.append(input())

def dequy():
	global a
	global b
	global spec
	if len(a) == 0:
		return
	temp = daotu(a[0])
	cur = a[0]
	if temp in a and isvalid(cur):
		b += cur
		a.remove(temp)
		a.remove(cur)
		dequy()
		b += temp
	elif not isvalid(cur):
		spec.append(cur)
		a.remove(cur)
		dequy()
	else:
		a.remove(cur)
		dequy()
dequy()
if len(spec) > 0:
	b = b[:len(b) // 2] + spec[0] + b[len(b) // 2:]
print(len(b))
print(b)


import sys
input = sys.stdin.readline
(n, length) = map(int, input().split())
l = []
d = dict()
for _ in range(n):
	x = input()
	x = x[:length]
	l += [x]
	d[x] = 1
d2 = dict()
l = []
for i in d:
	r = i[::-1]
	if r in d and r[::-1] != r:
		d[r] += 1
	else:
		d2[r] = 1
ans = 0
d4 = dict()
l2 = []
for i in d:
	ans += d[i] // 2
	d4[i] = 1
	if d[i] // 2 > 0 and i[::-1] not in d4:
		d4[i] = 1
		l += [i]
		l2 += [i[::-1]]
l2.reverse()
if ans % 2 == 0:
	for i in d2:
		if i == i[::-1]:
			ans += 1
			l += [i]
			break
l += l2
print(ans * length)
print(''.join(l))


(n, m) = map(int, input().split())
word_list = []
final_string = ''
middle = False
for i in range(n):
	word = input()
	word_list.append(word)

def reverse(word):
	new_word = ''
	for i in range(len(word)):
		new_word += word[-i - 1]
	return new_word
while len(word_list) != 0:
	curr_word = word_list.pop()
	new_word = reverse(curr_word)
	if curr_word == new_word and middle == False:
		middle = True
		mid_string = final_string
		if len(mid_string) % 2 == 0:
			mid_way = int(len(mid_string) / 2)
			final_string = mid_string[:mid_way] + curr_word + mid_string[mid_way:]
	for i in word_list:
		if i == new_word:
			back_word = word_list.pop(word_list.index(i))
			final_string = curr_word + final_string
			final_string += back_word
print(len(final_string))
print(final_string)


(n, m) = map(int, input().split())
import collections
c = collections.Counter()
ans = []
for _ in range(n):
	s = input()
	r = s[::-1]
	if c[r] != 0:
		ans.append(s)
		c[r] -= 1
	else:
		c[s] += 1
mid = ''
for x in c:
	if c[x] != 0:
		if all((x[i] == x[-i - 1] for i in range(len(x)))) and len(mid) < len(x):
			mid = x
r = []
for x in ans[::-1]:
	r.append(x[::-1])
ans.append(mid)
ans += r
ans = ''.join(ans)
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
f = []
l = []
p = ''
x = []
m = 0
for _ in range(n):
	s = input()
	if s[::-1] in x:
		f.append(s)
		l.append(s[::-1])
		x.remove(s[::-1])
	elif s == s[::-1] and len(s) > m:
		m = len(s)
		p = s
	else:
		x.append(s)
y = ''.join(f) + p + ''.join(l[::-1])
print(len(y))
print(y)


(n, m) = map(int, input().split())
a = []
b = []
pa = []
for i in range(n):
	s = input()
	if s == s[::-1]:
		pa.append(s)
	elif s[::-1] in a:
		b.append(s)
		a.remove(s[::-1])
	else:
		a.append(s)
x = ''
for i in b:
	x += str(i)
for i in pa:
	x += str(i)
	break
b = b[::-1]
for i in b:
	x += str(i[::-1])
print(len(x))
print(x)


(a, b) = map(int, input().split())
STR = []
temp = ''
temp1 = ''
temp2 = ''
for i in range(0, a):
	S = input()
	if S == S[::-1] and len(temp2) < len(S):
		temp2 = S
	if S[::-1] not in STR:
		STR.append(S)
	else:
		temp = temp + S
		temp1 = S[::-1] + temp1
res = temp + temp2 + temp1
if len(res) == 0:
	print(0)
else:
	print(len(res))
	print(res)


(n, m) = map(int, input().split())
d = []
for i in range(n):
	d.append(input())
used = []
r = ''
for i in range(n):
	if d[i][::-1] == d[i]:
		r = d[i]
		break
for i in range(n):
	if d[i][::-1] != d[i]:
		if d[i][::-1] in d and d[i][::-1] not in used:
			r = r + d[i]
			used.append(d[i])
			r = d[i][::-1] + r
print(len(r))
print(r)


(n, m) = map(int, input().split())
s = []
check = 0
c = []
for i in range(n):
	s.append(input())
for i in s:
	if i[::-1] in s and i != i[::-1]:
		c.insert(0, i)
		c.append(i[::-1])
		s.remove(i[::-1])
	elif i == i[::-1] and check == 0:
		c.insert(len(c) // 2, i)
		check = 1
print(len(''.join(c)))
print(''.join(c))


String = input().split(' ')
N = int(String[0])
M = int(String[1])
dict = {}
for i in range(N):
	Str = input()
	dict[Str] = 0
count = 0
flag = 0
Str = ''
Str1 = ''
for i in dict:
	rev = i[::-1]
	if i == rev:
		flag = 1
		Str1 = i
	elif dict.get(rev) != None and dict[rev] == 0:
		count += 2
		Str += i
		dict[rev] = 1
		dict[i] = 1
count += flag
Str = Str + Str1 + Str[::-1]
print(count * M)
print(Str)


(n, k) = map(int, input().split())
d = {}
f = ''
m = ''
b = ''
while n > 0:
	s = input()
	if d.get(s):
		d[s] += 1
	else:
		d[s] = 1
	n -= 1
for st in d.keys():
	if st == st[-1::-1]:
		f += d[st] // 2 * st
		b = d[st] // 2 * st + b
		if d[st] % 2:
			m = st
	elif d.get(st[-1::-1]):
		c = min(d[st], d[st[-1::-1]])
		f += c * st
		b = c * st[-1::-1] + b
		d[st] -= c
		d[st[-1::-1]] -= c
print(len(f + m + b))
print(f + m + b)


(a, b) = map(int, input().split())
x = set()
ans = ''
mid = ''
rev = ''
for i in range(int(a)):
	s = input()
	re = s[::-1]
	if re == s:
		mid = re
	elif re in x:
		ans = ans + re
		rev = s + rev
	x.add(s)
ans = ans + mid + rev
print(len(ans))
print(ans)


(n, k) = map(int, input().split())
(f, s, m) = ('', '', '')
l = [input() for i in range(n)]
c = 0
for e in l:
	if e == e[::-1]:
		if c % 2 == 0:
			m += e
			c += 1
	elif e[::-1] in l:
		f += e
		s += e
		l.remove(e[::-1])
a = f + m + s[::-1]
print(len(a))
print(a)


(n, m) = map(int, input().strip().split(' '))
arr = []
for i in range(0, n):
	arr.append(str(input()))
revi = 0
maxx = 0
maxi = 0
rev = []
d = {}
for i in range(0, n - 1):
	for j in range(i + 1, n):
		if arr[i] == arr[i][::-1]:
			if len(arr[i]) > maxx:
				maxx = max(maxx, len(arr[i]))
				maxi = i
		if arr[i] == arr[j][::-1]:
			if arr[i] not in d.keys():
				revi += 1
				rev.append(i)
				rev.append(j)
				d[arr[i]] = d.get(arr[i], 0) + 1
				d[arr[j]] = d.get(arr[j], 0) + 1
			else:
				d.pop(arr[i])
if arr[n - 1] == arr[n - 1][::-1]:
	if len(arr[i]) > maxx:
		maxx = max(maxx, len(arr[i]))
		maxi = n - 1
st = ''
if revi > 0:
	for i in range(0, len(rev), 2):
		st = st + arr[rev[i]]
		st = arr[rev[i + 1]] + st
if maxx > 0:
	st = st[:len(st) // 2] + arr[maxi] + st[len(st) // 2:]
print(len(st))
print(st)


from sys import stdin, stdout
words = set((i.strip() for i in stdin.readlines()[1:]))
words_without_palindromes = words.copy()
first_half = ''
middle = ''

def is_palindrome(word):
	for i in range(len(word) // 2 + 1):
		if word[i] != word[-i - 1]:
			return False
	return True
for i in words:
	reversed_i = i[::-1]
	if reversed_i in words_without_palindromes:
		words_without_palindromes.remove(i)
		if is_palindrome(i):
			middle = i
		else:
			words_without_palindromes.remove(reversed_i)
			first_half = first_half + i
word = first_half + middle + first_half[::-1]
print(str(len(word)) + '\n' + word)


(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
arr = {}
for _ in range(n):
	arr[input()] = 0
(out1, out2, out3) = ('', '', '')
for s in list(arr):
	try:
		arr.pop(s)
		f = s
		f = f[::-1]
		if f in arr.keys():
			out1 = out1 + s
			out2 = f + out2
			arr.pop(f)
		elif s == f and len(out3) < len(f):
			out3 = f
	except:
		pass
out = out1 + out3 + out2
print(len(out))
print(out)


(n, m) = map(int, input().split())
p = []
ans = 0
for i in range(n):
	x = list(input())
	p.append(x)
r = []
for i in range(n - 1):
	for j in range(i + 1, n):
		temp = p[i] + p[j]
		b = temp[:]
		b.reverse()
		if temp == b:
			ans += 1
			r.append(p[i])
			r.append(p[j])
extra = 0
e = []
for i in range(n):
	temp = p[i]
	b = temp[:]
	b.reverse()
	if temp == b:
		extra += 1
		e = b
		break
req = ans * 2 * m + extra * m
g = req // m
y = []
for i in range(len(r)):
	if i % 2 == 0:
		y.append(r[i])
if extra != 0:
	y.append(e)
temp = []
for i in range(len(r)):
	if i % 2 == 1:
		temp.append(r[i])
temp.reverse()
y = y + temp
h = ''
for i in y:
	for j in i:
		h += j
print(len(h))
print(h)


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	s = input().strip()
	if s in d.keys():
		d[s].insert(0, s)
	elif s[::-1] in d.keys():
		d[s[::-1]].append(s)
	else:
		d[s] = [s]
ky = list(d.keys())
for k in ky:
	if k != k[::-1] and len(d[k]) & 1:
		del d[k]
c = 0
flag = 1
st = ''
f = list(d.keys())
for k in f:
	h = len(d[k])
	if k == k[::-1]:
		if h & 1:
			if flag:
				st += k * h
				flag = 0
				c += h * m
			else:
				st = st + k * (h // 2)
				st = k * (h // 2) + st
				c += (h - 1) * m
		del d[k]
for k in d.keys():
	h = len(d[k])
	c += h * m
	st = k * (h // 2) + st
	st = st + h // 2 * k[::-1]
print(c)
print(st)


import os
import sys
from io import BytesIO, IOBase
from collections import deque

def solution(strings, n, m):
	queue1 = deque()
	queue2 = deque()
	self_pal = []
	for i in range(n):
		if strings[i] == strings[i][::-1]:
			self_pal.append(strings[i])
			strings[i] = '-1'
	for i in range(n):
		if strings[i][::-1] in strings:
			queue1.append(strings[i])
			queue2.appendleft(strings[i][::-1])
			strings[i] = '-1'
	if queue1 or queue2 or self_pal:
		if self_pal:
			res = ''.join(queue1) + self_pal[0] + ''.join(queue2)
		else:
			res = ''.join(queue1) + ''.join(queue2)
		print(len(res))
		print(res)
		return
	print(0)
	print('')

def main():
	(n, m) = [int(x) for x in input().split()]
	strings = []
	for _ in range(n):
		s = input()
		strings.append(s)
	solution(strings, n, m)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


def isPalindorme(string):
	if string == string[::-1]:
		return 1
	else:
		return 0
	return 0
(n, m) = map(int, input().split())
string = []
for i in range(0, n):
	s = input()
	string.append(s)
pal_dic = {}
pair_pal_dic = {}
for index1 in range(len(string)):
	for index2 in range(len(string)):
		if index1 != index2:
			if isPalindorme(string[index1] + string[index2]):
				pair_pal_dic[string[index1]] = string[index2]
				string[index1] = string[index1] + 'x'
				string[index1] = string[index1] + 'y'
		elif isPalindorme(string[index1]):
			pal_dic[string[index1]] = string[index1]
String = ''
String2 = ''
for key in pair_pal_dic:
	String += key
	String2 = pair_pal_dic[key] + String2
for key in pal_dic:
	String += key
	break
String += String2
l = len(String)
if l == 0:
	print(0)
	print()
else:
	print(l)
	print(String)


(n, m) = map(int, input().split())
l = []
r = []
for i in range(0, n):
	l.append(input())
	r.append(''.join(reversed(l[i])))
f = 0
for i in range(0, n):
	if l[i] == ''.join(reversed(l[i])) and f == 0:
		f += 1
	elif f == 1 and l[i] == ''.join(reversed(l[i])):
		l[i] += '12'
l = set(l)
r = set(r)
se = set(l).intersection(r)
l = list(l)
s = []
st = ''
for i in se:
	s.append(i)
for i in s:
	if i == ''.join(reversed(i)):
		st = i
		s.remove(i)
		break
le = len(s)
for i in range(0, le):
	if ''.join(reversed(s[i])) in s[i + 1:le]:
		st = s[i] + st + ''.join(reversed(s[i]))
print(len(st))
print(st)


def isp(s):
	return s == s[::-1]
(n, m) = map(int, input().split())
parr = []
sa = ''
sb = ''
used = [True for i in range(n)]
word = []
for i in range(n):
	s = input()
	for j in range(0, i):
		if used[j]:
			if s[::-1] == word[j]:
				used[j] = False
				used[i] = False
				sa += s
				sb = word[j] + sb
	word.append(s)
m = 0
ms = ''
for i in range(n):
	if used[i]:
		if isp(word[i]):
			if len(word[i]) > m:
				m = len(word[i])
				ms = word[i]
print(len(sa) + len(sb) + len(ms))
print(sa + ms + sb)


from collections import defaultdict
(x, y) = map(int, input().split())
ans = []
for i in range(x):
	ans.append(input())
non = defaultdict(list)
yo = defaultdict(list)
for i in range(len(ans)):
	if ans[i][::-1] in ans and ans[i] != ans[i][::-1]:
		if non[ans[i]] == [] and non[ans[i][::-1]] == []:
			non[ans[i]] = [ans.count(ans[i][::-1]), ans.count(ans[i])]
	elif ans[i] == ans[i][::-1]:
		if yo[ans[i]] == []:
			yo[ans[i]] = [ans.count(ans[i]), len(ans[i])]
kap = 0
s = ''
arr = ''
mini = 0
for i in non:
	if len(non[i]) > 0:
		kap = kap + len(i) * min(non[i])
		s = s + min(non[i]) * i
for i in yo:
	if len(yo[i]) > 0:
		if yo[i][0] % 2 == 0:
			kap = kap + len(i) * yo[i][0] // 2
			s = s + yo[i][0] // 2 * i
		elif yo[i][1] > mini:
			arr = i
print(2 * kap + len(arr))
if 2 * kap + len(arr):
	print(s + arr + s[::-1])


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def is_palind(s):
	ln = len(s)
	for i in range(ln):
		if s[i] != s[ln - 1 - i]:
			return False
	return True

def main():
	(n, m) = [int(x) for x in stdin.readline().split()]
	npalinds = []
	palinds = []
	alls = []
	for i in range(n):
		s = stdin.readline().strip()
		if is_palind(s) == True:
			palinds.append(s)
		else:
			npalinds.append(s)
		alls.append(s)
	res = ''
	used = [False] * (n + 1)
	for (ind, s) in enumerate(palinds):
		if palinds.count(s) % 2 == 1:
			if len(s) > len(res):
				res = s
	if res in palinds:
		used[alls.index(res)] = True
	reslist = deque()
	reslist.append(res)
	for i in range(len(alls)):
		if used[i] == False:
			p = alls[i]
			for j in range(len(alls)):
				if used[j] == False and i != j:
					q = alls[j]
					if is_palind(p + q):
						reslist.appendleft(p)
						reslist.append(q)
						used[i] = True
						used[j] = True
	res = ''.join(reslist)
	stdout.write('%d\n%s' % (len(res), res))
	return 0
main()


(n, m) = map(int, input().split())
total = ans = pal = ''
for i in range(n):
	s = input()
	if s == s[::-1]:
		pal = s
	if s[::-1] in total:
		ans += s
	total = total + s + ' '
if pal == '' and ans == '':
	print(0, '\n')
else:
	h = ans + pal + ans[::-1]
	print(len(h), '\n' + h)


t = 1
(m, n) = list(map(int, input().split()))
a = []
while m:
	m -= 1
	s = input()
	a.append(s)
strings = {}
(start, end, mid) = ('', '', '')
for str_ in a:
	if str_[::-1] in strings and strings[str_[::-1]]:
		start += str_
		end = str_[::-1] + end
		strings[str_[::-1]] -= 1
	else:
		strings[str_] = strings.get(str_, 0) + 1
	if len(str_) > len(mid):
		if str_ == str_[::-1]:
			mid = str_
pal = start + mid + end
print(len(pal))
print(pal)


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	d[input()] = 1
s1 = ''
s2 = ''
p = ''
for i in d:
	if d[i]:
		r = i[::-1]
		d[i] = 0
		try:
			if d[r]:
				s1 += i
				s2 = r + s2
				d[r] = 0
			elif p == '' and i == r:
				p = r
		except:
			pass
print(len(s1 + p + s2))
print(s1 + p + s2)


def ispal(s):
	if s == s[::-1]:
		return 1
	return 0
(n, m) = map(int, input().split())
A = []
vis = [0] * n
for i in range(n):
	A.append(list(input()))
	if ispal(A[i]):
		vis[i] = 1
B = []
C = []
ans = 0
for i in range(n):
	if vis[i] != -1:
		for j in range(i + 1, n):
			if vis[j] != -1 and A[i] == A[j][::-1]:
				vis[i] = -1
				vis[j] = -1
				B.extend(A[i])
				C.append(A[j])
				ans = ans + 2
				break
for i in range(n):
	if vis[i] == 1:
		ans = ans + 1
		B.extend(A[i])
		break
C.reverse()
for j in C:
	B.extend(j)
print(len(B))
print(*B, sep='')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	s = input()
	a.append(s)
b = {}
c = []
for i in range(n):
	new = a[i][::-1]
	if new == a[i]:
		b[a[i]] = b.get(a[i], 0) + 1
	elif new in a:
		if len(c) == 0:
			c.append(a[i])
			c.append(new)
		else:
			mid = len(c) // 2
			c.insert(mid, a[i])
			c.insert(mid + 1, new)
		a[i] = 'abc'
if len(b) != 0:
	Keymax = max(b, key=b.get)
	string = Keymax * b[Keymax]
	mid = len(c) // 2
	c.insert(mid, string)
c = ''.join(c)
print(len(c))
if len(c) != 0:
	print(c)


(n, m) = map(int, input().split())
pal = {}
non_pal = {}
for _ in range(n):
	x = input()
	if x == x[::-1]:
		if x not in pal:
			pal[x] = 1
		else:
			pal[x] += 1
	elif x in non_pal:
		non_pal[x] += 1
	else:
		non_pal[x] = 1
epal = {}
opal = {}
for i in pal:
	if pal[i] % 2 == 0:
		epal[i] = pal[i]
	else:
		opal[i] = pal[i]
ans = []
b = []
vis = {}
for i in non_pal:
	if i[::-1] in non_pal:
		if i not in vis:
			if i[::-1] not in vis:
				vis[i] = True
				vis[i[::-1]] = True
				x = min(non_pal[i], non_pal[i[::-1]])
				ans.append((i, x))
a = []
for i in ans:
	for j in range(i[1]):
		a.append(i[0])
if len(pal) > 0:
	if len(pal) == 1:
		k = []
		for i in pal:
			k.append(i)
		a.append(k[0])
	else:
		e = []
		o = []
		for i in epal:
			e.append((epal[i], i))
		for i in opal:
			o.append((opal[i], i))
		for i in e:
			for j in range(i[0] // 2):
				a.append(i[1])
		e = e[::-1]
		o = sorted(o, reverse=True)
		for i in o:
			for j in range(i[0] // 2):
				a.append(i[1])
		o = o[::-1]
		a.append(o[0][1])
		for i in o:
			for j in range(i[0] // 2):
				a.append(i[1])
		for i in e:
			for j in range(i[0] // 2):
				a.append(i[1])
ans = ans[::-1]
for i in ans:
	for j in range(i[1]):
		a.append(i[0][::-1])
x = ''.join(map(str, a))
print(len(x))
print(x)


def isPal(s):
	s1 = s[::-1]
	if s1 == s:
		return True
	else:
		return False
arr1 = []
arr2 = []
f = input().split()
n = int(f[0])
m = int(f[1])
cont = -1
s = ''
for i in range(0, n):
	arr1.append(input())
for k in range(0, len(arr1)):
	for j in range(k + 1, len(arr1)):
		checkstr = arr1[k] + arr1[j]
		checkstr1 = checkstr[::-1]
		if checkstr == checkstr1:
			arr2.append(arr1[k])
			arr2.append(arr1[j])
			cont += 2
for l in range(0, len(arr1)):
	if isPal(arr1[l]):
		arr2.append(arr1[l])
for _ in range(0, cont, +2):
	s += arr2[_]
if len(arr2) - 1 > cont:
	s += arr2[cont + 1]
for t in range(cont, 0, -2):
	s += arr2[t]
if len(s) == 0:
	print(0)
else:
	s1 = s.replace(' ', '')
	print(len(s1))
	print(s1)


def count(a, n):

	def ispal(s):
		if s == s[::-1]:
			return 1
		else:
			return 0
	start = end = mid = ''
	while True:
		if ispal(a[0]) == 1:
			if a[0] in a[1:]:
				start = start + a[0]
				end = a[0] + end
			else:
				mid = a[0]
			a.remove(a[0])
		elif a[0][::-1] not in a:
			a.remove(a[0])
		else:
			start = start + a[0]
			end = a[0][::-1] + end
			a.remove(a[0][::-1])
			a.remove(a[0])
		if a == []:
			break
	return start + mid + end
a = []
(n, m) = map(int, input().split())
for i in range(n):
	a.append(input())
res = count(a, n)
x = len(res)
if x > 0:
	print(x)
	print(res)
else:
	print(0)


import collections

def calc(words, n, m):
	if m == 0:
		return (n, '')
	if n == 0:
		return (0, '')
	res = collections.deque([''])
	while words:
		cur = words.pop()
		rev = cur[::-1]
		if rev in words:
			res.append(cur)
			res.appendleft(rev)
			words.remove(rev)
		elif rev == cur and (not res[len(res) // 2]):
			res[len(res) // 2] = cur
	return ''.join(res)
(n, m) = map(int, input().split())
words = set()
for _ in range(n):
	words.add(input())
s = calc(words, n, m)
print(len(s))
print(s)


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def ispalin(st):
	for i in range(len(st) // 2):
		if st[i] != st[len(st) - 1 - i]:
			return False
	return True
(n, k) = Ri()
st = []
for i in range(n):
	temp = ri()
	st.append(temp)
pairs = []
flag = [False] * len(st)
for i in range(len(st)):
	if flag[i]:
		continue
	for j in range(i + 1, len(st)):
		if flag[j]:
			continue
		if st[i] == st[j][::-1]:
			pairs.append([st[i], st[j]])
			flag[i] = True
			flag[j] = True
			break
rem = len(st) - 2 * len(pairs)
if rem == 0:
	st = ''
	begin = ''
	end = ''
	for i in pairs:
		begin += i[0]
		end = i[1] + end
	st = begin + end
	print(len(st))
	print(st)
else:
	strr = ''
	begin = ''
	end = ''
	for i in pairs:
		begin += i[0]
		end = i[1] + end
	i = 0
	tflag = False
	for i in range(len(st)):
		if not flag[i] and ispalin(st[i]):
			tflag = True
			break
	if tflag:
		strr = begin + st[i] + end
	else:
		strr = begin + end
	print(len(strr))
	print(strr)


def ans(l, n, m):
	if m == 1:
		s = list(set(l))
		c = []
		for i in s:
			c.append(l.count(i))
		i = c.index(max(c))
		a = s[i] * max(c)
		return a
	e = []
	f = []
	g = []
	for i in range(len(l)):
		if l[i] == l[i][::-1]:
			f.append(l[i])
		else:
			for j in range(i + 1, len(l)):
				if l[i] == l[j][::-1]:
					e.append(l[i])
					g.append(l[j])
					break
	h = list(set(f))
	ct = []
	for i in h:
		ct.append(f.count(i))
	c = ''
	if len(ct) != 0:
		j = ct.index(max(ct))
		c = h[j] * max(ct)
	b = ''
	a = ''
	g = g[::-1]
	if len(e) != 0:
		for i in range(len(e)):
			a += e[i]
			b += g[i]
	return a + c + b
(n, m) = map(int, input().split())
l = []
for i in range(n):
	s = input()
	l.append(s)
z = ans(l, n, m)
print(len(z))
print(ans(l, n, m))


(n, m) = list(map(int, input().split()))
s = [input() for i in range(n)]
ans = []
used = [False] * n
for i in range(n):
	if not used[i]:
		for j in range(i + 1, n):
			if not used[j] and s[i] == s[j][::-1]:
				used[i] = True
				used[j] = True
				ans.append(s[j])
				break
ans = ''.join(ans)
tmp_len = 0
tmp = ''
for i in range(n):
	if not used[i] and s[i] == s[i][::-1] and (len(s[i]) > tmp_len):
		tmp = s[i]
		tmp_len = len(s[i])
print(len(ans) + len(tmp) + len(ans))
print(ans + tmp + ans[::-1])


(x, y) = map(int, input().split())
list1 = []
list_0 = []
for x0 in range(x):
	str1 = input()
	list1.append(str1)
	list_0.append(str1)
list2 = []
list3 = []
list5 = []
for item in list1:
	list0 = list_0
	item0 = item[::-1]
	if item == item0:
		list5.append(item)
	list0.remove(item)
	if item0 in list0:
		list2.append(item)
		list3.append(item0)
list4 = list3[::-1]
str2 = ''.join(list2)
str3 = ''.join(list4)
if list5 != []:
	str5 = list5[0]
	str4 = str2 + str5 + str3
else:
	str4 = str2 + str3
if str4 == '':
	print('0')
else:
	print(len(str4))
	print(str4)


(n, m) = map(int, input().split())
arrofstr = []
ans = ''
center = ''
for i in range(n):
	arrofstr += [input()]
dicofstr = {}
for i in range(n):
	s = arrofstr[i]
	dicofstr[s] = arrofstr.count(s[::-1])
for s in dicofstr.keys():
	if s == s[::-1]:
		if dicofstr[s] % 2 == 0:
			ans += s * (dicofstr[s] // 2)
		else:
			ans += s * ((dicofstr[s] - 1) // 2)
			center = s
	elif dicofstr[s] > 0 and dicofstr[s] <= dicofstr[s[::-1]]:
		ans += s * dicofstr[s]
		dicofstr[s] = 0
	elif dicofstr[s] > 0:
		ans += s * dicofstr[s[::-1]]
		dicofstr[s[::-1]] = 0
print(2 * len(ans) + len(center))
print(ans + center + ans[::-1])


def one():
	return int(input())

def more():
	return map(int, input().split())

def lis():
	return list(map(int, input().split()))

def st():
	return input()
(n, m) = more()
d = {}
single = None
for i in range(n):
	s = st()
	if s in d:
		d[s] += 1
	else:
		d[s] = 1
pre = []
post = []
for i in d:
	r = i[::-1]
	if r == i:
		if d[i] == 1:
			single = i
		else:
			for j in range(d[i] // 2):
				pre.append(i)
				post.append(i)
			d[i] %= 2
			if d[i] == 1:
				single = i
	elif r in d:
		for j in range(min(d[i], d[r])):
			pre.append(i)
			post.append(r)
		d[i] = 0
		d[r] = 0
count = len(pre) + len(post) + int(bool(single))
print(m * count)
for i in pre:
	print(i, end='')
if single:
	print(single, end='')
for i in reversed(post):
	print(i, end='')


import sys

def reverse(s):
	return s[::-1]

def main():
	(n, m) = [int(s) for s in sys.stdin.readline().strip().split()]
	a = []
	p = set()
	d = {}
	for _ in range(n):
		s = sys.stdin.readline().strip()
		rev = reverse(s)
		a.append(s)
		if s == rev:
			p.add(s)
		if s < rev:
			d[s] = d.get(s, 0) + 1
		else:
			d[rev] = d.get(rev, 0) + 1
	res = []
	for k in d.keys():
		l = d[k] // 2
		res += [k] * l
		d[k] -= l * 2
	mid = ''
	for pal in p:
		if d[pal] > 0:
			mid = pal
			break
	s = ''.join(res)
	print(len(s) * 2 + len(mid))
	print(s + mid + reverse(s))
main()


z = input()
z = z.split(' ')
n = int(z[0])
m = int(z[1])
list = []
for i in range(n):
	list.append(input())
k = ''
l = ''
same = []
left = []
right = []
for i in range(n):
	p = list[i]
	q = p[::-1]
	if p != '-1':
		if p == q:
			if len(same) == 0:
				same.append(q)
			list[list.index(q)] = '-1'
		elif q in list:
			left.append(p)
			right.append(q)
			list[list.index(p)] = '-1'
			list[list.index(q)] = '-1'
s = ''
right = right[::-1]
for i in left:
	s += i
for i in same:
	s += i
for i in right:
	s += i
print(len(s))
print(s)


from collections import defaultdict, Counter
(n, m) = map(int, input().strip().split())
ls = []
for _ in range(n):
	st = input()
	ls.append(st)
start = ''
end = ''
temp = ''
ans = 0
dic = defaultdict(int)
f = 1
for (i, val) in enumerate(ls):
	if i not in dic:
		for (j, value) in enumerate(ls):
			if j not in dic:
				if i != j and val == value[::-1]:
					dic[i] = 1
					dic[j] = 1
					ans += 2 * m
					start += val
					end = value + end
				elif val == value[::-1] and f == 1:
					ans += m
					temp = val
					f = 0
print(ans)
if ans > 0:
	print(start + temp + end)


(n, m) = map(int, input().split())
store = []
front = ''
mid = ''
back = ''
for i in range(n):
	s = str(input())
	store.append(s)
for i in range(n):
	rev = store[i][::-1]
	if rev == store[i]:
		mid = rev
	elif rev in store:
		front = front + store[i]
		back = rev + back
		store[i] = 'AB'
		store[store.index(rev)] = 'BC'
final = front + mid + back
print(len(final))
print(final)


a = [int(x) for x in input().split()]
ans = ''
temp_list = []
temp_list2 = []
temp_set = set()
for i in range(a[0]):
	string = input()
	temp_list.append(string)
for i in temp_list:
	if i not in temp_set:
		if i == i[::-1]:
			temp_list2.append(i)
			temp_set.add(i)
		elif i[::-1] in temp_list:
			ans = i + ans + i[::-1]
			temp_set.add(i)
			temp_set.add(i[::-1])
if len(temp_list2) != 0:
	ans = ans[:len(ans) // 2] + temp_list2[0] + ans[len(ans) // 2:]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
pairs = []
is_solo_palindrome = []
s = [input() for i in range(n)]
while s:
	last = s.pop()
	for j in range(len(s)):
		if last == s[j][::-1]:
			s = s[:j] + s[j + 1:]
			pairs.append(last)
			break
	else:
		if last == last[::-1]:
			is_solo_palindrome.append(last)
mid = max(is_solo_palindrome, key=len) if is_solo_palindrome else ''
f = ''.join(pairs)
res = f + mid + f[::-1]
print(len(res))
print(res)


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	s = input()
	res = ''.join(reversed(s))
	if res in d:
		d[res] += 1
	else:
		d[s] = 1
ans = ''
for keys in d:
	if d[keys] == 1 and ''.join(reversed(keys)) == keys:
		ans += keys
		break
for keys in d:
	if d[keys] % 2 == 0:
		ans = keys * (d[keys] // 2) + ans
		zz = ''.join(reversed(keys))
		ans += zz * (d[keys] // 2)
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
s = []
ans = ''
for i in range(n):
	x = input()
	if x == x[::-1]:
		if len(ans) == 0:
			ans = x
	else:
		s.append(x)
while len(s) > 0:
	x = s.pop()
	y = x[::-1]
	if y in s:
		ans = x + ans + y
		s.remove(y)
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
a = set()
b = []
for i in range(n):
	s = input()
	a.add(s)
	b.append(s)
ans = ''
good = ''
for i in b:
	if i != i[::-1] and i in a and (i[::-1] in a):
		ans = ans + i
		a.remove(i)
		a.remove(i[::-1])
	elif i == i[::-1] and len(good) < len(i):
		good = i
print(2 * len(ans) + len(good))
print(ans + good + ans[::-1])


(q, z) = [int(x) for x in input().split()]
str1 = []
for x in range(q):
	str1.append(input())
start = []
mid = ''
for x in range(q):
	if str1[x] == str1[x][::-1]:
		mid = str1[x]
	elif str1[x][::-1] in str1 and (not str1[x][::-1] in start):
		start.append(str1[x])
start = ''.join(start)
final = start + mid + start[::-1]
print(len(final))
print(final)


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	(n, m) = [int(x) for x in input().split()]
	s = []
	for i in range(n):
		s.append([input(), True])
	answers = []
	for i in range(n):
		for j in range(i + 1, n):
			a = s[i][0]
			b = s[j][0]
			if s[i][1] and s[j][1] and (a == b[::-1]):
				answers.append([a, b])
				s[i][1] = False
				s[j][1] = False
	middle = ''
	l = -1
	for i in range(n):
		a = s[i][0]
		if s[i][1] and a == a[::-1] and (len(a) > l):
			middle = a
			l = len(middle)
	left = ''
	right = ''
	for p in answers:
		left += p[0]
	for p in answers[::-1]:
		right += p[1]
	ans = left + middle + right
	print(len(ans))
	print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
strings = [input() for _ in range(n)]
(left_side, right_side) = ([], [])
palindrome = None
for string in strings:
	if string in right_side:
		continue
	if string[::-1] == string:
		palindrome = string
		continue
	p_string = string[::-1]
	for comp in strings:
		if p_string == comp:
			left_side += [string]
			right_side += [p_string]
			break
if palindrome:
	print(len(left_side) * m * 2 + m)
	print(''.join(left_side) + palindrome + ''.join(right_side[::-1]))
else:
	print(len(left_side) * m * 2)
	print(''.join(left_side) + ''.join(right_side[::-1]))


(n, m) = map(int, input().split())
ls = []
for i in range(n):
	ls.append(input())
s1 = ''
s2 = ''
s3 = ''
count = 0
for i in range(n):
	j = i
	for k in range(j, n):
		if ls[i][::-1] == ls[k] and k != i:
			s1 = s1 + ls[i]
			s2 = ls[k] + s2
		elif ls[j] == ls[j][::-1] and count == 0:
			s3 = s3 + ls[j]
			count = 1
s1 = s1 + s3 + s2
print(len(s1))
print(s1)


(n, m) = map(int, input().split())
strings = []
for i in range(n):
	strings.append(input())
vis = [0] * n
ans = ''
for i in range(n):
	tmp = strings[i]
	for j in range(i + 1, n):
		if tmp == strings[j][::-1]:
			ans += tmp
			vis[i] = 1
			vis[j] = 1
			break
res = ''
for i in range(n):
	if strings[i] == strings[i][::-1] and vis[i] == 0:
		res += strings[i]
		break
if len(res) != 0 or len(ans) != 0:
	print(2 * len(ans) + len(res))
	print(ans + res + ans[::-1])
else:
	print(0)


(m, n) = list((int(i) for i in input().split()))
A = []
for _ in range(m):
	s = input()
	A.append(s)
ans = ''
special = ''
B = [False for i in range(m)]
for s in A:
	a = s[::-1]
	if a in A and B[A.index(a)] is not True:
		if A.index(a) != A.index(s):
			B[A.index(a)] = True
			B[A.index(s)] = True
			ans += a
			ans = s + ans
		else:
			special = a
l = len(ans)
one = ans[0:l // 2]
two = ans[l // 2:]
newans = one + special + two
print(len(newans))
print(newans)


(n, m) = map(int, input().split())
l1 = []
l2 = []
for _ in range(n):
	l1.append(input())
st = ''
mid = ''
end = ''
for i in range(len(l1)):
	w = l1[i]
	wr = w[::-1]
	if w in l2 or wr in l2:
		continue
	elif wr in l1:
		if w == wr:
			mid = w
		else:
			st += w
			end = wr + end
	l2.append(w)
print(len(st + mid + end))
print(st + mid + end)


import math

def palindrome(s1, s2, m):
	rev = ''.join(reversed(s1))
	if s2 == rev:
		return True
	return False

def palin(s, m):
	rev = ''.join(reversed(s))
	if s == rev:
		return True
	return False
(n, m) = [int(ele) for ele in input().split()]
s = []
for _ in range(n):
	s.append(input())
s.sort()
pdrome = []
mem = {}
for st in s:
	mem[st] = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if mem[s[i]] == 0 and mem[s[j]] == 0:
			if palindrome(s[i], s[j], m):
				pdrome.append(s[i])
				pdrome.append(s[j])
				mem[s[i]] = 1
				mem[s[j]] = 1
for st in mem.keys():
	if mem[st] == 0:
		if palin(st, m):
			pdrome.append(st)
			break
longPalin = ''
for i in range(len(pdrome) - 1):
	if i % 2 == 0:
		longPalin += pdrome[i]
if len(pdrome) % 2 != 0:
	longPalin += pdrome[-1]
for i in range(len(pdrome) - 1, -1, -1):
	if i % 2 != 0:
		longPalin += pdrome[i]
print(len(longPalin))
print(longPalin)


(n, m) = map(int, input().split())
l = []
l1 = [0] * n
for i in range(n):
	s = input()
	l.append(s)
i = 0
l3 = []
l4 = []
while i < n:
	if l1[i] == 0:
		s1 = l[i]
		s2 = s1[::-1]
		f = 0
		for j in range(i + 1, n):
			if l[j] == s2:
				l3.append(l[i])
				l3.append(l[j])
				l1[j] = 1
				f = 1
				break
		if f == 0:
			if s1 == s2:
				l4.append(s1)
	i += 1
s1 = ''
m = len(l3)
i = 0
while i < m:
	s1 = s1 + l3[i]
	i = i + 2
if len(l4) != 0:
	s1 = s1 + l4[0]
j = m - 1
while j > 0:
	s1 = s1 + l3[j]
	j = j - 2
print(len(s1))
print(s1)


(n, m) = map(int, input().split())
s = [input() for _ in range(n)]
s.sort(key=lambda x: -len(x))
vst = [0] * n
ans = ''
for i in range(n):
	for j in range(i + 1, n):
		if vst[j]:
			continue
		x = s[i] + s[j]
		if x == x[::-1]:
			ans = s[i] + ans + s[j]
			vst[j] = 1
		else:
			x = s[j] + s[i]
			if x == x[::-1]:
				ans = s[j] + ans + s[i]
				vst[j] = 1
		if vst[j]:
			break
anslen = len(ans)
if anslen % 2 == 0:
	for i in range(n):
		if not vst[i]:
			if s[i] == s[i][::-1]:
				ans = ans[:anslen // 2] + s[i] + ans[anslen // 2:]
				anslen += len(s[i])
				break
print(anslen, ans, sep='\n')


(n, m) = map(int, input().split())
x = []
for i in range(n):
	s = input()
	x.append(s)
a = []
used = [0 for i in range(n)]
for i in range(n - 1):
	for j in range(i + 1, n):
		s1 = x[i]
		s2 = x[j]
		if s1 == s2[::-1] and (not used[i]) and (not used[j]):
			a.append([s1, s2])
			used[i] = 1
			used[j] = 1
b = []
for i in range(n):
	if not used[i]:
		s = x[i]
		t = 0
		for j in range(m // 2):
			if s[j] != s[m - j - 1]:
				t = 1
				break
		if not t:
			b.append(s)
ans = ''
for i in range(len(a)):
	ans += a[i][0]
if b:
	ans += b[0]
for i in range(len(a) - 1, -1, -1):
	ans += a[i][1]
print(len(ans))
print(ans)


import sys
(n, l) = (int(x) for x in input().split())
strings = []
for q in range(n):
	strings.append(input())
balanced = []
equals = []
instrings = {}
for x in range(n):
	if strings[x] not in instrings:
		instrings[strings[x]] = 0
	if strings[x] == strings[x][::-1]:
		balanced.append(strings[x])
	for y in range(n):
		if strings[y] not in instrings:
			instrings[strings[y]] = 0
		if x != y:
			if strings[x] == strings[y] or strings[x] == strings[y][::-1]:
				if instrings[strings[x]] == 1 or instrings[strings[y]] == 1:
					pass
				else:
					equals.append((strings[x], strings[y]))
					instrings[strings[x]] = 1
					instrings[strings[y]] = 1
palindrome = ''
if len(balanced) == 0 and len(equals) == 0:
	print(0)
	sys.exit()
if len(balanced) > 0:
	for x in balanced:
		if instrings[x] != 1:
			palindrome = x
			break
for x in equals:
	palindrome = x[0] + palindrome + x[1]
print(len(palindrome))
print(palindrome)


l = list(map(int, input().split()))
name = [[] for j in range(l[0])]
for i in range(l[0]):
	name[i] = list(input())
(n, c) = (0, 0)
k = []
h = []
for i in range(l[0]):
	name[i] = name[i][::-1]
	if name[i] in name[i + 1:l[0]]:
		k = k + name[i][::-1]
		n = n + 2 * len(name[i])
		name[i + 1:l[0]].remove(name[i])
	elif name[i] == name[i][::-1]:
		if c < len(name[i]):
			c = len(name[i])
			h = name[i]
o = list(k[::-1])
k = k + h
k = k + o
print(n + c)
print(''.join(k))


from collections import deque
data1 = [int(x) for x in input().split(' ')]
n = data1[0]
m = data1[1]
strings = []
for line in range(n):
	strings.append(input())
comps = []
singles = []
while len(strings) > 0:
	found = False
	s = strings[-1]
	for i in range(len(strings) - 1):
		if strings[i] == s[::-1]:
			s0 = strings[-1]
			s1 = strings.pop(i)
			comps.append((s0, s1))
			found = True
			break
	if found == False:
		if s == s[::-1]:
			singles.append(s)
	strings.pop(-1)
d = deque()
if len(singles) > 0:
	d.append(singles[0])
for c in comps:
	d.appendleft(c[0])
	d.append(c[1])
sol = ''.join(d)
l = len(sol)
print(l)
print(sol)


import sys
from collections import deque
(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
ans = deque()
used = [0 for _ in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		if a[j] == a[i][::-1] and (not used[i]) and (not used[j]):
			ans.append(a[j])
			ans.appendleft(a[i])
			used[i] = 1
			used[j] = 1
res = []
for i in ans:
	res.append(i)
for i in range(n):
	if not used[i]:
		if a[i] == a[i][::-1]:
			res.insert(len(res) // 2, a[i])
			break
print(sum(map(len, res)))
for i in res:
	print(i, end='')


def main():
	(n, m) = map(int, input().split())
	pal = ''
	ws = []
	p_pal = []
	for _ in range(n):
		w = input()
		ws.append(w)
		if isPal(w):
			if not pal:
				pal += w
			continue
		w_r = w[-1::-1]
		if w_r in ws:
			p_pal.append(w)
	if p_pal or pal:
		print(solve(pal, p_pal))
	else:
		print(0)

def isPal(w):
	letters = list(w)
	for i in range(len(w) // 2):
		if letters[i] != letters[-1 - i]:
			return False
	return True

def solve(pal, p_pal):
	long_pal = ''
	for i in range(len(p_pal)):
		long_pal += p_pal[i]
	if pal:
		long_pal += pal
	for i in range(len(p_pal)):
		p_pal[-1 - i] = p_pal[-1 - i][-1::-1]
		long_pal += p_pal[-1 - i]
	return f'{len(long_pal)}\n{long_pal}'
main()


(n, m) = list(map(int, input().split()))
d = {}
left = right = ''
for _ in range(n):
	s = input()
	s1 = s[::-1]
	if s in d:
		left += s1
		right = s + right
		del d[s]
	else:
		d[s1] = True
longest_palin = ''
for key in d:
	if key == key[::-1]:
		if len(key) > len(longest_palin):
			longest_palin = key
res = left + longest_palin + right
print(len(res))
print(res)


import sys
input = lambda : sys.stdin.readline().rstrip()
arr = []
(n, m) = map(int, input().split())
ans = []
for _ in range(n):
	s = [i for i in input()]
	arr.append(s)
ansz = []
for i in range(n):
	src = []
	flag = 0
	for k in range(m - 1, -1, -1):
		src.append(arr[i][k])
	for j in range(i + 1, n):
		if arr[j] == src:
			ans.append(arr[i])
			ans.append(arr[j])
			flag = 1
			break
	if flag == 0:
		f = 0
		for p in range(m):
			if arr[i][p] != arr[i][m - 1 - p]:
				f = 1
				break
		if f == 0:
			ansz = []
			for ip in range(m):
				ansz.append(arr[i][ip])
st = ''
for i in range(0, len(ans), 2):
	st += ''.join(map(str, ans[i]))
st += ''.join(map(str, ansz))
for i in range(len(ans) - 1, -1, -2):
	st += ''.join(map(str, ans[i]))
print(len(st))
print(st)


def check(a, b):
	if a == b[::-1]:
		return True
	else:
		return False

def check1(a):
	if a == a[::-1]:
		return True
	else:
		return False
(a, b) = map(int, input().split())
li = []
for _ in range(a):
	li.append(input())
c = 0
d = ''
e = ''
for i in range(a):
	for j in range(i + 1, a):
		if check(li[i], li[j]):
			c += 1
			d = li[j] + d
			e += li[i]
			li[i] = '-1'
			li[j] = '-1'
			break
ans = c * 2 * b
k = ''
for i in li:
	if i != '-1':
		if check1(i):
			k = i
			ans += b
			break
print(ans)
print(e, end='')
print(k, end='')
print(d, end='')


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	x = input()
	if x not in d.keys():
		d[x] = 1
	else:
		d[x] += 1
ans = []
o = []
for i in d.keys():
	r = i[::-1]
	if i == r:
		if d[i] % 2:
			o.append(i * d[i])
		else:
			ans.append(i * d[i])
	elif r in d.keys():
		mn = min(d[r], d[i])
		ans.append(i * mn)
		ans.append(r * mn)
	d[i] = 0
x = len(ans)
fin = []
for i in range(0, x, 2):
	fin.append(ans[i])
if len(o) > 0:
	fin.append(o[0])
for i in range(x - 1, -1, -2):
	fin.append(ans[i])
s = ''
for i in range(len(fin)):
	s += fin[i]
print(len(s))
print(s)


(n, m) = map(int, input().split())
slist = [input() for _ in range(n)]
memo = []
center = ''
while slist != []:
	s = slist[0]
	t = s[::-1]
	if s != t and t in slist:
		memo.append(s)
		del slist[slist.index(t)]
	elif s == t:
		center = s
	del slist[0]
s = ''
for _ in memo:
	s += _
t = s[::-1]
ans = s + center + t
print(len(ans))
print(ans)


n = int(input().split()[0])
strings = [input() for x in range(n)]
used = [False] * n
erg = ''
middle = ''
for i in range(n):
	for j in range(i + 1, n):
		if not (used[j] or used[i]) and strings[i][::-1] == strings[j]:
			erg += strings[j]
			used[j] = True
			used[i] = True
	if not used[i] and strings[i] == strings[i][::-1]:
		middle = strings[i]
print(2 * len(erg) + len(middle))
print(erg + middle + erg[::-1])


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
same = ''
ans = ''
while a:
	s = a.pop()
	if s[::-1] in a:
		ans += s
		a.pop(a.index(s[::-1]))
	elif s == s[::-1]:
		same = s
if same:
	ans = ans + same + ans[::-1]
else:
	ans = ans + ans[::-1]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
single = set()
paired = []
for _ in range(n):
	s = input()
	if {s, s[::-1]} & single:
		paired.append(s)
		single -= {s, s[::-1]}
	else:
		single.add(s)
x = ''.join(paired)
for s in single:
	if s == s[::-1]:
		break
else:
	s = ''
x += s + x[::-1]
print(len(x))
print(x)


import copy
(n, m) = map(int, input().split())
s = []
h = []
for i in range(n):
	a = list(input())
	d = True
	for j in range(m // 2):
		if a[j] != a[m - 1 - j]:
			d = False
			break
	h.append(d)
	s.append(a)
res = []
s1 = copy.deepcopy(s)
for e in s1:
	e.reverse()
for x in range(n):
	for y in range(x + 1, n):
		if s[x] == s1[y]:
			res = res + s[x]
			res = s[y] + res
			s[x] = None
			s[y] = None
r = ''
for i in range(n):
	if h[i] and s[i] != None:
		r = s[i]
		break
print(len(res) + len(r))
for charac in res[0:len(res) // 2]:
	print(charac, end='')
for r2 in r:
	print(r2, end='')
for charac in res[len(res) // 2:]:
	print(charac, end='')
print()


(n, m) = map(int, input().split())
s = [''] * n
(pals, mid, midlens) = ('', '', 0)
for i in range(n):
	s1 = input()
	s[i] = s1
	s2 = s1[::-1]
	if s2 == s1:
		l = len(s1)
		if midlens < l:
			mid = s1
			midlens = l
	else:
		for j in range(i):
			if s[j] == s2:
				pals += s2
				s[j] = ''
fin = pals + mid + pals[::-1]
print(len(fin))
print(fin)


(n, m) = map(int, input().split())
strings = list((input() for i in range(n)))
ok = set((strings[i] for i in range(len(strings)) if strings[i] != strings[i][::-1]))
ans = max((strings[i] if strings[i] == strings[i][::-1] else '' for i in range(len(strings))))
for s in strings:
	if s[::-1] in ok:
		ans = s + ans + s[::-1]
		ok.remove(s)
		ok.remove(s[::-1])
print('{}\n{}'.format(len(ans), ans))


(n, m) = [int(n) for n in input().split()]
strings = list()
for t in range(n):
	strings.append(input())
palindrome = list()
front = list()
back = list()
for i in range(len(strings)):
	if strings[i] == strings[i][::-1]:
		palindrome.append(strings[i])
	elif strings[i][::-1] in strings:
		front.append(strings[i])
		back.append(strings[i][::-1])
		strings[i] = -1
back.reverse()
output = ''.join(front) + max(palindrome, default='') + ''.join(back)
print(len(output))
print(output)


def is_pal(s):
	idx = m // 2
	if m & 1:
		return s[:idx] == s[idx + 1:][::-1]
	return s[:idx] == s[idx:][::-1]
(n, m) = map(int, input().split())
start = []
mid = []
end = []
for _ in range(n):
	s = input()
	if is_pal(s) and (not mid):
		mid.append(s)
	elif not start:
		start.append(s)
	else:
		for i in start:
			if s == i[::-1]:
				end.append(s)
				break
		if not end or end[-1] != s:
			start.append(s)
end = ''.join(end)
start = end[::-1]
if mid:
	ans = start + mid[0] + end
else:
	ans = start + end
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
Sts = []
Ans = ''

def palin(s1, s2):
	if len(s1) != len(s2):
		return False
	else:
		ri = len(s2) - 1
		for c in s1:
			if c != s2[ri] or ri < 0:
				return False
			ri -= 1
		return True

def s(st):
	global Ans
	for s in Sts:
		if palin(s, st):
			Ans += st
			Sts.remove(s)
			return
	Sts.append(st)
while n > 0:
	n -= 1
	S = str(input())
	s(S)
for st in Sts:
	if palin(st[0:len(st) // 2], st[len(st) // 2 + len(st) % 2:]):
		Ans = Ans + st + Ans[::-1]
		print(len(Ans))
		print(Ans)
		exit(0)
Ans += Ans[::-1]
print(len(Ans))
print(Ans)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(x, y):
	return f(x) // (f(y) * f(x - y))
(n, m) = map(int, input().split())
la = []
za = []
ans1 = ''
ans2 = ''
maxi = 0
hash = defaultdict(int)
for i in range(n):
	la.append(input())
	hash[la[i]] += 1
for i in range(n):
	z = la[i][::-1]
	if hash[z] > 0 and hash[la[i]] > 0:
		if z != la[i]:
			hash[z] -= 1
			hash[la[i]] -= 1
			ans1 += la[i]
		elif hash[z] > 1:
			hash[z] -= 1
			hash[la[i]] -= 1
			ans1 += la[i]
ans = ''
for i in hash:
	if hash[i] > 0 and i[::-1] == i:
		ans = ans1 + i + ans1[::-1]
		break
if len(ans) != 0:
	print(len(ans))
	print(ans)
else:
	print(len(ans1) + len(ans1[::-1]))
	print(ans1 + ans1[::-1])


def check_palindrom(s):
	for l in range(m // 2):
		if s[l] != s[m - l - 1]:
			return False
	return True

def check_palindrom2(a, b):
	if m % 2 != 0:
		if a[m // 2] != b[m // 2]:
			return False
	for l in range(m):
		if a[l] != b[m - l - 1]:
			return False
	return True

def getPali(s):
	l = ''
	for h in range(len(s) - 1, -1, -1):
		l += s[h]
	return l
(n, m) = map(int, input().split())
strings = []
for i in range(n):
	strings.append(input())
f = 0
count = 0
com = ''
res = ''
for i in range(n):
	if check_palindrom(strings[i]) and f == 0:
		com = strings[i]
		count += 1
		f = 1
		continue
	for j in range(i + 1, n):
		if check_palindrom2(strings[i], strings[j]):
			count += 2
			res += strings[i]
			break
print(count * m)
k = getPali(res)
res += com
res += k
print(res)


def main():
	(n, _) = map(int, input().split())
	string_list = []
	for _ in range(n):
		string = input()
		string_list.append(string)
	taken = [False for _ in range(n)]
	ans_list = []
	middle = ''
	for index_one in range(n):
		if taken[index_one]:
			continue
		string_one = string_list[index_one]
		for index_two in range(index_one + 1, n):
			string_two = string_list[index_two]
			if string_one == string_two[::-1]:
				taken[index_two] = True
				ans_list.insert(0, string_one)
				ans_list.append(string_two)
				break
		else:
			if string_one == string_one[::-1]:
				middle = string_one
	length = len(ans_list)
	if length == 0:
		ans = middle
	else:
		ans = ''
		for index in range(length):
			ans += ans_list[index]
			if index + 1 == length // 2:
				ans += middle
	print(len(ans))
	print(ans)
main()


(num, length) = map(int, input().split())
unpaired = []
paired = []
natpalin = []
for i in range(num):
	newword = input()
	if newword[::-1] in unpaired:
		unpaired.remove(newword[::-1])
		paired.append(newword)
	else:
		unpaired.append(newword)
	if newword in natpalin:
		natpalin.remove(newword)
	elif len(newword) % 2 == 0 and newword[:int(len(newword) / 2)] == newword[::-1][:int(len(newword) / 2)]:
		natpalin.append(newword)
	elif len(newword) % 2 == 1 and newword[:int((len(newword) - 1) / 2)] == newword[::-1][:int((len(newword) - 1) / 2)]:
		natpalin.append(newword)
natpalin.sort(key=len)
phalf = ''.join(paired)
final = phalf
if len(natpalin) > 0:
	final += natpalin[-1]
final += phalf[::-1]
print(len(final))
if len(final) != 0:
	print(final)


def pallindrome(s):
	rev = ''.join(reversed(s))
	if s == rev:
		return 1
	return 0
(n, m) = map(int, input().split())
a = []
h = ''
for i in range(n):
	b = str(input())
	a.append(b)
c = []
d = []
for i in range(len(a)):
	rev = ''.join(reversed(a[i]))
	if rev in a[i + 1:]:
		c.append(a[i])
		d.append(rev)
	if pallindrome(a[i]) == 1:
		h = a[i]
d.reverse()
st = ''.join(c) + h + ''.join(d)
print(len(st))
print(st)


from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)
(N, M) = map(int, input().split())
for _ in range(N):
	s = input().strip()
	if s[::-1] == s:
		d2[s] += 1
	else:
		d1[s] += 1
		d1[s[::-1]] += 1
rs = []
rss = set()
for key in d1:
	if key[::-1] in rss:
		continue
	tn = d1[key] // 2
	rss.add(key)
	rs += [key] * tn
fk = False
mn = ''
for key in d2:
	tn = d2[key] // 2
	rs += [key] * tn
	if not fk and d2[key] % 2:
		mn = key
t = ''.join(rs)
t = t + mn + t[::-1]
print(len(t))
print(t)


def isPal(a, b):
	if len(a) != len(b):
		return False
	for i in range(len(a)):
		if a[i] != b[len(b) - i - 1]:
			return False
	return True
(n, m) = map(int, input().split())
tab = [input() for i in range(n)]
pals = set()
ajout = True
for i in range(n):
	for j in range(i):
		if i != j and isPal(tab[i], tab[j]):
			pals.add((tab[i], tab[j]))
result = ''
for mot in tab:
	if isPal(mot, mot) and len(mot) > len(result):
		result = mot
for p in pals:
	result = p[0] + result + p[1]
print(len(result))
print(result)


def isPal(s):
	return s == s[::-1]
(n, m) = map(int, input().split())
l = [input() for i in range(n)]
d = []
countt = 0
uni = ''
ans = ''
for s in l:
	p = s[::-1]
	if not isPal(s):
		if p in l and p not in d:
			d.append(s)
			ans += s
		elif countt == 0 and isPal(s):
			uni = s
			countt += 1
	elif countt == 0:
		uni = s
		countt += 1
rev = ans[::-1]
ans += uni + rev
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
(d, s) = ([], [])
e = set()
r = []
a = ''
for i in range(n):
	d.append(input())
for i in range(n):
	for j in range(i + 1, n):
		if d[i] == d[j][::-1]:
			s.append(d[i])
			e.add(d[i])
for i in range(n):
	if d[i] == d[i][::-1] and d[i] not in e:
		r.append(d[i])
for i in s:
	a += i
if r:
	a += max(r, key=len)
for i in s[::-1]:
	a += i[::-1]
print(len(a))
print(a)


(n, m) = map(int, input().split())
ss = []
for i in range(n):
	ss.append(input())
ans = ''
for i in range(n):
	if ss[i] == ss[i][::-1]:
		ans = ss[i]
for i in range(n):
	for j in range(i):
		if ss[i] == ss[j][::-1]:
			ans = ss[i] + ans + ss[j]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	s = input()
	a.append(s)
head = []
tail = []
for i in range(n):
	s1 = a[i]
	for j in range(n):
		if i == j:
			continue
		if s1 == a[j][::-1]:
			head.append(s1)
			tail.append(a[j])
			a[i] = '/-'
			a[j] = '/-'
			break
tail.reverse()
s = ''
for i in range(n):
	if a[i] == a[i][::-1]:
		s = a[i]
		break
ss = ''.join(head) + s + ''.join(tail)
print(len(ss))
print(ss)


(n, m) = map(int, input().split())
center = ''
ans = []
inp = set()
for _ in range(n):
	s = input()
	t = s[::-1]
	if s == t:
		center = s
	elif t in inp:
		ans.append(s)
	else:
		inp.add(s)
ans = ''.join(ans)
ans = ans + center + ans[::-1]
print(len(ans))
print(ans)


import sys
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
npal = pal = ''
a = set()
for i in range(int(input().split()[0])):
	s = input()
	s1 = s[::-1]
	if s == s1:
		pal = s
	elif s1 in a:
		npal += s
	a.add(s)
ans = npal + pal + npal[::-1]
print(len(ans), ans, sep='\n')


(n, m) = map(int, input().split(' '))
A = []
start = ''
end = ''
mid = ''
for i in range(n):
	a = input()
	A.append(a)
	e = a[::-1]
	if e in A and e != a:
		start += a
		end = e + end
	elif e == a:
		mid = a
ans = start + mid + end
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
res = ''
mid = ''
p = []
self = []
for _ in range(n):
	s = input()
	rev = s[::-1]
	if s not in p:
		p.append(rev)
	else:
		p.remove(s)
		res += s
		if rev in self:
			self.remove(s)
	if s == s[::-1]:
		self.append(s)
if len(self) != 0:
	mid = self[0]
res = res + mid + res[::-1]
print(len(res))
print(res)


(x, y) = map(int, input().split())
a = []
s = ''
p = ''
for i in range(x):
	a.append(str(input()))
for i in range(x):
	if ''.join(reversed(a[i])) in a and a[i] != ''.join(reversed(a[i])) and (a[i] != ''):
		s += a[i]
		a[i] = ''
		a[a.index(''.join(reversed(a[i])))] = ''
	elif i == ''.join(reversed(a[i])) and a.count(a[i]) >= 2 and (a[i] != ''):
		s += i
		a[i] = ''
		a[a.index(''.join(reversed(a[i])))] = ''
	elif a[i] == ''.join(reversed(a[i])) and a[i] != '':
		p = a[i]
print(len(s) * 2 + len(p))
print(s + p + ''.join(reversed(s)))


(n, m) = map(int, input().split())
sum = ''
ans = ''
chance = ''
for i in range(n):
	s = input()
	if s[::-1] in sum:
		ans += s
	sum += s + ' '
	if s == s[::-1]:
		chance = s
if chance == '' and ans == '':
	print(0)
	print()
else:
	h = ans + chance + ans[::-1]
	print(len(h))
	print(h)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
strs = []
res = []
p = []
for i in range(n):
	x = input()
	if ''.join(list(reversed(x))) in strs:
		res.append(x)
	elif x == ''.join(list(reversed(x))):
		p.append(x)
	strs.append(x)
str1 = ''.join(res)
if len(p) > 0:
	str2 = p[0]
else:
	str2 = ''
str3 = ''.join(list(reversed(str1)))
s = str1 + str2 + str3
print(len(s))
print(s)


(n, l) = map(int, input().split())
arr = list()
for i in range(n):
	arr.append(str(input()))

def getRes(newStr, arr):
	for (ind, x) in enumerate(arr):
		for l in range(ind + 1, len(arr)):
			if x == arr[l][::-1]:
				newStr = x + newStr + arr[l]
	return newStr

def findCenter(newStr, arr):
	for (ind, x) in enumerate(arr):
		if x == x[::-1]:
			newStr = x
			del arr[ind]
	res = getRes(newStr, arr)
	print(len(res), res)

def lol(arr):
	newStr = ''
	center = findCenter(newStr, arr)
lol(arr)


(n, m) = map(int, input().split())
(l, lre) = ([], [])
(sel, com) = (0, 0)
ans = []
anss = ''
for i in range(n):
	s = input()
	l.append(s)
	lre.append(s[::-1])
for i in range(n):
	if sel == 0:
		if l[i] == lre[i]:
			sel += 1
			anss = l[i]
	for j in range(i + 1, n):
		if lre[i] == l[j]:
			ans.append(l[j])
			com += 1
			break
print((sel + com * 2) * m)
str = ''
for i in range(com):
	str += ans[i]
print(str + anss, end='')
print(str[::-1])


(a, b) = list(map(int, input().split()))
l = []
c = []
r = []
sour = []
k = False
ch = [0] * a
for _ in range(a):
	sour.append(input())
for i in range(a - 1):
	for j in range(i + 1, a):
		if ch[i] == 0 and ch[j] == 0:
			if sour[i] == sour[j]:
				l.append(sour[i])
				r.insert(0, sour[j])
				(ch[i], ch[j]) = (1, 1)
			elif sour[i] == ''.join(reversed(sour[j])):
				l.append(sour[i])
				r.insert(0, sour[j])
				(ch[i], ch[j]) = (1, 1)
				break
for i in range(a):
	if ch[i] == 0:
		if sour[i] == ''.join(reversed(sour[i])):
			c.append(sour[i])
			ch[i] = 1
			break
ans = ''
ans = ''.join(l) + ''.join(c) + ''.join(r)
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
l = {}
x = ''
y = ''
for i in range(n):
	s = input()
	t = s[::-1]
	if t in l:
		l[t] += 1
	else:
		l[s] = 1
p = 0
for i in l:
	if l[i] == 1:
		j = i[::-1]
		if i == j:
			y = i
			p = 1
	else:
		for k in range(l[i] // 2):
			x = x + i
x1 = x[::-1]
z = x + y + x1
print(len(z))
print(z)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
import math
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)

def solve():
	(n, m) = takeivr()
	dict_1 = dd(lambda : 0)
	for i in range(n):
		dict_1[takesr()] = 1
	flag = False
	ans = ''
	for i in list(dict_1.keys()):
		if ispalindrome(i):
			flag = i
		elif i[::-1] in dict_1 and dict_1[i[::-1]]:
			ans += i
			dict_1[i] = 0
	first = ans
	if flag != False:
		first += flag
	first += ans[::-1]
	print(len(first))
	print(first)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def takein():
	return int(sys.stdin.readline().rstrip('\r\n'))

def takesr():
	return sys.stdin.readline().rstrip('\r\n')

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


(n, m) = map(int, input().split())
l = []
k = []
t = []
ans = ''

def rev(s):
	g = ''
	for i in range(len(s) - 1, -1, -1):
		g += s[i]
	return g

def od(s):
	h = set()
	for i in s:
		h.add(i)
	if len(h) == 1:
		return True
	return False

def is_pal(s):
	for j in range(len(s) // 2):
		if s[j] != s[len(s) - 1 - j]:
			return False
	return True
for i in range(n):
	s = input()
	l.append(s)
for i in l:
	if is_pal(i) and l.count(i) % 2 == 1:
		t.append(i)
for i in range(n - 1):
	for j in range(i + 1, n):
		if rev(l[i]) == l[j] and (not od(l[i])):
			k.append(l[i])
for i in range(n):
	if od(l[i]) and l.count(l[i]) == 1:
		t.append(l[i])
for i in k:
	ans += i
if len(t) > 0:
	ans += t[0]
k.reverse()
for i in k:
	ans += rev(i)
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
L = []
for i in range(0, n):
	s = input()
	L.append(s)
vis = [0] * n
k1 = []
k2 = []
for i in range(0, len(L)):
	if vis[i] == 0:
		for j in range(0, len(L)):
			if vis[j] == 0 and L[i] == L[j][::-1] and (i != j):
				vis[j] = 1
				vis[i] = 1
				k1.append(L[i])
				k2.append(L[j])
k2 = k2[::-1]
st = ''
for i in range(0, len(L)):
	if vis[i] == 0:
		if L[i] == L[i][::-1]:
			st = L[i]
			break
ans = ''
for i in range(0, len(k1)):
	ans += k1[i]
ans += st
for i in range(0, len(k2)):
	ans += k2[i]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
currWord = []
currWords = []
for i in range(n):
	s = input()
	flag = True
	for word in currWords:
		if s == word[::-1]:
			currWord.append(word)
			currWords.remove(word)
			flag = False
			break
	if flag:
		currWords.append(s)
middleWordLength = 0
middleWord = ''
for i in currWords:
	if i == i[::-1]:
		middleWord = i
		middleWordLength = m
		break
print(m * len(currWord) * 2 + middleWordLength)
print(''.join(currWord) + middleWord + ''.join(currWord)[::-1])


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(input()))
v = []
ans = []
for i in range(n):
	if l[i][::-1] == l[i]:
		ans = l[i]
for i in range(n):
	for j in range(n):
		if i < j and (not i in v) and (not j in v):
			if l[i][::-1] == l[j]:
				ans = l[i] + ans + l[j]
				v.append(i)
				v.append(j)
print(len(ans))
print(''.join(ans))


def func(s1, s2):
	return s1 == s2[::-1]

def func2(s1):
	return s1 == s1[::-1]
(n, m) = map(int, input().split())
list1 = []
list2 = []
list3 = []
list4 = []
list5 = []
for i in range(n):
	s = input()
	list1.append(s)
for i in range(n):
	for j in range(i + 1, n):
		s1 = list1[i]
		s2 = list1[j]
		if func(s1, s2):
			list2.append(list1[i])
			list2.append(list1[j])
			list4.append(list1[i])
			list5.append(list1[j])
for i in range(n):
	s1 = list1[i]
	t = list2.count(s1)
	if func2(s1) and t == 0:
		list3.append(s1)
ans = 0
ans1 = []
if len(list3) > 0:
	ans = m
ans = ans + m * len(list2)
print(ans)
list5 = list5[::-1]
ans1.extend(list4)
if len(list3) > 0:
	y = list3[0]
	ans1.append(y)
ans1.extend(list5)
a = ''
a = a.join(ans1)
print(a)


import math
(n, m) = [int(x) for x in input().split()]
inputArray = []
answer = []
palindromeString = []
for _ in range(n):
	inputArray.append(input())
while len(inputArray) > 0:
	reversedString = inputArray[0][::-1]
	if inputArray[0] == reversedString:
		if reversedString in inputArray[1:]:
			answer.insert(0, inputArray[0])
			answer.append(reversedString)
			inputArray = inputArray[1:]
			inputArray.remove(reversedString)
		else:
			palindromeString.append(reversedString)
			inputArray = inputArray[1:]
	elif reversedString in inputArray[1:]:
		answer.insert(0, inputArray[0])
		answer.append(reversedString)
		inputArray = inputArray[1:]
		inputArray.remove(reversedString)
	else:
		inputArray = inputArray[1:]
if len(palindromeString) == 0:
	printtableAnswer = ''.join(answer)
	print(len(printtableAnswer))
	print(printtableAnswer)
else:
	maxString = max(palindromeString)
	answer.insert(int(len(answer) / 2), maxString)
	printtableAnswer = ''.join(answer)
	print(len(printtableAnswer))
	print(printtableAnswer)


int_inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
mul = lambda : map(int, input().split())
mulf = lambda : map(float, input().split())
seq = lambda : list(map(int, input().split()))
import math
from collections import Counter, defaultdict
(a, b) = mul()
A = []
for i in range(a):
	k = input()
	A.append(k)
l = ''
p = {}
for i in A:
	if i == i[::-1]:
		if len(i) > len(l):
			l = i
		continue
	if i[::-1] in A and i not in p:
		p[i[::-1]] = i
		continue
ans = ''
for i in p.keys():
	ans += i
ans += l
f = list(p.values())
for i in f[::-1]:
	ans += i
print(len(ans))
print(ans)


nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
strings = []
palindroms = []
pal = ''
for i in range(n):
	s = input()
	if pal == '' and s == s[::-1]:
		pal = s
	else:
		rev = s[::-1]
		flag = False
		for j in range(len(strings)):
			if rev == strings[j]:
				flag = True
				strings.pop(j)
				palindroms.append(s)
				break
		if not flag:
			strings.append(s)
ans = ''
l = 2 * m * len(palindroms) + len(pal)
for i in palindroms:
	ans = ans + i
ans = ans + pal + ans[::-1]
print(l)
print(ans)


(n, m) = input().split()
n = int(n)
m = int(m)
start = ''
end = ''
mid = ''
a = set()
for i in range(0, n):
	b = input()
	if b[::-1] in a:
		start += b[::-1]
		end = b + end
	else:
		a.add(b)
for s in a:
	if s == s[::-1]:
		mid = s
		break
ans = start + mid + end
print(len(ans))
print(ans)


import re
(n, m) = input().split()
n = int(n)
m = int(m)
l = []
w = []
q = []
q1 = []
count1 = 0
count = 0
for i in range(0, n):
	s = input()
	l.append(s)
	w.append(s)
d = []
c = 1
count1 = 0
count2 = 0
s = ''
for i in range(0, n):
	for j in range(0, n):
		if l[i] == l[j][::-1] and i != j and (c == 1):
			s = s + l[i] + l[j]
			count1 += len(l[i])
			count2 += len(l[j])
			l[i] = '*'
			l[j] = '*'
			c = 0
		elif l[i] == l[j][::-1] and i != j:
			s = s[0:count1] + l[i] + l[j] + s[len(s) - count2:len(s)]
			count1 += len(l[i])
			count2 += len(l[j])
			l[i] = '*'
			l[j] = '*'
s = s.replace('*', '')
for i in range(0, n):
	if l[i] == l[i][::-1] and l[i] != '*':
		s = s[0:len(s) // 2] + l[i] + s[len(s) // 2:len(s)]
		break
print(len(s))
print(s)


(n, m) = map(int, input().split())
pair = []
own = []
mentu = []
for _ in range(n):
	s = list(input())
	if s == s[::-1]:
		own.append(s)
	elif 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)


(n, m) = map(int, input().split())
container = set()
length = 0
answer = mid = ''
for _ in range(n):
	string = input()
	reversal = string[::-1]
	if reversal in container:
		answer += string
		length += m
	elif reversal == string:
		mid = reversal
	container.add(string)
print(length * 2 + m if mid else length * 2)
print(answer + mid + answer[::-1])


(a, b) = map(int, input().split(' '))
d_s = {}
d1 = {}
d2 = {}
z = []
for i in range(a):
	s = input()
	z.append(s)
	s1 = s[::-1]
	if s == s1:
		d_s[s] = d_s.get(s, 0) + 1
	else:
		d1[s] = d1.get(s, 0) + 1
		d2[s1] = d2.get(s1, 0) + 1
ans = 0
max1 = 0
c = ''
w = ''
q = ''
for i in range(a):
	a1 = z[i]
	same = d_s.get(a1, 0)
	if same > 0:
		if same > 1:
			ans += 2 * len(a1)
			w += a1
			q += a1
			d_s[a1] -= 2
		elif same > 0:
			if len(a1) >= max1:
				max1 = max(max1, len(a1))
				c = a1
			d_s[a1] -= 1
	elif d1.get(a1, 0) > 0 and d2.get(a1, 0) > 0:
		d1[a1] -= 1
		d2[a1] -= 1
		a2 = a1[::-1]
		d1[a2] -= 1
		d2[a2] -= 1
		w += a1
		q += a1
		ans += 2 * len(a1)
ans += max1
print(ans)
print(w + c + q[::-1])


(n, m) = map(int, input().split())
rev = []
a = []
ans = ''
for i in range(n):
	s = input()
	sr = s[::-1]
	if sr in rev:
		a.append(s)
		rev.remove(sr)
	else:
		rev.append(s)
for s in rev:
	sr = s[::-1]
	if s == sr:
		ans = s
		break
for i in a:
	ans = i + ans + i[::-1]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	a = input()
	l.append(a)
flag = 0
p = []
q = []
for i in range(len(l)):
	str1 = l[i]
	for j in range(i + 1, len(l)):
		str2 = l[j]
		if str1 == str2[::-1]:
			p.append(str1)
temp = ''
for i in l:
	if i == i[::-1]:
		temp += i
		break
if len(p) == 0:
	for i in l:
		if i == i[::-1]:
			flag = 1
			print(len(i))
			print(i)
			break
	if flag == 0:
		print(0)
elif len(temp) == 0:
	str = ''
	for i in p:
		str += i
	tp = str
	tp1 = tp + str[::-1]
	print(len(tp1))
	print(tp1)
else:
	str = ''
	for i in p:
		str += i
	tp = str
	tp1 = tp + temp
	tp2 = tp1 + str[::-1]
	print(len(tp2))
	print(tp2)


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

def isPalindrome(s):
	j = m - 1
	for i in range(j):
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True
strings = list()
for i in range(n):
	a = input()
	strings.append(a)
ans = list()
rev = list()
for i in strings:
	if i[::-1] in strings and i[::-1] != i:
		if i[::-1] not in ans:
			ans.append(i)
			rev.append(i[::-1])
for i in strings:
	if (i[::-1] == i or i[::-1] not in strings) and isPalindrome(i):
		ans.append(i)
		break
now = ''
for i in ans:
	now += i
i = len(rev) - 1
while i >= 0:
	now += rev[i]
	i -= 1
print(len(now))
print(now)


s = input().split(' ')
a = int(s[0])
b = s[1]
dictionary = []
palindrome = ''
leng = 0
for i in range(a):
	temp = input()
	leng = len(palindrome)
	rev = ''
	for j in range(len(temp) - 1, -1, -1):
		rev = rev + temp[j]
	if rev != temp:
		dictionary.append([temp, rev])
	elif rev == temp and leng == 0:
		palindrome = temp
inputs = [i[0] for i in dictionary]
for i in dictionary:
	d = i[1]
	len2 = len(inputs)
	if d in inputs:
		if len2 > 1:
			if leng > 0:
				palindrome = i[0] + palindrome + d
				inputs.remove(d)
				inputs.remove(i[0])
			else:
				palindrome = i[0] + palindrome + d
				inputs.remove(d)
				inputs.remove(i[0])
		else:
			break
l = len(palindrome)
if l == 0:
	print(0)
else:
	print(l)
	print(palindrome)


def checkin(string, notpal):
	for i in notpal:
		if string[::-1] == i:
			return True
	return False

def palindrome(string):
	if string == string[::-1]:
		return True
	else:
		return False
(n, m) = input().split()
n = int(n)
str = ''
pal = False
notpal = []
while n:
	n -= 1
	string = input()
	if palindrome(string):
		if pal:
			pass
		else:
			pal = True
			str = str[:len(str) // 2] + string + str[len(str) // 2:]
	elif checkin(string, notpal):
		str = string[::-1] + str + string
		notpal.remove(string[::-1])
	else:
		notpal.append(string)
print(len(str))
print(str)


(n, m) = map(int, input().split())
mas = []
for i in range(n):
	mas.append(input())
pair = [-1] * n
for i in range(n):
	if pair[i] == -1:
		s = mas[i][::-1]
		j = i + 1
		while j < n:
			if pair[j] == -1:
				if mas[j] == s:
					pair[i] = j
					pair[j] = i
					j = n + 1
			j += 1
a = ''
for i in range(n):
	if pair[i] == -1:
		if mas[i] == mas[i][::-1]:
			a = mas[i]
			break
f = ''
l = ''
for i in range(n):
	if pair[i] > i:
		f += mas[i]
		l = mas[pair[i]] + l
answer = f + a + l
print(len(answer))
print(answer)


(n, m) = map(int, input().split())
l1 = []
l2 = []
l3 = []
l4 = []
l5 = []
s = ''
for i in range(n):
	a = input()
	l1.append(a)
	l2.append(a[::-1])
for i in range(len(l1)):
	if l1[i] == l2[i]:
		l3.append(l1[i])
for i in range(len(l1)):
	for j in range(i + 1, len(l1)):
		if l1[i] == l1[j][::-1]:
			l4.append(l1[i])
			l5.append(l1[j])
if l3 != []:
	l4.append(l3[-1])
for i in range(len(l5) - 1, -1, -1):
	l4.append(l5[i])
for i in l4:
	s = s + i
print(len(s))
print(s)


(a, b) = map(int, input().split())
arr = []
for i in range(a):
	s = input()
	arr.append(s)
(ans, temp) = ('', '')
for i in range(a):
	paici = 0
	for j in range(i + 1, a):
		if arr[i] == arr[j][::-1] and arr[i] != '$$':
			paici = 1
			ans += arr[i]
			arr[i] = '$$'
			arr[j] = '$$'
			break
	if paici == 0:
		if arr[i] == arr[i][::-1] and arr[i] != '$$':
			aa = temp + arr[i]
			if aa == aa[::-1]:
				temp += arr[i]
				arr[i] = '$$'
ss = ans[::-1]
ans += temp
ans += ss
print(len(ans))
print(ans)


def reverse(s):
	return s[::-1]

def isPalindrome(s):
	rev = reverse(s)
	if s == rev:
		return True
	return False
(n, m) = list(map(int, input().split()))
dic = dict()
for i in range(n):
	s = input()
	if isPalindrome(s):
		dic[s] = 1
	elif s[::-1] in dic.keys():
		dic[s[::-1]] = 2
	else:
		dic[s] = 0
self_pal = []
pal_ex = []
for key in dic.keys():
	if dic[key] == 1:
		self_pal.append(key)
	elif dic[key] == 2:
		pal_ex.append(key)
ans = ''
for i in range(len(pal_ex)):
	ans += pal_ex[i]
if len(self_pal) > 0:
	ans += self_pal[0]
for i in range(len(pal_ex) - 1, -1, -1):
	ans += reverse(pal_ex[i])
print(len(ans))
print(ans)


def ispal(a):
	for i in range(len(a) // 2):
		if a[i] != a[len(a) - i - 1]:
			return False
	return True
(n, m) = map(int, input().split())
a = {}
for _ in range(n):
	a[input()] = 1
ans = 0
(b, c) = ([], [])
prev = ['', False]
for i in list(a.keys()):
	if ispal(i):
		if len(i) > len(prev[0]):
			ans += len(i)
			ans -= len(prev[0])
			if prev[1] == False:
				prev = [i, len(b) - 1]
				b.append(list(prev))
			else:
				b[prev[1]][0] = i
	else:
		st = i[::-1]
		if st in a:
			ans += 2 * len(i)
			b.append(i)
			c.append(st)
			a.pop(st)
			a.pop(i)
if ans:
	print(ans)
	abc = ''
	end = ''
	for i in b:
		if type(i) == list:
			end = i[0]
		else:
			abc += i
	abc += end
	for i in range(len(c) - 1, -1, -1):
		abc += c[i]
	print(abc)
else:
	print(0)
	print()


inline = list(input().split())
(n, m) = (int(inline[0]), int(inline[1]))
flag = 0
key = 0
a = []
b = []
vis = []
for i in range(n):
	a.append(input())
	b.append(0)
	vis.append(0)
	if a[i] == a[i][::-1]:
		flag = 1
		key = i
		b[i] = 1
c = ''
i = 0
while i < n:
	if not b[i] and (not vis[i]) and (a[i][::-1] in a):
		c += a[i]
		vis[a.index(a[i][::-1])] = 1
	i += 1
r = c[::-1]
if flag == 1:
	ans = c + a[key] + r
else:
	ans = c + r
print(len(ans))
print(ans)


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

def is_pal(s):
	return s == s[::-1]
seen = set()
best_single = ''
res = ''
for i in range(n):
	s = input()
	if s[::-1] in seen:
		res = res + s
	elif is_pal(s) and len(s) > len(best_single):
		best_single = s
	seen.add(s)
print(len(res) * 2 + len(best_single))
print(res + best_single + res[::-1])


(n, m) = [*map(int, input().split())]
a = []
f = []
d = ''
final = ''
temp = ''
for _ in range(n):
	s = input()
	a.append(s)
for i in a:
	if i == i[::-1]:
		d += i
		f.append(i)
		break
for j in range(n):
	for k in range(n - 1):
		for l in range(k + 1, n):
			op = a[l]
			op = op[::-1]
			if a[k] == op:
				if k not in f and l not in f:
					f.append(k)
					f.append(l)
					final += a[k]
					break
if len(d) != 0:
	temp += d
	d = ''
po = final[::-1]
final += temp
final += po
print(len(final))
if len(final) != 0:
	print(final)


has_tests = False

def solve_case():
	(n, m) = get([int])
	strs = set(get(str, n))
	accepted = set()
	longest_palindrome = ''
	ans = []
	for s in strs:
		if s in accepted:
			continue
		rev = s[::-1]
		if s == rev:
			longest_palindrome = max(longest_palindrome, s, key=len)
		elif rev in strs:
			accepted.add(s)
			accepted.add(rev)
			ans.append(s)
	left = ''.join(ans)
	ans = left + longest_palindrome + left[::-1]
	print(len(ans))
	print(ans)

def get(x, times=None):
	if times is not None:
		return [get(x, times=None) for _ in range(times)]
	if isinstance(x, list):
		return list(map(x[0], input().strip().split()))
	return x(input().strip())
if has_tests:
	for _ in range(get(int)):
		print(solve_case())
else:
	solve_case()


def ispallindrome(string):
	k = len(string) - 1
	j = 0
	while j < k:
		if string[j] != string[k]:
			return False
		j += 1
		k -= 1
	return True
result = []
pallindrome = []
(n, m) = list(map(int, input().split()))
s = []
for i in range(n):
	s.append(input())
j = 0
while s:
	x = s[j]
	s.remove(s[j])
	if x[::-1] in s:
		result.insert(0, x[::-1])
		result.append(x)
		s.remove(x[::-1])
	elif ispallindrome(x) == True:
		if len(pallindrome) == 0 or len(pallindrome[0]) < len(x):
			pallindrome.append(x)
if len(result) % 2 == 0:
	try:
		result.insert(len(result) // 2, pallindrome[0])
	except IndexError:
		None
if len(result) == 0:
	print(0)
else:
	x = ''.join(result)
	print(len(x))
	print(x)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
(n, m) = map(int, input().split())
l = []
for i in range(n):
	s = input()
	l.append(s)
left = ''
right = ''
p = ''
for j in range(len(l)):
	flag = 0
	for k in range(j + 1, len(l)):
		if l[j] == l[k][::-1]:
			left += l[j]
			right = l[k] + right
			flag = 1
			break
	if flag == 0 and len(l[j]) > len(p) and (l[j] == l[j][::-1]):
		p = l[j]
s1 = left + p + right
print(len(s1))
print(s1)


(m, n) = map(int, input().split())
words = list()
status = list()
for i in range(m):
	words.append(input())
	status.append(1)
ans = 0
string = ''
palinwords = list()
center = ''
flag = 1
for i in range(len(words)):
	word = words[i]
	rev = ''.join(reversed(words[i]))
	if flag == 1:
		if word == rev:
			flag = 0
			ans += n
			status[i] = 0
			center = word
	if status[i] == 1:
		for k in range(i + 1, len(words)):
			if rev == words[k]:
				palinwords.append(word)
				ans += n * 2
				status[k] = 0
				break
string += center
for i in palinwords:
	rev = ''.join(reversed(i))
	string = i + string + rev
print(ans)
print(string)


from sys import stdin

def solve():
	(n, m) = map(int, input().split())
	d = {}
	d2 = {}
	v = stdin.readlines()
	for i in range(n):
		d.setdefault(v[i].strip(), []).append(i)
	s = []
	o = []
	for i in range(n):
		st = v[i].strip()
		st2 = st[::-1]
		if d.get(st) and d.get(st2):
			if st == st2:
				if len(d[st]) > 1:
					s.append((st, len(d[st]) // 2))
					if len(d[st]) % 2 == 0:
						d[st] = []
						continue
				o.append(st)
				d[st] = []
				continue
			s.append((st, min(len(d[st2]), len(d[st]))))
			d[st] = []
			d[st2] = []
	l = 0
	p = ''
	for el in s:
		l += el[1]
		p += el[0]
	if o:
		p = p + max(o, key=lambda x: len(x)) + p[::-1]
	else:
		p = p + p[::-1]
	print(len(p))
	print(p)
for i in range(1):
	solve()


import sys
(n, m) = map(int, input().split())
d = dict()
s1 = set()
answer = []
g = sys.stdin.readlines()
for i in range(n):
	s = g[i].replace('\n', '')
	d[s] = True
	s1.add(s)
count = 0
middle = ''
for s in d.keys():
	if d[s] == False:
		continue
	sr = s[::-1]
	if sr in s1:
		d[sr] = False
		d[s] = False
		if sr == s:
			middle = s
		else:
			answer.append((s, sr))
sanswer = ''
for t in answer:
	sanswer += t[0]
sanswer += middle
for i in range(len(answer) - 1, -1, -1):
	sanswer += answer[i][1]
print(len(sanswer))
print(sanswer)


(n, m) = map(int, input().split())
l1 = []
l2 = []
l3 = []
l4 = []
for i in range(n):
	inp = input()
	l1.append(inp)
for j in range(n):
	sj = l1[j][::-1]
	if sj == l1[j]:
		l3.append(sj)
	elif sj in l1:
		l4.append(l1[j])
		l2.append(sj)
		l1[l1.index(sj)] = ''
if len(l3) == 0:
	pass
else:
	for k in range(0, len(l3)):
		if len(l3[k]) >= 1:
			l4.append(l3[k])
			break
if len(l2) == 0:
	pass
else:
	l2.reverse()
	for a in range(0, len(l2)):
		l4.append(l2[a])
print('')
print(len(l4) * m)
for b in l4:
	print(b, end='')


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil, pi, sin, cos, acos, atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = 1
for _ in range(t):
	(n, m) = inp()
	arr = []
	for i in range(n):
		arr.append(ips())
	ch = deque()
	dic = {}
	for i in range(n):
		if arr[i] == arr[i][::-1]:
			dic[len(arr)] = arr[i]
	if len(dic) == 0:
		pass
	else:
		val = dic[max(list(dic.keys()))]
		ch.append(val)
	for i in range(n):
		for j in range(i + 1, n):
			if arr[i] == arr[j][::-1]:
				ch.appendleft(arr[i])
				ch.append(arr[j])
	ans = ''
	for i in ch:
		ans += i
	out(len(ans))
	out(ans)


from sys import stdin
from math import ceil
mod = 1000000007
(n, m) = map(int, stdin.readline().split())
arr = []
for i in range(n):
	s = stdin.readline().strip()
	arr.append(s)
f = []
mid = []
for i in range(n - 1):
	if arr[i] == arr[i][::-1]:
		mid.append(arr[i])
	elif arr[i][::-1] in arr[i + 1:]:
		f.append(arr[i])
if arr[-1] == arr[-1][::-1]:
	mid.append(arr[-1])
if len(f) == 0 and len(mid) == 0:
	print(0)
else:
	if len(mid) == 0:
		print(len(f) * (2 * m))
		s = ''
		for i in range(len(f)):
			s += f[i]
		for i in range(len(f) - 1, -1, -1):
			s += f[i][::-1]
	else:
		print(len(f) * (2 * m) + m)
		s = ''
		for i in range(len(f)):
			s += f[i]
		s += mid[0]
		for i in range(len(f) - 1, -1, -1):
			s += f[i][::-1]
	print(s)


def ispalindrome(s):
	l = list(s)
	if l == l[::-1]:
		return True
	else:
		return False
(n, m) = map(int, input().split())
p = n
l = []
while p > 0:
	p = p - 1
	a = input()
	l.append(a)
ls = []
l2 = []
for i in range(n):
	for j in range(i + 1, n):
		if i != j:
			if ispalindrome(l[i] + l[j]) == True:
				ls.append([l[i], l[j]])
for i in range(n):
	if ispalindrome(l[i]) == True:
		l2.append(l[i])
s = ''
r = ''
c = 0
p = len(ls)
for i in range(p):
	s = s + ls[i][0]
	c = c + 1
if l2 != []:
	c = c + 1
	s = s + l2[0]
for i in range(p - 1, -1, -1):
	s = s + ls[i][1]
	c = c + 1
print(c * m)
print(s)


def check_1(word):
	return word == word[::-1]

def check_2(word_1, word_2):
	return word_1 == word_2[::-1]

def main():
	(n, m) = [int(x) for x in input().split()]
	words = []
	res = []
	for i in range(n):
		words.append(input())
	for i in range(n):
		word_1 = words[i]
		if check_1(word_1):
			res.append(word_1)
			words.remove(word_1)
			break
	n = len(words)
	for i in range(n):
		word_1 = words[i]
		for j in range(i + 1, n):
			word_2 = words[j]
			if check_2(word_1, word_2):
				res = [word_1] + res + [word_2]
	res = ''.join(res)
	print(len(res))
	print(res)
main()


from sys import stdin
import math

def inp():
	return stdin.readline().strip()
(n, m) = [int(x) for x in inp().split()]
s = []
ar = []
left = []
right = []
mid = []
for i in range(n):
	s.append(str(inp()))
for i in range(n):
	for j in range(i, n):
		test = False
		if i != j:
			sym = 0
			needed = []
			for k in range(m):
				needed.append(s[i][k])
			for k in range(m):
				if s[j][m - 1 - k] == needed[k]:
					sym += 1
			if sym == m:
				right.append(s[i])
				left.append(s[j])
				test = True
	if not test:
		if s[i] == s[i][::-1]:
			mid.append(s[i])
lonS = ''
if mid:
	longest = len(mid[0])
	lonS = mid[0]
	for i in mid:
		if len(i) > longest:
			longest = len(i)
			lonS = i
	length = len(left) * m * 2 + len(lonS)
else:
	length = len(left) * m * 2
print(length)
print(''.join(left) + ''.join(lonS) + ''.join(right[::-1]))


(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)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math

def reverse(s):
	return s[::-1]
(n, m) = mi()
l = []
for i in range(n):
	s = si()
	l.append(s)
c = 0
d = ''
for i in range(n):
	if l[i] == reverse(l[i]):
		if len(l[i]) > c:
			d = l[i]
l1 = []
l2 = []
for i in range(n):
	for j in range(i + 1, n):
		if l[i] == reverse(l[j]):
			l1.append(l[i])
			l2.append(l[j])
ans = ''
l2 = l2[::-1]
for i in range(len(l1)):
	ans += l1[i]
ans += d
for i in range(len(l2)):
	ans += l2[i]
print(len(ans))
print(ans)


(a, b) = input().split()
(a, b) = (int(a), int(b))
ss = []
ser = ''
lf = ''
rf = ''
used = [0] * a
for i in range(a):
	s = input()
	ss.append(s)
for i in range(a):
	if used[i] == 1:
		continue
	for j in range(i + 1, a):
		if used[j] == 1:
			continue
		if ss[i] == ss[j][::-1]:
			used[i] = 1
			used[j] = 1
			lf += ss[i]
			rf = ss[j] + rf
			break
	if used[i] == 1:
		continue
	if ss[i] == ss[i][::-1]:
		if len(ss[i]) > len(ser):
			ser = ss[i]
ans = lf + ser + rf
print(len(ans))
print(ans)


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
for tt in range(t):
	(n, m) = invr()
	a = []
	for i in range(n):
		s = insr()
		a.append(list(s))
	q = [0] * len(a)
	for i in range(len(a)):
		for j in range(i + 1, len(a)):
			if a[i] == list(reversed(a[j])):
				q[i] = 1
		if q[i] == 0 and a[i] == list(reversed(a[i])):
			q[i] = 2
	qq = []
	qw = ['']
	w = []
	for i in range(len(a)):
		if q[i] == 1:
			qq = qq + a[i]
			w = w + a[i]
		elif q[i] == 2:
			qw = qw + a[i]
	if len(qw) > m:
		qw = list(qw[1:m + 1])
	else:
		qw = []
	print(len(qq + qw + list(reversed(w))))
	print(''.join(qq + qw + list(reversed(w))))


import math
tc = 1
for _ in range(tc):
	(n, m) = [int(x) for x in input().split()]
	s = [''] * n
	k = 0
	ans = ''
	z = ''
	for i in range(n):
		s[i] = input()
	for i in range(n):
		c = 0
		for j in range(i + 1, n):
			if s[i] == s[j][::-1]:
				ans = s[i] + ans + s[j]
				k = k + 1
				c = c + 1
		if c == 0:
			if s[i] == s[i][::-1]:
				z = s[i]
	ans = ans[0:m * k] + z + ans[m * k:]
	print(len(ans))
	print(ans)


(n, m) = input().split()
(n, m) = (int(n), int(m))
ans = ''
inothope = ''
a = []
for i in range(n):
	a.append(input())
for i in range(len(a)):
	t = a[i]
	if t == t[::-1]:
		inothope = t
	for j in range(i + 1, n):
		k = a[j]
		if a[i] == k[::-1]:
			ans = ans + a[i]
			break
ans = ans + inothope + ans[::-1]
print(len(ans))
print(ans)


buff = input()
n = int(buff.split(' ')[0])
m = int(buff.split(' ')[1])
s = []
for _ in range(n):
	s.append(input())
res = []
for i in range(n):
	res.append([])
	for j in range(i + 1, n):
		if s[i] == s[j][::-1]:
			res[i].append(j)
start = ''
end = []
pal = ''
for i in range(n):
	if len(res[i]) > 0:
		start += s[i]
		end.append(s[res[i][0]])
	elif len(s[i]) % 2 == 0:
		if s[i][:len(s[i]) // 2] == s[i][len(s[i]) // 2:][::-1]:
			pal = s[i]
	elif s[i][:len(s[i]) // 2] == s[i][len(s[i]) // 2 + 1:][::-1]:
		pal = s[i]
end_s = ''
for i in end[::-1]:
	end_s += i
end = end_s
print(len(start) * 2 + len(pal))
print(start + pal + end)


(n, m) = list(map(int, input().split()))
a = []
b = []
c = []
for _ in range(n):
	a.append(input())
for i in range(n):
	if a[i][::-1] != a[i] and a[i][::-1] in a and (a[i][::-1] not in b):
		b.append(a[i])
	if a[i][::-1] == a[i]:
		c.append(a[i])
result = ''
if len(b) != 0:
	for d in b:
		result = result + d
if len(c) != 0:
	result = result + c[0]
if len(b) != 0:
	for d in b[::-1]:
		result = result + d[::-1]
if len(result) != 0:
	print(len(result))
	print(result)
else:
	print(0)


def if_palindrome(st):
	fl = True
	for i in range(len(st) // 2):
		if st[i] != st[len(st) - 1 - i]:
			fl = False
	return fl
(n, m) = [int(i) for i in input().split()]
d = dict()
st = ''
md = ''
for i in range(n):
	a = input()
	if a[::-1] in d.keys():
		d[a[::-1]] = 1
	elif if_palindrome(a):
		d[a] = 2
	else:
		d[a] = 0
for i in d:
	if d[i] == 1:
		st += i
	elif d[i] == 2:
		if len(i) > len(md):
			md = i
res = st + md + st[::-1]
print(len(res))
print(res)


(n, m) = list(map(int, input().split()))
l = []
for i in range(n):
	l.append(input())
s = []
l.sort(reverse=True)
for i in range(len(l)):
	if l[i] == l[i][::-1]:
		s.append(l[i])
		l[i] = -1
		break
for i in range(len(l)):
	if l[i] != -1:
		if l[i][::-1] in l and l[i] != l[i][::-1]:
			s.insert(0, l[i])
			s.append(l[l.index(l[i][::-1])])
			l[l.index(l[i][::-1])] = -1
			l[i] = -1
print(len(''.join(s)))
if len(s) != 0:
	print(''.join(s))


def checkPalindromeSelf(word):
	return word == word[::-1]
input1 = input().split(' ')
numStrings = int(input1[0])
lenStrings = int(input1[1])
myArray = []
for i in range(0, numStrings):
	temp = input()
	myArray.append(temp)
left = ''
right = ''
middle = ''
for i in range(0, numStrings):
	reversedWord = myArray[i][::-1]
	if reversedWord == myArray[i]:
		middle = myArray[i]
	else:
		for j in range(i + 1, numStrings):
			if reversedWord == myArray[j]:
				left += myArray[i]
				right = reversedWord + right
				break
answer = left + middle + right
print(len(answer))
print(answer)


def rev(s):
	t = ''
	for wqe in s:
		t = wqe + t
	return t
(n, m) = map(int, input().split())
a = [input() for asf in range(n)]
ans = set()
for i in range(n):
	for j in range(i + 1, n):
		if a[i] == rev(a[j]):
			ans.add(i)
			break
I = -1
for i in range(n):
	if i not in ans:
		if a[i] == rev(a[i]):
			I = i
			break
s = ''
for x in ans:
	s += a[x]
if I != -1:
	s += a[I] + rev(s)
else:
	s += rev(s)
print(len(s))
print(s)


def ispal(s):
	return s == s[::-1]
mp = {}
s = ''
(n, m) = input().split()
for i in range(int(n)):
	x = input()
	if mp.get(x):
		mp[x] += 1
	else:
		mp[x] = 1
lst = []
for i in mp:
	if ispal(i):
		if mp[i] % 2:
			s = i
		for j in range(1, mp[i], 2):
			lst.append(i)
	else:
		rev = i[::-1]
		if mp.get(rev):
			for j in range(min(mp[rev], mp[i])):
				lst.append(i)
	mp[i] = 0
lst = ''.join(lst)
lst = lst + s + lst[::-1]
print(len(lst))
print(lst)


def reverse(s):
	return s[::-1]

def is_palidrome_own(s):
	if s == reverse(s):
		return True
	else:
		return False

def is_palidrome(s, o):
	if s == reverse(o):
		return True
	else:
		return False
(n, m) = (int(z) for z in input().split())
own = ''
list = []
right = ''
left = ''
l = []
for i in range(n):
	temp = input()
	l.append(temp)
for word in l:
	if is_palidrome_own(word) is True:
		own = word
	p = reverse(word)
	if p in l and is_palidrome_own(p) != True:
		list.append(p)
		left = left + word
		l.remove(p)
list.reverse()
right = ''.join(list)
ans = left + own + right
length = len(ans)
print(length)
print(ans)


(n, m) = list(map(int, input().split()))
strings = []
for _ in range(n):
	strings.append(input().strip())
pairs = {}
pal = []

def is_p(s):
	for i in range(len(s) // 2):
		if s[i] != s[len(s) - 1 - i]:
			return False
	return True
for i in range(n):
	if is_p(strings[i]):
		pal.append(strings[i])
	else:
		for j in range(i + 1):
			if strings[i] == strings[j][::-1] and strings[j][::-1] not in pairs:
				pairs[strings[i]] = strings[j]
res = []
for x in pairs:
	res.append(x)
	res.insert(0, pairs[x])
if pal:
	res.insert(len(pairs), pal[0])
res = ''.join(res)
print(len(res))
print(res)


l = list(map(int, input().split()))
(n, m) = (l[0], l[1])
arr = []
arr2 = []
arrsym = []
key = 0
for i in range(n):
	s = str(input())
	k = s[m - 1::-1]
	if s == k:
		arrsym.append(s)
	else:
		key = 0
		for i in range(len(arr2)):
			if arr2[i] == k:
				arr.append((arr2[i], s))
				key = 1
				del arr2[i]
				break
		if key == 0:
			arr2.append(s)
stri = ''
for j in arr:
	stri += j[0]
for j in arrsym:
	stri += j
	break
for j in range(len(arr)):
	stri += arr[len(arr) - 1 - j][1]
print(len(stri))
print(stri)


(n, m) = map(int, input().split())
s1 = ''
s2 = ''
sc = ''
dat = []
for _ in range(n):
	dat.append(input())
while 0 < len(dat):
	s = dat[0]
	del dat[0]
	if sc == '':
		if s == ''.join(reversed(s)):
			sc = s
			continue
	for j in range(0, len(dat)):
		ss = ''.join(reversed(dat[j]))
		if s == ss:
			s1 = s1 + s
			s2 = dat[j] + s2
			del dat[j]
			break
res = s1 + sc + s2
print(len(res))
print(res)


def main():
	(n, m) = map(int, input().split())
	ans_start = ''
	ans_middle = ''
	lista = []
	for i in range(0, n):
		s = input()
		lista.append(s)
	for i in range(0, len(lista)):
		for j in range(i, len(lista)):
			if lista[i] == lista[j][::-1]:
				if lista[i] != lista[j]:
					ans_start += lista[i]
				elif len(lista[i]) > len(ans_middle):
					ans_middle = lista[i]
	print(len(ans_start) * 2 + len(ans_middle))
	print(ans_start + ans_middle + ans_start[::-1])
main()


(issou, singe) = map(int, input().split())
qlf = []
for i in range(issou):
	sanctionllg = input()
	qlf.append(sanctionllg)
d = []
f = []
while len(qlf) > 1:
	(a, b) = (-1, -1)
	for i in range(len(qlf)):
		if a != -1:
			break
		for j in range(i):
			khey = list(qlf[i])
			khey.reverse()
			khey = ''.join(khey)
			if khey == qlf[j]:
				a = i
				b = j
				break
	if a == -1:
		break
	d.append(qlf[a])
	f.append(qlf[b])
	del qlf[a]
	del qlf[b]
for s in qlf:
	khey = list(s)
	khey.reverse()
	khey = ''.join(khey)
	if s == khey:
		d.append(s)
		break
f.reverse()
cg2020 = ''.join(d + f)
print(len(cg2020))
print(cg2020)


import itertools
(n, m) = map(int, input().split())
ss = list([input() for i in range(n)])
pals = []
npals = []
u = set()
for i in range(n):
	for j in range(i + 1, n):
		if ss[i] == ''.join(list(reversed(ss[j]))):
			pals.append([i, j])
			u.add(i)
			u.add(j)
for i in range(n):
	if ss[i] == ''.join(list(reversed(ss[i]))) and i not in u:
		npals.append(i)
		break
a = ''
if len(npals) != 0:
	a += ss[npals[0]]
for (i, j) in pals:
	a = ss[i] + a + ss[j]
print(len(a))
print(a)


from math import *
import itertools
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
b = [-1] * n
for i in range(n):
	for j in range(i, n):
		t = list(reversed(a[j]))
		t = ''.join(t)
		if a[i] == t:
			b[i] = j
			b[j] = i
			break
		t = list(reversed(a[i]))
		t = ''.join(t)
		if a[i] == t:
			b[i] = i
			break
s = ''
for i in range(len(b)):
	if b[i] >= 0 and (not b[i] == i):
		s += a[i]
		b[b[i]] = -1
		b[i] = -1
ml = -1
mi = -1
for i in range(len(b)):
	if b[i] >= 0:
		if len(a[i]) > ml:
			ml = len(a[i])
			mi = i
ans = len(s) * 2
anss = ''.join(s[:])
if mi >= 0:
	ans += ml
	s += a[mi]
print(ans)
t = list(reversed(anss))
t = ''.join(t)
print(s + t)


(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())
u = []
a = []
for i in range(n):
	a.append(input())
	u.append(False)
s = ''
t = ''
for i in range(n):
	for j in range(n):
		if u[i] == False and u[j] == False and (a[i] == a[j][::-1]) and (i != j):
			u[i] = True
			u[j] = True
			s = s + a[i]
			t = a[j] + t
for i in range(n):
	if u[i] == False and a[i] == a[i][::-1]:
		s = s + a[i]
		break
s = s + t
print(len(s))
print(s)


def reverse(s):
	return s[::-1]

def isPalindrome(s):
	rev = reverse(s)
	if s == rev:
		return True
	return False
(n, m) = map(int, input().split())
ans1 = ''
ans2 = ''
ans3 = ''
arr = []
pan = []
s = input()
if isPalindrome(s):
	pan.append(s)
else:
	arr.append(s)
for i in range(1, n):
	s = input()
	s_r = reverse(s)
	if s_r in arr and isPalindrome(s) == False:
		ans1 = ans1 + s
		ans2 = s_r + ans2
		arr.remove(s_r)
	elif isPalindrome(s) == False:
		arr.append(s)
	if isPalindrome(s):
		pan.append(s)
cnt = []
for i in range(len(pan)):
	cnt.append(pan.count(pan[i]))
if len(pan) != 0:
	mx = cnt.index(max(cnt))
	ans3 = pan[mx] * cnt[mx]
ans = ans1 + ans3 + ans2
print(len(ans))
print(ans)


(N, M) = [int(x) for x in input().split()]
strs = set((input() for _ in range(N)))
has_pal = {}
is_pal = {}
for s in strs:
	is_pal[s] = s[::-1] == s
	has_pal[s] = not is_pal[s] and s[::-1] in strs
mid = ''
for s in is_pal:
	if is_pal[s]:
		mid = s
		break
pals = []
for s in strs:
	if has_pal[s] and s[::-1] not in pals:
		pals.append(s)
left = ''.join(pals)
right = left[::-1]
res = left + mid + right
print(len(res))
print(res)


(n, x) = input().split(' ')
(n, x) = (int(n), int(x))
arr = []
taken = []
for i in range(n):
	u = input()
	arr.append(u)
	taken.append(False)
ans = ''
m = []
for i in range(n):
	for j in range(n):
		arrjr = arr[j]
		arrjr = arrjr[::-1]
		if arr[i] == arrjr and i != j and (taken[j] == False) and (taken[j] == False):
			taken[j] = True
			taken[i] = True
			m.append(arr[i])
			m.insert(0, arr[j])
			break
for p in range(n):
	if taken[p] == False:
		arrpr = arr[p]
		arrpr = arrpr[::-1]
		if arr[p] == arrpr:
			m.insert(len(m) // 2, arr[p])
			break
if len(m) == 0:
	print('0')
else:
	print(len(m) * x)
	print(''.join(m))


(n, m) = [int(x) for x in input().split()]
d = {}
count = 0
flag = 0
ans = ''
palin = ''
for i in range(0, n):
	s = str(input())
	if s == s[::-1]:
		flag = 1
		if len(s) > len(palin):
			palin = s
	if s[::-1] in d:
		count += 2
		ans = s + ans + s[::-1]
	else:
		d[s] = 0
len = (count + flag) * m
ans = ans[0:int(count * m / 2)] + palin + ans[int(count * m / 2):]
print(len)
print(ans)


(n, m) = map(int, input().split())
l = []
f = []
s = []
mid = []
for i in range(n):
	st = input()
	l.append(st)
for i in l:
	l1 = list(i)
	l1.reverse()
	st1 = ''.join(l1)
	if st1 == i:
		mid.append(i)
	elif st1 in l:
		if i not in f and i not in s:
			f.append(i)
			s.append(st1)
s.reverse()
f1 = ''.join(f)
c = 0
if len(mid) != 0:
	c = mid.count(mid[0])
	ind = 0
for j in range(1, len(mid)):
	c1 = mid.count(mid[j])
	if c1 > c:
		c = c1
		ind = j
m1 = ''
for k in range(c):
	m1 += mid[ind]
s1 = ''.join(s)
print(len(f1) + len(m1) + len(s1))
print(f1 + m1 + s1)


def isp(s):
	i = 0
	j = len(s) - 1
	while i < j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True
(n, m) = map(int, input().split())
a = set()
ans = ''
cent = ''
for z in range(n):
	s = input()
	sr = s[::-1]
	if sr in a:
		a.remove(sr)
		ans += s
	elif s not in a:
		a.add(s)
for s in a:
	if isp(s):
		cent = s
		break
ansr = ans[::-1]
anss = ans + cent + ansr
print(len(anss))
print(anss)


(n, m) = [int(x) for x in input().split()]
ss = []
for _ in range(n):
	ss.append(input())
taken = [False for _ in range(n)]
ans = 0
ansString = ''
for i in range(n - 1):
	for j in range(i + 1, n):
		if taken[i] == False and taken[j] == False and (ss[i][::-1] == ss[j]):
			ans += 2
			ansString = ansString + ss[i]
			taken[i] = True
			taken[j] = True
temp = ansString[::-1]
for i in range(n):
	if taken[i] == False and ss[i] == ss[i][::-1]:
		ans += 1
		ansString = ansString + ss[i]
		break
ansString = ansString + temp
ans *= m
print(ans)
print(ansString)


(n, m) = list(map(int, input().split()))
array = []
for _ in range(n):
	array.append(input().strip())
pal = ''
for i in array:
	if i == i[::-1]:
		if len(pal) == 0:
			pal += i
revs = ''
for i in range(n - 1):
	for j in range(i + 1, n):
		if array[i] == array[j][::-1]:
			revs += array[i]
ans = revs + pal + revs[::-1]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
strings = {input() for _ in range(n)}
full_pairs = set()
self_palindrome = set()
for s in strings:
	rev = s[::-1]
	if rev in full_pairs:
		continue
	if s == rev:
		self_palindrome.add(s)
	elif rev in strings:
		full_pairs.add(s)
left = ''.join(full_pairs)
mid = ''
if self_palindrome:
	mid = next(iter(self_palindrome))
palindrome = left + mid + left[::-1]
print(len(palindrome))
print(palindrome)


def ispalin(list):
	length = len(list)
	yes = 1
	for i in range(length):
		if list[i] != list[length - i - 1]:
			yes = 0
			break
	return yes
nm = list(map(int, input().split()))
mat = []
words = []
for i in range(nm[0]):
	a = list(input())
	mat.append(a)
	word = ''
	for j in range(nm[1]):
		word = word + a[j]
	words.append(word)
yep = []
for i in range(nm[0]):
	for j in range(i + 1, nm[0]):
		good = 1
		for k in range(nm[1]):
			if mat[i][k] != mat[j][nm[1] - k - 1]:
				good = 0
				break
		if good:
			word1 = ''
			word2 = ''
			for l in range(nm[1]):
				word1 = word1 + mat[i][l]
				word2 = word2 + mat[j][l]
			yep.append(word1)
			yep.append(word2)
			break
length1 = len(yep)
for i in range(length1):
	words.remove(yep[i])
palin = []
for i in mat:
	if ispalin(i):
		word = ''
		for j in range(nm[1]):
			word = word + i[j]
		palin.append(word)
if len(palin) > 0:
	print((length1 + 1) * nm[1])
	output = ''
	for i in range(length1 + 1):
		if i < length1 / 2:
			output = output + yep[2 * i]
		elif i == length1 / 2:
			output = output + palin[0]
		elif i > length1 / 2:
			output = output + yep[2 * (length1 - i) + 1]
	print(output)
else:
	print(length1 * nm[1])
	output = ''
	for i in range(length1):
		if i < length1 / 2:
			output = output + yep[2 * i]
		else:
			output = output + yep[2 * (length1 - 1 - i) + 1]
	print(output)


from sys import stdin, stdout
from collections import deque
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()

def is_palindrome(s):
	(L, R) = (0, len(s) - 1)
	while L < R:
		if s[L] != s[R]:
			return False
		L += 1
		R -= 1
	return True

def main():
	(n, m) = (int(x) for x in rll())
	(words, palins) = (set(), set())
	(L, R) = (deque(), deque())
	for line in stdin:
		s = line.split()[0]
		curr_palin = is_palindrome(s)
		if curr_palin:
			palins.add(s)
		words.add(s)
		mirror = s[::-1]
		if mirror in words and (not curr_palin):
			L.appendleft(mirror)
			R.append(s)
	mid = deque('')
	if len(palins) > 0:
		mid = deque(palins.pop())
	ans = ''.join(L + mid + R)
	stdout.write(str(len(ans)))
	stdout.write('\n')
	stdout.write(str(ans))
	stdout.write('\n')
	stdout.close()
main()


from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
mod = 1000000007
(n, m) = map(int, input().split())
d = {}
s = {}
for _ in range(n):
	t = input()
	if t not in d:
		d[t] = 1
	else:
		d[t] += 1
st = ''
for i in d:
	if i == i[::-1] and len(i) > len(st):
		st = i
d[st] = -1
for i in d:
	if i == i[::-1]:
		continue
	if i[::-1] in d and d[i[::-1]] > 0:
		st = i + st + i[::-1]
		d[i] = 0
print(len(st))
print(st)


(n, length) = map(int, input().split())
strings = []
for _ in range(n):
	strings.append(input())
res_left = ''
res_right = ''
res_remain = ''
check = True
for string in strings:
	if string[::-1] in strings:
		if string != string[::-1]:
			res_left = res_left + string
			res_right = string[::-1] + res_right
			strings.remove(string[::-1])
		elif check:
			res_remain = string
			check = False
res = res_left + res_remain + res_right
print(len(res))
print(res)


(n, m) = map(int, input().split(' '))
l = []
res = ''
front = ''
back = ''
for i in range(int(n)):
	s = input()
	if s[::-1] == s:
		res = s
	elif s[::-1] in l:
		front += s
		back = s[::-1] + back
	l.append(s)
res = front + res + back
print(len(res))
print(res)


(n, m) = map(int, input().split())
s = [input() for i in range(n)]
used = [0] * 105
ans = []
alone = -1
for i in range(n):
	if used[i]:
		continue
	for j in range(i + 1, n):
		if used[j]:
			continue
		if s[i] == s[j][::-1]:
			ans.append([i, j])
			used[i] = 1
			used[j] = 1
			break
for i in range(n):
	if used[i]:
		continue
	temp = s[i][-(m // 2):]
	if s[i][:m // 2] == temp[::-1] or m == 1:
		alone = i
		break
if alone == -1:
	print(len(ans) * 2 * m)
else:
	print(len(ans) * 2 * m + m)
for x in ans:
	print(s[x[0]], end='')
if alone != -1:
	print(s[alone], end='')
for x in ans[::-1]:
	print(s[x[1]], end='')
print()


from itertools import combinations
(n, m) = map(int, input().split())
li = [input() for _ in range(n)]
ptn = combinations(li, 2)
ans = []
for I in li:
	if all([i == j for (i, j) in zip(I, I[::-1])]):
		ans.append(I)
		break
for (I, J) in ptn:
	if all([i == j for (i, j) in zip(I, J[::-1])]):
		ans.append(I)
		ans = [J] + ans
strans = ''.join(ans)
print(len(strans))
print(strans)


(n, m) = map(int, input().split())
p = []
np = []
for _ in range(n):
	s = input()
	if s[::-1] in np:
		p.append(s)
		np.remove(s[::-1])
	else:
		np.append(s)
x = ''
for s in np:
	if s == s[::-1]:
		x = s
		break
lp = ''.join(p)
ans = lp + x + lp[::-1]
print(len(ans))
print(ans)


(n, m) = list(map(int, input().split()))
pals = set()
revs = set()
words = []
for i in range(n):
	words.append(input())
for i in words:
	if i == i[::-1]:
		pals.add(i)
	for j in words:
		if i != j and i == j[::-1] and (i not in revs) and (j not in revs):
			revs.add(i)
pals = list(pals)
word = ''
if pals:
	pals.sort(key=lambda a: -len(a))
	word = pals[0]
for i in revs:
	word = i + word + i[::-1]
print(len(word))
print(word)


import math
from sys import stdin, stdout

def main():
	(n, m) = list(map(int, stdin.readline().split()))
	word = set()
	length = 0
	stri = ''
	ts = 1
	if m % 2 == 1:
		ts = 0
	for _ in range(n):
		w = stdin.readline().rstrip()
		if w[::-1] in word:
			stri = w + stri + w[::-1]
			word.remove(w[::-1])
			length += m * 2
		else:
			word.add(w)
	for w in word:
		if w[0:int(m / 2)] == w[m:int(m / 2) - ts:-1]:
			stri = stri[0:int(length / 2)] + w + stri[int(length / 2) - 0:length]
			length += m
			break
	stdout.write(str(length) + '\n')
	stdout.write(stri)
main()


def preprocess(n, m, stringList):
	visited = [0] * n
	coupleList = []
	for i in range(n - 1):
		if not visited[i]:
			for j in range(i + 1, n):
				if not visited[j]:
					if stringList[i][::-1] == stringList[j]:
						coupleList.append((stringList[i], stringList[j]))
						visited[i] = visited[j] = 1
				if visited[i]:
					break
	singleList = [stringList[i] for i in range(n) if not visited[i]]
	return (coupleList, singleList)

def findPalindromes(coupleList, singleList):
	ans = ''
	l = len(coupleList)
	for ele in coupleList:
		ans += ele[0]
	for string in singleList:
		if string[::-1] == string:
			ans += string
			break
	for i in range(l - 1, -1, -1):
		ans += coupleList[i][1]
	l = len(ans)
	return (l, ans)

def solve(n, m, stringList):
	(coupleList, singleList) = preprocess(n, m, stringList)
	(l, ans) = findPalindromes(coupleList, singleList)
	print(l)
	print(ans)

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


def reverse(s):
	str = ''
	for i in s:
		str = i + str
	return str
(n, m) = map(int, input().split())
l = []
st = ''
for _ in range(n):
	l.append(input())
al = l.copy()
for i in al:
	tt = reverse(i)
	if tt in al:
		if tt == i:
			st += tt
			break
for i in al:
	tt = reverse(i)
	if tt in al:
		if tt == i:
			continue
		st = tt + st + reverse(tt)
		al.remove(tt)
print(len(st))
print(st)


def problemA():
	t = int(input())
	for _ in range(t):
		(x, y, a, b) = map(int, input().split())
		if (y - x) % (a + b) == 0:
			print((y - x) // (a + b))
		else:
			print(-1)

def problemB():
	(n, m) = map(int, input().split())
	ss = set()
	res = []
	for i in range(n):
		s = input()
		rs = s[::-1]
		if rs in ss:
			res.append(s)
			ss.remove(rs)
		else:
			ss.add(s)
	long = ''
	for s in ss:
		if s == s[::-1] and len(s) > len(long):
			long = s
	res = ''.join(res)
	res = res + long + res[::-1]
	print(len(res))
	print(res)

def problemG():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = map(int, input().split())
		res = 0
		print(a)
problemB()


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

def is_pal(S):
	global 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)


(n, m) = map(int, input().split())
lines = list()
cent = ''
(half1, half2) = ('', '')
for i in range(n):
	lines.append(input())
for i in range(n):
	if lines[i] == lines[i][::-1]:
		cent = lines[i]
	elif lines[i][::-1] in lines[i + 1:]:
		half1 += lines[i]
		half2 = lines[i][::-1] + half2
s = half1 + cent + half2
print(len(s))
print(s)


from math import factorial
from collections import Counter
from heapq import heapify, heappop, heappush
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	(m, n) = RL()
	ars = set()
	res = []
	rec = set()
	tag = False
	for _ in range(m):
		s = input()
		if s[::-1] in ars:
			res = [s] + res + [s[::-1]]
		elif s == s[::-1] and tag == False:
			res.insert(len(res) // 2, s)
			tag = True
		ars.add(s)
	res = ''.join(res)
	print(len(res))
	print(res)
main()


def isPalindrom(p):
	t = ''.join(reversed(p))
	return t == p

def solve(p):
	palin = []
	pairs = []
	for i in p:
		rever = ''.join(reversed(i))
		if rever in p and (not isPalindrom(i)) and (not rever in pairs):
			pairs.append(i)
		elif isPalindrom(i):
			palin.append(i)
	res = ''
	if palin:
		res = res + palin[0]
	for i in pairs:
		res = i + res + ''.join(reversed(i))
	print(len(res))
	print(res)
problem = []
(m, n) = input().split(' ')
m = int(m)
n = int(n)
for i in range(m):
	l = input()
	problem += [l]
solve(problem)


def isPalindrome(s):
	if s == s[::-1]:
		return True
	return False
(n, m) = map(int, input().split())
array = []
palindrome = []
for _ in range(n):
	i = input()
	if isPalindrome(i):
		palindrome.append(i)
	else:
		array.append(i)
string = ''
for i in array:
	if i[::-1] in array:
		string += i
		array.remove(i[::-1])
max_len = 0
pal = ''
if palindrome != []:
	pal = palindrome[0]
final = string + pal + string[::-1]
if final == '':
	print(0)
else:
	print(len(final))
	print(final)


(n, m) = map(int, input().split())
d = dict()
m = ''
mx = -10 ** 15
for i in range(n):
	a = input()
	d[a] = d.get(a[::-1], 0) + 1
left = ''
right = ''
for i in d.keys():
	if d[i] >= 2:
		for j in range(d[i] // 2):
			left = i + left
			right += i[::-1]
	if d[i] % 2 != 0:
		if i == i[::-1] and len(i) > mx:
			m = i
			mx = len(i)
ans = left + m + right
print(len(ans))
print(ans)


import sys
(n, m) = list(map(int, sys.stdin.readline().rstrip().split()))
words = []
check = [-1] * n
is_pal = [-1] * n
for i in range(n):
	word = sys.stdin.readline().rstrip()
	words.append(word)
	if word == word[::-1]:
		is_pal[i] = 1
for i in range(n):
	for j in range(i + 1, n):
		if words[i] == words[j][::-1]:
			check[i] = j
			check[j] = i
re = ''
max_len = 0
max_pal = -1
for i in range(n):
	if is_pal[i] == 1:
		if check[i] == -1 and max_len < len(words[i]):
			max_len = len(words[i])
			max_pal = i
if max_pal != -1:
	re = words[max_pal]
for i in range(n):
	if check[i] != -1:
		re = words[i] + re + words[check[i]]
		check[check[i]] = -1
		check[i] = -1
print(len(re))
print(re)


from bisect import bisect_left
from math import floor
(n, m) = [int(x) for x in input().split()]
strings = [input() for x in range(n)]
strings.sort()
palin = ''
mid = False

def is_palin(s):
	for i in range(floor(len(s) / 2)):
		if s[i] != s[len(s) - 1 - i]:
			return False
	return True
for i in range(len(strings)):
	if not mid and is_palin(strings[i]):
		mid = True
		if palin:
			palin = palin[:int(len(palin) / 2)] + strings[i] + palin[int(len(palin) / 2):]
		else:
			palin = strings[i]
		continue
	bro = strings[i][::-1]
	bro_i = bisect_left(strings, bro, lo=i + 1)
	if bro_i != len(strings) and strings[bro_i] == bro:
		palin = strings[i] + palin + bro
print(len(palin))
print(palin if palin else '')


(n, m) = map(int, input().split())
l = []
l1 = []
for i in range(n):
	s = input()
	l.append(s)
f = 0
s = ''
for i in l:
	if i[::-1] in l:
		if i == i[::-1] and f == 0:
			s = i
			f = 1
		elif i != i[::-1]:
			if i[::-1] not in l1:
				l1.append(i)
s1 = ''.join(l1)
print(2 * m * len(l1) + len(s))
print(s1 + s + s1[::-1])


(N, l) = input().split()
N = int(N)
strs = []
ignore = []
for _ in range(N):
	strs.append(input())
start = ''
middle = ''
end = ''
for i in range(N):
	st = strs[i]
	st_rev = st[::-1]
	if st in ignore or st_rev in ignore:
		continue
	elif st == st_rev:
		middle = st
	elif st_rev in strs:
		start = st + start
		end = end + st_rev
	ignore.append(st)
	ignore.append(st_rev)
result = start + middle + end
print(len(result))
print(result)


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

def same(s1, s2):
	m = len(s1)
	for i in range(m):
		if s1[i] != s2[m - i - 1]:
			return False
	return True

def get_same_index(lines, s):
	for i in range(len(lines)):
		if same(lines[i], s):
			return i
	return None
(n, m) = map(int, input().split())
lines = []
pal = ''
part1 = ''
part2 = ''
for i in range(n):
	s = input()
	if pal == '' and is_pal(s):
		pal = s
	else:
		index = get_same_index(lines, s)
		if not index == None:
			part1 = part1 + lines.pop(index)
			part2 = s + part2
		else:
			lines.append(s)
result = part1 + pal + part2
print(len(result))
print(result)


pallist = []
mirlist = []
strlist = []
(n, m) = map(int, input().split())
for i in range(n):
	st = input()
	strlist.append(st)
for item in strlist:
	if item == item[::-1]:
		pallist.append(item)
	elif item[::-1] in strlist:
		if item not in mirlist and item[::-1] not in mirlist:
			mirlist.append(item)
first = ''
second = ''
for item in mirlist:
	first += item
for item in reversed(mirlist):
	second += item[::-1]
for item in pallist:
	first += item
	break
print(len(first + second))
print(first + second)


from sys import stdin
inp = lambda : int(stdin.readline().strip())
lip = lambda : [int(i) for i in stdin.readline().strip().split(' ')]
sip = lambda : stdin.readline().strip()
(n, m) = lip()
S = []
for _ in range(n):
	S.append(sip())
d = {}
pal = -1
for i in range(n):
	for j in range(i + 1, n):
		if S[i] == S[j][::-1] and i not in d:
			d[i] = j
			break
	else:
		if pal == -1 and S[i] == S[i][::-1]:
			pal = i
ans = ''
keys = sorted(d.keys())
for k in keys:
	ans += S[k]
if pal != -1:
	ans += S[pal]
for k in reversed(keys):
	ans += S[d[k]]
print(len(ans))
print(ans)


(n, k) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
(x, y) = ([], [])
for i in range(n):
	d = l[i][::-1]
	if l[i] != d and d in l and (d not in x and d not in y):
		x.append(l[i])
		y.append(d)
s = ''
m = 0
for i in range(n):
	if l[i] not in x and l[i] not in y:
		if l[i] == l[i][::-1]:
			if len(l[i]) > m:
				m = len(l[i])
				s = l[i]
r = ''.join(x) + s + ''.join(y[::-1])
print(len(r))
print(r)


(n, m) = map(int, input().split())
arr = [input() for i in range(n)]
(hihi, hehe, cay) = ('', '', 0)
okmen = ''
for i in range(len(arr)):
	if arr[i] != '-1' and arr[i][::-1] in arr[i + 1:]:
		hihi += arr[i]
		hehe = arr[i][::-1] + hehe
		arr[arr.index(arr[i][::-1])] = '-1'
		arr[i] = '-1'
	if cay == 0 and arr[i] != '-1' and (arr[i] == arr[i][::-1]):
		cay = 1
		okmen = arr[i]
print(len(hihi) + len(okmen) + len(hehe))
print(hihi + okmen + hehe)


(n, m) = map(int, input().split())
mid = ''
l = set()
start = ''
end = ''
for i in range(n):
	s = input()
	if s == s[::-1]:
		if mid == '':
			mid += s
	elif s[::-1] in l:
		start += s
		end = s[::-1] + end
		l.discard(s)
	else:
		l.add(s)
f = start + mid + end
print(len(f))
print(f)


(n, m) = map(int, input().split())
d = {}
l = []
for _ in range(n):
	l.append(input())
for i in set(l):
	d[i] = l.count(i)
s = ''
m = ''
e = ''
for i in d.keys():
	r = i[::-1]
	if d.get(r, 0) != 0:
		if i != r:
			p = min(d[i], d[r])
			s += p * i
			e = p * r + e
		else:
			p = d[i]
			s += p // 2 * i
			e = p // 2 * i + e
			if p % 2:
				m = i
		d[r] = 0
print(len(s + m + e))
print(s + m + e)


(n, k) = map(int, input().split())
l = []
f = ''
for _ in range(n):
	s = input()
	l.append(s)
i = 0
while i < len(l):
	q = l[i]
	w = q[::-1]
	if w in l[i + 1:]:
		f = q + f + w
		l.remove(l[i])
		l.remove(w)
	else:
		i += 1
k = ''
for i in l:
	if i == i[::-1]:
		if l.count(i) % 2 == 1:
			k += i
			break
f = list(f)
if k != '':
	f.insert(len(f) // 2, k)
f = ''.join(f)
print(len(f))
print(f)


(n, m) = [int(i) for i in input().split()]
l = []
for i in range(n):
	l.append(input())
res1 = ''
res2 = ''
pal = ''
for i in range(n):
	if l[i] == l[i][::-1]:
		pal = l[i]
		continue
	for j in range(i + 1, n):
		if l[i] == l[j][::-1]:
			res1 += l[i]
			res2 += l[j][::-1]
res = res1 + pal + res2[::-1]
print(len(res))
print(res)


(n, m) = map(int, input().split())
x = set()
ans = ''
mid = ''
rev = ''
for i in range(n):
	s = input()
	r = s[::-1]
	if r == s:
		mid = r
	elif r in x:
		ans = ans + r
		rev = s + rev
	x.add(s)
ans = ans + mid + rev
print(len(ans))
print(ans)


from bisect import *
from math import *
(n, m) = input().split()
n = int(n)
m = int(m)
arr = []
set1 = set()
set2 = set()
for i in range(n):
	arr.append(input())
	set1.add(arr[-1])
	set2.add(arr[-1])
ans_list = []
pal_list = []
for i in arr:
	set1.remove(i)
	i_inv = i[-1::-1]
	if i_inv in set1:
		ans_list.append((i, i_inv))
		set2.remove(i)
		set2.remove(i_inv)
for i in set2:
	if i == i[-1::-1]:
		pal_list.append(i)
str_out = ''
for i in ans_list:
	str_out += i[0]
if len(pal_list) > 0:
	str_out += pal_list[0]
for i in range(len(ans_list) - 1, -1, -1):
	str_out += ans_list[i][1]
print(len(str_out))
print(str_out)


def palin(s):
	l = len(s)
	for i in range(l // 2):
		if s[i] != s[l - 1 - i]:
			return 0
	return 1
(n, m) = map(int, input().split())
l = []
for i in range(n):
	a = input()
	l.append(a)
f = -1
p = 0
b = []
c = []
for i in range(n):
	for j in range(i, n):
		if palin(l[i] + l[j]):
			if i == j:
				if f == -1:
					f = i
					s = l[i]
					break
			else:
				b.append(l[i])
				c.insert(0, l[j])
				l.pop(j)
				n -= 1
				p += 1
				break
if f != -1:
	print(m + 2 * p * m)
else:
	print(2 * p * m)
for i in b:
	print(i, end='')
if f != -1:
	print(s, end='')
for i in c:
	print(i, end='')


(n, m) = map(int, input().split())
s = [''] * n
kouho = []
result_mid = ''
result_left = ''
result_right = ''
for i in range(n):
	s[i] = input()
for i in range(n):
	s_i_rev = s[i][::-1]
	if s[i] not in kouho:
		kouho.append(s_i_rev)
	else:
		result_left = s[i] + result_left
		result_right = result_right + s_i_rev
		kouho.remove(s[i])
for j in range(len(kouho)):
	if kouho[j] == kouho[j][::-1]:
		if len(result_mid) < len(kouho[j]):
			result_mid = kouho[j]
result = result_left + result_mid + result_right
print(len(result))
print(result)


def is_palindrome(word):
	lw = len(word)
	for i in range(lw // 2):
		if word[i] != word[-(i + 1)]:
			return False
	return True
(n, l) = map(int, input().split())
tab = []
for _ in range(n):
	tab.append(str(input()))
result = ''
for i in range(n):
	if is_palindrome(tab[i]):
		result = tab[i]
		tab[i] = ''
		break
for i in range(n):
	for j in range(i + 1, n):
		if tab[i] == tab[j][::-1]:
			result = tab[i] + result + tab[j]
			tab[i] = ''
			tab[j] = ''
print(len(result))
print(result)


(n, m) = map(int, input().split())
before = []
word = []
for _ in range(n):
	word.append(list(input()))
center = []
while word:
	temp = word.pop(0)[::-1]
	f = False
	for i in range(len(word)):
		if word[i] == temp:
			f = True
			break
	if f:
		word.pop(i)
		before.append(temp)
	elif temp == temp[::-1]:
		center = [temp]
shin = ''
after = [before[i][::-1] for i in range(len(before))]
ans = before + center + after[::-1]
for i in range(len(ans)):
	ans[i] = ''.join(ans[i])
	shin += ans[i]
print(len(shin))
print(shin)


(n, m) = map(int, input().split())
strings = []
for bruhhhh in range(n):
	strings.append(input())
lt = []
mid = []
rt = []

def isReverse(str1, str2):
	if str1 == ''.join(reversed(str2)):
		return 1
	else:
		return 0
for x in range(n):
	for y in range(x + 1, n):
		if x != y:
			if isReverse(strings[x], strings[y]) == 1:
				lt.append(strings[x])
				rt.append(strings[y])
for z in strings:
	if z not in lt and z not in rt:
		if z == z[::-1]:
			mid.append(z)
if len(mid) > 0:
	imbored = [mid[0]]
else:
	imbored = []
print(len(''.join(lt + imbored + rt)))
print(''.join(lt + imbored + rt[::-1]))


(n, m) = map(int, input().split())
l1 = []
palina = ''
sa = ''

def reverse(s1):
	s2 = ''
	for i in range(len(s1) - 1, -1, -1):
		s2 = s2 + s1[i]
	return s2

def palin(s1):
	for i in range(0, int(len(s1) / 2)):
		if s1[i] != s1[-i - 1]:
			return 0
	else:
		return 1
for i in range(0, n):
	s1 = input()
	s2 = reverse(s1)
	if s2 in l1:
		l1.append(s1)
		sa = sa + s2
	elif palin(s1):
		palina = s1
		l1.append(s1)
	l1.append(s1)
sb = reverse(sa)
final = sa + palina + sb
print(len(final))
print(final)


(n, k) = map(int, input().split())
arr = []
g = {}
for _ in range(n):
	s = input()
	arr.append(s)
	g[s] = 1
ans = ''
for i in arr:
	t = i[::-1]
	if g.get(t) and i != t:
		ans += t
		g.pop(t)
		g.pop(i)
f = 0
for i in g:
	if i == i[::-1]:
		ans += i[:(len(i) + 1) // 2]
		f = k % 2
		break
if f:
	ans += ans[:-1][::-1]
else:
	ans += ans[::-1]
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
s = [input() for _ in range(n)]
o = ''
seen = []
m = False
for i in range(n):
	c = s[i]
	if c != c[::-1] and c[::-1] in s and (c not in seen):
		o += c
		o = c[::-1] + o
		seen.append(c)
		seen.append(c[::-1])
	if c == c[::-1] and (not m):
		o = o[:len(o) // 2] + c + o[len(o) // 2:]
		m = 1
		seen.append(c)
print(len(o))
print(o)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	s = input()
	l.append(s)
ans = ''
k = ''
for i in range(n):
	if l[i][::-1] in l:
		x = l.index(l[i][::-1])
		if i != x:
			ans += l[i]
			l[i] = ''
		else:
			k = l[i]
			l[i] = ''
m = ans[::-1]
ans += k + m
print(len(ans))
print(ans)


def pal(y):
	if len(y) <= 1:
		return False
	if y[0] != y[-1]:
		return True
	return pal(y[1:-1])
(n, m) = map(int, input().split())
s = []
w = []
q = []
for i in range(n):
	a = input()
	s.append(a)
t = 0
while t != len(s):
	if s[t][::-1] in s and pal(s[t]):
		a = s[t]
		w.append(a)
		q.append(a[::-1])
		if a[::-1] in s:
			s.remove(a[::-1])
			t -= 1
		if a in s:
			s.remove(a)
	t += 1
for i in s:
	if i == i[::-1]:
		w.append(i)
		break
q.reverse()
z = w + q
z = ''.join(z)
print(len(z))
print(z)


(n, m) = map(int, input().split())
s = []
y = ''
for i in range(n):
	s.append(input())
	count = 0
	x = ''
for i in range(int(n)):
	j = i + 1
	if s[i] == s[i][::-1]:
		y = s[i]
		continue
	while j < n:
		if s[i] == s[j][::-1]:
			count += 1
			x = s[i] + x + s[j]
			break
		j += 1
x = x[:int(len(x) / 2)] + y + x[int(len(x) / 2):]
print(len(x))
print(x)


from math import *

def binarySearch(arr, x, i):
	l = i
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans

def ceil(a, b):
	if a % b == 0:
		return int(a / b)
	else:
		return a // b + 1
(n, m) = map(int, input().split())
s = []
for i in range(n):
	ss = input()
	s.append(ss)
s.sort()
h = [0] * n
ans = []
ans1 = []
for i in range(n):
	ind = binarySearch(s, s[i][::-1], i + 1)
	if ind != -1 and h[ind] != 1 and (h[i] != 1):
		ans.append(s[i])
		ans1.append(s[i][::-1])
		h[i] = 1
		h[ind] = 1
ans2 = []
for i in range(n):
	if h[i] == 0 and s[i] == s[i][::-1]:
		ans2.append(s[i])
if len(ans) > 0:
	if len(ans2) > 0:
		rslt = ''.join(ans) + ans2[0] + ''.join(ans1[::-1])
		print(len(rslt))
		print(rslt)
	else:
		rslt = ''.join(ans) + ''.join(ans1[::-1])
		print(len(rslt))
		print(rslt)
elif len(ans) == 0:
	if len(ans2) > 0:
		print(m)
		print(ans2[0])
	else:
		print(0)
else:
	rslt = ''.join(ans) + ''.join(ans1[::-1])
	print(len(rslt))
	print(rslt)


(n, m) = map(int, input().split())
a = list()
use = ''
middle = ''
str1 = ''
for i in range(0, n):
	ele = input()
	rev = ele[::-1]
	if rev in a:
		use = use + ele
	a.append(ele)
	if ele == rev:
		middle = ele
use = use + middle + use[::-1]
print(len(use))
print(use)


(n, _) = map(int, input().split())
strlist = []
revlist = []
ans = ''
temp = ''
for i in range(n):
	st = input()
	strlist.append(st)
	if st in revlist:
		ans += st
		revlist.remove(st)
		continue
	if st == st[::-1] and len(temp) == 0:
		temp = st
	revlist.append(st[::-1])
ans = ans + temp + ans[::-1]
print(len(ans), ans)


options = []
right = ''
middle = ''
(n, m) = map(int, input().split())
for _ in range(n):
	x = input()
	y = x[::-1]
	if y in options:
		right += x
	if x == y:
		middle = x
	options.append(x)
palindrome = right + middle + right[::-1]
print(len(palindrome))
print(palindrome)


(n, m) = map(int, input().split())
l = []
p = []
o = []
c = 0
for i in range(n):
	t = str(input())
	u = []
	for i in range(m - 1, -1, -1):
		u.append(t[i])
	w = ''.join(u)
	if t not in l and w not in l:
		if m % 2 == 0:
			d = t[0:m // 2]
			z = t[m // 2:m]
			g = []
			for i in range(len(z) - 1, -1, -1):
				g.append(z[i])
			s = ''.join(g)
			if d == s:
				o.append(t)
		else:
			d = t[0:m // 2]
			z = t[m // 2 + 1:m]
			g = []
			for i in range(len(z) - 1, -1, -1):
				g.append(z[i])
			s = ''.join(g)
			if d == s:
				o.append(t)
	elif w in l or t in l:
		p.insert(0, t)
		p.append(w)
		c += 1
	l.append(t)
f = len(o)
if f > 0:
	for i in range(f):
		if o[i] not in p:
			p.insert(c, o[i])
			break
	k = ''.join(p)
	print(len(k))
	print(k)
elif f == 0:
	k = ''.join(p)
	print(len(k))
	print(k)
elif len(p) == 0:
	print(0)
	print()


def most_frequent(List):
	counter = 0
	num = List[0]
	for i in List:
		curr_frequency = List.count(i)
		if curr_frequency > counter:
			counter = curr_frequency
			num = i
	return num

def palindrome(a1):
	r = len(a1) - 1
	b1 = list()
	while r >= 0:
		b1.append(a1[r])
		r = r - 1
	return ''.join((char for char in b1))
a = [int(a) for a in input().split()]
b = list()
r = 0
k = ''
d = list()
t = 0
while r < a[0]:
	b.append(input())
	if b[r] == palindrome(b[r]):
		d.append(b[r])
		b[r] = '0'
		t = 1
	r = r + 1
if t == 1:
	e = d.copy()
	f = most_frequent(e)
	g = d.count(f)
	r = 0
	while r < g:
		k = k + f
		r = r + 1
r = 0
while r < a[0]:
	if palindrome(b[r]) in b and b[r] != '0':
		k = b[r] + k + palindrome(b[r])
		w = b[r]
		b[r] = '0'
		b[b.index(palindrome(w))] = '0'
	r = r + 1
print(len(k))
print(k)


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
from math import gcd
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
(t, n) = inp()
d = dd(int)
left = ''
mid = ''
right = ''
for i in range(t):
	s = input().strip()
	if d[s[::-1]] > 0:
		d[s[::-1]] -= 1
		left += s
		right = s[::-1] + right
	else:
		d[s] += 1
for k in d:
	if d[k] == 1 and k == k[::-1]:
		mid = k
		break
ans = left + mid + right
print(len(ans))
print(ans)


(n, m) = input().split()
n = int(n)
m = int(m)
words = []
for _ in range(n):
	words.append(input())
polyndroms = dict()
for word in words:
	if word not in polyndroms:
		if word == word[::-1]:
			polyndroms[word] = 1
		elif word[::-1] in polyndroms:
			polyndroms[word[::-1]] = 2
		else:
			polyndroms[word] = 0
side = ''
centre = ''
for word in polyndroms:
	if polyndroms[word] == 1 and len(centre) == 0:
		centre += word
	elif polyndroms[word] == 2:
		side += word
result = side + centre + side[::-1]
print(len(result))
print(result)


(n, m) = map(int, input().split())
rec = {}
a = []
for i in range(n):
	t = input()
	a.append(t)
	rec[t] = rec.get(t, 0) + 1
ans = []
ansLen = 0
flag = 0
for i in a:
	temp = i[::-1]
	if rec.get(temp, 0) != 0 and i != temp:
		ans.insert(0, i)
		ans.append(temp)
		rec[i] -= 1
		rec[temp] -= 1
		ansLen += 2 * m
	elif rec.get(temp, 0) != 0 and i == temp:
		if rec[temp] % 2 == 0:
			ans.insert(0, i)
			ans.append(temp)
			rec[i] -= 1
			rec[temp] -= 1
			ansLen += 2 * m
		elif flag == 0:
			ans.insert(ansLen // m // 2, i)
			rec[i] -= 1
			ansLen += m
			flag = 1
print(ansLen)
print(''.join(ans))


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	(n, m) = cin()
	d = {}
	a = []
	for i in range(n):
		s = sin()
		if s not in d:
			d[s] = 1
		else:
			d[s] += 1
		a.append(s)
	x = []
	y = []
	for i in a:
		j = i[::-1]
		if j in d and d[i] > 0 and (d[j] > 0):
			if i != j:
				p = min(d[i], d[j])
				d[i] -= p
				d[j] -= p
				for jj in range(p):
					x.append(i)
					y.append(j)
			else:
				p = d[i] // 2
				d[i] -= 2 * p
				for jj in range(p):
					x.append(i)
					y.append(j)
	for i in d:
		j = i[::-1]
		if i == j and d[i] >= 1:
			x.append(i)
			break
	y = y[::-1]
	s = ''
	for i in x:
		s += i
	for i in y:
		s += i
	print(len(s))
	print(s)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	a.append(input())
s1 = ''
s2 = ''
check = ''
for i in range(len(a) - 1):
	for j in range(i + 1, len(a)):
		check = a[j]
		if a[i] == check[::-1]:
			s1 = s1 + a[i]
			s2 = s2 + check[::-1]
			a[j] = ''
max1 = 0
p = ''
s2 = s2[::-1]
for i in a:
	if i == i[::-1]:
		if len(i) > max1:
			p = i
print(len(s1 + p + s2))
print(s1 + p + s2)


import sys
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
W = [0] * n
A = []
B = []
for i in range(0, n):
	W[i] = sys.stdin.readline().strip()
c = 0
for i in range(0, n):
	if W[i] != 0:
		j = i + 1
		while j < n:
			if W[j] == ''.join(reversed(W[i][:])):
				A.append(W[i])
				B.append(W[j])
				W[i] = 0
				W[j] = 0
				j = n
				c = c + 2 * m
			else:
				j = j + 1
i = 0
while i < n:
	if W[i] != 0:
		if W[i] == ''.join(reversed(W[i][:])):
			A.append(W[i])
			c = c + m
			i = n
		else:
			i = i + 1
	else:
		i = i + 1
print(c)
C = ''.join(reversed(B))
print(''.join(A) + C)


(n, m) = map(int, input().split())
a = []
s = ''
for i in range(n):
	a.append(input())
z = a.copy()
c = []
while len(z) != 0:
	b = z[0][::-1]
	if z[0] == b:
		c.append(z[0])
	z.pop(0)
	if b in z:
		s = s + b
if len(c) >= 1:
	s = s + c[0] + s[::-1]
else:
	s = s + s[::-1]
print(len(s))
print(s)


(n, m) = map(int, input().strip().split())
flag = True
ans_len = 0
ans_str = ''
my_set = set()
for i in range(n):
	x = input()
	if x == x[::-1]:
		if not flag:
			continue
		flag = False
		current_len = len(ans_str)
		ans_len += m
		if ans_str:
			ans_str = ans_str[:current_len // 2] + x + ans_str[current_len // 2:]
		else:
			ans_str = x
	else:
		my_set.add(x)
		if x[::-1] in my_set:
			ans_len += m + m
			ans_str = x + ans_str + x[::-1]
print(ans_len)
print(ans_str)


(a, b) = map(int, input().split())
l = []
for i in range(a):
	l.append(input())
final = ''
for x in l:
	if x == x[::-1]:
		final += x
		break
for y in range(a):
	if l[y][::-1] in l[y + 1:]:
		final = l[y] + final
		final += l[y][::-1]
print(len(final))
print(final)


(n, m) = map(int, input().split())
d = {}
for i in range(n):
	s = str(input())
	if s not in d:
		d[s] = 1
	else:
		d[s] += 1
(t, count) = (0, 0)
l1 = [0] * (n // 2 + 1)
l2 = [0] * (n // 2 + 1)
for i in d:
	r = ''.join(reversed(i))
	if t == 0 and r == i:
		count += 1
		t = 1
		j = r
	elif r in d and r != i:
		k = min(d[r], d[i])
		if k != 0:
			l1.append(i)
			l2.append(r)
			count += k * 2
	d[i] = 0
	if r in d:
		d[r] = 0
ans = ''
print(count * m)
for i in l1:
	if i != 0:
		ans += i
if t == 1:
	ans += j
for i in reversed(l2):
	if i != 0:
		ans += i
print(ans)


def polind(str: str):
	newStr = str[::-1]
	if str == newStr:
		return True
	return False
(n, m) = map(int, input().split())
inpStr = list()
revStr = list()
for i in range(n):
	inpStr.append(input())
	revStr.append(inpStr[i][::-1])
twoWord = ''
oneWord = ''
for i in range(n):
	for j in range(i, n):
		if i != j and inpStr[i] == revStr[j]:
			twoWord += inpStr[i]
		elif polind(inpStr[i]):
			oneWord = inpStr[i]
outputStr = twoWord + oneWord + twoWord[::-1]
print(len(outputStr))
print(outputStr)


(n, m) = map(int, input().split())
S = []
for _ in range(n):
	S.append(input())
pair = []
palindrome = []
pair_count = 0
palindrome_count = 0
for i in range(n):
	for j in range(i, n):
		if S[i] == S[j][::-1]:
			if i != j:
				pair.append(S[i])
				pair_count += 1
			else:
				palindrome.append(S[i])
				palindrome_count += 1
print((pair_count * 2 + min(palindrome_count, 1)) * m)
ans = ''
if palindrome_count >= 1:
	ans = palindrome[0]
for p in pair:
	ans = p + ans + p[::-1]
print(ans)


(n, m) = map(int, input().split())
d = dict()
for _ in range(n):
	s = input()
	x = s[::-1]
	if x not in d:
		d[s] = 1
	else:
		d[x] += 1
n = ''
m = ''
flag = 1
for i in d:
	if d[i] == 1 and flag == 1:
		w = i[::-1]
		if i == w:
			m = m + i
			flag = 0
	else:
		for k in range(d[i] // 2):
			n = n + i
p = n[::-1]
n = n + m + p
print(len(n))
print(n)


def pallindrome(a):
	x = []
	y = -1
	for i in range(len(a)):
		s = a[i]
		if s == s[::-1]:
			x.append(1)
			if len(s) > y:
				y = i
		else:
			x.append(0)
	return (x, y)
(n, m) = map(int, input().split())
l = []
for i in range(n):
	s = input()
	l.append(s)
(m, l1) = pallindrome(l)
m1 = []
s1 = ''
for i in range(len(l)):
	if l[i] not in m1 and m[i] != 1:
		x = l[i]
		if x[::-1] in l:
			s1 += l[i]
			m1.append(x[::-1])
s2 = s1[::-1]
if l1 != -1:
	s1 += l[l1] + s2
	print(len(s1))
	print(s1)
else:
	s1 += s2
	print(len(s1))
	if len(s1) != 0:
		print(s1)


def judge(str1, str2, b):
	for i in range(b):
		if str1[i] != str2[b - 1 - i]:
			return False
	return True

def do(li, a, b):
	ans = ''
	add = ''
	for i in range(a):
		if judge(li[i], li[i], b):
			add = li[i]
		for j in range(i + 1, a):
			if judge(li[i], li[j], b):
				ans += li[i]
	maxsize = len(add) + len(ans) * 2
	print(maxsize)
	print(ans + add + ans[::-1])

def solve():
	while True:
		try:
			(a, b) = map(int, input().split())
			li = []
			for _t in range(a):
				li.append(input())
			do(li, a, b)
		except EOFError:
			break
solve()


(word, palindrome) = (set(), set())
ans = anss = ansrev = ''
(n, m) = map(int, input().split())
while n > 0:
	word_i = input()
	rev = word_i[::-1]
	if rev in word:
		ansrev = rev + ansrev
		anss = anss + word_i
		word.remove(rev)
		if rev in palindrome:
			palin.remove(rev)
	else:
		word.add(word_i)
	if rev == word_i:
		palindrome.add(word_i)
	n -= 1
if len(palindrome) != 0:
	ans = ansrev + list(palindrome)[0] + anss
else:
	ans = ansrev + anss
length = len(ans)
print(length)
if length != 0:
	print(ans)


(n, m) = map(int, input().split())
s = set()
possible_palin_inset = ''
is_palin = ''
for i in range(n):
	x = str(input())
	if x[::-1] in s:
		possible_palin_inset += x
	if x == x[::-1]:
		is_palin = x
	s.add(x)
print(len(possible_palin_inset) * 2 + len(is_palin))
print(possible_palin_inset + is_palin + possible_palin_inset[::-1])


(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)


def main():
	(n, m) = [int(s) for s in input().strip().split()]
	S = set()
	(L, R, center) = ([], [], '')
	for _ in range(n):
		s = input().strip()
		if s[::-1] in S:
			L.append(s)
			R.append(s[::-1])
		if s == s[::-1]:
			center = s
		S.add(s)
	result = ''.join(L) + center + ''.join(R[::-1])
	print(len(result))
	print(result)
main()


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)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(int)
for i in range(n):
	s = input()
	d[s] += 1
left = []
right = []
cnt = 0
keys = set(d.keys())
for s in keys:
	value = d[s]
	r = s[::-1]
	if r == s:
		k = value // 2
	else:
		k = min(value, d[r])
	d[s] -= k
	d[r] -= k
	cnt += 2 * k * m
	for i in range(k):
		left.append(s)
		right.append(r)
left = ''.join(left)
right = ''.join(right[::-1])
mid = ''
for (s, value) in d.items():
	if value == 0:
		continue
	r = s[::-1]
	if r == s:
		cnt += m
		mid = s
		break
ans = left + mid + right
print(cnt)
print(ans)


(n, m) = map(int, input().split())
string = [input() for _ in range(n)]
store = []
palindrome = []
for i in range(n):
	if string[i] == string[i][::-1]:
		palindrome.append(string[i])
	for j in range(i + 1, n):
		if string[i] == string[j][::-1]:
			store.append((string[i], string[j]))
			break
if len(palindrome):
	ans = palindrome[0]
else:
	ans = ''
for (a, b) in store:
	ans = a + ans + b
print(len(ans))
print(ans)


def reversed_string(string):
	return ''.join(reversed(string))

def is_reverse(string1, string2):
	return string1 == reversed_string(string2)

def is_palindrome(string):
	return is_reverse(string, string)

def longest_palindrom(strings):
	used_string_indices = set()
	left_part = []
	right_part = []
	for (idx1, string1) in enumerate(strings):
		if idx1 in used_string_indices:
			continue
		for idx2 in range(idx1 + 1, len(strings)):
			string2 = strings[idx2]
			if not is_reverse(string1, string2):
				continue
			left_part.append(string1)
			right_part.append(string2)
			used_string_indices.add(idx1)
			used_string_indices.add(idx2)
			break
	not_used_strings_with_index = filter(lambda s: s[0] not in used_string_indices, enumerate(strings))
	not_used_strings = map(lambda s: s[1], not_used_strings_with_index)
	palindromes = list(filter(lambda s: is_palindrome(s), not_used_strings))
	middle_palindrome = palindromes[0] if palindromes else ''
	return ''.join(left_part) + middle_palindrome + ''.join(reversed(right_part))
(str_length, _) = map(int, input().split())
strings = []
for _ in range(str_length):
	strings.append(input())
result = longest_palindrom(strings)
print(len(result))
print(result)


(N, M) = map(int, input().split())
A = []
U = []
for i in range(N):
	A.append(input())
	U.append(False)
pre = ''
suf = ''
for i in range(N):
	for j in range(N):
		if i < j and A[i] == A[j][::-1] and (not U[i]) and (not U[j]):
			U[i] = True
			U[j] = True
			pre = A[i] + pre
			suf = suf + A[j]
mid = ''
for i in range(N):
	if A[i] == A[i][::-1] and (not U[i]):
		U[i] = True
		mid = A[i]
		break
print(len(pre + mid + suf))
print(pre + mid + suf)


import sys
input = sys.stdin.readline
f = set()
(n, m) = map(int, input().split())
a = []
for i in range(n):
	s = input()
	s = s.rstrip('\n')
	f.add(s)
	a.append(s)
(pal, pal1) = (set(), set())
sp = set()
for i in range(n):
	if a[i][::-1] in f and a[i] != a[i][::-1]:
		pal.add(a[i])
		pal1.add(a[i][::-1])
		f.remove(a[i])
		f.remove(a[i][::-1])
	elif a[i] == a[i][::-1]:
		sp.add(a[i])
if len(pal) == 0 and len(sp) == 0:
	print(0)
	print()
else:
	s = ''
	s1 = ''
	for i in pal:
		s += i
		s1 = i[::-1] + s1
	for i in sp:
		s += i
		break
	print(len(s) + len(s1))
	print(s + s1)


import sys
(n, m) = map(int, input().split())
ss = []

def solve(ss):
	ans_n = 0
	pre = []
	post = []
	only_middle = ''
	for i in ss:
		for j in ss:
			if i != j:
				if j[::-1] == i:
					if i not in pre and j not in pre and (i not in post) and (j not in post):
						pre.append(i)
						post.append(j)
						ans_n += 2 * m
				elif i[::-1] == j:
					if i not in pre and j not in pre and (i not in post) and (j not in post):
						pre.append(j)
						post.append(i)
						ans_n += 2 * m
				elif i[::-1] == i and only_middle == '' and (i not in pre) and (j not in pre) and (i not in post) and (j not in post):
					only_middle = i
					ans_n += m
			if i == j and i[::-1] == i and (only_middle == ''):
				ans_n += m
				only_middle = i
	print(ans_n)
	print(''.join(pre) + only_middle + ''.join(post[::-1]))
for i in range(n):
	s = sys.stdin.readline().strip()
	ss.append(s)
solve(ss)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
palin = {}
alone = None
droed = ''
(n, len1) = map(int, input().split())
for i in range(n):
	str1 = input()
	reverserino = str1[::-1]
	findrever = palin.get(reverserino, 0)
	if findrever:
		droed = str1 + droed
		droed = droed + reverserino
		findrever -= 1
		palin[reverserino] -= 1
		if alone == reverserino and findrever == 1:
			alone == None
	else:
		freq = palin.get(str1, 0)
		palin[str1] = freq + 1
		if str1 == reverserino:
			if alone == None:
				alone = str1
if alone:
	lenrino = len(droed) // 2
	res = droed[:lenrino] + alone + droed[lenrino:]
	print(len(res))
	print(res)
else:
	print(len(droed))
	print(droed)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	(n, m) = inar()
	d = defaultdict(int)
	ar = []
	for i in range(n):
		s = input()
		ar.append(s)
		d[s] += 1
	(a, b) = ('', '')
	mid = ''
	mx = 0
	for i in ar:
		if i in d and d[i] > 0:
			tp = i[::-1]
			if tp == i:
				if mx < len(i):
					mid = i
					mx = len(i)
			elif tp in d and d[tp] > 0:
				a += i
				b = tp + b
				d[tp] -= 1
				d[i] -= 1
	print(len(a + mid + b))
	print(a + mid + b)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
words = []
for i in range(n):
	words.append(input())
res = ''
resv = ''
check = words[:]
bali = ''
for word in words:
	if word in check:
		if word == word[::-1] and bali == '':
			bali = word
		check.remove(word)
		if word[::-1] in check:
			res += word
			check.remove(word[::-1])
			if bali == word:
				bali = ''
resv = res[::-1]
fin = res + bali + resv
print(len(fin))
print(fin)


(m, n) = map(int, input().split())
lst = [input() for x in range(m)]
ans = 0
res = ''
for i in range(m):
	if lst[i] != '&':
		for j in range(i + 1, m):
			if lst[i] == lst[j][::-1]:
				ans += n + n
				res = res[0:len(res) // 2] + lst[i] + lst[i][::-1] + res[len(res) // 2:]
				lst[j] = lst[i] = '&'
				break
for i in lst:
	if i != '&' and i == i[::-1]:
		ans += n
		res = res[0:len(res) // 2] + i + res[len(res) // 2:]
		break
print(ans)
print(res)


n = list(map(int, input().rstrip().split()))
arr = []
palindrome = []
one_word_palindrome = ''
flag = True
pal = ''
for i in range(n[0]):
	arr.append(input())
for i in arr:
	if i[::-1] in arr:
		if arr.index(i[::-1]) == arr.index(i) and flag:
			one_word_palindrome = i
			flag = False
		elif arr.index(i[::-1]) != arr.index(i):
			if i[::-1] not in palindrome:
				palindrome.append(i)
for i in palindrome:
	pal += i
pal += one_word_palindrome
palindrome.reverse()
for i in palindrome:
	pal += i[::-1]
print(len(pal))
print(pal)


n = list(map(int, input().split(' ')))
lista = []
for i in range(n[0]):
	lista.append(input())
res = ''
ver = True
indi = 0
while indi < len(lista):
	i = lista[indi]
	if lista.count(i[::-1]) > 0 and i != i[::-1]:
		res = i + res + i[::-1]
		lista.remove(i)
		lista.remove(i[::-1])
	elif i == i[::-1]:
		if lista.count(i[::-1]) > 1:
			res = i + res + i[::-1]
			lista.remove(i)
			lista.remove(i[::-1])
		elif ver:
			res = res[:len(res) // 2] + i + res[len(res) // 2:]
			ver = False
			lista.remove(i)
		else:
			indi += 1
	else:
		indi += 1
print(len(res))
print(res)


(n, m) = map(int, input().split())
d = dict()
for i in range(n):
	s = input()
	rs = s[::-1]
	if s in d.keys():
		d[s] += 1
	elif rs in d.keys():
		d[rs] += 1
	else:
		d[s] = 1
f = ''
l = ''
oc = ''
for (s, count) in d.items():
	f += s * (count // 2)
	l += s * (count // 2)
	if count % 2 == 1:
		rs = s[::-1]
		if s == rs:
			oc = s
rl = l[::-1]
ans = f + oc + rl
print(len(ans))
print(ans)


(n, m) = map(int, input().split())
s = ['' for i in range(n)]
t = ['' for i in range(n)]
vis = [False for i in range(n)]
for i in range(n):
	s[i] = input()
	t[i] = s[i][::-1]
(ans1, ans2, ans3) = ('', '', '')
for i in range(n):
	if vis[i] == True:
		continue
	ok = False
	for j in range(i + 1, n):
		if vis[j]:
			continue
		if s[i] == t[j]:
			vis[j] = True
			vis[i] = True
			ans1 += s[i]
			ans2 = s[j] + ans2
			ok = True
			break
	if ok == False:
		if s[i] == t[i]:
			ans3 = s[i]
ans = ans1 + ans3 + ans2
print(len(ans))
print(ans)


from collections import *
(n, m) = map(int, input().split())
l = [input() for i in range(n)]
dic = Counter(l)
ans = ''
s = set()
x = ''
for i in dic:
	if i[::-1] in dic and i[::-1] not in s:
		if i == i[::-1] and dic[i] == 1:
			if len(i) > len(x):
				x = i
				s.add(i)
			continue
		elif i == i[::-1] and dic[i] % 2 == 0:
			ans += i * (dic[i] // 2)
			s.add(i)
			continue
		elif i == i[::-1] and dic[i] % 2 == 1:
			if len(i) * (dic[i] - 1) > len(x):
				x = i * (dic[i] - 1)
				s.add(i)
				continue
		elif i == i[::-1]:
			s.add(i)
			continue
		ans += i * min(dic[i], dic[i[::-1]])
		s.add(i)
if len(ans) == 0 and len(x) == 0:
	print(0)
	print()
	exit()
if x == '':
	print(2 * len(ans))
	print(ans + ans[::-1])
else:
	print(2 * len(ans) + len(x))
	print(ans + x + ans[::-1])


(n, m) = list(map(int, input().split()))
l = []
for _ in range(n):
	l.append(input())
l2 = list()
l1 = list()
s = set()
for i in range(n):
	if l[i][::-1] == l[i] and i not in s:
		l1.append(i)
		s.add(i)
	elif l[i][::-1] in l and i not in s:
		l2.append([i, l.index(l[i][::-1])])
		s.add(i)
		s.add(l.index(l[i][::-1]))
if len(l1) == 0 and len(l2) == 0:
	print(0)
else:
	string1 = ''
	string2 = ''
	for i in l2:
		string1 += l[i[0]]
		string2 = l[i[1]] + string2
	if len(l1) > 0:
		string1 += l[l1[0]]
	print(len(string1 + string2))
	print(string1 + string2)


(n, m) = map(int, input().split())
ar = []
sm = []
m = ''

def palin(s):
	return s == s[::-1]
for _ in range(n):
	s = input()
	if s[::-1] in ar:
		sm.append(s)
		sm.insert(0, s[::-1])
	elif palin(s):
		m = s
	ar.append(s)
sm.insert(len(sm) // 2, m)
s = ''.join(sm)
print(len(s))
print(s)


def reverse(s):
	return s[::-1]

def isPalindrome(s):
	rev = reverse(s)
	if s == rev:
		return True
	return False
(n, m) = (int(i) for i in input().split())
strings = {}
for i in range(n):
	s = input()
	if reverse(s) in dict.keys(strings):
		strings[reverse(s)] = 1
	else:
		strings[s] = 0
res = []
palindromString = ''
for key in dict.keys(strings):
	if strings[key] == 1:
		res.append(key)
	elif isPalindrome(key):
		palindromString = key
print(len(res) * 2 * m + (m if palindromString != '' else 0))
joined = ''.join(res)
print(joined + palindromString + reverse(joined))


import sys
(count, length) = map(int, sys.stdin.readline().strip().split())

def isPalindrom(string):
	length = len(string)
	left = string[:length // 2 + length % 2]
	right = string[length // 2:][::-1]
	if left == right:
		return True
	else:
		return False
strings = []
startAns = ''
endAns = ''
for inp in range(count):
	string = sys.stdin.readline().strip()
	reverse = string[::-1]
	if reverse in strings:
		startAns += string
		endAns = reverse + endAns
		strings.remove(reverse)
	else:
		strings.append(string)
ans = startAns
pos = 0
while pos < len(strings):
	if isPalindrom(strings[pos]):
		ans += strings[pos]
		break
	pos += 1
ans += endAns
print(len(ans))
print(ans)


for u in range(1):
	(n, l) = [int(i) for i in input().split()]
	(norm, rever) = ([], [])
	for i in range(n):
		a = input()
		norm.append(a)
		rever.append(a[::-1])
	s = ''
	m = 0
	while norm != []:
		a = norm[0]
		if a in rever and a != a[::-1]:
			s += a
			s = a[::-1] + s
			norm.remove(a[::-1])
			rever.remove(a)
			rever.remove(a[::-1])
		elif a in rever and norm.count(a) != 1:
			s += a
			s = a[::-1] + s
			norm.remove(a[::-1])
			rever.remove(a)
			rever.remove(a[::-1])
		elif a == a[::-1] and m == 0:
			s = s[:len(s) // 2] + a + s[len(s) // 2:]
			m = 1
			rever.remove(a[::-1])
		norm.remove(a)
	print(len(s))
	print(s)


(n, m) = map(int, input().split())
head = []
tail = []
middle = ''
singles = set()
for i in range(n):
	line = input().strip()
	rev = line[::-1]
	if rev in singles:
		head.append(line)
		tail.append(rev)
		singles.remove(rev)
	elif line == rev:
		middle = line
	else:
		singles.add(line)
answer = ''.join(head + [middle] + list(reversed(tail)))
print(len(answer))
print(answer)


str_list = []
Result = []
List = list(map(int, input().strip().split()))[:2]
num_str = List[0]
len_str = List[1]
count = 0
palindrome_within = None
for i in range(0, num_str):
	str_list.append(input())
for i in range(0, num_str):
	txt = str(str_list[i])
	reversed_str = txt[::-1]
	for j in range(i + 1, num_str):
		if str_list[j] == reversed_str:
			Result.append(str_list[i])
			del str_list[i]
			str_list.insert(i, -1)
			del str_list[j]
			str_list.insert(j, -1)
for i in range(0, num_str):
	txt = str(str_list[i])
	reversed_str = txt[::-1]
	if str_list[i] == reversed_str:
		Result.append(str_list[i])
		palindrome_within = True
		break
if len(Result) == 0:
	print(0)
elif palindrome_within is True:
	print(len(Result) * len_str * 2 - len_str)
	for i in range(0, len(Result)):
		print(Result[i], end='')
	for i in range(len(Result) - 2, -1, -1):
		txt = Result[i]
		reversed_str = str(txt)[::-1]
		print(reversed_str, end='')
else:
	print(len(Result) * len_str * 2)
	for i in range(0, len(Result)):
		print(Result[i], end='')
	for i in range(len(Result) - 1, -1, -1):
		txt = Result[i]
		reversed_str = str(txt)[::-1]
		print(reversed_str, end='')


from collections import defaultdict
(n, m) = map(int, input().split())
cnt = defaultdict(int)
cur = ''
for _ in range(n):
	s = input()
	r = s[::-1]
	if cnt[r] > 0:
		cnt[r] -= 1
		cur = s + cur + r
	else:
		cnt[s] += 1
for (s, c) in cnt.items():
	if c > 0 and s == s[::-1]:
		cur = cur[:len(cur) // 2] + s + cur[len(cur) // 2:]
		break
print(len(cur))
print(cur)


(n, m) = map(int, input().split())
s = [input() for _ in range(n)]
l = [0] * n
ans = ''
ans2 = ''
for i in range(n):
	for j in range(i + 1, n):
		if s[i][::-1] == s[j]:
			ans += s[i]
			ans2 += s[j]
			l[i] = 1
			l[j] = 1
j = ''
for i in range(n):
	if l[i] == 0:
		if s[i] == s[i][::-1]:
			j = s[i]
sol = ans + j + ans[::-1]
print(len(sol))
print(sol)


r = lambda x: ''.join(reversed(x))
(n, m) = map(int, input().split(' '))
s = [input() for i in range(n)]
sr = [r(i) for i in s]
rs = [[], []]
vis = {}
for x in s:
	if vis.get(x, False):
		continue
	if x == r(x):
		rs[1].append(x)
		vis[x] = True
	else:
		if x in sr:
			rs[0].append(x)
			vis[r(x)] = True
		vis[x] = True
_1 = ''.join(rs[0])
_2 = '' if not rs[1] else rs[1][0]
_3 = _1 + _2 + r(_1)
print(len(_3))
print(_3)


(n, m) = map(int, input().split())
s = [input() for i in range(n)]
used = [0] * n
ans = []
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if used[i] or used[j]:
			continue
		if s[i] == s[j][::-1]:
			used[i] = 1
			used[j] = 1
			ans.append(s[i])
p = ''
for i in range(n):
	if used[i]:
		continue
	if s[i] == s[i][::-1]:
		p = s[i]
left = ''.join(ans)
print((len(ans) * 2 + (1 if p else 0)) * m)
print(left + p + left[::-1])


(t, _) = map(int, input().split())
word_count = {}
ans = ''
for _ in range(t):
	word = input()
	try:
		word_count[word] += 1
	except KeyError:
		word_count[word] = 1
for word in word_count:
	if word == word[::-1]:
		while word_count[word] >= 2:
			ans += word
			word_count[word] -= 2
	else:
		while word[::-1] in word_count and word_count[word[::-1]] >= 1 and (word_count[word] >= 1):
			ans += word
			word_count[word[::-1]] -= 1
			word_count[word] -= 1
mid = ''
for word in word_count:
	if word_count[word] >= 1 and word == word[::-1] and (len(word) > len(mid)):
		mid = word
ans += mid + ans[::-1]
print(len(ans))
print(ans)


(n, m) = list(map(int, input().split()))
words = set()
zlo = ''
pal = ''
for i in range(n):
	slovo = input()
	words.add(slovo)
	word = ''
	for j in range(m - 1, -1, -1):
		word += slovo[j]
	if word == slovo:
		zlo = word
	elif word in words:
		pal += word
lap = ''
for i in range(len(pal) - 1, -1, -1):
	lap += pal[i]
palin = pal + zlo + lap
print(len(palin))
print(palin)


from sys import stdin, stdout
import traceback
from collections import Counter
read = stdin.readline
write = stdout.write
writeln = lambda x: write(str(x) + '\n')

def reads(typ=int):
	return list(map(typ, read().split()))

class Sol:

	@classmethod
	def input(cls):
		s = cls()
		return s

	def solve(self):
		(n, m) = reads()
		ss = []
		cnt = Counter()
		components = []
		for _ in range(n):
			s = read().strip()
			s_rev = s[::-1]
			if s_rev in cnt:
				components.append(s)
				cnt[s_rev] -= 1
			else:
				cnt[s] += 1
		max_palindrome = ''
		for (s, v) in cnt.items():
			if v <= 0:
				continue
			if s[::-1] == s and len(s) > len(max_palindrome):
				max_palindrome = s
		left = ''.join(components)
		ret = left + max_palindrome + left[::-1]
		return (len(ret), ret)
try:
	(a, b) = Sol.input().solve()
	writeln(a)
	writeln(b)
except Exception as e:
	print('Got exception:', repr(e))
	print(traceback.format_exc())


(n, m) = map(int, input().split())
l = []
k = 0
ans = ''
flag = 0
for i in range(n):
	s = str(input())
	if s == s[-1::-1] and flag == 0:
		ans = s
		k += 1
		flag = 1
	l.append(s)
for i in range(n):
	for j in range(i + 1, n):
		if l[i] == l[j][-1::-1]:
			k += 2
			ans = l[i] + ans + l[j]
			break
if k == 0:
	print(0)
else:
	print(k * m)
	print(ans)


from collections import defaultdict
(n, m) = map(int, input().split())
l = [[input(), 0] for i in range(n)]
x = ''
y = ''
f = ''
for i in range(n):
	if l[i][1] != 0:
		continue
	for j in range(n):
		if i != j and l[j][1] == 0:
			if l[i][0] == l[j][0][::-1]:
				x = x + l[i][0]
				y = l[j][0] + y
				l[i][1] = l[j][1] = 1
for i in l:
	if i[1] == 0:
		if i[0] == i[0][::-1]:
			f = f + i[0]
			break
t = x + f + y
print(len(t))
print(x + f + y)


import math
import collections
import functools
import sys
import os

def solve():
	(n, m) = map(int, input().split())
	table = [''] * n
	for i in range(n):
		table[i] = input()
	t = set()
	cen = ''
	re = ''
	for i in range(n):
		temp = table[i][::-1]
		if temp == table[i]:
			cen = temp
			continue
		if temp in t:
			re = table[i] + re + temp
		t.add(table[i])
	tn = len(re) // 2
	re = re[:tn] + cen + re[tn:]
	print(len(re))
	print(re)

def main():
	T = 1
	while T:
		solve()
		T -= 1
main()


(n, m) = map(int, input().split())
l = ''
r = ''
c = ''
cen = []

def ispal(x):
	i = 0
	j = len(x) - 1
	while i <= j:
		if x[i] != x[j]:
			return False
		i += 1
		j -= 1
	return True
arr = [input() for i in range(n)]
dic = {}
for i in arr:
	try:
		dic[i] += 1
	except:
		dic[i] = 1
for i in arr:
	x = i[::-1]
	try:
		if x == i:
			if dic[x] > 1:
				l += x
				r = x + r
				dic[x] -= 2
			elif dic[i] == 1:
				dic[i] -= 1
				c = i
		if dic[x] >= 1:
			dic[i] -= 1
			dic[x] -= 1
			l += i
			r = x + r
	except:
		continue
ans = l + c + r
print(len(ans))
print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
strs = [input() for i in range(n)]
used = [False for i in range(n)]

def palindrome(x: int, y: int) -> bool:
	if strs[x] == strs[y][::-1]:
		return True
	else:
		return False

def self_palindrome(x: int) -> bool:
	if strs[x] == strs[x][::-1]:
		return True
	else:
		return False
ans = []
self_pa = []
for i in range(n):
	for j in range(i + 1, n):
		if not used[i] and (not used[j]):
			if palindrome(i, j):
				ans.append(i)
				ans.append(j)
				(used[i], used[j]) = (True, True)
for i in range(n):
	if not used[i] and self_palindrome(i):
		self_pa.append(i)
		break
up = len(ans)
print(up * m + len(self_pa) * m)
for i in range(0, up, 2):
	print(strs[ans[i]], end='')
for i in self_pa:
	print(strs[i], end='')
for i in range(up - 1, -1, -2):
	print(strs[ans[i]], end='')
print()


(t, n) = map(int, input().split())
pal_st = []
rev_st = []
st = []
cou = 0
for _ in range(t):
	string = input()
	if string[::-1] == string:
		pal_st.append(string)
	elif string[::-1] in st:
		rev_st.append((string, string[::-1]))
		cou += 2 * len(string[::-1])
		st.remove(string[::-1])
	else:
		st.append(string)
m = 0
ans = ''
if pal_st != []:
	ans += max(pal_st, key=len)
	m = len(max(pal_st, key=len))
print(m + cou)
for (i, j) in rev_st:
	ans = i + ans + j
print(ans)


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

def is_palindrome(s1, s2):
	eh = True
	for i in range(len(s1)):
		if s1[i] != s2[m - i - 1]:
			eh = False
			break
	return eh

def is_palindrome_alone(s1):
	eh = True
	for i in range(len(s1)):
		if s1[i] != s1[m - i - 1]:
			eh = False
			break
	return eh
together = []
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		if a[i] != -1 and a[j] != -1 and is_palindrome(a[i], a[j]):
			together.append([a[i], a[j]])
			a[i] = -1
			a[j] = -1
alone = []
for (i, s) in enumerate(a):
	if s != -1 and is_palindrome_alone(s):
		alone.append(s)
		a[i] = -1
		break
stack = []
ans = []
for i in together:
	ans.append(i[0])
	stack.append(i[1])
for i in alone:
	ans.append(i)
while len(stack):
	ans.append(stack.pop())
ans = ''.join(ans)
print(len(ans))
print(ans)


import sys
import copy
from math import *
input = sys.stdin.readline

def bo(i):
	return ''.join(list(i)[::-1])
t = 1
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		s = input().rstrip()
		a.append(s)
	d = {}
	p = {}
	for i in a:
		if i not in d:
			d[i] = 1
			if list(i) == list(i)[::-1]:
				p[i] = 1
			else:
				p[i] = 0
		else:
			d[i] += 1
	z = ''
	r = ''
	u = {}
	for i in d:
		if list(i) == list(i)[::-1]:
			z += i * (d[i] // 2)
			u[bo(i)] = 1
			if d[i] % 2 == 1:
				r = i
		elif bo(i) in d and i not in u:
			z += i * min(d[bo(i)], d[i])
			u[bo(i)] = 1
		if list(i) == list(i)[::-1] and p[i] == 1 and (d[i] - min(d[bo(i)], d[i]) > 0):
			r = i
	if len(r) == m:
		z += r
	uu = ''
	for i in d:
		if list(i) == list(i)[::-1]:
			uu += i * (d[i] // 2)
		elif bo(i) in u and i not in u:
			uu += i * min(d[bo(i)], d[i])
	uu = list(uu)
	uu = uu[::-1]
	uu = ''.join(uu)
	z += uu
	print(len(z))
	print(z)


def pali(x):
	return x[::-1]
(n, m) = map(int, input().split())
arr = []
for _ in range(n):
	arr.append(input())
arr1 = [0 for i in range(n)]
t = 0
lhs = ''
rhs = ''
midd = ''
for i in range(n):
	for j in range(n):
		if i != j:
			if pali(arr[i]) == arr[j] and arr1[i] == 0 and (arr1[j] == 0):
				lhs += arr[i]
				rhs = arr[j] + rhs
				t += 2 * m
				arr1[i] += 1
				arr1[j] += 1
for i in arr:
	if pali(i) == i:
		midd += i
		t += m
		break
print(t)
print(lhs + midd + rhs)


(x, y) = map(int, input().split())
a = set()
l = []
for i in range(x):
	l.append(input())
	a.add(l[-1])
s = set()
m = ''
for i in a:
	r = i[::-1]
	if i != r and r in a and (r not in s):
		s.add(i)
	elif r == i and len(i) > len(m):
		m = i
s = ''.join(list(s))
o = s + m + s[::-1]
print(len(o))
print(o)


(n, m) = map(int, input().split())
strings = []
for i in range(n):
	strings.append(input())
dic = {}
for i in strings:
	if i in dic:
		if i == i[::-1]:
			dic[i][2] = 1
		dic[i][0] += 1
	elif i[::-1] in dic:
		if i == i[::-1]:
			dic[i[::-1]][2] = 1
		dic[i[::-1]][1] += 1
	else:
		dic[i] = [1, 0, 0]
		if i == i[::-1]:
			dic[i][2] = 1
middle = ''
f = False
for i in dic:
	if dic[i][2] == 1:
		(x, y, z) = dic[i]
		f = True
		if x % 2 != 0:
			dic[i][0] -= 1
			middle = i
if f == True and middle == '':
	for i in dic:
		if dic[i][2] == 1:
			(x, y, z) = dic[i]
			if x % 2 == 0:
				dic[i][0] -= 1
				middle = i
for i in dic:
	if dic[i][2] == 1:
		add = dic[i][0] // 2
		middle = i * add + middle + i[::-1] * add
	else:
		(x, y, z) = dic[i]
		add = min(x, y)
		middle = i * add + middle + i[::-1] * add
print(len(middle))
print(middle)


(n, m) = map(int, input().split())
strings = []
for i in range(n):
	strings.append(input().strip())
dic = {}
pall = []
for string in strings:
	reverse = string[::-1]
	if reverse in dic:
		dic[reverse] += 1
	else:
		dic[string] = 1
ans = ''
initial = False
added = 0
for key in dic.keys():
	if dic[key] == 2:
		ans = key + ans + key[::-1]
		added += 1
	elif not initial and key == key[::-1]:
		ans = ans[:m * added] + key + ans[m * added:]
		initial = True
print(len(ans))
print(ans)


import collections
local = False
if local:
	file = open('B.txt', 'r')

def readInput():
	if local:
		return file.readline()
	else:
		return input()

def solve(n, m, strs):
	ans = ''
	seen = set()
	i = 0
	while i < len(strs):
		seen.add(strs[i])
		i += 1
	for s in strs:
		if len(s) > 1 and s in seen:
			rev = s[::-1]
			if rev in seen and rev != s:
				seen.remove(s)
				seen.remove(rev)
				ans = s + ans + rev
	longest = ''
	for s in seen:
		if len(s) > len(longest) and isPalin(s):
			longest = s
	ans = ans[0:len(ans) // 2] + longest + ans[len(ans) // 2:]
	return ans

def isPalin(s):
	(l, r) = (0, len(s) - 1)
	while l < r:
		if s[l] != s[r]:
			return False
		l += 1
		r -= 1
	return True

def addEvToDeq(ans, s):
	(l, r) = (0, len(s) - 1)
	while l < r:
		ans.append(s[r])
		ans.appendleft(s[l])
		l += 1
		r -= 1
nm = readInput().split()
(n, m) = (int(nm[0]), int(nm[1]))
strs = [''] * n
for i in range(n):
	strs[i] = readInput().rstrip()
res = solve(n, m, strs)
print(len(res))
print(res)


(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) = map(int, input().split())
s = []
PAL = []
PAL_L_R = []
ans = ''
for i in range(n):
	s.append(input())
	SAME = 0
	for x in range(len(s[i]) // 2):
		if s[i][x] != s[i][-x - 1]:
			PAL_L_R.append(s[i])
			SAME = 1
			break
	if SAME == 0:
		PAL.append(s[i])
PAL_L = []
PAL_R = []
while len(PAL_L_R) > 0:
	i = 0
	swap = False
	while i < len(PAL_L_R):
		if PAL_L_R[0] == PAL_L_R[-1 - i][::-1]:
			PAL_L.append(PAL_L_R[0])
			PAL_R.append(PAL_L_R[-1 - i])
			PAL_L_R.remove(PAL_L_R[-1 - i])
			PAL_L_R.remove(PAL_L_R[0])
			swap = True
			i = 0
		i += 1
	if swap == False:
		PAL_L_R.remove(PAL_L_R[0])
while len(PAL_L) > 0:
	ans += ''.join(PAL_L[0])
	PAL_L.remove(PAL_L[0])
if len(PAL) >= 1:
	ans += ''.join(max(PAL))
while len(PAL_R) > 0:
	ans += ''.join(PAL_R[-1])
	PAL_R.remove(PAL_R[-1])
print(len(ans))
print(ans)


(n, m) = map(int, input().split(' '))
strings = []
for _ in range(n):
	strings.append(input())
strings_set = set(strings)
front = []
back = []
middle = []
for s in strings:
	if s not in strings_set:
		continue
	strings_set.remove(s)
	s_pal = s[::-1]
	if s_pal == s and (not middle):
		middle.append(s)
	elif s_pal in strings_set:
		front.append(s)
		back.append(s_pal)
		strings_set.remove(s_pal)
result = ''.join(front) + ''.join(middle) + ''.join(reversed(back))
print(len(result))
print(result)


(n, m) = [int(x) for x in input().split()]
s = []
ori = []
rev = []
p = []
for _ in range(n):
	st = input()
	s.append(st)
	l = st[::-1]
	if st == l:
		if st in p:
			ori.append(st)
			rev.append(st)
			p.remove(st)
		else:
			p.append(st)
	elif l in s:
		ori.append(st)
		rev.append(l)
if len(ori) == 0 and len(p) == 0:
	print(str(0) + '\n')
else:
	length = 2 * m * len(ori)
	pal = ''
	for x in ori:
		pal = pal + x
	if len(p) > 0:
		pal = pal + p[0]
		length = length + m
	for x in rev[::-1]:
		pal = pal + x
	print(length)
	print(pal)


(n, m) = map(int, input().split())
v = list()
for i in range(n):
	v.append(input())
g1 = ''
g2 = ''
pal = ''
for i1 in range(n):
	if len(v) == 0:
		break
	h = v[0]
	del v[0]
	r = True
	for i2 in range(len(v)):
		if h[::-1] == v[i2]:
			r = False
			g1 += h
			g2 = v[i2] + g2
			del v[i2]
			break
	if h == h[::-1] and r:
		pal = h
print(len(g1) * 2 + len(pal))
print(g1 + pal + g2)


import sys
import math
input = sys.stdin.readline

def reverse(s):
	str = ''
	for i in s:
		str = i + str
	return str
(n, m) = map(int, input().split())
dc = dict()
st = list()
rev = list()
for i in range(n):
	s = input()
	if reverse(s[0:m]) in dc.keys():
		st.append(s[0:m])
		rev.append(reverse(s[0:m]))
		dc.pop(reverse(s[0:m]), None)
	else:
		dc[s[0:m]] = 1
flag = 0
for i in dc.keys():
	if flag == 1:
		break
	if reverse(i) in dc.keys():
		st.append(i)
		flag = 1
print(len(st) * m + len(rev) * m)
for i in range(len(st)):
	print(st[i], end='')
for i in range(len(rev) - 1, -1, -1):
	print(rev[i], end='')
print()


import math
t = 1
while t:
	(x, y) = map(int, input().split())
	l = []
	j = []
	k = []
	m = []
	t1 = []
	t2 = []
	for i in range(x):
		l1 = input()
		l.append(l1)
	for i in range(x):
		r = l[:i] + l[i + 1:]
		if l[i][::-1] in r:
			j.append(l[i])
			k.append(l[i][::-1])
		if l[i] == l[i][::-1]:
			m.append(l[i])
	for i in range(len(j)):
		if j[i] not in t1 and j[i][::-1] not in t1:
			t1.append(j[i])
			t2.append(j[i][::-1])
	str1 = str()
	str2 = str()
	for i in range(len(t1)):
		str1 = str1 + t1[i]
	for i in range(len(t2) - 1, -1, -1):
		str2 = str2 + t2[i]
	if len(m) > 0:
		print(len(str1 + m[0] + str2))
		print(str1 + m[0] + str2)
	elif len(str1 + str2) > 0:
		print(len(str1 + str2))
		print(str1 + str2)
	else:
		print(0)
	t = t - 1


(n, m) = map(int, input().split())
seen = set()
double = ''
single = ''
for _ in range(n):
	s = input()
	if s[::-1] == s and len(s) > len(single):
		single = s
	elif s[::-1] in seen:
		double += s
	else:
		seen.add(s)
print('{}'.format(len(double) * 2 + len(single)))
print('{}{}{}'.format(double, single, double[::-1]))


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		x = str(input())
		a.append(x)
	v = [False] * n
	ans = 0
	res = ''
	for i in range(n):
		if not v[i]:
			for j in range(i + 1, n):
				if a[i] == a[j][::-1]:
					ans += 2
					res += a[i]
	temp = res[::-1]
	for i in range(n):
		if not v[i] and a[i][:m // 2] == a[i][::-1][:m // 2]:
			ans += 1
			res += a[i]
			break
	print(ans * m)
	print(res + temp)
main()


import sys

def get_reversed(s, length):
	reversed_string = ''
	for i in range(0, length):
		reversed_string += s[length - i - 1]
	return reversed_string

def solve():
	string_number = None
	string_length = None
	strings = set()
	left_strings = None
	for line in sys.stdin:
		if string_number is None:
			ns = line.split()
			string_number = int(ns[0])
			string_length = int(ns[1])
			left_strings = string_number
		else:
			strings.add(line.strip())
			left_strings -= 1
			if left_strings == 0:
				break
	palindrome_head = ''
	palindrome_tail = ''
	palindrome_pendding = None
	used_string = set()
	for s in strings:
		if s in used_string:
			continue
		palindrome_s = get_reversed(s, string_length)
		if s == palindrome_s:
			palindrome_pendding = s
		elif palindrome_s in strings:
			palindrome_head += s
			palindrome_tail = palindrome_s + palindrome_tail
			used_string.add(palindrome_s)
	result_string = palindrome_head
	if palindrome_pendding is not None:
		result_string += palindrome_pendding
	result_string += palindrome_tail
	print(len(result_string))
	print(result_string)
solve()