A double linear crossword of length L is a string of L lowercase alphabetic characters arranged in a line in such a way that there are at least two methods (so called decompositions) to split this string into the words from the given list. Look at the example for L=17:
| | | |
a n d a t a r e a l l a s t a s k
| | | | |
The words were taken from the following list: all, an, and, are, area, as, ask, at, data, last, or, read, real, task.
The words from the first decomposition may not appear in the second one and vice versa. In addition, no word can be repeated in any decomposition.
No word in one decomposition can end in the same place of the string where a word in the other composition ends, except, naturally, for the end of the string (otherwise the crossword can be separated into two independent crosswords). One of the compositions may consist of a single word.
You should write a program to construct the first, in lexicographic order, double linear crossword of length L for a given list of words.
Strings are arranged in the lexicographic order with respect of the following rules:
- If the first letter of a string appears in latin alphabet before the first letter of another string, then the former string precedes in lexicographic order.
- If the first letters of some strings match, then the corresponding letters of these strings are compared until they stop matching.
- If a mismatching is not found, the shorter string goes first.