#P2462. [SDOI2007] 游戏

    ID: 1468 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2007各省省选山东Special Judge

[SDOI2007] 游戏

Description

Xiao Mumu and Xiao Dengzi are two smart kids who started learning English when they were five.

Their English teacher taught them a very simple game. The teacher gave them a list of English words, all in lowercase and without special symbols. The word list is as follows:

ab arc arco bar bran carbon carbons

cobra crab crayon narc

They are asked to find a word chain from the list. The rules of the chain are:

  1. Every letter that appears in the previous word must also appear in the next word, and the number of occurrences of each letter in the next word must be at least that in the previous word.

  2. The length of the next word must be exactly 1 more than the length of the previous word.

For the above example, a valid chain is:

ab bar crab cobra carbon carbons

Whoever makes a longer chain wins. Xiao Mumu definitely does not want to lose, so he comes to you and pesters you until you help him just to avoid being bothered. As for Xiao Dengzi? Maybe he went to find Guo Daniu. Hehe, a programming contest between you and Guo Daniu? Good luck!

Description

Input Format

The first line contains an integer nn (1n100001 \le n \le 10000).
Each of the next nn lines contains one word, with length at most 100100.

Output Format

On the first line, output the maximum chain length ansans.
On each of the next ansans lines, output one word representing your chain.

ab
arc
arco
bar
bran
carbon
carbons
cobra
crab
crayon
narc
6
ab
bar
crab
cobra
carbon
carbons

Hint

Translated by ChatGPT 5