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

using namespace std;

const int N = 15;
const int INF = 0xfffffff;

int dp[N][1<<15];
char str[N][25];
int AddNum[N][N];

template< typename T > T Max(T a, T b) { return a>b?a:b; }
template< typename T > T Min(T a, T b) { return a<b?a:b; }

bool judge(int i,int j)
{
    if(strcmp(str[i],str[j])==0)
        return true;
    int len1=strlen(str[i]);
    int len2=strlen(str[j]);
    int l,k,p;
    for(k=0; k<=len1-len2; k++)
    {
        for(p=0; p<len2&&k+p<len1; p++)
            if(str[i][k+p]!=str[j][p])
                break;
        if(p==len2)
            return true;
    }
    for(k=0; k<=len2-len1; k++)
    {
        for(p=0; p<len1&&k+p<len2; p++)
            if(str[i][p]!=str[j][k+p])
                break;
        if(p==len1)
            return true;
    }
    return false;
}

//bool judge( int i, int j  )
//{
//    if ( strcmp( str[i], str[j] ) == 0 ) return true;
//
//    int leni = strlen(str[i]), lenj = strlen(str[j]);
//    int k, p;
//    for ( k = 0; k < leni-lenj; k++ )
//    {
//        for ( p = 0; p < lenj && k+p < leni; p++ )
//            if ( str[i][k+p] != str[j][p] ) break;
//        if ( p == lenj) return true;
//    }
//    for ( k = 0; k < lenj-leni; k++ )
//    {
//        for ( p = 0; p < leni && k+p < lenj; p++ )
//            if ( str[j][k+p] != str[i][p] ) break;
//        if ( p == leni) return true;
//    }
//    return false;
//}

//int PreInit(int li, int lj)
//{
//    int leni = strlen(str[li]), lenj = strlen( str[lj] );
//    int next[25];
//    int i = 0,j = 0, k = -1; next[0] = -1;
//    while (j< lenj)
//    {
//        if ( k == -1 || str[lj][j] == str[lj][j] ) next[++j] = ++k;
//        else k = next[k];
//    }
//    i = 0, j = 0;
//    while ( i < leni && j < lenj )
//    {
//        if ( j == -1 || str[li][i] == str[lj][j] )
//        {
//            ++i, ++j;
//            if ( j == lenj ) return 0;
//        }
//        else j = next[j];
//    }
//    return lenj - j;
//}

int PreInit(int i,int j)//荳、荳ェ蟄礼ャヲ荳イ霑樊磁蠅槫刈逧?柄蠎ヲ
{
    int l,k,p;
    int len1=strlen(str[i]);
    int len2=strlen(str[j]);
    int len=min(len1,len2);
    for(l=len; l>=0; l--)
    {
        for(k=len1-l,p=0; k<len1&&p<len2; k++,p++)
            if(str[i][k]!=str[j][p])
                break;
        if(k==len1||p==len2)
            return len2-l;
    }
}

int dfs( int k, int state,const int &n )
{
    if ( dp[k][state] != INF ) return dp[k][state];
    if ( state == 0 ) return dp[k][0]=0;

    for ( int i = 0; i < n; i++ )
    {
        if ( state&(1<<i) )
        {
            int sta = state^(1<<i);
            dp[k][state] = Min( dp[k][state], dfs( i, sta, n )+AddNum[k][i] );
        }
    }
    return dp[k][state];
}

//int main()
//{
//    #ifndef ONLINE_JUDGE
//        freopen( "test.in", "r", stdin );
//    #endif
//    int n;
//    while ( scanf("%d", &n) != EOF )
//    {
//        if ( n == 0 ) break;
//
//        for ( int i = 0; i < n; i++ )
//        {
//            scanf("%s", str[i]);
//            for ( int j = 0; j < i; j++ )
//                if ( judge(i, j) )
//                {
//                    if ( strlen( str[i] ) > strlen( str[j] ) )
//                        strcpy( str[j], str[i] );
//                    i--, n--;
//                }
//        }
//        memset(AddNum, 0, sizeof(AddNum));
//        for ( int i = 0; i < n; i++ )
//            for ( int j = 0; j < n; j++ )
//            {
////                if ( i == j ) continue;
//                AddNum[i][j] = PreInit(i, j);
//
//            }
////        for ( int i = 0; i < n; i++ )
////        {
////            for ( int j = 0; j < n; j++ )
////                printf("%d  ", AddNum[i][j]);
////            puts("");
////        }
//
//        for ( int i = 0; i < n; i++ )
//            for ( int j = 0; j < (1<<n); j++ )
//                dp[i][j] = INF;
////        cout << n<< endl;
//        int ans = INF;
//        int state = (1<<n)-1;
//        for ( int i = 0; i < n; i++ )
//        {
//            ans = Min( ans, dfs( i, state^(1<<i), n )+ (int)strlen( str[i] ) );
//        }
//
//        printf("%d\n", ans);
//    }
//    return 0 ;
//}

int main()
{

    int i,j;
    int minn;
    int n;
    while(scanf("%d",&n)&&n)
    {
        for(i=0; i<n; i++)
        {
            scanf("%s",str[i]);
            for(j=0; j<i; j++)
            {
                if(judge(i,j))
                {
                    if(strlen(str[i])>strlen(str[j]))//譛牙ュ礼ャヲ荳イ陲ォ蜿ヲ荳?クェ蛹?性逧?慮蛟呻シ梧滑遏ュ逧?ュ礼ャヲ荳イ逶エ謗・隕?尠謗?
                        strcpy(str[j],str[i]);
                    i--;
                    n--;
                }
            }
        }
        for(i=0; i<n; i++)
            for(j=0; j<n; j++)
            {
                AddNum[i][j]=PreInit(i,j);
            }

            for(j=0; j<n; j++)
            for(i=0; i<(1<<n); i++)
                dp[j][i]=INF;
        int state=(1<<n)-1;
        minn=INF;
        for(i=0; i<n; i++)
        {
            int d = dfs(i, state^(1<<i), n)+strlen(str[i]);
            minn=min(minn, d);
        }
        printf("%d\n",minn);
    }
    return 0;
}