Problem
You keep score for a game with odd rules. You get a list operations, applied in order to a record that starts empty. Each operation is one of:
- An integer x: record a new score of x.
- "+": record a new score equal to the sum of the previous two scores.
- "D": record a new score equal to double the previous score.
- "C": cancel the previous score, removing it from the record.
Return the sum of all scores left in the record.
Example 1
- Input
- ["5", "2", "C", "D", "+"]
- Output
- 30
- Why
- record: 5, 10, 15
Example 2
- Input
- ["5", "-2", "4", "C", "D", "9", "+", "+"]
- Output
- 27
- Why
- record: 5, -2, -4, 9, 5, 14
Example 3
- Input
- ["1", "C"]
- Output
- 0
Constraints
1 <= operations.length <= 1000Each operation is "C", "D", "+", or an integer in [-3 * 10^4, 3 * 10^4].Every "+" has at least two scores before it, and every "C" and "D" at least one.