Magic Tower
Statement
Goal
You are a powerful magician-developer moving through a strange valley where towers magically appear.Each tower has a height, and you have the ability to create or destroy towers.
- Creating a tower cost the energy same as its height.
- Destroying a tower gives you the same energy as its height.
if A is positive, this means you create a tower of height A, which costs you A units of energy.
If A is negative, this means you destroy a tower of height |A|, which gives you |A| units of energy.
Your objective is to calculate the energy remaining after performing a series of actions on the towers.
Input
Line 1: An integer N for the number of actions to perform.
Next N lines: An integer A for an action.
Next N lines: An integer A for an action.
Output
Line 1: An integer representing the energy remaining after all actions have been performed.
Constraints
1 ≤ N ≤ 10^4.
-10^4 ≤ A ≤ 10^4.
-10^4 ≤ A ≤ 10^4.
Example
Input
5 4 -2 3 -1 2
Output
-6
Game modes
Fastest
Test cases
Test 1 Test
Input
5
4
-2
3
-1
2
Output
-6
Validator 1 Validator
Input
5
4
-2
3
-1
1
Output
-5
Test 2 Test
Input
3
5
-3
2
Output
-4
Validator 2 Validator
Input
3
5
-3
3
Output
-5
Test 3 Test
Input
4
6
-4
-2
1
Output
-1
Validator 3 Validator
Input
4
6
-4
-2
2
Output
-2
Test 4 Test
Input
2
10
-3
Output
-7
Validator 4 Validator
Input
2
9
-5
Output
-4
Solution language
Solution
Stub generator input