In the jelly row "mirkAAkkx", we find and pop the bomb pattern "kk"!
An explosion always happens at the tail of what we just stacked. So we push chars one by one, and when the top matches the pattern, we pop them at once. (LIFO!)
Jelly Factory - Pop the Defect Pattern
Description
On a jelly factory conveyor belt, jellies labeled with letters are lined up in a row.
The quality checker knows a fixed 'bomb pattern' string.
Whenever this bomb pattern appears consecutively in the jelly row, that part goes pop! and disappears.
When jellies vanish, the ones on each side stick together, which can create a new bomb pattern.
Keep popping until no bomb pattern remains, then print the final jelly row.
If everything pops and nothing is left, print "EMPTY".
Input
Line 1: jelly row string `line`
Line 2: bomb pattern string `bomb`
Output
The remaining string after all explosions. "EMPTY" if empty
Constraints
•1 ≤ length of line ≤ 1,000,000
•1 ≤ length of bomb ≤ 36
•line and bomb consist only of letters and digits
Examples
Example 1
Input
line = "mirkAAkkx", bomb = "kk"
Output
mirkAAx
Explanation
Pushing "mirkAAkkx" left to right, the consecutive "kk" forms and pops once, leaving "mirkAAx". No "kk" remains, so the result is "mirkAAx".
Example 2
Input
line = "acxcxca", bomb = "cxc"
Output
axca
Explanation
Pushing "acxcxca", the moment "cxc" completes it pops. Removing that "cxc" leaves "a" + "xca" = "axca", and no "cxc" remains, so the result is "axca".