#K52887. Dynamic Array Operations

    ID: 29409 Type: Default 1000ms 256MiB

Dynamic Array Operations

Dynamic Array Operations

You are given an initially empty array and a sequence of q operations. There are three types of operations:

  • 1 x: Append the integer x to the end of the array.
  • 2: Remove the last element of the array. If the array is empty, do nothing.
  • 3: Print the maximum value in the array. If the array is empty, print EMPTY.

For example, consider the sequence of operations below:

9
1 5
1 10
3
2
3
1 7
2
2
3

The outputs for the type 3 operations are as follows: 10, 5 and EMPTY.

Note: When outputting numbers, print each result on a new line.

You may find the formula for maximum operation interesting: $$\max_{i=1}^{n}a_i$$, which in this problem means the max element in the current array.

inputFormat

The first line of input contains an integer q, the number of operations. Each of the following q lines contains an operation in one of the following formats:

  • 1 x — Append integer x to the array.
  • 2 — Remove the last element from the array.
  • 3 — Print the maximum value in the array, or EMPTY if the array is empty.

outputFormat

For each operation of type 3, output the result on a new line. If the array is empty during a 3 operation, output EMPTY.

## sample
9
1 5
1 10
3
2
3
1 7
2
2
3
10

5 EMPTY

</p>