Codeforces Beta Round 54 (Div. 2)
D
Calendar
Codeforces
2000
原题
← CE →
翻译中…

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.

翻译中…

Input

翻译中…

The first line contains an integer $*n*$ ($1 ≤ *n* ≤ 10^{4}$, $*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.

翻译中…

样例

Input #1
4
b
aa
hg
c
.
Output #1
aa.b
c.hg
InputCopy OutputCopy
Input #2
2
aa
a
!
Output #2
a!aa
InputCopy OutputCopy
Input #3
2
aa
a
|
Output #3
aa|a
InputCopy OutputCopy
题目信息
题号
58D
时间限制
2 s
内存限制
256 MB
标签
贪心
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。