All problems

Problem 391

Remove Adjacent Duplicates

Easy · 10 pts · String, Stack

Problem

Repeatedly find two adjacent equal letters in the string and remove both of them, until no two adjacent letters are equal. Removing a pair can bring two new equal letters together, which must then be removed as well. The final result is the same no matter which pair you remove first. Print the final string, or EMPTY if nothing is left. A stack processes the string in one pass.

Input

A single string S of lowercase letters.

Output

Print the final string, or EMPTY.

Constraints

1 <= |S| <= 100000

Example input

abbaca

Example output

ca

Explanation

In 'abbaca', removing 'bb' gives 'aaca', and then removing 'aa' gives 'ca', which has no equal neighbours.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Stock Span Next: Remove K Adjacent Duplicates