Stack Push Counter
EasyPractice library · +10 XPstacksimulationarrays
You are given a sequence of integers. You need to process this sequence using a stack. For each integer in the sequence, you must push it onto the stack. After processing all integers, your task is to print the total number of push operations performed.
Input
The first line contains an integer N, the number of integers in the sequence. The second line contains N space-separated integers.
Output
Print a single integer, the total number of push operations.
Constraints
1 <= N <= 1000 Each integer in the sequence is between -1000 and 1000.
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
5 10 20 30 40 50
Output
5
There are 5 elements, so 5 push operations.
Example 2
Input
3 -1 0 1
Output
3
There are 3 elements, so 3 push operations.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 10 20 30 40 50
Example 2 input
3 -1 0 1