#include <bits/stdc++.h>
using namespace std;
int d[2020][2020] = {};
int a[2020] = {};
int main() {
  int n, h, l, r;
  cin >> n >> h >> l >> r;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  d[0][a[0] - 1] = 1 + (l <= a[0] - 1 && a[0] - 1 <= r ? 1 : 0);
  d[0][a[0]] = 1 + (l <= a[0] && a[0] <= r ? 1 : 0);
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < h; ++j) {
      int prev = d[i - 1][j];
      if (prev > 0) {
        int c = (j + a[i]) % h;
        d[i][c] = max(d[i][c], prev + (l <= c && c <= r ? 1 : 0));
        c = (j + a[i] - 1) % h;
        d[i][c] = max(d[i][c], prev + (l <= c && c <= r ? 1 : 0));
      }
    }
  }
  int res = -1;
  for (int i = 0; i < h; ++i) {
    res = max(res, d[n - 1][i]);
  }
  cout << res - 1 << endl;
}
