Simple Prefix Compression

No attempts yetTime limit1sMemory limit128 MB

Problem

Many databases store character fields (and especially indices) using prefix compression. This technique compresses a sequence of strings A1,A2,,ANA_1, A_2, \ldots, A_N as follows.

The first string A1A_1 is stored in full. For every subsequent string Ai+1A_{i+1}, let jj be the length of the longest common prefix it shares with the previous string AiA_i — the largest jmin(p,q)j \le \min(p, q) such that the first jj characters of Ai=ai,1ai,2ai,pA_i = a_{i,1} a_{i,2} \cdots a_{i,p} and Ai+1=ai+1,1ai+1,2ai+1,qA_{i+1} = a_{i+1,1} a_{i+1,2} \cdots a_{i+1,q} are equal. Then Ai+1A_{i+1} is stored as a single control character whose code is jj, followed by the remaining characters ai+1,j+1ai+1,j+2ai+1,qa_{i+1,j+1} a_{i+1,j+2} \cdots a_{i+1,q}. Its stored length is therefore 1+(qj)1 + (q - j).

If j=0j = 0 (the two strings have no common prefix), the string is still prefixed by one control byte, so its stored length is one greater than its original length.

Compute the minimal total stored length of the whole sequence.

Input

The first line contains an integer NN. Each of the next NN lines contains one string AiA_i.

Output

Print a single integer: the minimal total length of the compressed strings.

Constraints

  • 1N100001 \le N \le 10000
  • 1length(Ai)2551 \le \operatorname{length}(A_i) \le 255