#3012. [Usaco2012 Dec]First!

[Usaco2012 Dec]First!

题目描述

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\tt omm, moo\tt moo, mom\tt mom, and ommnom\tt ommnom she could make mom\tt mom appear first using the standard alphabet and that she could make omm\tt omm appear first using the alphabet abcdefghijklonmpqrstuvwxyz\tt abcdefghijklonmpqrstuvwxyz. However, Bessie couldn't figure out any way to make moo\tt moo or ommnom\tt 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 X[j]X[j] occurs earlier in the alphabet than Y[j]Y[j].

题目大意:给定 nn 个总长不超过 mm 的互不相同的字符串,现在你可以任意指定字符之间的大小关系。问有多少个串可能成为字典序最小的串,并输出这些串。

输入格式

Line 1: A single line containing nn, the number of strings Bessie is playing with.

Lines 2..1+n: Each line contains a non-empty string. The total number of characters in all strings will be no more than 3×1053\times 10^5. All characters in input will be lowercase characters a\tt a through z\tt z. Input will contain no duplicate strings.

输出格式

Line 1: A single line containing kk, the number of strings that could be lexicographically first.

Lines 2..1+k: The 1+i th line should contain the iith 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

提示

INPUT DETAILS: The example from the problem statement.

OUTPUT DETAILS: Only omm\tt omm and mom\tt mom can be ordered first.

数据规模与约定

对于100%的数据,n3×104n \leq 3\times 10^4m3×105m \leq 3\times 10^5