4860: The Smallest String Concatenation 最小的字符串串联

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:12 通过:4

题目描述

你会得到一个 n 个字符串的列表 a1,a 2,...,a n。您希望按某种顺序将它们连接在一起,以便生成的字符串在字典顺序上最小。
给定字符串列表,输出字典顺序最小的串联。

You're given a list of n strings a1,a2,...,an. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation.
Input
The first line contains integer n − the number of strings (1≤n≤5·104).
Each of the next n lines contains one string ai (1≤|ai|≤50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.
Output
打印唯一的字符串 a − 字典顺序最小的字符串串联。
例子
Input
4
abba
abacaba
bcd
er
Output
abacabaabbabcder
Input
5
x
xx
xxa
xxaa
xxaaa
Output
xxaaaxxaaxxaxxx
Input
3
c
cb
cba
Output
cbacbc

输入格式

第一行包含整数 n − 字符串数 (1≤n≤5·104)。
接下来的 n 行中的每一行都包含一个字符串 i1≤|ai|≤50) 仅由小写英文字母组成。字符串长度的总和不会超过
5·104.

输出格式

打印唯一的字符串 a − 字典顺序最小的字符串串联。

输入样例 复制

4
abba
abacaba
bcd
er

输出样例 复制

abacabaabbabcder