Problem: Recent improvements in information and communication technology have made it possible to provide municipal service to a wider area more quickly and with less costs. Stimulated by this, and probably for saving their not sufficient funds, mayors of many cities started to discuss on mergers of their cities.

There are, of course, many obstacles to actually put the planned mergers in practice. Each city has its own culture of which citizens are proud. One of the largest sources of friction is with the name of the new city. All citizens would insist that the name of the new city should have the original name of their own city at least as a part of it. Simply concatenating all the original names would, however, make the name too long for everyday use.

You are asked by a group of mayors to write a program that finds the shortest possible name for the new city that includes all the original names of the merged cities. If two or more cities have common parts, they can be overlapped. For example, if "FUKUOKA", "OKAYAMA", and "YAMAGUCHI" cities are to be merged, "FUKUOKAYAMAGUCHI" is such a name that include all three of the original city names. Although this includes all the characters of the city name "FUKUYAMA" in this order, it does not appear as a consecutive substring, and thus "FUKUYAMA" is not considered to be included in the name.



Input

The input is a sequence of datasets. Each dataset begins with a line containing a positive integer n (n ≤ 14), which denotes the number of cities to be merged. The following n lines contain the names of the cities in uppercase alphabetical letters, one in each line. You may assume that none of the original city names has more than 20 characters. Of course, no two cities have the same name.

The end of the input is indicated by a line consisting of a zero.

Output

For each dataset, output the length of the shortest possible name of the new city in one line. The output should not contain any other characters.

Examples

Input

3


Output

16


Input

3
FUKUOKA
OKAYAMA
YAMAGUCHI
3
FUKUOKA
FUKUYAMA
OKAYAMA
2
ABCDE
EDCBA
4
GA
DEFG
CDDE
ABCD
2
ABCDE
C
14
AAAAA
BBBBB
CCCCC
DDDDD
EEEEE
FFFFF
GGGGG
HHHHH
IIIII
JJJJJ
KKKKK
LLLLL
MMMMM
NNNNN
0


Output

16
19
9
9
5
70

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
const int N=14;
const int INF=1e9;
string str[20],s[20];
int dp[20][1<<15],ok[20][20];
int n;
int check(int x,int y)
{
	int i,j,r=0,l1=s[x].size(),l2=s[y].size();
	for(i=0;i<l1;i++)
	{
		for(j=0;i+j<l1&&j<l2;j++)if(s[x][i+j]!=s[y][j])break;
		if(i+j==l1&&r<j)r=j;
	}
	return r;
}
bool ck(int x,int y)
{
	int l1=str[x].size(),l2=str[y].size();
	int i,j;
	for(i=0;i<l2;i++)
	{
		for(j=0;j<l1&&i+j<l2;j++)if(str[x][j]!=str[y][i+j])break;
		if(j==l1)return true;
	}
	return false;
}
int dfs(int x,int zt)
{

	if(dp[x][zt]!=-1)return dp[x][zt];
	dp[x][zt]=INF;
	int i;
	for(i=0;i<n;i++)
	{
		if((zt&(1<<i))&&i!=x)
		{
			int t=dfs(i,zt-(1<<x))+s[x].size()-ok[i][x];

			if(dp[x][zt]>t)dp[x][zt]=t;
		}
	}

	return dp[x][zt];
}
int main()
{      
	int i,j,k;
	while(~scanf("%d",&n))
	{       
                memset(dp,-1,sizeof(dp));
		if(!n)break;
		for(i=0;i<n;i++)cin >> str[i];
		k=0;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(i!=j&&ck(i,j))break;
			}
			if(j==n)s[k++]=str[i];
		}

		n=k;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				ok[i][j]=check(i,j);
			}
		}
		
		for(i=0;i<n;i++)dp[i][1<<i]=s[i].size();
		int L=(1<<n);
		for(i=0;i<n;i++)dfs(i,L-1);
		int r=INF;
		for(i=0;i<n;i++)if(r>dp[i][L-1])r=dp[i][L-1];
		printf("%d\n",r);
	}
	return 0;
}