To celebrate the
While watching the movie, Wesley reminisced,
I hate this problem.
With the flavour text out of the way, Wesley noted that his Huffman Encoding was wrong; however, Wesley realized that he could still recover the Wesley-ically smallest message.
If two messages have different lengths, the shorter one is Wesley-ically shorter.
If two messages have the same length, the first character that differs between a Wesley-ically smaller string and a larger one will appear earlier in the alphabet for the Wesley-ically smaller string.
Wesley has
Can you help Wesley recover the Wesley-ically smallest message?
Constraints
Note that
The length of each binary string is at most
The binary strings mapped from the same lowercase letter are all the same length.
Note that a letter can map to multiple binary strings.
The data guarantee that there is at least one valid, decoded message.
Subtask 1 [20%]
The one pairing will have a binary string length of
Subtask 2 [80%]
No additional constraints.
Input Specification
The first line will contain
The second line will contain
The next
Output Specification
Output the Wesley-ically smallest message that could be encoded to create
Sample Input 1
3 5
10101
a 10
b 1
c 0
Sample Output 1
aab
Sample Input 2
5 20
10001010001000110001
h 0
h 1
r 0100
i 10001
f 10001
Sample Output 2
frhff
Comments