Under construction

Still being built. Things may change

String Censorship

Time limit1.5sMemory limit128 MB

Summary
Repeatedly delete the first then last occurrence of a pattern string from a text until it's absent, and output the final text.
Level

Medium6 of 10

Topics
String matching, Stack, Simulation
Solved
No attempts yet

Problem

Given a text T and a forbidden word A, remove occurrences of A by repeating the following procedure.

  1. If the current text does not contain A, stop.
  2. Delete the first occurrence of A in the current text.
  3. If the current text does not contain A, stop.
  4. Delete the last occurrence of A in the current text.
  5. Go back to step 1.

Write a program that prints the text remaining after the whole procedure finishes.

Input

The first line contains the word A. The second line contains the text T.

Both A and T consist only of lowercase English letters. The length of A is at most 25, and the length of T is at most 300,000.

Output

Print the text remaining after all censorship steps are complete.

Examples3

  1. Example 1

    Input
    ne
    lukanevolisarmu
    
    Expected output
    lukavolisarmu
    
  2. Example 2

    Input
    aba
    ababacccababa
    
    Expected output
    bacccab
    
  3. Example 3

    Input
    banana
    babananananadeda
    
    Expected output
    deda