eolymp
bolt
Try our new interface for solving problems
Problems

Grouped Word

Grouped Word

A word is grouped if, for each letter in the word, all occurrences of that letter form exactly one consecutive sequence. In other words, no two equal letters are separated by one or more letters that are different. For example, the words "ccazzzzbb" and "code" are grouped, while "aabbbccb" and "eolimpeolimp" are not. A grouped word was divided into several parts. You are given all the parts in random order. Reconstruct the original word and print it. \InputFile Consists of multiple test cases. The first line of each test case contains the nuumber \textbf{n} (1 ≤\textbf{ n ≤ 50)} of word parts. The second line contains \textbf{n} parts of the word in random order. The length of each part is no more than \textbf{20} symbols '\textbf{a}' - '\textbf{z}'. \OutputFile For each test case print in a separate line the original word. If there is more than one possible answer, print "\textbf{MANY}" instead. If no grouped word could have resulted in the given parts, print "\textbf{IMPOSSIBLE}" instead.
Time limit 1 second
Memory limit 128 MiB
Input example #1
3
aaa a aa
2
ab bba
4
orr rd woo www
1
abcb
Output example #1
aaaaaa
IMPOSSIBLE
wwwwooorrrd
IMPOSSIBLE