#P9810. [CCC 2015 S1] Zero That Out
[CCC 2015 S1] Zero That Out
Problem Description
Given integers , maintain a sequence and perform the following operations in order:
- When , delete the last number that was added to the sequence.
- Otherwise, add to the sequence.
For example, when , the operations are as follows.
| Sequence | |
|---|---|
You need to compute the sum of all numbers in the final sequence.
Input Format
The first line contains an integer .
The next lines each contain an integer .
Output Format
Output one line with one integer, representing the sum of all numbers in the final sequence.
4
3
0
4
0
0
10
1
3
5
4
0
0
7
0
0
6
7
Hint
Constraints:
, .
It is guaranteed that when , the sequence is not empty.
Translated by ChatGPT 5