Drawing Lines
InterviewTime limit1sMemory limit256 MB
Given N segments on a number line, find the total length of their union, counting overlaps once and printing it as an integer.
Problem
Junyong's nephew Junseop was drawing several line segments parallel to one straight line with a crayon.
Watching Junseop, Junyong became curious about the total length of the segments after projecting every line Junseop drew onto the number line.
You, who need to stay on Junyong's good side, must write a program that answers Junyong's question.
Input
The first line gives , the number of lines Junseop drew.
Lines 2 through give the start coordinate and the end coordinate of each line Junseop drew, in that order. and are integers separated by a space.
ranges from 1 to 10,000. The start and end coordinates of a line are natural numbers from 1 to 10,000.
Output
Print the total length of the lines projected onto the number line as an integer.
Hint
Sample explanation
- Orange lines: the lines Junseop drew
- Green lines: the lines projected onto the number line