102610: [AtCoder]ABC261 A - Intersection

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:5 Solved:0

Description

Score : $100$ points

Problem Statement

We have a number line. Takahashi painted some parts of this line, as follows:

  • First, he painted the part from $X=L_1$ to $X=R_1$ red.
  • Next, he painted the part from $X=L_2$ to $X=R_2$ blue.

Find the length of the part of the line painted both red and blue.

Constraints

  • $0\leq L_1<R_1\leq 100$
  • $0\leq L_2<R_2\leq 100$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$L_1$ $R_1$ $L_2$ $R_2$

Output

Print the length of the part of the line painted both red and blue, as an integer.


Sample Input 1

0 3 1 5

Sample Output 1

2

The part from $X=0$ to $X=3$ is painted red, and the part from $X=1$ to $X=5$ is painted blue.

Thus, the part from $X=1$ to $X=3$ is painted both red and blue, and its length is $2$.


Sample Input 2

0 1 4 5

Sample Output 2

0

No part is painted both red and blue.


Sample Input 3

0 3 3 7

Sample Output 3

0

If the part painted red and the part painted blue are adjacent to each other, the length of the part painted both red and blue is $0$.

Input

题意翻译

题意: 高桥君将从$L_1$到$R_1$的部分涂成红色,将从$L_2$到$R_2$的部分涂成蓝色。 求同时涂有红色和蓝色的部分的长度。 ### 注:即使红色和蓝色涂的部分相接,两种颜色涂的部分的长度也为0。

Output

分数:100分

问题描述

我们有一个数轴。高桥按照以下方式涂了一些部分:

  • 首先,他将从$X=L_1$到$X=R_1$的部分涂成红色。
  • 接下来,他将从$X=L_2$到$X=R_2$的部分涂成蓝色。

求线段中同时涂成红色和蓝色的部分的长度。

约束

  • $0\leq L_1<R_1\leq 100$
  • $0\leq L_2<R_2\leq 100$
  • 输入中的所有值都是整数。

输入

从标准输入以以下格式获取输入:

$L_1$ $R_1$ $L_2$ $R_2$

输出

以整数形式打印线段中同时涂成红色和蓝色的部分的长度。


样例输入 1

0 3 1 5

样例输出 1

2

从$X=0$到$X=3$的部分涂成红色,从$X=1$到$X=5$的部分涂成蓝色。

因此,从$X=1$到$X=3$的部分同时涂成红色和蓝色,其长度为$2$。


样例输入 2

0 1 4 5

样例输出 2

0

没有部分同时涂成红色和蓝色。


样例输入 3

0 3 3 7

样例输出 3

0

如果涂成红色和涂成蓝色的部分相邻,则同时涂成红色和蓝色的部分的长度为$0$。

加入题单

算法标签: