5050: Calendar日历

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:4 通过:4

题目描述

D. Calendar
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n/2 lines of strictly equal length, each of which contains exactly two names and exactly one separator character between them. The name of every city should be used in the calendar exactly once. For historical reasons the symbol d is used as the separator of words in the calendar.
The BerOilGasDiamondBank management wants to show that all its branches are equally important to it, that's why the order of their appearance in the calendar should be following: if we "glue"(concatinate) all the n/2 calendar lines (from top to bottom) to make a single line, then the lexicographically minimal line is obtained. No separator character will be used to separate calendar lines. For example, if the lines are "bertown!berville", "newberville!bera", then the resulting line is "bertown!bervillenewberville!bera". In some sense one has to find the lexicographically minimal calendar, where the comparison of calendars happens line by line.
Help BerOilGasDiamondBank and construct the required calendar.

BerOilGasDiamondBank在n个城市设有分行,n是偶数。银行管理层希望发布一个日历,将所有这些城市的名称写在两列中:日历应由 n / 2 行长度严格相等的行组成,每行都包含两个名称,它们之间只有一个分隔符。每个城市的名称应该在日历中使用一次。由于历史原因,符号 d 用作日历中单词的分隔符。

BerOilGasDiamondBank 管理层希望表明其所有分支机构对它同样重要,这就是为什么它们在日历中出现的顺序应该遵循:如果我们“粘合”(连接)所有 n / 2 个日历行(从上到下)形成一条线,那么获得字典顺序最小的行。不会使用分隔符来分隔日历行。例如,如果行是“bertown!berville”,“newberville!bera”,则生成的行是“bertown!bervillenewberville!bera”。从某种意义上说,人们必须找到字典顺序最小的日历,其中日历的比较逐行进行。

帮助BerOilGasDiamondBank并构建所需的日历。


Input
The first line contains an integer n (1≤n≤104, n is even) which is the number of branches. Then follow n lines which are the names of the cities. All the names consist of lowercase Latin letters; their lengths are no less than 1 and no more than 10 symbols. The next line contains a single symbol d (d has an ASCII-code from 33 to 126 inclusively, excluding lowercase Latin letters) which is the separator between words in the calendar lines. It is guaranteed that the calendar is possible to be constructed and all the names are different.
Output
Print n/2 lines of similar length which are the required calendar. Every line should contain exactly two words and exactly one separator between them. If there are several solutions, print the lexicographically minimal one. The lexicographical comparison of lines is realized by the "<" operator in the modern programming languages.
Examples
Input
4
b
aa
hg
c
.
Output
aa.b
c.hg
Input
2
aa
a
!
Output
a!aa
Input
2
aa
a
|
Output
aa|a

输入样例 复制


输出样例 复制