King's Cup
Congratulations! Your team has just won AUCPL Season 1, walking away with the prize money and bragging rights that will last a lifetime. Naturally, you decide to celebrate at the Adelaide Unibar.
After a few rounds in, the brews are hitting hard, and the bar menu is starting to get a bit slurred. You can no longer distinguish between the drink names; it all looks like one big string of characters. You can choose any contiguous subset of characters from this menu to order, and the bartender will guess what you mean, and whip you up a tasty drink. However, some words are considered "forbidden" at the Unibar, and saying them will get you kicked out of the bar, so be careful what you say!
Being the last AUCPL, and determined to go out in style, you decide you want the lexicographically largest drink you can order without accidentally saying a forbidden word. In other words, out of all the possibilities, pick the latest one in alphabetical order that keeps your team safe from the bartender's wrath.
What do you say?
Input
The first line contains two integers
and
, the number of characters on the drinks menu, and the number of forbidden words the Unibar has.
The next line contains a string
, the menu as your drunken self perceives it.
The next lines contain
and
, where:
is the length of the
th forbidden word.
is the forbidden word itself.
It is guaranteed that the sum of is no greater than
.
Output
Output the lexicographically largest substring on the menu that does not contain any forbidden words. If you can't say anything without saying a forbidden word, output "Silence".
Clarifications
- You might need to select pypy3 if you want to solve this using Python.
Example
Input 1
17 6
GRASSHOPPERMIMOSA
3 ASS
2 SS
3 SSH
3 HOP
4 PERM
4 FUCK
Output 1
SHO
Out of all the substrings you could choose to speak, "SHO" is the 25th lexicographically largest one, but all the lexicographically largest one that does not contain a forbidden word.
Input 2
15 3
ALLHAILTHEKINGS
4 HAIL
3 AIL
2 LL
Output 2
THEKINGS
Input 3
25 4
ABCABABCBBCBABBCCABBCBCAA
3 CBC
3 CBB
2 CC
7 ABACABA
Output 3
CBABBC
Comments