Hide

Problem B
Snowfall

The Yraglac cross-country skiing team would like to know if there will be enough snow on the ground to train after a certain number of days. They have a weather forecast in an unconventional format, described in the input section, and would like you to help them figure out how much snow there will be on the ground after all of the days in the forecast have passed.

Assume the ground starts out bare (with no snow).

Input

The first line of input contains an integer $n$ ($1 \leq n \leq 100$), the number of days in the weather forecast.

Each of the next $n$ lines contains two space-separated integers $t \in \{ 0, 1\} $ and $a$ $(1 \leq a \leq 50)$, with the $i^\text {th}$ line containing weather information about the $i^\text {th}$ day.

If $t = 0$, then $a$ millimeters of snow will fall on that day.

If $t=1$, then up to $a$ millimeters of snow will melt.

Output

A single integer, the depth of the snow after all $n$ days have passed, in millimeters.

Sample Input 1 Sample Output 1
3
1 4
0 5
1 2
3
Sample Input 2 Sample Output 2
4
0 5
1 2
1 2
0 6
7

Please log in to submit a solution to this problem

Log in