#K63727. Remove Adjacent Duplicate Letters

    ID: 31818 Type: Default 1000ms 256MiB

Remove Adjacent Duplicate Letters

Remove Adjacent Duplicate Letters

You are given a string ( s ). Your task is to repeatedly remove adjacent duplicate letters from the string until no such pair exists. Formally, while there exist two consecutive characters that are equal, remove them, and continue the process.

For example, if ( s = \texttt{'abbaca'} ), after processing the string becomes ( \texttt{'ca'} ). This problem can be efficiently solved using a stack-based approach.

inputFormat

The input consists of a single line containing the string ( s ). The string will contain only lowercase letters and will have a length of at most ( 10^6 ).

outputFormat

Output a single line containing the final string after removing all adjacent duplicates. If the result is an empty string, output an empty line.## sample

abbaca
ca