Substrings

Order all given strings as the consecutive length-L windows of one string of length L+N-1 and print the lexicographically smallest such string.

Hard8GraphDFSStringSortingNo attempts yetTime limit2sMemory limit256 MB

Problem

Since phage ΦX174 was sequenced in 1977, the DNA of thousands of organisms has been decoded and stored in databases. Almost every genome sequenced today is read by shotgun sequencing. The method does not read whole chromosomes. It produces the sequences of many thousands of short fragments, each one tens to hundreds of nucleotides long. The ends of the fragments overlap, so aligning the overlaps and joining the fragments in the right order rebuilds the original sequence. Assembly gets harder as the genome gets larger, and assembly algorithms are a major research area in bioinformatics.

This problem is assembly cut down to its simplest form. You are given NN strings, all of length LL. Find a string SS of length L+N1L + N - 1 such that every one of the NN given strings is a substring of SS and no two of them start at the same position. Because SS has length L+N1L + N - 1, a substring of length LL can start at exactly NN positions, so each input string takes one of those positions.

Input

The input has NN lines, and each line holds one string of length LL. NN and LL are not given separately. The strings use English uppercase and lowercase letters only, and uppercase and lowercase letters count as different characters. 2N1000002 \le N \le 100000, 2L1000002 \le L \le 100000, and N×L5×1024×1024N \times L \le 5 \times 1024 \times 1024. Every input has at least one answer.

Output

Print the string of length L+N1L + N - 1 on one line. The NN substrings of length LL cut from it must equal the NN input strings exactly, duplicates included. If several strings satisfy the condition, print the lexicographically smallest one. Characters compare by their ASCII value, so every uppercase letter comes before every lowercase letter.