#include<iostream>
#include<queue>
using namespace std;
struct node{
int n,k,l;
bool s;
};
int main(){
queue<node> q;
node o[500],t;
int n,a,b;
cin>>n>>a>>b;
for(int i=0;i<n;i++){
cin>>o[i].k;
o[i].n=i+1;
if(i+1==a) o[i].s==false;
else o[i].s==true;
}
t.n=a;
t.k=o[a-1].k;
t.s=false;
t.l=0;
q.push(t);
while(!q.empty()){
node top=q.front();
q.front().s=false;
q.pop();
if(b==top.n){
cout<<top.l;
return 0;
}
if(top.k<top.n&&o[top.n-top.k-1].s){
o[top.n-top.k-1].l=top.l+1;
q.push(o[top.n-top.k-1]);
}
if(top.k+top.n<=n){
o[top.n+top.k-1].l=top.l+1;
q.push(o[top.n+top.k-1]);
}
}
cout<<-1;
return 0;
}
测试点1-5,9,14,15 WA,测试点8TLE