9476: ABC215 —— C - One More aab aba baa
[Creator : ]
Description
Find the $K$-th lexicographically smallest string among the strings that are permutations of a string $S$.
What is a permutation of a string?A string $A$ is said to be a permutation of a string $B$ when any character occurs the same number of times in $A$ and $B$.
What is a permutation of a string?A string $A$ is said to be a permutation of a string $B$ when any character occurs the same number of times in $A$ and $B$.
Input
Input is given from Standard Input in the following format:
```
$S$ $K$
```
```
$S$ $K$
```
Output
Print the answer.
Constraints
- $1 \le |S| \le 8$
- $S$ consists of lowercase English letters.
- There are at least $K$ distinct strings that are permutations of $S$.
- $S$ consists of lowercase English letters.
- There are at least $K$ distinct strings that are permutations of $S$.
Sample 1 Input
aab 2
Sample 1 Output
aba
There are three permutations of a string aab: {{ aab, aba, baa }}. The 2-nd lexicographically smallest of them is aba.
Sample 2 Input
baba 4
Sample 2 Output
baab
Sample 3 Input
ydxwacbz 40320
Sample 3 Output
zyxwdcba