Air conditioner
An air conditioner is a fantastic device that helps maintain optimal indoor climate conditions. Its primary function is to lower the temperature when it's hot and raise it when it's cold, thereby setting a specific air temperature in a room.
Recently, a Bindbrooms brand air conditioner was installed in the school principal's office. This model is designed to operate within a temperature range from a to b, inclusive. The remote control features two buttons, "+" and "-", along with a field for entering a number. When a number d is entered and the "+" button is pressed, the air conditioner increases the current temperature by d degrees, but not beyond b degrees (if the resulting temperature exceeds b, it is set to b). Conversely, pressing the "-" button with d in the input field decreases the temperature by d degrees, but not below a. Unfortunately, the current temperature is not displayed anywhere, but the initial temperature and the log of all button presses on the remote are available.
Write a program to determine the final temperature set by the air conditioner.
Input
The first line contains three integers a, b, c (-100 ≤ a ≤ c ≤ b ≤ 100), where a and b define the allowable temperature range, and c is the initial temperature. The second line contains an integer N (0 ≤ N ≤ 100), representing the number of temperature changes. Each of the following N lines specifies a temperature change. The first character of each line (+ or -) indicates the button pressed, immediately followed by a non-negative integer that was entered in the input field at the time of pressing the button. The number entered cannot exceed 99.
Output
Output a single integer representing the temperature set after all changes.