#C9498. Array Game: Operations on an Array
Array Game: Operations on an Array
Array Game: Operations on an Array
You are given a series of operations to perform on an initially empty array. There are two types of operations:
- A x: Append the integer x to the array. In latex: $$A\ x$$.
- R: Remove the most recent element from the array (if the array is not empty), represented in latex as $$R$$.
After processing all operations in order, output the sum of the elements remaining in the array.
inputFormat
The first line contains an integer \(n\), the number of operations. Each of the following \(n\) lines contains a single operation. The operation is either in the format A x
(where x
is an integer) or R
.
outputFormat
Output a single integer representing the sum of the array after all operations have been performed.
## sample5
A 1
A 2
A 3
R
A 5
8