Hide

Problem C
Metro building

There are n (n105) cities in OI Kingdom. The emperor of the Kingdom wants to build some undirected metro-lines to make the Kingdom connected. Each city has an official name Ai, and an unofficial name Bi. The beauty of a metro-line between city i and j is w=|LCP(Ai,Bj)|+|LCP(Bi,Aj)|, where LCP denotes the longest common prefix of two strings, and |S| denotes the length of a string S. The overall beauty of a plan is the sum of beauty of all the metro-line in the plan. The king wants to know the highest possible overall beauty of the Kingdom, if it’s connected using the least possible number of metro-lines.

It is guaranteed that |Ai|+|Bi|105. It is also guaranteed that Ai and Bi only contains lowercase English letters.

Input

In the first there is an integer n105.

Then follow n lines, the ith of which contains the string Ai.

Then follow n more lines, the ith of which contains the string Bi.

Output

Output a single line containing an integer, the maximum overall beauty of the kingdom.

Sample Input 1 Sample Output 1
3
aaa
bbc
bb
bbb
ac
bbc
6
Hide

Please log in to submit a solution to this problem

Log in