Problem D
Names
There are $n$ ($2 \leq n \leq 300$) students, each of which has a string of length between $1$ and $300$ as his name. Since their names are very long, they want to change their names. The new names must be non-empty subsequences of the initial name, and must also be pair-wise distinct (however the old names are not necessarily distinct). Your task is to choose names for them, such that the longest new name is as short as possible.
A subsequence of a string $s = s_1s_2...s_ k$ is obtained by deleting some (but not all and possibly none) of the characters of the string. Formally, it’s any string of the form $s_{m_1}s_{m_2}...s_{m_ l}$ where $1 \leq m_1 < m_2 < ... < m_ l \leq k$ is an increasing sequence of integers in $[1,k]$.
Input
The first line consists of an integer $2 \leq n \leq 300$, the number of students.
Then follows $n$ lines containing one string of between $1$ and $300$ each, denoting the name of $i^{th}$ student. Each name consists only of lower-case English letters.
Output
If there is no solution, output $-1$.
Otherwise, output $n+1$ lines, with the first line containing an integer $m$, denoting the length of the longest new names, and the $(i+1)^{th}$ line containing the new name of the $i^{th}$ student.
If there are multiple solutions, you may output anyone of them.
Sample Input 1 | Sample Output 1 |
---|---|
4 aw we shu le |
1 a w u l |