Nathan is a big fan of recreational mathematics. For one of his problems, he needs to add together very large numbers. He created a class called BigInteger
to help with the adding, but he isn't done yet! Nathan needs to stress test his code, so he devised the following problem.
There will be instructions (which are given as a string of length ). There are two types of instructions:
0
to9
: Add this digit to the end of the current number. Afterwards, add the current number to the total.-
: Remove the last digit from the current number. It is guaranteed that the current number will not be empty after this instruction. Afterwards, add the current number to the total.
At the beginning, the total is and the current number is . Nathan wrote a program in Python to solve this problem, but it is slow and drains his battery too much. Can you help Nathan double-check his answers?
Input Specification
The first line will contain the integer .
The second line will contain a string of length . Every character in this string can be found in 0123456789-
.
Constraints
In all subtasks, .
Subtask | Points | Additional Constraints |
---|---|---|
1 | 5 | |
2 | 15 | After each instruction, there will be at most one non-zero digit in the current number. |
3 | 20 | The instruction - will not appear. |
4 | 40 | |
5 | 20 | No additional constraints. |
Output Specification
Print the total. Leading zeroes will be ignored by the checker. If your program does not print anything, the total is assumed to be .
Sample Input 1
8
0100---5
Sample Output 1
00000127
Explanation for Sample Output 1
Notice that leading zeroes are allowed in the output.
Sample Input 2
4
1817
Sample Output 2
2017
Explanation for Sample Output 2
The numbers to be added are , , , and . The total is .
Sample Input 3
2
0-
Sample Output 3
00
Comments