Under construction

Still being built. Things may change

Almost Prefix-Free Codes

Time limit2sMemory limit1024 MB

Summary
Choose the largest subset of given words such that the longest common prefix of any two chosen words has length at most k.
Level

Hard8 of 10

Topics
Trie, Tree, Dynamic programming, Greedy
Solved
No attempts yet

Problem

In coding theory, prefix-free codes are used often: sets of words such that no word is a prefix of another. (A word α\alpha is a prefix of a word β\beta if α\alpha can be obtained from β\beta by deleting zero or more characters from its end. For example, the words <<>>, <>, <>, and <> are prefixes of the word <>.) For instance, the set of words <>, <>, and <> is a prefix-free code, while the set <>, <>, <> is not, because <> is a prefix of <>.

Professor Deshifro works at the laboratory for the study of useless information and is researching his new invention: almost prefix-free codes. A set of words is called an almost prefix-free code of level kk if the longest common prefix of any two words in the set has length at most kk. For example, the set <>, <>, <> is an almost prefix-free code of level 2, while the set <>, <>, <> is not, because the longest common prefix of <> and <> has length 3.

The next task Professor Deshifro has assigned to his assistants is the following: given a set of words and a number kk, choose from the given words a maximum set that is an almost prefix-free code of level kk. As the most junior assistant, you have been tasked with writing the corresponding program.

Input

The first line of the input file contains two integers nn and kk: the number of words in the given set and the level of the almost prefix-free code to be built (1≤n≤100 0001 \le n \le 100\,000, 0≤k≤2000 \le k \le 200). The next nn lines contain one word each. The words consist of lowercase Latin letters. The length of each word is from 1 to 200 characters. The total length of all words does not exceed 10610^6. All words are distinct.

Output

On the first line of the output file, print a single number mm: the maximum number of words that can be chosen from the given set so that they form an almost prefix-free code of level kk. The next mm lines must contain the chosen words.

Examples1

  1. Example 1

    Input
    6 2
    aba
    bacaba
    abacaba
    baca
    abac
    caba
    
    Expected output
    3
    aba
    bacaba
    caba