#P12347. Stack Operations and Product Query
Stack Operations and Product Query
Stack Operations and Product Query
You are given an initially empty stack and a series of operations. There are three types of operations:
1. 1 x: Push the integer x onto the top of the stack.
2. 2: Pop the top element from the stack (if the stack is empty, do nothing).
3. 3 y: Compute the product of the top y numbers in the stack. If the product is greater than or equal to , output OVERFLOW
. If there are fewer than y numbers in the stack, output ERROR
.
inputFormat
The first line contains an integer n
, representing the number of operations. Each of the next n
lines contains an operation in one of the following forms:
• 1 x
: Push x
onto the stack.
• 2
: Pop the top element from the stack.
• 3 y
: Query the product of the top y
elements. Output OVERFLOW
if the product is at least , or ERROR
if the stack has fewer than y
elements.
outputFormat
For each query operation (type 3), output the corresponding result on a new line. The result is either the computed product (if it is less than ), OVERFLOW
if the product is at least , or ERROR
if there are insufficient numbers in the stack.
sample
5
1 2
1 3
3 2
2
3 2
6
ERROR
</p>