#K81902. List Operations and Minimum Query

    ID: 35856 Type: Default 1000ms 256MiB

List Operations and Minimum Query

List Operations and Minimum Query

You are given an initial integer and a sequence of operations to perform on a list. Initially, the list contains only the given integer. There are three kinds of operations:

  • ADD x: Append the integer x to the end of the list.
  • REMOVE: Remove the last element from the list.
  • FIND_MIN: Find the minimum value in the list and output it.

When an operation FIND_MIN is encountered, record the current minimum of the list. Your task is to process all operations in order and output the results of each FIND_MIN operation.

The operations follow the following logic:

  • If the operation is of the format ADD x, append \(x\) to the list.
  • If the operation is REMOVE, remove the last (most recently appended) element from the list.
  • If the operation is FIND_MIN, compute \(min(list)\) and output it immediately.

It is guaranteed that the operations are valid.

inputFormat

The input will be read from stdin and has the following format:

  1. The first line contains a single integer, \(initial\), which is the initial value in the list.
  2. The second line contains an integer \(n\) representing the number of operations.
  3. The following \(n\) lines each contain a string representing one of the operations: ADD x, REMOVE, or FIND_MIN.

outputFormat

The output should be written to stdout. For each FIND_MIN operation encountered, output the minimum value in the list, each on a separate line. If no FIND_MIN operation is present, output nothing.

## sample
5
6
ADD 3
ADD 2
ADD 8
FIND_MIN
REMOVE
FIND_MIN
2

2

</p>