Legible Words II X81292


Statement
 

pdf   zip

html

In computer science we often consider words made of letters. Again, we define that a word is legible iff there are no three consecutive consonants.

You have already calculated the number of legible words of given length. But now you feel that simply counting the words is not enough. Your new challenge is to calculate the i-th of these words, according to the Measharan alphabet.

Input

Input consists of several cases. Each case consists of three lines: W (the string of all letters in the Measharan alphabet), T (the types of all letters in W), N I (where N the length of the words to consider, and I is the index of the word to output).

W1 is the first letter in the alphabet, W2 is the second, and so on. Ti is c iff Wi is a consonant, and v iff Wi is a vowel. Each letter is encoded as a lowercase letter of the English alphabet (a..z).

As in Legible Words, it is guaranteed that the total number of N-letter words will never be greater than 1018, and 1 ≤ N ≤ 100.

After the last case the input contains a line containing only 0.

Output

Output the i-th N-letter legible word, according to the lexicographic ordering (if we have two words u, v such that u1 u2uk = v1 v2vk, and uk+1vk+1, and uk+1 comes before vk+1 in W, then u is before v in the lexicographic ordering).

Public test cases
  • Input

    abcde
    vcccv
    3 25
    abcde
    vcccv
    3 26
    abcde
    vcccv
    3 30
    abcde
    vcccv
    3 31
    abcde
    vcccv
    3 32
    abcde
    vcccv
    3 98
    0
    

    Output

    aee
    baa
    bae
    bba
    bbe
    eee
    
  • Information
    Author
    Eryk Kopczynski
    Language
    English
    Official solutions
    Unknown.
    User solutions
    C++