#P3065. [USACO12DEC] First! G

    ID: 2104 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>字符串2012USACO哈希,HASH字典树,Trie 树

[USACO12DEC] First! G

Description

Bessie has been playing with strings again. She found that by changing the order of the alphabet she could make some strings come before all the others lexicographically (dictionary ordering).

For instance Bessie found that for the strings omm, moo, mom, and ommnom she could make mom appear first using the standard alphabet and that she could make omm appear first using the alphabet abcdefghijklonmpqrstuvwxyz. However, Bessie couldn't figure out any way to make moo or ommnom appear first.

Help Bessie by computing which strings in the input could be lexicographically first by rearranging the order of the alphabet. To compute if string XX is lexicographically before string YY find the index of the first character in which they differ, jj. If no such index exists then XX is lexicographically before YY if XX is shorter than YY. Otherwise XX is lexicographically before YY if XjX_j occurs earlier in the alphabet than YjY_j.

Input Format

* Line 11: A single line containing N(1N30,000)N (1 \le N \le 30,000), the number of strings Bessie is playing with.

* Lines 21+N2\sim 1+N: Each line contains a non-empty string. The total number of characters in all strings will be no more than 300,000300,000. All characters in input will be lowercase characters a through z. Input will contain no duplicate strings.

Output Format

* Line 11: A single line containing KK, the number of strings that could be lexicographically first.

* Lines 21+K2 \sim 1+K: The (1+i)(1+i) th line should contain the ith string that could be lexicographically first. Strings should be output in the same order they were given in the input.

4
omm
moo
mom
ommnom

2
omm
mom

Hint

The example from the problem statement.

Only omm and mom can be ordered first.