#include <bits/stdc++.h>
using namespace std;
ifstream in("in.txt");
int a[2003][2003];
int main() {
  int n, h, l, r, x;
  cin >> n >> h >> l >> r;
  a[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    for (int j = 0; j < h; ++j) {
      if (a[(j + h - x) % h][i - 1]) {
        a[j][i] = a[(j + h - x) % h][i - 1] + (l <= j && j <= r);
      }
      if (a[(j + h - x + 1) % h][i - 1]) {
        a[j][i] =
            max(a[j][i], a[(j + h - x + 1) % h][i - 1] + (l <= j && j <= r));
      }
    }
  }
  x = 0;
  for (int i = 0; i < h; ++i) {
    x = max(x, a[i][n]);
  }
  cout << x - 1;
  return 0;
}
