Problem2345--USACO-2015DecBronze P1. Fence Painting

2345: USACO-2015DecBronze P1. Fence Painting

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

几个季节的炎热夏天和寒冷冬天给农夫约翰的篱笆造成了损失,他决定是时候在他最喜欢的奶牛贝西的帮助下重新粉刷篱笆了。不幸的是,虽然贝西非常擅长绘画,但她并不善于理解农夫约翰的指示。

如果我们将栅栏视为一维数字线,Farmer John绘制x=a和x=b之间的间隔。例如,如果a=3和b=5,则Farmer John绘制长度为2的间隔。贝西误解了农夫约翰的指示,画出了从x=c到x=d的区间,这可能与农夫·约翰的部分或全部区间重叠。请确定现在被油漆覆盖的围栏的总长度。

输入:

输入的第一行包含整数a和b,由空格(a<b)分隔。第二行包含整数c和d,用空格分隔(c<d)。

a、b、c和d的值都在0到100之间(包括0到100)。

输出:

请输出一行,其中包含涂有油漆的围栏的总长度。




Several seasons of hot summers and cold winters have taken their toll on Farmer John's fence, and he decides it is time to repaint it, along with the help of his favorite cow, Bessie. Unfortunately, while Bessie is actually remarkably proficient at painting, she is not as good at understanding Farmer John's instructions.

If we regard the fence as a one-dimensional number line, Farmer John paints the interval between x=ax=a and x=bx=b. For example, if a=3a=3 and b=5b=5, then Farmer John paints an interval of length 2. Bessie, misunderstanding Farmer John's instructions, paints the interval from x=cx=c to x=dx=d, which may possibly overlap with part or all of Farmer John's interval. Please determine the total length of fence that is now covered with paint.

INPUT FORMAT (file paint.in):

The first line of the input contains the integers aa and bb, separated by a space (a<ba<b). The second line contains integers cc and dd, separated by a space (c<dc<d).
The values of aa, bb, cc, and dd all lie in the range 0…1000…100, inclusive.

OUTPUT FORMAT (file paint.out):

Please output a single line containing the total length of the fence covered with paint.

SAMPLE INPUT:

7 10
4 8

SAMPLE OUTPUT:

6

Here, 6 total units of fence are covered with paint, from x=4x=4 all the way through x=10x=10.

Problem credits: Brian Dean

Sample Input Copy

7 10
4 8

Sample Output Copy

6

HINT

Here, 6 total units of fence are covered with paint, from x=4x=4 all the way through x=10x=10.

Source/Category