Поликлиника
Many people come to the doctor every day. Each patient goes to doctor on reception for a whole number of minutes, but the doctor can take different amounts of time for different patients. Doctor starts reception at t[1]
minutes and finishes at t[2]
minutes. It means that any patient independently of his reception time, can come to doctor at the moments of time t[1]
, t[1]
+ 1, ..., t[2]
- 1. To go to see a doctor at another time or when the doctor takes another patient is prohibited. If the patient comes to the polyclinic at the time t, he expects the first moment of time s ≥ t such that at this moment the doctor is taking a reception, and already had time to examine all patients who came to the clinic before, that is until the moment t. If the doctor does not have time to examine everyone before the end of the working day, the rest of the patients should come the next day.
Knowing the time when doctor starts and ends the reception, who and when will come to the reception on a particular day, and also how much time will be examined by the doctor each patient, determine the time when it is necessary to come to the reception for Petya Pyatochkin, to be guaranteed to get this day to the doctor, and his expectation time must be as small as possible. In the case of several alternative options for such time, determine the smallest (the earliest) of them.
Input
В первой строке приведено три числа: количество желающих попасть на прием n, время начала приема t[1]
и время завершения приема t[2]
, больший чем t[1]
.
Во второй строке перечислены n чисел a[1]
, a[2]
, …, a[n]
- время, когда в поликлинику зашли соответственно первый, второй, ..., n-ый желающий попасть к доктору. Числа a[1]
, a[2]
, …, a[n]
попарно различны и расположены в порядке возрастания.
В третьей строке перечислены n чисел b[1]
, b[2]
, ..., b[n]
- время, необходимое доктору на осмотр соответственно первого, второго, ..., n-го пациента.
Все входные числа натуральные. Количество пациентов n не больше 10^5
, остальные числа не превосходят 10^9
.
Сутки на планете, где проживает Петя Пяточкин, длятся значительно дольше, чем на Земле, поэтому время начала приема t[1]
, время завершения приема t[2]
, а также числа a[1]
, a[2]
, ..., a[n]
и b[1]
, b[2]
, ..., b[n]
могут быть большими чем 1440 - количество минут в земных сутках.
Output
Вывести наименьший момент времени, когда Петя Пяточкин должен прийти в поликлинику, чтобы гарантированно попасть к доктору, подождав приема как можно меньше времени. Если Петя придет одновременно с другим человеком, его как младшего пропустят вперед.