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.