#d11402. 单词合并

单词合并

Word Merging

Problem Description

xyq has nn words and wants to turn them into a single sentence.

Concretely, he merges the words two at a time, from left to right. When merging two words, find the largest i≥0i \ge 0 such that the length-ii suffix of the first word equals the length-ii prefix of the second word, then append the part of the second word after position ii to the end of the first word.

Output the final merged word.

Input Format

The first line contains an integer nn (n≤105n \le 10^5), the number of words.

The next line contains nn strings ss, separated by spaces, representing the words. The total length of all strings is guaranteed not to exceed 10610^6.

Output Format

One line containing a single string: the merged answer.

Sample Input

5
sample please ease in out

Sample Output

sampleaseinout