The Jedi and the Sith warfare is ruthless, and every leak of information could be lethal to the Light side’s revolution, that is why encoded messages were created. You need to write a program that decodes the incoming messages and the names of those that sent them.
On the first line of input you will receive n, an integer. On the next n lines you will be receiving strings of random ASCII characters with random length, which will represent the encoded text.
After that you will receive 2 lines. They will contain patterns. You must extract all names that consist of English alphabet letters, with length equal to the length of the pattern given on the first line, and prefix the given pattern itself. Then you must extract all messages which consist of English alphabet letters and digits, with length equal to the length of the pattern given on the second line, and prefix the given pattern itself. A character which does not follow the content conditions specified above denotes the end of a particular Jedi name / message.
On the last line of input you will get integers separated by a space. Every integer is an index of a message. The first Jedi found in the encoded text corresponds to the first index and the message at that index, the second Jedi to the second index and so on… If a particular message’s index is non-existent you ignore it and assign the next message with a valid index to the current Jedi, if such a message does not exist the Jedi is left with no message. In the situation that a Jedi’s message has an invalid index and he skips through the messages to find a valid one, the Jedi after him (if one exists) will take the message after the one the first Jedi took. If there are more indexes than needed, ignore the extra indexes.
Input:
-
On the first line you will get the integer n.
-
On the next n lines you will get random amounts of random ASCII characters.
-
After that you will get the two patterns each on a new line.
-
On the last line you will get integers separated by a single space.
Output:
-
The output is simple. You must print the Jedi, if the messages are less than the Jedi, print only those Jedi that have messages.
-
Jedi must be printed in the following format: {Jedi name} – {Jedi message}
Constraints:
-
N will be a valid integer in the range [0, 1000].
-
The encoded text will consist of ASCII characters.
-
The prefix patterns can consist of any ASCII character.
-
The integers (indexes of messages) will be valid integers in range [0, 1000].
-
Allowed time / memory: 100ms / 16MB.
Examples:
Input
|
Output
|
4
1-02948091jeknm,a sd,nbjwhu3hroLKjahefkljalsj#=#=#pesho
1gjq&&&geo*nhvjsfbsbdkfjq.311/.24/3.4,l2
3u827582929@@@@#=#=#gosho
&&&ped-&&&eraeesmdfjbdfspefkowekf
#=#=#
&&&
2 1
|
pesho - ped
gosho - geo
|
Input
|
Output
|
5
asdasdasd------Petkan123asdasd sasd
------Goshko-asdasdfddfgasdada 1r23
------Lilqna564!3876876429
*)(@*#)(&$%*^&------Stamat+as
:-@-@-ONIGH u305uvwoenh N{-@-@-OAIHF
------
-@-@-
2 1 1 3
|
Petkan - OAIHF
Goshko - ONIGH
Lilqna - ONIGH
|