#D3920. Delivery to a Luxurious House
Delivery to a Luxurious House
Delivery to a Luxurious House
B-Mansion and courier
Problem Statement
Taro lives alone in a mansion. Taro, who loves studying, intends to study in his study in the house today. Taro can't concentrate outside the study, so he always studies in the study.
However, on this day, of courier service to Taro arrived. () The arrival time of the third courier is . It is painful to have the delivery person wait at the front door, so Taro decided to be at the front door by the time the courier arrives. Due to the large size of the mansion, it takes one way to move between the study and the entrance.
On the other hand, Taro wants to study for as long as possible. Find the maximum amount of time Taro can study in the study from time to time .
Taro is in the study at time , and the courier does not arrive earlier than the time , and the courier does not arrive later than the time . Also, the time it takes for Taro to receive the courier can be ignored.
Input
Each dataset consists of two lines. The first line consists of three integers separated by blanks. These integers satisfy , , . The second line consists of integers separated by blanks. Each fills and is also ().
Output
Output an integer representing the maximum amount of time Taro can study on one line.
Sample Input 1
1 1 5 3
Output for the Sample Input 1
3
Sample Input 2
2 1 10 2 7
Output for the Sample Input 2
6
Sample Input 3
2 4 10 6 8
Output for the Sample Input 3
2
Example
Input
1 1 5 3
Output
3
inputFormat
Input
Each dataset consists of two lines. The first line consists of three integers separated by blanks. These integers satisfy , , . The second line consists of integers separated by blanks. Each fills and is also ().
outputFormat
Output
Output an integer representing the maximum amount of time Taro can study on one line.
Sample Input 1
1 1 5 3
Output for the Sample Input 1
3
Sample Input 2
2 1 10 2 7
Output for the Sample Input 2
6
Sample Input 3
2 4 10 6 8
Output for the Sample Input 3
2
Example
Input
1 1 5 3
Output
3
样例
1 1 5
3
3