Antipalindromic words P89248


Statement
 

pdf   zip

In this problem, we say that a word is antipalindromic if it does not contain any subword that is a palindrome (with the exception of empty subwords and single letters). Write a program that prints all the antipalindromic words of length nn that can be made up with the first xx lowercase letters.

Input

Input consists of nn and xx. Suppose 1≤n≤501 \le n \le 50 and 1≤x≤261 \le x \le 26.

Output

Print, in alphabetic order, all the antipalindromic words of length nn that can be made up with the first xx lowercase letters.

Public test cases
  • Input

    8 3
    

    Output

    abcabcab
    acbacbac
    bacbacba
    bcabcabc
    cabcabca
    cbacbacb
    
  • Input

    3 4
    

    Output

    abc
    abd
    acb
    acd
    adb
    adc
    bac
    bad
    bca
    bcd
    bda
    bdc
    cab
    cad
    cba
    cbd
    cda
    cdb
    dab
    dac
    dba
    dbc
    dca
    dcb
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++