Question
Crate Value Sum Challenge

In a large warehouse, there are 106 crates numbered sequentially from 1 to 106, with each crate’s value matching its number. However, due to certain conditions, the values of crates within specified ranges [L, R] are set to zero. Given N such ranges, which may overlap, can you determine the total sum of all crate values from 1 to 106 after applying these conditions?

Input
The first line of the input contains a single integer N.
The next N lines of the input contains two space-separated integers L and R.

Constraints
0 ≤ N ≤ 105
1 ≤ L ≤ R ≤ 106
Output
Print a single integer denoting the answer.
Example
Sample Input
5
2 20
23 200
21 21
101 2000
2002 999998
Sample Output
2002023
Explanation
Boxes having number 1, 22, 2001, 999999, 1000000 does not belong to any range.
So the sum of these numbers is 2002023 which is our answer.

Online