Problem C
Metro building
There are $n$ ($n \leq 10^5$) 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 $A_ i$, and an unofficial name $B_ i$. The beauty of a metro-line between city $i$ and $j$ is $w = |LCP(A_ i,B_ j)|+|LCP(B_ i,A_ j)|$, 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 $\sum |A_ i|+|B_ i| \leq 10^5$. It is also guaranteed that $A_ i$ and $B_ i$ only contains lowercase English letters.
Input
In the first there is an integer $n \leq 10^5$.
Then follow $n$ lines, the $i^{th}$ of which contains the string $A_ i$.
Then follow $n$ more lines, the $i^{th}$ of which contains the string $B_ i$.
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 |