Legible Words II X81292


Statement
 

pdf   zip

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 ii-th of these words, according to the Measharan alphabet.

Input

Input consists of several cases. Each case consists of three lines: WW (the string of all letters in the Measharan alphabet), TT (the types of all letters in WW), NIN\ \ I (where NN the length of the words to consider, and II is the index of the word to output).

W1W_1 is the first letter in the alphabet, W2W_2 is the second, and so on. TiT_i is c iff WiW_i is a consonant, and v iff WiW_i 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 NN-letter words will never be greater than 101810^{18}, and 1N1001 \leq N \leq 100.

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

Output

Output the ii-th NN-letter legible word, according to the lexicographic ordering (if we have two words uu, vv such that u1u2uk=v1v2vku_1 u_2 \ldots u_k = v_1 v_2 \ldots v_k, and uk+1vk+1u_{k+1} \neq v_{k+1}, and uk+1u_{k+1} comes before vk+1v_{k+1} in WW, then uu is before vv 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++