Given words, print all the ways to concatenate them so that there are no two equal adjacent letters.
Input consists of an between 1 and 8, followed by words, each one made up of between 1 and 10 lowercase letters. No word has two adjacent equal letters.
Print all the correct ways to concatenate the words, one per line.
You can print the solutions to this exercise in any order.
Input
2 z abcdz
Output
zabcdz
Input
3 adefghijka b cxyzc
Output
adefghijkabcxyzc adefghijkacxyzcb badefghijkacxyzc bcxyzcadefghijka cxyzcadefghijkab cxyzcbadefghijka
Input
2 ie ei
Output
Input
3 a b b
Output
bab bab