We need to implement an editor consisting of a buffer of length n≥ 0 and a cursor placed on some character 0 ≤ i < n of the buffer (or at the end of the buffer if i=n). The editor must support some basic operations (moving the cursor, inserting or removing characters) and two special commands: Cut (text is removed from the buffer and moved to the clipboard) and Paste (text is removed from the clipboard and moved to the buffer). Removing pasted text from the clipboard prevents the buffer from growing exponentially in the number of commands.
Implement such an editor, starting with an empty buffer (i = n = 0).
Input
Input consists of at most 106 commands, one per line, of the following form:
Output
Output one line for each O command.
Input
O I a O I b I c I d O D D D O M -2 I z O D O
Output
* a* abcd* abcd* abz*cd abz*d
Input
I a I b I c I d M -1 D I e I f I g I h O M -5 C 3 O M 100 M -1 P O P O R O
Output
abcefgh* ab*gh abgcef*h abgcef*h *