Permutations#6248

Permutations

5 secondi
128 megabyte
Molto facile

A permutation of a set is an arrangement of all the distinct elements of that set. For example, all the permutations of the set \{2, 3, 5\} are given below.

2 3 5

2 5 3

3 2 5

3 5 2

5 2 3

5 3 2

If each permutation is regarded as a number, the permutations in the above list are arranged in increasing order. Thus, the permutations are listed in lexicographic order. Note that the permutation in position is 3 5 2, while the last, which is position , is 5 3 2.

For another example, all the permutations of the set \{b, e, i, n\} are listed in tabular form below:

b e i n e b i n i b e n n b e i

b e n i e b n i i b n e n b i e

b i e n e i b n i e b n n e b i

b i n e e i n b i e n b n e i b

b n e i e n b i i n b e n i b e

b n i e e n i b i n e b n i e b

The permutations here are listed in dictionary order, which is another way of describing lexicographic order. Note that the permutation in position is b i n e, while in position it is n b i e.

Given a set of distinct digits or letters, your task is to determine the permutation of the set in a given position when the permutations are assumed to be listed in lexicographic order.

Input

The input consists of one or more lines. Each line consists of a string that is composed either entirely of distinct letters or entirely of distinct digits. The letters or digits are already in order. The length of the string does not exceed , followed by a space and a number that gives the position of the required permutation.

Output

The output consists of one or more lines. Each output line consists of the given input followed by the equal sign and followed by the permutation in the required position. If the given position is beyond the total number of permutations, output "No permutation".

Esempi

Esempio 1

Loading
Loading