#K83172. Distinct Sums of Ranges

    ID: 36139 Type: Default 1000ms 256MiB

Distinct Sums of Ranges

Distinct Sums of Ranges

You are given N ranges. The i-th range is specified by two integers Li and Ri.

You need to determine the number of distinct sums of the form:

$$ S = X_1 + X_2 + \cdots + X_N $$

where for each i, the number Xi can be chosen from the interval:

$$ X_i \in [L_i, R_i] $$

Thus, the smallest possible sum is

$$ S_{min} = \sum_{i=1}^{N} L_i, $$

and the largest possible sum is

$$ S_{max} = \sum_{i=1}^{N} R_i. $$

The total number of distinct sums is then:

$$ \text{answer} = S_{max} - S_{min} + 1. $$

Read the input from stdin and print the answer to stdout.

inputFormat

The first line contains a single integer N denoting the number of ranges.

Each of the following N lines contains two space-separated integers L and R representing the inclusive range from which a number can be chosen.

It is guaranteed that L ≤ R for every range.

outputFormat

Output a single integer representing the total number of distinct sums that can be formed by selecting one number from each range.

## sample
3
1 1
2 2
3 3
1

</p>