#C917. Sum of Intervals
Sum of Intervals
Sum of Intervals
Given a set of intervals, your task is to calculate the total length covered by these intervals. Note that if some intervals overlap, the overlapping section should be counted only once. Formally, if the intervals are given as \([a,b)\), the length of an interval is \(b-a\).
The program should read the input from stdin and write the result to stdout. The result is a single integer representing the sum of the lengths of the union of all intervals.
inputFormat
The input begins with an integer \(n\) (\(0 \le n \le 10^5\)), which represents the number of intervals. Each of the next \(n\) lines contains two integers \(a\) and \(b\) (with \(a \leq b\)) representing an interval \([a, b)\). You may assume that \(a\) and \(b\) both fit in a 32-bit signed integer.
outputFormat
Output a single integer on a new line representing the total length covered by the intervals, counting overlapping parts only once.
## sample0
0