409769: GYM103736 J IHI's Magic String
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
J. IHI's Magic Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
IHI has recently acquired a magic power that can perform the following operations on strings:
- puts a character at the end of a string.
- deletes a character at the end of a string (does not operate if the string is empty).
- replaces all current character $$$x$$$ in the string to characters $$$y$$$.
All characters are lowercase.
Now IHI has a string that starts empty, he wants to know what the final string is after $$$q$$$ operations.
InputThe first line contains a number $$$q$$$ $$$(1 \leq q \leq 10^5)$$$ indicating the number of operations.
The next $$$q$$$ lines represent $$$q$$$ operations.
There are three types of operations:
- $$$1$$$ $$$x$$$: In the first operation, you should put character $$$x$$$ at the end of the string.
- $$$2$$$: In the second operation, you should delete a character at the end of the string if and only if this string is not empty.
- $$$3$$$ $$$x$$$ $$$y$$$: In the third operation, replace $$$x$$$ in the string with $$$y$$$.
If the final string is empty, you should output "The final string is empty".
Otherwise, output the final string in one line.
ExamplesInput5 1 a 1 b 1 c 3 a c 1 bOutput
cbcbInput
6 1 a 1 b 1 c 1 c 3 a c 3 c aOutput
abaaInput
5 1 a 1 c 3 a c 2 2Output
The final string is empty