Module: Prefix function, Z function


Problem

9 /10


Almost unprefixed codes

Problem

In coding theory, unprefixed codes are often used as sets of words, none of which is a prefix. The word α is said to prefix the word β if α is obtained from β by deleting zero or more characters in end. For example, the words a, ab and aba are prefixes of the word aba. For example, the set of words aba, aa and bac is an unprefixed code, while the set of abac, aba< /code>, ba is not present because the word aba is a prefix of the word abac.

 Professor Decipher works in the Useless Information Research Lab and studies his new invention of near-prefix codes. A set of words is called an almost prefix-free code of level k if the greatest common prefix of any two words from the set does not exceed k in length. For example, the set abac, abc, ba is a nearly unprefixed level 2 code, and the set abac, abab, ba do not exist because the longest common prefix of abac and abab is 3.

 The next task that Professor Decifro set for his laboratory assistants is as follows: given a set of words and a number k, it is required to choose from the given words the maximum set, which is almost prefix-free level code k. You, as a junior laboratory assistant, were assigned to write the corresponding program.

 
Input
The first line of the input file contains two integers: n and k the number of words in the given set and the level of almost unprefixed code to be built (\(1<= n <= 100000\), \(0 <= k <= 200\)). The next n lines contain one word each. Words consist of lowercase letters of the Latin alphabet. The length of each word is from 1 to 200 characters. The total length of all words does not exceed \(10^6\). All words are different.
 
Output
Output a single number m - the maximum number of words that can be selected from the given set so that they form an almost unprefixed k level code. 

 

Examples
# Input Output
1
6 2
aba
bacaba
abacaba
baca
abac
caba
3