This page is still under construction.

Parts of this page are still being built. What you see may change.

XEN 3166

Interview

Time limit2sMemory limit512 MB

Summary
Assign each country a length-K subsequence starting with its first letter so that code order matches name lexicographic order, or report impossible.
Level

Hard8 of 10

Topics
Greedy, String, Sorting
Solved
No attempts yet

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 T=T1T2…T∣T∣T = T_1T_2\ldots T_{|T|} is a subsequence of a string S=S1S2…S∣S∣S = S_1S_2\ldots S_{|S|} if integers 1≤u1<u2<⋯<u∣T∣≤∣S∣1 \le u_1 < u_2 < \cdots < u_{|T|} \le |S| exist with Sui=TiS_{u_i} = T_i for all 1≤i≤∣T∣1 \le i \le |T|. For example, "ID", "IN", and "IND" are subsequences of "INDIA", but "IDN", "INN", and "Z" are not subsequences of "INDIA".

A string S=S1S2…S∣S∣S = S_1S_2\ldots S_{|S|} is lexicographically smaller than a string T=T1T2…T∣T∣T = T_1T_2\ldots T_{|T|} if at least one of the following holds:

  • ∣S∣<∣T∣|S| < |T| and Si=TiS_i = T_i for all 1≤i≤∣S∣1 \le i \le |S|.
  • An index ii exists with Si<TiS_i < T_i and Sj=TjS_j = T_j for all 1≤j<i1 \le j < i.

For example, suppose there are two countries, K=2K = 2, 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 (1≤N≤10001 \le N \le 1000, 1≤K≤2001 \le K \le 200), 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.

Examples2

  1. Example 1

    Input
    2 2
    INDIA
    INDONESIA
    
    Expected output
    YES
    IA
    ID
    
  2. Example 2

    Input
    3 2
    IBAA
    IAAA
    IAAC
    
    Expected output
    NO