Cut and Paste

We need to implement an editor consisting of a buffer of length n0n\ge 0 and a cursor placed on some character 0i<n0 \le i < n of the buffer (or at the end of the buffer if i=ni=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=0i = n = 0).

Input

Input consists of at most 10610^6 commands, one per line, of the following form:

Output

Output one line for each O command.

Problem information

Author: Omer Gimenez

Generation: 2026-01-25T11:07:29.010Z

© Jutge.org, 2006–2026.
https://jutge.org