Recover the original song by collapsing repeated remix separators into single word separators.
Dubstep
A song was remixed by inserting the word WUB many times into the original lyrics. To restore the original song, remove every occurrence of WUB and place a single space between consecutive words that were separated by one or more WUBs.
Given the remixed string, output the original lyrics with words separated by single spaces only.
Notes
- The remixed string consists only of uppercase Latin letters.
- The substring
WUBmay appear at the beginning, middle, or end of the string. - Consecutive occurrences of
WUBshould still result in just one space between adjacent words.
Input Format
A single string s representing the remixed song.
Output Format
Print the restored original song with words separated by single spaces and no leading or trailing spaces.
Constraints
1 <= |s|(length is finite and manageable for standard string processing)scontains only uppercase Latin letters- The substring
WUBmay appear multiple times
Example 1
Input
WUBWUBABCWUB
Output
ABC
Explanation
All WUB blocks are removed, leaving a single word.
Example 2
Input
WUBWUBABCWUBWUBDEFWUB
Output
ABC DEF
Explanation
The remaining words are ABC and DEF, separated by a single space.
Show 1 more example
Example 3
Input
WUBABCWUBDEFWUBGHI
Output
ABC DEF GHI
Explanation
Each run of WUB acts as one separator between words.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.