#K416. Simulate Robot Commands

    ID: 26901 Type: Default 1000ms 256MiB

Simulate Robot Commands

Simulate Robot Commands

This problem simulates a robotic arm that manipulates a stack of boxes based on a series of commands. The robot can perform three operations:

  • 1 x y: Pick up a box of weight x from position y and push it onto the stack.
  • 2 0 0: Check the validity of the current stack. A stack is considered valid if for every two adjacent boxes, the box below is at least as heavy as the one above. Formally, a stack with weights \(w_0, w_1, \dots, w_{k}\) from bottom to top is valid if for all \(0 \le i < k\), $$w_i \ge w_{i+1}.$$ An empty stack is valid by default.
  • 3 0 0: Remove the box from the top of the stack (if the stack is non-empty).

Your task is to simulate these commands and output the result of each validity check (command type 2) on a new line as either Valid or Invalid.

inputFormat

The input is given via standard input (stdin) and has the following format:

  1. The first line contains an integer N, representing the number of commands.
  2. Each of the next N lines contains three integers: c x y, where c denotes the command type.
  • If c = 1, push a box of weight x onto the stack (the value y is provided but not used).
  • If c = 2, check if the current stack is valid (using the rule $$w_i \ge w_{i+1}$$ for every adjacent pair). In this case, x and y will be 0.
  • If c = 3, pop the top box from the stack if it is non-empty (again, x and y will be 0).

outputFormat

For each command of type 2, output a single line containing either Valid or Invalid, indicating whether the stack is valid at that moment.

## sample
7
1 10 5
1 20 3
2 0 0
3 0 0
2 0 0
1 15 2
2 0 0
Invalid

Valid Invalid

</p>