Compute the total painted length covered by two given intervals on a number line.
Easy1IntervalsMathNo attempts yetTime limit2sMemory limit512 MBSeveral seasons of hot summers and cold winters have worn down Farmer John's fence, so he decides to repaint it with the help of his favorite cow, Bessie. Bessie is remarkably good at painting, but she is not as good at understanding Farmer John's instructions.
Regard the fence as a one-dimensional number line. Farmer John paints the interval between x=a and x=b. For example, if a=3 and b=5, he paints an interval of length 2. Bessie misunderstands the instructions and paints the interval from x=c to x=d, which may overlap part or all of Farmer John's interval.
Determine the total length of fence that is now covered with paint.
The first line contains the integers a and b, separated by a space. (a<b)
The second line contains the integers c and d, separated by a space. (c<d)
The values of a, b, c, and d all lie between 0 and 100, inclusive.
Print a single line containing the total length of fence covered with paint.
A part of the fence that both of them paint counts once. If the two intervals are disjoint, or meet at a single point, the answer is the sum of the two lengths.