Polyclinic
Every day, numerous patients visit the doctor. Each patient spends a whole number of minutes during their appointment, but the duration varies from patient to patient. The doctor begins seeing patients at t[1]
minutes and concludes at t[2]
minutes. This means a patient can enter at any time t[1]
, t[1]
+ 1, ..., up to t[2]
- 1. Arriving at any other time or during another patient's appointment is not permitted. If a patient arrives at the clinic at time t, they wait for the first available moment s ≥ t when the doctor is free and has already attended to all patients who arrived earlier, i.e., before time t. If the doctor cannot see all patients by the end of the session, those remaining must return the following day.
Given the start and end times of the doctor's session, the arrival times of patients on a specific day, and the duration of each patient's examination, determine the optimal time for Petryk Pyatochkin to arrive to ensure he sees the doctor that day with minimal waiting. If multiple times are possible, find the earliest one.
Input
The first line contains three numbers: the number of patients n, the session start time t[1]
, and the session end time t[2]
, where t[2]
is greater than t[1]
.
The second line provides n numbers a[1]
, a[2]
, ..., a[n]
- the arrival times of the first, second, ..., n-th patient at the clinic. These numbers are distinct and sorted in ascending order.
The third line contains n numbers b[1]
, b[2]
, ..., b[n]
- the examination durations for the first, second, ..., n-th patient.
All input numbers are natural numbers. The number of patients n does not exceed 10^5
, and the other numbers do not exceed 10^9
.
On Petryk Pyatochkin's planet, a day is significantly longer than on Earth, so the start time t[1]
, end time t[2]
, as well as the numbers a[1]
, a[2]
, ..., a[n]
and b[1]
, b[2]
, ..., b[n]
can exceed 1440 - the number of minutes in an Earth day.
Output
Output a single natural number - the earliest time Petryk Pyatochkin should arrive at the clinic to ensure he sees the doctor that day with minimal waiting. If Petryk arrives at the same time as another patient, he will be seen first because he is younger.