New Cow Brands

No attempts yetTime limit1sMemory limit128 MB

Problem

Farmer John is replacing the red-hot branding iron with RFID tags for his cows.

Each RFID tag stores a code that is exactly $N$ ($3 \le N \le 15$) characters long. Every character is an uppercase letter from A to Z, and no letter appears more than once within a single code.

The letter used at each position of the code is chosen from a fixed set of allowed letters for that position. Each such set is listed in alphabetical order.

A machine lists every valid code in alphabetical (lexicographic) order and numbers them starting from $1$. Each new batch of cows uses the next unused block of codes, and Farmer John keeps track of how many codes have already been used.

Given the numbers $\text{start}$ and $\text{finish}$ of the first and last codes of the next batch, with $1 \le \text{start} < \text{finish} \le 22{,}000{,}000$ and $\text{finish} - \text{start} < 2000$, print, in alphabetical order, every code numbered from $\text{start}$ to $\text{finish}$ inclusive.

Input

  • The first line contains three space-separated integers $N$, $\text{start}$, and $\text{finish}$.
  • Each of the next $N$ lines contains a string of $1$ to $26$ distinct uppercase letters, listed in alphabetical order: the allowed letters for that position of the code.

Output

Print $\text{finish} - \text{start} + 1$ lines. The $i$-th line contains the code numbered $\text{start} + i - 1$ (codes are numbered from $1$ in alphabetical order).