RADIO | 프로그래밍의 벗 PivotOJ
PivotOJ

RADIO

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2007 Regional Competition - JuniorsBOJ 3135

문제

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
코드를 제출하려면 로그인하세요.