Compensated words

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’.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T21:33:02.364Z

© Jutge.org, 2006–2026.
https://jutge.org