Олимпиадный тренинг

Задача 31900. Iterating over lines #4


Задача

Темы: Рекурсия
In the alphabet of the language of the tribe «tumba-yumba» four letters: "K", "L", "M" and "N". We need to display all possible words consisting of n letters that contain at least two identical letters, not necessarily adjacent. The program should not build other words that do not match the condition. 
 
Input Output
2
KK
LL
MM
NN


(c) K.Yu. Polyakov