#include <bits/stdc++.h>
using namespace std;
int dp[2005][2005] = {0};
long long int n, t, m, h, l, r;
int check(int v) { return v >= l && v <= r; }
void solve() {
  cin >> n >> h >> l >> r;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> t;
    v.push_back(t);
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= h; j++) dp[i][j] = INT32_MIN;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < h; j++) {
      dp[i][j] = max(dp[i - 1][(j - v[i - 1] + h) % h],
                     dp[i - 1][(j - v[i - 1] + 1 + h) % h]) +
                 (j >= l && j <= r);
    }
  }
  int mx = 0;
  for (int i = 0; i < h; i++) {
    mx = max(mx, dp[n][i]);
  }
  cout << mx << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  { solve(); }
  return 0;
}
