#P3121. [USACO15FEB] Censoring G
[USACO15FEB] Censoring G
Description
FJ copied all the articles from a magazine and turned them into a string of length at most . He has a list of words, denoted by . He wants to delete these words from .
Each time, FJ finds in the earliest occurrence of any word from the list (the earliest occurrence means the smallest starting position), and then deletes that word from . He repeats this operation until no listed word remains in . Note that deleting a word may cause another listed word to appear in .
FJ noticed that within the list, no word is a substring of another, which implies that the starting positions of occurrences of listed words in are pairwise distinct.
Please help FJ perform these operations and output the final .
Input Format
The first line contains a string, the article .
The second line contains an integer, the number of words in the list .
Lines through each contain a string; the string on line , , denotes the -th word.
Output Format
Output a single line containing the string after all operations.
begintheescapexecutionatthebreakofdawn
2
escape
execution
beginthatthebreakofdawn
Hint
Constraints
For all test points, it is guaranteed that:
- $1 \leq |s|, \sum\limits_{i = 1}^n |t_i|, n \leq 10^5$.
- All strings contain only lowercase letters.
- After the operations finish, will not become an empty string.
- For all , is not a substring of .
Here, for a string , denotes its length.
Hint
During the process, a prefix of may be completely deleted; pay special attention to this.
Translated by ChatGPT 5
京公网安备 11011102002149号