Consider all possible selections (combinations) of the letters A, B and C :
A, AB, ABC, AC, B, BC, and C. Here they are sorted into dictionary order. If each selection is assigned an index then the selections correspond to the following indices.
|
There are two parts to the problem: Firstly you must find the index for a particular selection of letters. For example the index of the selection AC is 4. Secondly, you must find a selection n units below this. For example if n = 2, then the required selection is BC (two below AC). |
The input will be three lines. The first line will be a number, k, (1 <= k <= 26), the number of letters in the selection. The selection will be made of the first k letters of the alphabet. (E.g. k = 5, then selections will be made of the five letters, A, B, C, D, and E.) The next line contains a particular selection. You will have to find its index.
The last line contains a number, n, (0 <= n <= 30000). Add n to the index just found and find the corresponding selection.
The output will be one line containing the index of the selection, and another line containing a selection corresponding to the modified index.
Input
3 AC 2
Output
4 BC
(4 is the index of AC, BC is the selection 2 below it.)
Input
4 AC 3
Output
6 B