#C10699. Process Operations on a List

    ID: 39932 Type: Default 1000ms 256MiB

Process Operations on a List

Process Operations on a List

You are given an initial integer n and an integer m representing the number of operations to perform. A list is initialized with the value n. Then, you will perform m operations sequentially on the list. The operations are of two types:

  • ADD a: Append the integer a to the end of the list.
  • REMOVE: Remove the last element from the list if it exists.

If all elements are removed from the list at any point, the final state is considered to be EMPTY. Otherwise, output the final state of the list by printing its elements in order separated by a single space.

Note: Each operation is executed in the given order. If a REMOVE operation is executed on an empty list, do nothing.

inputFormat

The input is read from stdin and is structured as follows:

  • The first line contains two integers n and m where n is the initial integer and m is the number of operations.
  • The following m lines each contain an operation. An operation is either in the format ADD a or REMOVE.

outputFormat

Output the final state of the list to stdout. If the list is not empty, print its elements separated by a space. If the list is empty (i.e., all elements have been removed), print EMPTY.

## sample
5 1
ADD 10
5 10