Problem
You are given an array A of length N. Processing the array from left to right:
- If A[i] > 0, a group containing A[i] tickets is added to the end of a queue.
- If A[i] = 0, the earliest unprocessed group in the queue is removed, and its size is added to the score.
- If the queue is empty, nothing happens.
Find the final score.
Input
- First line: N
- Second line: N space-separated integers A[i]
Output