LCS Spanning Tree
时间限制:C/C++/Rust/Pascal 5秒,其他语言10秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述

Given a complete undirected graph of n vertices and n strings , the weight of edge connecting vertices i and j is equal to the length of the longest common substring (LCS) between s_i and s_j. Compute the maximum total weight of any spanning tree on this graph.
A substring of a string can be obtained by removing some (possibly zero) characters from the beginning and/or the end of that string. For example, "maca", "aca" and "cau" are all substrings of "macau", while "acu" is not.

输入描述:

There is only one test case in each test file.
The first line of the input contains one integer n () indicating the number of vertices and strings.
For the following n lines, the i-th line contains one string s_i () consisting only of lowercase English letters.
It's guaranteed that the sum of lengths of all strings will not exceed .

输出描述:

Output one line containing one integer indicating the answer.
示例1

输入

复制
4
icpc
macau
regional
contest

输出

复制
4
示例2

输入

复制
3
ababa
babab
aba

输出

复制
7