cho.sh
Notes
Loading...

Undo

Time limit

2s

Memory limit

128 MB

Problem

Minsik made a text editor that supports only the following two commands.

  • type c: append the character c to the end of the current text.
  • undo t: undo, in reverse order, every command executed during the previous t seconds immediately before this command is executed.

The editor is initially empty.

Consider the following sequence.

  • Time 1: type a
  • Time 2: type b
  • Time 3: type c
  • Time 5: undo 3

At the end of time 3, the text is abc. At time 5, undo 3 must undo the commands from the previous 3 seconds in reverse order, so c is removed and then b is removed. Only a remains.

An undo command can itself be undone by a later undo command.

Consider this sequence.

  • Time 1: type a
  • Time 2: type b
  • Time 3: undo 2
  • Time 4: undo 2

At time 2, the text is ab. At time 3, all commands from the previous 2 seconds are undone, so the text becomes empty. At time 4, the undo performed at time 3 is undone first, and then the type b command from time 2 is undone. Therefore, the final text is a.

Given the commands and the time when each command is executed, determine the text that remains after all commands are performed.

Input

The first line contains the number of commands N.

Each of the next N lines contains a command and the time when it is executed. The times are given in increasing order. In type c, c is a lowercase English letter. In undo t, t is an integer from 1 to 10^9, inclusive. N is a positive integer not greater than 50.

Output

Print the text remaining in the editor after all commands are performed.