Forbidden words P89318


Statement
 

pdf   zip

Write a program that, given a number nn, prints all the words that are a permutation of the first nn lowercase letters, with one restriction: there cannot be two letters xx and yy such that yy is immediately to the right of xx in the word and yy is the letter following xx in the alphabet.

Input

Input consists of a natural number nn between 1 and 9.

Output

Print in order and one per line all the words that satisfy the restriction.

Public test cases
  • Input

    3
    

    Output

    acb
    bac
    cba
    
  • Input

    4
    

    Output

    acbd
    adcb
    badc
    bdac
    bdca
    cadb
    cbad
    cbda
    dacb
    dbac
    dcba
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python