#C2629. Stack Operations Processing

    ID: 45966 Type: Default 1000ms 256MiB

Stack Operations Processing

Stack Operations Processing

You are given a series of operations to be performed on a stack. The operations are described as follows:

  • PUSH X: Push the integer \(X\) onto the top of the stack.
  • POP: Remove the top element of the stack if the stack is not empty.
  • INC K V: Add \(V\) to each of the bottom \(K\) elements of the stack. More formally, if the current stack has \(m\) elements, then for every \(i = 1\) to \(\min(K, m)\), the \(i^{\text{th}}\) element from the bottom is increased by \(V\).

After all operations are processed, output the sum of all elements remaining in the stack.

inputFormat

The first line of input contains an integer (n), representing the number of operations. Each of the subsequent (n) lines contains one operation. The operations can be one of the following:

  1. PUSH X — push the integer (X) onto the stack.
  2. POP — remove the top element from the stack if it exists.
  3. INC K V — add (V) to each of the bottom (K) elements in the stack.

outputFormat

Print a single integer which is the sum of the elements in the stack after processing all the operations.## sample

5
PUSH 5
PUSH 2
INC 2 3
POP
PUSH 10
18