#t445. 奇怪的电梯
奇怪的电梯
The Strange Elevator
Problem Background
Special for beginners, ^_^
Problem Description
Each floor of the building can stop the elevator, and the -th floor () has a number .
The elevator has only four buttons: open, close, up, down. The number of floors moved up or down equals the number on the current floor.
Of course, if the requirement cannot be met, the corresponding button will not work. For example: 3 3 1 2 5 represents (), starting from the st floor. On the st floor, pressing up goes to the th floor; pressing down does not work, because there is no nd floor.
Then, from floor to floor , what is the minimum number of button presses?
Input Format
The input has two lines. The first line contains three space-separated positive integers (, ). The second line contains space-separated positive integers, representing .
Output Format
Output a single line: the minimum number of button presses. If unreachable, output .
Sample Input 1
5 1 5
3 3 1 2 5
Sample Output 1
3
Constraints
Time limit 1s, memory limit 1024KiB for each test case.