#P12368. Edge Character Removal
Edge Character Removal
Edge Character Removal
Given a string \(S\), we define an edge character as follows. For any index \(i\) (using 1-indexing) such that \(2 \le i \le |S|-1\):
- If \(S_i = S_{i-1}\) and \(S_i \neq S_{i+1}\), then both \(S_i\) and \(S_{i+1}\) are called edge characters.
- If \(S_i \neq S_{i-1}\) and \(S_i = S_{i+1}\), then both \(S_{i-1}\) and \(S_i\) are called edge characters.
All other characters are not edge characters.
In one operation, all edge characters in the string \(S\) are removed simultaneously. Note that after one operation, the remaining characters are concatenated (preserving their original order) and new edge characters may be formed. After performing \(2^{64}\) such operations the process will eventually stabilize to a fixed string. If the final string is empty, output EMPTY
instead.
Task: Given a string \(S\), simulate the operation repeatedly until no more edge characters can be removed, and output the resulting string (or EMPTY
if it is empty).
Note: Even though \(2^{64}\) operations are applied, the process always stabilizes in a finite number of steps.
inputFormat
The input consists of a single line containing the string \(S\). \(S\) consists of between 1 and 105 characters.
outputFormat
Output the final string after performing the operation repeatedly until no more deletions occur. If the final string is empty, output EMPTY
(in all capital letters).
sample
aaa
aaa