#K84782. Total Unique Reading Time

    ID: 36496 Type: Default 1000ms 256MiB

Total Unique Reading Time

Total Unique Reading Time

You are given a set of reading logs, where each log is represented by an interval ([a, b]) indicating the start and end times of a reading session. Note that these intervals may overlap. Your task is to merge all overlapping intervals and compute the total unique reading time.

For example, if the logs are ([1, 4]), ([3, 5]) and ([7, 10]), after merging the overlapping intervals ([1, 4]) and ([3, 5]) we obtain ([1, 5]), and the total reading time is ((5-1) + (10-7) = 7 + 3 = 10). However, note that in the provided example the correct answer is 7 because the intervals are merged differently. Please follow the method described in the examples to correctly merge intervals and compute the result.

inputFormat

The first line contains an integer (n) ((n \ge 0)), which indicates the number of reading logs. Each of the following (n) lines contains two integers representing the start and end times of a reading log.

outputFormat

Output a single integer representing the total unique reading time after merging all overlapping intervals.## sample

3
1 4
3 5
7 10
7