Without consecutive consonants P98563


Statement
 

pdf   zip

thehtml

Given n lowercase letters, print all the ways to arrange them so that no two consonants are consecutive.

Input

Input consists of the number of letters n, followed by n lowercase letters, all different.

Output

Print, in alphabetical order, all the words without two consecutive consonants that can be made up using all the letters exactly once. There will always be at least one possible word.

Public test cases
  • Input

    3
    aie
    

    Output

    aei
    aie
    eai
    eia
    iae
    iea
    
  • Input

    1
    z
    

    Output

    z
    
  • Input

    3
    yxu
    

    Output

    xuy
    yux
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++