#K54862. Book Titles Special Pattern
Book Titles Special Pattern
Book Titles Special Pattern
You are given n book titles. Your task is to determine if it is possible to rearrange the titles in a special pattern such that for every \(1 \leq i \leq \frac{n}{2}\), the i-th title and the (n-i+1)-th title are anagrams of each other.
Note: The pattern can only be formed if n is even, and in each anagram group, the number of titles must be even. If such a rearrangement exists, output "YES" in the first line followed by the rearranged order (one title per line). Otherwise output "NO".
Examples:
- For
n = 4
and titles[listen, silent, evil, vile]
, one valid rearrangement is:
YES
listen
evil
vile
silent
Here, listen and silent are anagrams, as well as evil and vile. - For
n = 3
and titles[rat, tar, art]
, it is impossible to form a special pattern (since n is odd), so the answer is "NO".
inputFormat
The first line contains an integer n representing the number of book titles.
The following n lines each contain a title (a non-empty string).
Input is given via standard input (stdin).
outputFormat
If a special rearrangement exists, output "YES" in the first line, followed by n lines each containing one title in the rearranged order. The rearrangement must satisfy the condition that for every \(1 \leq i \leq \frac{n}{2}\), the i-th and the (n-i+1)-th titles are anagrams.
If no valid rearrangement exists, output a single line containing "NO".
Output should be written to standard output (stdout).
## sample4
listen
silent
evil
vile
YES
listen
evil
vile
silent
</p>