Problem
Dima – a programmer, so there are always a lot of windows open on his computer. Since Dima does not have a very large monitor, only one window can be displayed on it. At each point in time, the window manager keeps a list of open windows, the first window of the list is displayed on the monitor. Dima uses the keyboard shortcut Alt + Tab to switch windows. If you keep this button pressed for T
seconds, then. T
+ the first window in the current numbering will move to the first position, and the relative order of the remaining windows will not change.
For example, the figure below shows what happens to the window order if you press Alt + Tab for 3 seconds. If you hold Alt + Tab N – 1
second, the last window in the list will be the first one. The list of open windows is "looped", the last window is followed by the first window from the list, i.e. if you hold down Alt + Tab for N seconds, then the window that was the first in the list will remain in first place.
If you hold down Alt + Tab N + 1
for a second, the second window will move to the first position, and so on.
At the beginning of the working day, Dima's favorite development environment had the number M
in the list of open windows. During the day, Dima K
once used the keyboard shortcut Alt + Tab. Determine where his favorite development environment is at the end of the day.
Input:
The first line of the input contains an integer N
, \(1 <= N <= 10^5\) – the number of windows on the screen.
The second line contains an integer M
, \(1 <= M <= N \)– the number that Dima's favorite development environment had at the beginning of the day.
The third line contains an integer K
, \(1 <= K <= 10^5\) – number of times Dima pressed Alt + Tab. The following K
lines contain positive integers not exceeding 105 – the duration of each press in seconds.
Output:
The program should output a single integer – the position of Dima's favorite environment at the end of the working day.
Examples
# |
Input |
Output |
Note |
1 |
3
2
3
1
5
2
|
3 |
There are three windows on the screen. Let's number the windows from 1 to 3 in the same order as
which they were located at the beginning of the day. Dima's development environment
was number 2. Dima pressed Alt + Tab three times,
The press duration was 1, 5 and 2 seconds. Then
windows layout after each click will be like this:
Press for 1s, the second window moves to the beginning of – 2 1 3.
Pressed for 5 seconds, the third window moves to the top of – 3 2 1
Pressed for 2s, the third window moves to the top of – 1 3 2
As a result, Dima's development environment was in place 3 in the list
|