bolt
Try our new interface for solving problems
Problems

# Permutations

Time limit 5 seconds
Memory limit 128 MiB

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 { 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 magnitude. The permutations are said to be listed in lexicographic order. Note that the permutation in position 4 is 3 52 while the permutation in the last position, which is 6, 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 just another way of describing lexicographic order. Note that the permutation in position 4 is b i n e while the permutation in position 20 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 data

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 10 and is followed by a space and a number that gives the position of the required permutation.

## Output data

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 "No permutation".

## Examples

Input example #1
235 4
bein 20
123456 700
mnpqr 130
tuvwxyz 4000

Output example #1
235 4 = 352
bein 20 = nbie
123456 700 = 651342
mnpqr 130 = No permutation
tuvwxyz 4000 = ywuxvzt

Source ACM ICM Philippines Multi-Provincial Programming Contest 2013