Concatenated words

Given nn words, print all the ways to concatenate them so that there are no two equal adjacent letters.

Input

Input consists of an nn between 1 and 8, followed by nn words, each one made up of between 1 and 10 lowercase letters. No word has two adjacent equal letters.

Output

Print all the correct ways to concatenate the nn words, one per line.

Information about the checker

You can print the solutions to this exercise in any order.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T22:03:16.032Z

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