100 #ABC215C. [ABC215C] One More aab aba baa

[ABC215C] One More aab aba baa

Score : 300300 points

Problem Statement

Find the KK-th lexicographically smallest string among the strings that are permutations of a string SS.

What is a permutation of a string?

A string AA is said to be a permutation of a string BB when any character occurs the same number of times in AA and BB.

Constraints

  • 1S81 \le |S| \le 8
  • SS consists of lowercase English letters.
  • There are at least KK distinct strings that are permutations of SS.

Input

Input is given from Standard Input in the following format:

SS KK

Output

Print the answer.

aab 2
aba

There are three permutations of a string aab: {\{ aab, aba, baa }\}. The 22-nd lexicographically smallest of them is aba.

baba 4
baab
ydxwacbz 40320
zyxwdcba