Print Stack Size
You are given a sequence of operations to perform on an initially empty stack. The operations are 'push' and 'pop'. For each operation, you must first determine the size of the stack before the operation is performed, and then print this size. If a 'pop' operation is attempted on an empty stack, it is ignored (the stack remains empty), but you still print the size before the attempted pop (which is 0).
Input
The first line contains an integer N, the number of operations. The next N lines each contain a string, either "push" or "pop", representing an operation.
Output
Print N integers, each on a new line, representing the size of the stack before each operation.
Constraints
1 <= N <= 1000. Operations are either "push" or "pop".
Example 1
5 push push pop push pop
0 1 2 1 2
Sizes before operations: 0, 1, 2, 1, 2.
Example 2
3 pop pop push
0 0 0
Sizes before operations: 0, 0, 0.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 push push pop push pop
3 pop pop push