P1135 Strange Elevator

Background

Thanks to @[yummy](https://www.luogu.com.cn/user/101694) for providing some testdata.

Description

Hehe, one day I had a dream about a very strange elevator. The elevator can stop at every floor of the building, and on floor $i$ ( $1 \le i \le N$ ) there is a number $K_i$ ( $0 \le K_i \le N$ ). The elevator has only four buttons: Open, Close, Up, and Down. The number of floors moved up or down equals the number on the current floor. Of course, if the move would be invalid, the corresponding button will not work. For example: $3, 3, 1, 2, 5$ represents $K_i$ ( $K_1 = 3$, $K_2 = 3$, ... ), starting from floor $1$. On floor $1$, pressing "Up" takes you to floor $4$, and pressing "Down" does nothing because there is no floor $-2$. Then, what is the minimum number of button presses to get from floor $A$ to floor $B$?

Input Format

Two lines in total. The first line contains three positive integers separated by spaces, denoting $N, A, B$ ( $1 \le N \le 200$, $1 \le A, B \le N$ ). The second line contains $N$ non-negative integers separated by spaces, denoting $K_i$.

Output Format

One line: the minimum number of button presses. If it is impossible to reach, output `-1`.

Explanation/Hint

For 100% of the testdata, $1 \le N \le 200$, $1 \le A, B \le N$, $0 \le K_i \le N$. There are $16$ test points in total. The first $15$ test points are worth $6$ points each, and the last test point is worth $10$ points. Translated by ChatGPT 5