cho.sh
Notes
Loading...

Hopping Frog

Time limit

2s

Memory limit

128 MB

Problem

A frog is hopping across stepping stones numbered from 1 to N in a straight line. Each stone has one positive integer written on it. When the frog is standing on stone i, it may jump to another stone whose distance from i is a positive multiple of the number written on stone i. The frog may jump left or right, but only to stones numbered from 1 to N.

The frog starts on stone a and wants to reach stone b. Find the minimum number of jumps needed to reach stone b.

Input

The first line contains the number of stepping stones N(1 ≤ N ≤ 10,000).

The second line contains N positive integers in order, where the i-th integer is written on the i-th stone. Each integer is at most 10,000.

The third line contains two positive integers a and b. They mean that the frog starts on stone a and wants to reach stone b. Both a and b are at most N.

Output

Print the minimum number of jumps needed for the frog to move from stone a to stone b.

If stone b cannot be reached from stone a, print -1.

Hint

If the number written on stone 1 is 1, the frog can jump directly to stone 5 by moving a distance of 4, which is a multiple of 1.