question archive Chef has a string SPpatternSSPS
Subject:Computer SciencePrice: Bought3
Chef has a string SPpatternSSPS
. He also has another string , called . He wants to find the pattern in , but that might be impossible. Therefore, he is willing to reorder the characters of in such a way that occurs in the resulting string (an anagram of ) as a substring.
Since this problem was too hard for Chef, he decided to ask you, his genius friend, for help.
Can you find the lexicographically smallest anagram of Sthat contains P as substring?
Note: A string B is a substring of a string A if B can be obtained from A by deleting several (possibly none or all) characters from the beginning and several (possibly none or all) characters from the end.
Input
.
.
Output
For each test case, print a single line containing one string ? the smallest anagram of S
that contains P
Constraints
Example Input
3 akramkeeanany aka supahotboy bohoty daehabshatorawy badawy
Example Output
aaakaeekmnnry abohotypsu aabadawyehhorst