#P1061. Jam Number Sequence

    ID: 12634 Type: Default 1000ms 256MiB

Jam Number Sequence

Jam Number Sequence

Jam is a quirky scientist who avoids Arabic numerals in favor of lowercase letters, believing that this makes the world more colorful. In his numbering system, every "number" has the same number of digits (letters), and the letters are arranged in the usual alphabetical order. In a Jam number, each letter is distinct and appears in strictly increasing order. For example, if Jam specifies the letter range from $2\sim10$ (which corresponds to the letters {b, c, d, e, f, g, h, i, j}), then for numbers of fixed length 5, the Jam number immediately after bdfij is bdghi (i.e. there exists no Jam number P such that bdfij < P < bdghi).

Your task is to read from the input a Jam number together with the allowed letter range, and output the next 5 Jam numbers in order. If there are fewer than 5 subsequent Jam numbers, output all that exist.

Note: The allowed letter range is given as two integers m and n on the first line. They indicate that you may only use the letters corresponding to positions $m$ to $n$ of the alphabet (i.e. letter m is $\mathtt{chr}(\text{ord}('a')+m-1)$). The second line contains the current Jam number.

inputFormat

The input consists of two lines:

  1. The first line contains two integers m and n ($1 \le m < n \le 26$), representing the allowed range of lowercase letters (from $\mathtt{chr}(\text{ord}('a')+m-1)$ to $\mathtt{chr}(\text{ord}('a')+n-1)$).
  2. The second line contains a Jam number: a string of lowercase letters of fixed length, in strictly increasing order.

outputFormat

Output the next 5 Jam numbers (one per line). If there are fewer than 5 subsequent Jam numbers, output all of them.

sample

2 10
bdfij
bdghi

bdghj bdgij bdhij befgh

</p>