Plus
Pin


Problem description Progress
ID 38310. Transplants
Темы: Intersection of many    Segments   

On Novy Prospekt for unloading, it was decided to launch two new bus routes on different sections of the avenue.  The final stops of each of the buses are known. Determine the number of stops  where you can transfer from one bus to another.

Input
Four numbers are entered, not exceeding 100, specifying the numbers of the final stops. First for the first, then the second bus (see examples and picture).

Imprint
Your program should output a single number – desired number of stops.

Examples
# Input Output Explanation
1 3 6 4 2 2 The first bus runs from the 3rd stop to the 6th and back, and the second from the 2nd to the 4th and back. You can transfer from one bus to another at the 3rd and 4th stops. There are two of them.
2 3 1 5 10 0 buses do not have common stops.

ID 38583. Two buttons
Темы: Formula derivation    Segments    Intersection of many   

Alice and Bob control the robot. Each of them has one button that controls the robot. Alice started holding the button A seconds after starting the robot and released the button  B seconds after trigger. Bob started holding the button seconds after trigger and released the button after D seconds after trigger.  How many seconds did Alice and Bob hold their buttons at the same time?

Input
Input 4 integers: A, B, C and (\(1<=A<B<=100\)\(1<=C<D<=100\) ).

Imprint
Print the length of time (in seconds) that Alice and Bob held their buttons simultaneously.
 

 

Examples
# Input Output Explanations
1 0 75 25 100 50 Alice started holding the button 0 seconds after the robot started and released it 75 seconds after it started.
Bob started holding the button 25 seconds after launch and released it 100 seconds after launch.
Therefore, the time they both held down their buttons is 50 seconds from 25 seconds after launch to 75 seconds after launch.
2 0 33 66 99 0 Alice and Bob didn't hold down the buttons at the same time, so the answer is zero seconds.
3 10 90 20 80 60