This page is still under construction.

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

Censoring

Interview

Time limit1sMemory limit256 MB

Summary
Repeatedly delete the first occurrence of T from S, including matches formed by earlier deletions, and print what remains.
Level

Medium5 of 10

Topics
String matching, Stack
Solved
No attempts yet

Problem

Farmer John subscribed to a housekeeping magazine so his cows have something to read while they wait to be milked. The latest issue carries an article on cooking the perfect steak, and John would rather his cows never see it.

John concatenated all of the magazine text into a string SS of length at most 10610^6. He now wants to censor it by deleting the offending substring TT. He does it like this. Find the first occurrence of TT in SS and delete it. Repeat the same step, always deleting the first remaining occurrence, until TT no longer occurs in SS. One deletion can create a new occurrence of TT that was not there before.

Report the contents of SS once the censoring is finished.

Input

The first line contains the string SS. The second line contains the string TT. The length of TT is at most the length of SS, and both SS and TT consist only of lower-case letters a to z.

Output

Print the string SS after all deletions are complete. No input makes SS become empty during the deletion process.

Examples5

  1. Example 1

    Input
    whatthemomooofun
    moo
    
    Expected output
    whatthefun
    
  2. Example 2

    Input
    abcdefghij
    xyz
    
    Expected output
    abcdefghij
    
  3. Example 3

    Input
    abc
    abd
    
    Expected output
    abc
    
  4. Example 4

    Input
    banana
    a
    
    Expected output
    bnn
    
  5. Example 5

    Input
    aaaaaaa
    aaa
    
    Expected output
    a