Under construction

Still being built. Things may change

Password Generation

Interview

Time limit2sMemory limit128 MB

Summary
Generate all length-L increasing letter combinations from a given set of C letters that contain at least one vowel and two consonants, printed in lexicographic order.
Level

Easy3 of 10

Topics
Backtracking, Brute force, String
Solved
No attempts yet

Problem

A lab has installed a new security system that opens with a password instead of a key.

A password consists of L distinct lowercase English letters. It must contain at least one vowel (a, e, i, o, u) and at least two consonants. The letters in a password are assumed to appear in increasing alphabetical order. abc has the required form, while bac does not.

Given the C letters that may be used, write a program that prints every possible password satisfying these conditions in lexicographic order.

Input

The first line contains two integers L and C. (3 <= L <= C <= 15)

The second line contains C lowercase English letters separated by spaces. All given letters are distinct.

Output

Print every password satisfying the conditions in lexicographic order, one per line.

Examples1

  1. Example 1

    Input
    4 6
    a t c i s w
    
    Expected output
    acis
    acit
    aciw
    acst
    acsw
    actw
    aist
    aisw
    aitw
    astw
    cist
    cisw
    citw
    istw