← Home
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type WS struct {
	word string
	side int
}

func wordLess(a, b string, sep byte) bool {
	la, lb := len(a), len(b)
	m := la
	if lb < m {
		m = lb
	}
	for i := 0; i < m; i++ {
		if a[i] != b[i] {
			return a[i] < b[i]
		}
	}
	if la == lb {
		return false
	}
	if sep < 'a' {
		return la < lb
	}
	return la > lb
}

func processSame(words []string, sepStr string) []string {
	sort.Strings(words)
	m := len(words) / 2
	res := make([]string, m)
	for i := 0; i < m; i++ {
		res[i] = words[i] + sepStr + words[i+m]
	}
	return res
}

func processDiff(a, b []string, sep byte, sepStr string) []string {
	combined := make([]WS, 0, len(a)+len(b))
	for _, w := range a {
		combined = append(combined, WS{w, 0})
	}
	for _, w := range b {
		combined = append(combined, WS{w, 1})
	}
	sort.Slice(combined, func(i, j int) bool {
		return wordLess(combined[i].word, combined[j].word, sep)
	})

	qa := make([]string, 0, len(a))
	qb := make([]string, 0, len(b))
	ha, hb := 0, 0
	res := make([]string, 0, len(a))

	for _, x := range combined {
		if x.side == 0 {
			if hb < len(qb) {
				res = append(res, qb[hb]+sepStr+x.word)
				hb++
			} else {
				qa = append(qa, x.word)
			}
		} else {
			if ha < len(qa) {
				res = append(res, qa[ha]+sepStr+x.word)
				ha++
			} else {
				qb = append(qb, x.word)
			}
		}
	}

	return res
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

	var n int
	fmt.Fscan(in, &n)

	groups := make([][]string, 11)
	sumLen := 0
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		groups[len(s)] = append(groups[len(s)], s)
		sumLen += len(s)
	}

	var d string
	fmt.Fscan(in, &d)
	sep := d[0]
	sepStr := d

	k := 2 * sumLen / n
	labels := make([]string, 0, n/2)

	for l := 1; l <= 10; l++ {
		r := k - l
		if r < 1 || r > 10 || l > r {
			continue
		}
		if l == r {
			if len(groups[l]) > 0 {
				labels = append(labels, processSame(groups[l], sepStr)...)
			}
		} else {
			if len(groups[l]) > 0 {
				labels = append(labels, processDiff(groups[l], groups[r], sep, sepStr)...)
			}
		}
	}

	sort.Strings(labels)
	for _, s := range labels {
		fmt.Fprintln(out, s)
	}
}