An anagram of a string is any string that can be formed using the same letters as the original. (We consider the original string an anagram of itself as well.) For example, the string ACM has the following 6 anagrams, as given in alphabetical order:
ACM AMC CAM CMA MAC MCA
As another example, the string ICPC has the following 12 anagrams (in alphabetical order):
CCIP CCPI CICP CIPC CPCI CPIC ICCP ICPC IPCC PCCI PCIC PICC
Given a string and a rank K, you are to determine the Kth such anagram according to alphabetical order.
Warning: The value of K could be almost 245 in the largest tests, so you should use type long in Java, or type
ACM 5 ICPC 12 REGION 274 # 0
MAC PICC IGNORE