This page is still under construction.

Parts of this page are still being built. What you see may change.

Censoring

Time limit1sMemory limit256 MB

Summary
Repeatedly delete the leftmost occurrence of any of N forbidden words from string S until none remains and print the result.
Level

Medium7 of 10

Topics
String matching, Stack, Simulation
Solved
No attempts yet

Problem

One issue of a magazine has been flattened into a single string SS made of lowercase letters. Some words must not appear in it, so the NN censored words t1t_1 to tNt_N have to be deleted from SS.

Censoring works like this. Find the occurrence of a censored word in SS that starts at the smallest index, and delete that occurrence. Repeat until SS contains no occurrence of any censored word. Deleting one occurrence joins the characters around it, so a censored word that was not there before can appear.

No censored word is a substring of another censored word. At every step the occurrence with the smallest start index is therefore unique.

Print SS after censoring stops.

Input

The first line contains the string SS. It consists of lowercase letters and its length is at most 10510^5.

The second line contains NN, the number of censored words.

Each of the next NN lines contains one censored word, t1t_1 to tNt_N in order. Every word consists of lowercase letters, and the total length of the NN words is at most 10510^5.

Output

Print SS after every deletion is done. SS never becomes empty during the process.

Examples4

  1. Example 1

    Input
    begintheescapexecutionatthebreakofdawn
    2
    escape
    execution
    
    Expected output
    beginthatthebreakofdawn
    
  2. Example 2

    Input
    xaabbx
    1
    ab
    
    Expected output
    xx
    
  3. Example 3

    Input
    abcdefg
    3
    hij
    klm
    xyz
    
    Expected output
    abcdefg
    
  4. Example 4

    Input
    abababa
    1
    b
    
    Expected output
    aaaa