logo AlgoBeat OnlineJudge
登录 注册

#209270. [ICPC 2021 Macao R] LCS Spanning Tree

内存限制:1024 MiB 时间限制:5000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Given a complete undirected graph of vertices and strings , the weight of edge connecting vertices and is equal to the length of the longest common substring (LCS) between and . 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 () indicating the number of vertices and strings.

For the following lines, the -th line contains one string () 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

样例输出 1

4

样例输入 2

3
ababa
babab
aba

样例输出 2

7