Ruins X18624


Statement
 

pdf   zip

html

Recent excavations have revealed an ancient extinct language. Thanks to the ruins found, experts have deduced that there were vowels and consonants, and that all words could be formed, with one sole exception: a word could not have two or more consecutive vowels. For example, with the two vowels a and e, and consonant b, 11 words with three letters could be formed: aba, abb, abe, bab, bba, bbb, bbe, beb, eba, ebb, ebe.

Which words of size n could be formed with m given letters?

Input

Input consists of several cases, each with n and m, followed by m different lowercase letter. It holds that n ≥ 1, 2 ≤ m ≤ 26, and that each case has at least one vowel and one consonant.

Output

For each case, write in lexicographical order all words of length n that can be built with the m given letters. Write a line with 10 hyphens after each case.

Public test cases
  • Input

    3 3
    aeb
    
    1 2
    az
    
    3 2
    pe
    

    Output

    aba
    abb
    abe
    bab
    bba
    bbb
    bbe
    beb
    eba
    ebb
    ebe
    ----------
    a
    z
    ----------
    epe
    epp
    pep
    ppe
    ppp
    ----------
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++