Məsələlər
Permutations
Permutations
A permutation of a set is just an arrangement of all the distinct elements of the set. For example, all the permutations of the set \textbf{\{ 2, 3, 5\}} are given below.
\textbf{2 3 5}
\textbf{2 5 3}
\textbf{3 2 5}
\textbf{3 5 2}
\textbf{5 2 3}
\textbf{5 3 2}
If each permutation is regarded as a number, the permutations in the above list are arranged in increasing magnitude. The permutations are said to be listed in lexicographic order. Note that the permutation in position \textbf{4} is \textbf{3 5} \textbf{2} while the permutation in the last position, which is \textbf{6}, is \textbf{5 3 2}.
For another example, all the permutations of the set \textbf{\{ b, e, i, n \}} are listed in tabular form below.
\textbf{b e i n e b i n i b e n n b e i}
\textbf{b e n i e b n i i b n e n b i e}
\textbf{b i e n e i b n i e b n n e b i}
\textbf{b i n e e i n b i e n b n e i b}
\textbf{b n e i e n b i i n b e n i b e}
\textbf{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 just another way of describing lexicographic order. Note that the permutation in position \textbf{4} is \textbf{b i n e} while the permutation in position \textbf{20} is \textbf{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.
\InputFile
The input consists of one or more input lines. Each input line consists of a string that is composed either entirely of distinct letters or entirely of distinct digits. The letters or digits are already arranged in order. The length of the string is at most \textbf{10} and is followed by a space and a number that gives the position of the required permutation.
\OutputFile
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, then the output should indicate "\textbf{No permutation}".
Giriş verilənləri #1
235 4 bein 20 123456 700 mnpqr 130 tuvwxyz 4000
Çıxış verilənləri #1
235 4 = 352 bein 20 = nbie 123456 700 = 651342 mnpqr 130 = No permutation tuvwxyz 4000 = ywuxvzt