n = int(input())
ll = []
for i in range(n):
ll.append(input())
dp = [[0] * n for _ in range(1 << n)]
end = (1 << n) - 1
ans = 0
for i in range(n):
dp[1 << i][i] = len(ll[i])
ans = max(ans, dp[1 << i][i])
for i in range(1 << n):
for nex in range(n):
for pre in range(n):
if not dp[i | (1 << nex)][nex] and ll[pre][-1] == ll[nex][0] and i & (1 << pre) and not i & (1 << nex):
dp[i | (1 << nex)][nex] = dp[i][pre] + len(ll[nex])
ans = max(ans, dp[i | (1 << nex)][nex])
print(ans)
def dfs(x, pre):
if x == (1 << n) - 1:
return 0
ans = 0
for i in range(n):
if not x & (1 << i) and (not pre or ll[i][0] == pre):
ans = max(ans, dfs(x ^ (1 << i), ll[i][-1]) + len(ll[i]))
return ans
n, ll = int(input()), []
for _ in range(n):
ll.append(input())
print(dfs(0, ''))