Type The Strings
题号:NC244822
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Alice have n strings named S_1 to S_n . Each string has a length l_i. Now she wants to type them on the txt-editor (Sequence not required).

For each string S_i, she has two choice.

The first choice is to type all characters of S_i one by one (this will cost l_i).

The second choice is to choose one string S_j , which Alice has typed before , then paste it into a single line (this will cost k) . Now we call this string S , Alice can perform the following operation any time to get S_i .

- Delete any character from S , each character costs 1 .

- Insert any character anywhere in S , each character costs 1 .

Such as we want to get abac from bdc , we will do the following operations :

1. Paste bdc into a new line , cost k .

2. Delete the 2nd character d in bdc to get bc , cost 1 .

3. Insert a before the first character of bc to get abc , cost 1 .

4. Insert a after the second character of abc to get abac , cost 1 .

Totally cost .

Now Alice wants to type all the strings , please help her to find the minimum cost .

输入描述:

The first line contains two integer  .

The next n lines , each line contains an integer , and a string S_i with length l_i , Separates by a space .

S_i only has lowercase letters .

输出描述:

Print an integer  --- the minimum cost  .
示例1

输入

复制
2 1
4 baba
4 abaa

输出

复制
7

说明

In this sample , Alice can type the second string abaa first , cost 4 , then copy this string , cost 1 , cost 2 to get baba from abaa (abaa->aba->baba) . The total cost is 7 .