CF58D.Calendar

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

BerOilGasDiamondBank has branches in nn cities, at that nn 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/2n/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 dd 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/2n/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.

输入格式

The first line contains an integer nn ( 1<=n<=1041<=n<=10^{4} , nn is even) which is the number of branches. Then follow nn 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 dd ( dd 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.

输出格式

Print n/2n/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.

输入输出样例

  • 输入#1

    4
    b
    aa
    hg
    c
    .
    

    输出#1

    aa.b
    c.hg
    
  • 输入#2

    2
    aa
    a
    !
    

    输出#2

    a!aa
    
  • 输入#3

    2
    aa
    a
    |
    

    输出#3

    aa|a
    
首页