#55669: c++ bfs


61247091s@gapps.ntnu.edu.tw (wei)


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, p, l, r;
    if (!(cin >> n >> p >> l >> r)) return 0;

    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    vector<int> step(n, -1);
    queue<int> q;

    q.push(0);
    step[0] = 0;

    int ans = -1;

    while(!q.empty()){
        int curr = q.front();
        q.pop();

        if (curr == p) {
            ans = step[curr];
            break;
        }

        int next_positions[2] = {curr - l, curr + r};

        for (int next_pos : next_positions) {
            if (next_pos < 0 || next_pos >= n) continue;

            int target = v[next_pos];
            if (target < 0 || target >= n) continue;

            if (step[target] == -1) {
                step[target] = step[curr] + 1;
                q.push(target);
            }
        }
    }

    cout << ans << "\n";

    return 0;
}