Compensated words X46137


Statement
 

pdf   zip

Consider a word ss of length nn, with only letters ‘a’ and ‘b’. For any prefix pp of ss, let a(p)a(p) be the number of ‘a’ within pp, and let b(p)b(p) be the number of ‘b’ within pp. In this problem, we say that ss is compensated if and only if for every of the n+1n + 1 prefixes pp of ss we have |a(p)b(p)|2\vert a(p) - b(p) \vert \le 2.

For instance, “abbaaabb” is compensated, but “abbaaaab” is not, because “abbaaaa” is a prefix with five ‘a’ and two ‘b’. As other examples, neither “bbb” nor “bbbbbb” are compensated.

Given an nn, print all compensated words of this length.

Input

Input consists of an nn between 1 and 18.

Output

Print in alphabetical order all compensated words with nn characters chosen between ‘a’ and ‘b’.

Public test cases
  • Input

    1
    

    Output

    a
    b
    
  • Input

    4
    

    Output

    aaba
    aabb
    abaa
    abab
    abba
    abbb
    baaa
    baab
    baba
    babb
    bbaa
    bbab
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python