Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 1,931 Bytes
761e24d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<p>
Since you crave state-of-the-art technology, you've just purchased a phone with a great new feature: autocomplete!
Your phone's version of autocomplete has some pros and cons. On the one hand, it's very cautious. It only autocompletes a word when it knows exactly what you're trying to write. On the other hand, you have to teach it every word you want to use.
</p>

<p>
You have <strong>N</strong> distinct words that you'd like to send in a text message in order.
Before sending each word, you add it to your phone's dictionary.
Then, you write the smallest non-empty prefix of the word necessary for your phone to autocomplete the word.
This prefix must either be the whole word, or a prefix which is not a prefix of any other word yet in the dictionary.
</p>

<p>
What's the minimum number of letters you must type to send all <strong>N</strong> words?
</p>

<h3>Input</h3>

<p>
Input begins with an integer <strong>T</strong>, the number of test cases.
For each test case, there is first a line containing the integer <strong>N</strong>.
Then, <strong>N</strong> lines follow, each containing a word to send in the order you wish to send them.
</p>


<h3>Output</h3>

<p>
For the <strong>i</strong>th test case, print a line containing "Case #<strong>i</strong>: " followed by
the minimum number of characters you need to type in your text message.
</p>


<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 100 <br />
1 &le; <strong>N</strong> &le; 100,000 <br />
</p>

<p>
The <strong>N</strong> words will have a total length of no more than 1,000,000 characters. <br />
The words are made up of only lower-case alphabetic characters. <br />
The words are pairwise distinct. <br />
</p>

<p>
<strong>NOTE:</strong> The input file is about 10-20MB.
</p>


<h3>Explanation of Sample</h3>
<p>
In the first test case, you will write "h", "he", "l", "hil", "hill", for a total of 1 + 2 + 1 + 3 + 4 = 11 characters.
</p>