#C10090. Document Tracker

    ID: 39257 Type: Default 1000ms 256MiB

Document Tracker

Document Tracker

You are given a sequence of operations to modify a document. The document starts empty. Each operation is one of the following:

  • INSERT <word>: Append the given word at the end of the document.
  • DELETE: Remove the most recently inserted word from the document (if any exists).
  • UNDO: Revert the most recent operation that has been performed. If an INSERT was undone, the last inserted word is removed; if a DELETE was undone then the previously deleted word (if any) is restored.

After each operation, output the total number of words currently in the document. Note that operations that cannot take effect (for example, DELETE on an empty document or UNDO when there is no previous operation) are still recorded and will affect subsequent UNDO commands.

Your task is to simulate these operations and print the number of words in the document after each operation.

Note: If there are no operations, print nothing.

inputFormat

The input is given from stdin in the following format:

N
operation_1
operation_2
...
operation_N

Here, the first line contains an integer N (0 ≤ N ≤ 105), the number of operations. The following N lines each contain one operation which is either:

  • INSERT <word> (the word will not contain spaces)
  • DELETE
  • UNDO

outputFormat

Output to stdout a single line containing N integers separated by a space. Each integer is the number of words in the document after performing the corresponding operation. If N is 0, output nothing.

## sample
7
INSERT hello
INSERT world
DELETE
UNDO
INSERT evan
DELETE
UNDO
1 2 1 2 3 2 3