#K2411. MinimLang Stack Operations

    ID: 24731 Type: Default 1000ms 256MiB

MinimLang Stack Operations

MinimLang Stack Operations

You are given a sequence of operations to be performed on a stack. The operations simulate a simple programming language named MinimLang. There are four kinds of operations:

  • add X: Push the integer X onto the stack.
  • remove: Remove (pop) the element at the top of the stack. It is guaranteed that this operation is only called when the stack is non-empty.
  • peek: Output the current top element of the stack without removing it.
  • increment N: Increment the top N elements of the stack by 1. If the stack contains fewer than N elements, increment all of them by 1.

Mathematically, if the stack is represented as a sequence \(a_1, a_2, \dots, a_k\), where \(a_k\) is the top of the stack, then the increment N operation transforms the last \(\min(N, k)\) elements as follows:

[ a_{k-i+1} \leftarrow a_{k-i+1} + 1, \quad \text{for } i = 1,2,\dots,\min(N,k). ]

Your task is to process the list of operations in order and output the result of every peek operation.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains a single integer n which represents the number of operations.
  2. The following n lines each contain one operation. Each operation is one of the following commands:
    • add X
    • remove
    • peek
    • increment N

outputFormat

For each peek operation, print the resulting top element of the stack on a new line to standard output (stdout). If there are multiple peek operations, the outputs should appear in the same order as they are processed.

## sample
5
add 5
add 3
peek
increment 2
peek
3

4

</p>