XEN 3166
InterviewTime limit2sMemory limit512 MB
Assign each country a length-K subsequence starting with its first letter so that code order matches name lexicographic order, or report impossible.
Problem
There are N countries in the world, numbered 1 to N. Each country has a name and a code. Both are strings, and no two countries share the same name. In this problem every string consists only of uppercase English letters (A-Z).
One widely used code standard is ISO 3166, published by ISO. Xenia noticed that its order does not match the order of names. For example, "INDIA" has code "IN" while "INDONESIA" has code "ID". In dictionary order "INDONESIA" comes after "INDIA", but "IN" comes after "ID".
To fix this, Xenia defines her own standard, XEN 3166. Its rules are:
- The code of each country is a subsequence of its name.
- The first letter of each code equals the first letter of its name.
- The length of each code is exactly K.
- If a country with name S has code S' and a country with name T has code T', then S is lexicographically smaller than T if and only if S' is lexicographically smaller than T'.
A string is a subsequence of a string if integers exist with for all . For example, "ID", "IN", and "IND" are subsequences of "INDIA", but "IDN", "INN", and "Z" are not subsequences of "INDIA".
A string is lexicographically smaller than a string if at least one of the following holds:
- and for all .
- An index exists with and for all .
For example, suppose there are two countries, , and the names are "INDIA" and "INDONESIA". Valid assignments include the following.
- "ID" for "INDIA" and "IN" for "INDONESIA"
- "IA" for "INDIA" and "ID" for "INDONESIA"
- "II" for "INDIA" and "IO" for "INDONESIA"
Given N, K, and the list of names, assign codes to all countries under the XEN 3166 rules, or report that no such assignment exists.
Input
The first line contains two integers N and K (, ), the number of countries and the length of codes. Each of the next N lines contains one country name. Every name is a string of uppercase English letters (A-Z) with length from 1 to 200000. The sum of lengths over all names does not exceed 200000. No two names are equal.
Output
If an assignment under the XEN 3166 rules exists, print "YES" on the first line (without quotes). Print N more lines, one code per line in input order. The i-th of these lines is the code of the i-th country. If several assignments exist, print any of them.
If no such assignment exists, print "NO" in a single line (without quotes).
Hint
The first sample is the "INDIA" and "INDONESIA" case described in the statement.