#P12281. Enhanced Text Editor Simulation

    ID: 14391 Type: Default 1000ms 256MiB

Enhanced Text Editor Simulation

Enhanced Text Editor Simulation

Initially, the text file is empty. The enhanced text editor supports a set of commands to manipulate the text. The commands are as follows:

CommandFunction
[n]hMove the cursor left by \(n\) characters (stop at the beginning).
[n]lMove the cursor right by \(n\) characters (stop at the end).
insert "[text]"Insert the given [text] at the current cursor position and move the cursor to the right end of the inserted text.
d [n]hDelete \(n\) characters to the left of the cursor (if fewer than \(n\) exist, delete all).
d [n]lDelete \(n\) characters to the right of the cursor (if fewer than \(n\) exist, delete all).

You are given a series of commands to be executed sequentially. After processing all the commands, output the final text content.

inputFormat

The first line contains an integer T, the number of commands. Each of the following T lines contains one command. The commands can be of the following forms:

  1. [n]h
  2. [n]l
  3. insert "[text]"
  4. d [n]h
  5. d [n]l

Note: (n) is a positive integer and [text] denotes the string to be inserted.

outputFormat

Output the final text after all commands are executed.

sample

1
insert "hello"
hello