You are given \(10^6\) boxes that are numbered from \(1\) to \(10^6\). The value of each box is equal to its number.
There are \(N\) ranges and every range consists of two integers \(L\) and \(R\) denoting that the value of box in the range \([L,R] \) will turn out to be zero.
Find the sum of values of all boxes from \(1\) to \(10^6\) .
Note: The ranges may overlap.
Input format
- First line: Integer \(N\)
- Next N lines: Two space-separated integers \(L\) and \(R\)
Output format
Print a single integer denoting the answer.
Constraints
\(0 ≤ N ≤ 10^5 \)
\(1 ≤ L ≤ R ≤ 10^6 \)
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.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor