structNode { int floor_, cnt_; Node(int floor, int cnt) : floor_(floor), cnt_(cnt) {} };
queue<Node> q;
voidbfs() { while (!q.empty()) { Node u = q.front(); q.pop(); int uf = u.floor_, uc = u.cnt_; if (uf == B) { ans = uc; break; } for (int i = -1; i <= 1; i += 2) { int f = uf + i * dis[uf]; if (f < 1 || f > N || vis[f]) continue; vis[f] = 1; q.emplace(f, uc + 1); } } }
intmain() { cin >> N >> A >> B; for (int i = 1; i <= N; ++i) cin >> dis[i]; q.emplace(A, 0); vis[A] = 1; bfs(); cout << ans; return0; }