Under construction

Still being built. Things may change

Short Message 2

Interview

Time limit1sMemory limit1024 MB

Summary
Given N planet names made of lowercase letters, find the shortest string that contains every name as a substring.
Level

Medium5 of 10

Topics
Dynamic programming, Bit manipulation, String
Solved
No attempts yet

Problem

The Space Research Center has identified NN planets, each with a name SiS_i made up only of lowercase Latin letters. The researchers think that if some of these planets have intelligent life, they will reply to a message that contains the planet's name.

Sending cosmic messages is expensive, so we need a message that is as short as possible and contains all NN planet names as substrings.

Recall that a string ss is a substring of a string tt if ss can be obtained from tt by deleting some characters from the beginning and the end of tt.

Input

The first line of the input file contains the number of planets NN. Each of the next NN lines contains one planet name SiS_i.

Output

Print on the single line of the output file a message made of lowercase Latin letters that contains all NN planet names as substrings.

Examples1

  1. Example 1

    Input
    4
    aba
    ac
    ba
    caab
    
    Expected output
    abaaccaaba