There are
() 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 , and an unofficial name . The beauty of a metro-line
between city and
is , where
denotes the longest common prefix of two strings, and
denotes the length
of a string . 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 . It is also guaranteed that
and only contains lowercase English
letters.
Input
In the first there is an integer .
Then follow lines,
the of which
contains the string .
Then follow more
lines, the of
which contains the string .
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
|