RADIO
문제
Slavko is driving his new Karambol GT20 car with a top-of-the-line radio (which, of course, Slavko made himself in his basement, next to the laundry washer).
Slavko's radio is very hi-tech and is equipped with two buttons that are used to manually change the frequency, and several buttons that change the frequency to one of the predefined frequencies. More precisely:
- The first button increases the frequency by 1 (one) MHz;
- The second button decreases the frequency by 1 (one) MHz;
- Each of the remaining N buttons changes the frequency to one of the N predefined frequencies.
Your job is to write a program that, given two frequencies A and B, computes the smallest number of button presses needed to change the frequency from A to B.
입력
The first line contains two integers A and B (1 ≤ A, B < 1000, A ≠ B).
The second line of input contains the integer N (1 ≤ N ≤ 5).
The following N lines contain the predefined frequencies (one integer per line, each less than 1000).
출력
Output the smallest number of button presses needed to change the frequency from A to B.
예제
예제 1
100 15 1 15
1
예제 2
88 17 3 18 1 42
2
예제 3
64 120 1 567
56