#d255. 出栈序列判断
出栈序列判断
Stack Pop Sequence Judgment
Problem Description
There is a stack with elements, namely . By performing push and pop operations, we can push these elements into the stack one by one, then pop them out, and the sequence of popped elements written down in order is the pop sequence.
For example, when , if we perform push 1, push 2, pop, push 3, pop, pop, the elements we get from the pop operations are in order. That is, the pop sequence is .
Now you are given a valid pop sequence. Please output a valid operation sequence consisting of push and pop operations. Here the push operations must be performed in the order .
Input Format
The first line contains an integer . The next line contains integers, representing the pop sequence.
Output Format
Output lines, each containing one push or pop operation. It can be proved that the operation sequence corresponding to a pop sequence is unique.
Sample Input 1
3
2 3 1
Sample Output 1
push 1
push 2
pop
push 3
pop
pop
Sample Input 2
5
1 3 5 4 2
Sample Output 2
push 1
pop
push 2
push 3
pop
push 4
push 5
pop
pop
pop
Constraints
For of the data, , and the input is guaranteed to be a valid pop sequence.