Bob has a bank account! He uses it every day and it makes him happy.
Since the creation of the account, he has done transactions. Each transaction is represented as a decimal dollar amount .
However, Bob is also prone to changing his mind. Sometimes, he regrets buying products that aren't really useful; other times, he accidentally deposits money. Whenever Bob changes his mind, the amount will be listed as , signifying a reversal of the previous transaction. He can even reverse a reverse and so on.
Bob has queries, asking how much was added or subtracted from his balance from transaction to transaction inclusive. He also wants to know his final balance because he can't find it anywhere.
The balance can be negative at any point (Bob can be in debt!).
Input Specification
The first line will contain (), the number of transactions in total.
The next lines will each either contain a decimal (), the amount the balance changed by, or , a reversal. It is guaranteed that the first transaction will not be .
The next line will contain (), the number of queries.
The final lines will each contain two integers and (), the range of transactions to be considered.
Output Specification
For each query, print the amount of money added or subtracted from his balance between the specified transactions.
Finally, print the total amount of money in the bank account.
Subtasks
Subtask 1 [10%]
- There will be no s in the input.
Subtask 2 [20%]
Subtask 3 [70%]
- No further constraints.
Sample Input 1
5
6.50
-3.00
1.99
4.11
-0.12
2
1 3
2 5
Sample Output 1
5.49
2.98
9.48
Sample Input 2
6
12.00
-50.00
0
130.00
-120.00
16.00
4
1 2
2 5
3 3
4 6
Sample Output 2
-38.00
10.00
50.00
26.00
38.00
Explanation for Sample Output 2
For query , the balance changed by .
For query , was returned to the balance.
Comments