CF1003F.Abbreviation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a text consisting of n space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. wi is the i -th word of text. All words consist only of lowercase Latin letters.
Let's denote a segment of words w[i..j] as a sequence of words wi,wi+1,…,wj . Two segments of words w[i1..j1] and w[i2..j2] are considered equal if j1−i1=j2−i2 , j1≥i1 , j2≥i2 , and for every t∈[0,j1−i1] wi1+t=wi2+t . For example, for the text "to be or not to be" the segments w[1..2] and w[5..6] are equal, they correspond to the words "to be".
An abbreviation is a replacement of some segments of words with their first uppercase letters. In order to perform an abbreviation, you have to choose at least two non-intersecting equal segments of words, and replace each chosen segment with the string consisting of first letters of the words in the segment (written in uppercase). For example, for the text "a ab a a b ab a a b c" you can replace segments of words w[2..4] and w[6..8] with an abbreviation "AAA" and obtain the text "a AAA b AAA b c", or you can replace segments of words w[2..5] and w[6..9] with an abbreviation "AAAB" and obtain the text "a AAAB AAAB c".
What is the minimum length of the text after at most one abbreviation?
输入格式
The first line of the input contains one integer n ( 1≤n≤300 ) — the number of words in the text.
The next line contains n space-separated words of the text w1,w2,…,wn . Each word consists only of lowercase Latin letters.
It is guaranteed that the length of text does not exceed 105 .
输出格式
Print one integer — the minimum length of the text after at most one abbreviation.
输入输出样例
输入#1
6 to be or not to be
输出#1
12
输入#2
10 a ab a a b ab a a b c
输出#2
13
输入#3
6 aa bb aa aa bb bb
输出#3
11
说明/提示
In the first example you can obtain the text "TB or not TB".
In the second example you can obtain the text "a AAAB AAAB c".
In the third example you can obtain the text "AB aa AB bb".