Problem Statement
You are given a ciphertext ~S~ . It can be decrypted by the following procedure:
- Let ~T~ be an empty string.
- For each ~i = 1, 2, \dots, |S|~ in this order, do the following: ( ~|S|~ denotes the length of ~S~ )
- if the ~i~ -th character of ~S~ is
R
, reverse ~T~ ; - if the ~i~ -th character of ~S~ is not
R
, add that character to the end of ~T~ .
- if the ~i~ -th character of ~S~ is
- After the operation above, if there are two consecutive same characters in ~T~ , remove those two characters. Repeat this operation as long as it can be done. (We can prove that the final string obtained does not depend on the order the characters are removed.)
Print the string ~T~ obtained by this procedure.
Constraints
- ~S~ consists of lowercase English letters and
R
. - ~1 ≤ |S| ≤ 5 \times 10^5~
Input
Input is given from Standard Input in the following format:
~S~
Output
Print the answer.
Sample Input 1
ozRnonnoe
Sample Output 1
zone
We can decrypt it as follows:
- Initially, ~T~ is an empty string.
- Add
o
at the end of ~T~ , making ito
. - Add
z
at the end of ~T~ , making itoz
. - Reverse ~T~ , making it
zo
. - Add
n
at the end of ~T~ , making itzon
. - Add
o
at the end of ~T~ , making itzono
. - Add
n
at the end of ~T~ , making itzonon
. - Add
n
at the end of ~T~ , making itzononn
. - Add
o
at the end of ~T~ , making itzononno
. - Add
e
at the end of ~T~ , making itzononnoe
. - Delete two consecutive
n
s from ~T~ , making itzonooe
. - Delete two consecutive
o
s from ~T~ , making itzone
.
Sample Input 2
hellospaceRhellospace
Sample Output 2
The answer may be an empty string.
Comments