#P3025. [USACO11OPEN] Forgotten Password S

[USACO11OPEN] Forgotten Password S

Description

As often happens to us, Bessie has once again forgotten her barn manager password. She can only remember part of it.

First, she remembers that the password PP is a string of length LL (1L10001 \le L \le 1000), and that the password is formed by concatenating one or more words, each of which is recorded in her dictionary of NWNW (1NW10001 \le NW \le 1000) words. Every dictionary word WiW_i consists of 11 to 2020 lowercase Latin letters.

She only remembers some letters in the password and their positions. For example, Bessie remembers her password as a??l?ban???????, where ? stands for a letter she forgot. Her dictionary contains these words: apple cow farmer banana bananas pies. Therefore, two possible passwords for Bessie are applebananapies and applebananascow.

Now, given the letters Bessie still remembers and her dictionary, find a possible password. If there are multiple answers, output the lexicographically smallest one.

Input Format

The first line contains the length LL of her password and the number of words NWNW in the dictionary, separated by a space.

The second line contains the string PP of length LL.

Then follow NWNW lines, each containing a string WiW_i.

Output Format

Output exactly one line: Bessie’s password.

15 6 
a??l?ban??????? 
apple 
cow 
farmer 
banana 
bananas 
pies 

applebananapies 

Hint

Translated by ChatGPT 5