#K1616. Recursive Adjacent Duplicate Removal

    ID: 24517 Type: Default 1000ms 256MiB

Recursive Adjacent Duplicate Removal

Recursive Adjacent Duplicate Removal

This problem requires you to remove every pair of adjacent duplicate characters from a given string recursively until no more pairs can be removed. Specifically, whenever two adjacent characters are identical, they are removed and this process is repeated until the string is fully reduced to a state where no adjacent characters are the same. In mathematical terms, given a string ( s ), you want to compute ( f(s) ) such that if ( s = aabb ) then ( f(s) = "" ) (empty string), and if ( s = abc ) then ( f(s) = abc ).

The input is a single string containing only lowercase English letters, and the output should be the final string after all possible removals.

inputFormat

The input consists of a single line containing a string ( s ). Note that ( s ) contains only lowercase English letters and ( 1 \leq |s| \leq 10^5 ).

outputFormat

Output the final string after repeatedly removing adjacent duplicate pairs.## sample

abbaca
ca