#K5146. Compute Total Active Time
Compute Total Active Time
Compute Total Active Time
You are given a list of intervals, where each interval is represented as [L, R] indicating that a thread is active starting at time L and stopping at time R (exclusive). Some intervals may overlap. Your task is to compute the total active time, i.e. the sum of the lengths of the merged (non-overlapping) intervals.
More formally, if you merge all overlapping intervals, the total active time is given by \( \sum{(R_i - L_i)} \) for each merged interval \([L_i, R_i]\).
The input is read from standard input and the result should be printed to standard output.
inputFormat
The first line contains a single integer n representing the number of intervals.
The next n lines each contain two space-separated integers L and R representing the start and end times of a thread's activity interval.
outputFormat
Output a single integer, the total active time where there is at least one thread active.
Note that if the intervals overlap, the overlapping section should only be counted once.
## sample6
1 5
2 6
8 10
5 9
3 4
11 12
10
</p>