Mandarins
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Marichka plans to buy mandarins for Zenyk.
Marichka knows that Zenyk will be upset if the number of mandarins is from \(l_1\) to \(r_1\) inclusively. Marichka herself will be upset if the number of mandarins is from \(l_2\) to \(r_2\) inclusively.
Marichka is wondering what is the minimum number of mandarins she can buy so that everyone is happy. Of course, she needs to buy at least one mandarin.
Input
The first line contains 2 integers \(l_1\) and \(r_1\).
The second line contains 2 integers \(l_2\) and \(r_2\).
Output
Output a single integer — the minimum number of mandarins Marichka can buy.
Constraints
\(1 \le l_1 < r_1 \le 10^9\),
\(1 \le l_2 < r_2 \le 10^9\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 7 10 1 6 | 11 |
| Input (stdin) | Output (stdout) |
|---|---|
| 4 7 2 5 | 1 |
Source: The Algo Battles 2023 - Етап 5
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|