One More aab aba baa

AtCoder
IDabc215_c
Time2000ms
Memory256MB
Difficulty
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$. ## Constraints * $1 \le |S| \le 8$ * $S$ consists of lowercase English letters. * There are at least $K$ distinct strings that are permutations of $S$. ## Input Input is given from Standard Input in the following format: $S$ $K$ [samples]
Samples
Input #1
aab 2
Output #1
aba

There are three permutations of a string `aab`: ${$ `aab`, `aba`, `baa` $}$. The $2$\-nd lexicographically smallest of them is `aba`.
Input #2
baba 4
Output #2
baab
Input #3
ydxwacbz 40320
Output #3
zyxwdcba
API Response (JSON)
{
  "problem": {
    "name": "One More aab aba baa",
    "description": {
      "content": "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$ w",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc215_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Find the $K$\\-th lexicographically smallest string among the strings that are permutations of a string $S$.\nWhat is a permutation of a string?A string $A$ is said to be a permutation of a string $B$ w...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments