#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int mj = 2e5 + 5;
template <typename T>
void add(T& a, T b) {
  a += b;
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
}
template <typename T>
void mul(T& a, T b) {
  a = a * b % mod;
}
template <typename T>
void up_self(T& a, T b) {
  a = max(a, b);
}
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
string find_largest_pref_palindrome(const string& a) {
  string second = a;
  reverse(second.begin(), second.end());
  second = a + "%" + second;
  int c = 0;
  vector<int> pref(2 * ((int)a.size()) + 2);
  for (int i = 1; i < second.size(); i++) {
    while (c != 0 && second[i] != second[c]) c = pref[c - 1];
    if (second[i] == second[c]) c++;
    pref[i] = c;
  }
  return second.substr(0, c);
}
long long int binexpomodulo(long long int x, long long int y) {
  long long int res = 1;
  x %= mod;
  if (!x) return 0;
  while (y) {
    if (y & 1) {
      mul(res, x);
    }
    mul(x, x);
    y >>= 1;
  }
  return res;
}
long long int nCrInOr(long long int n, long long int r) {
  long long int res = 1;
  if (r > n - r) r = n - r;
  long long int rin = 1;
  for (long long int i = 1; i <= r; i++) rin = (rin * i) % mod;
  rin = binexpomodulo(rin, mod - 2);
  for (long long int i = 1; i <= r; i++) res = (res * (n - i + 1)) % mod;
  res = (res * rin) % mod;
  return res;
}
int msb(long long int n) {
  int ans;
  for (int i = 0; i < 64; i++)
    if (n & (1LL << i)) ans = i + 1;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, h, l, r;
  cin >> n >> h >> l >> r;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ;
  vector<vector<int>> dp(n + 1, vector<int>(n + 1, INT_MIN));
  long long int sum = 0;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    for (int j = 0; j <= n; j++) {
      up_self(dp[i + 1][j],
              dp[i][j] + (((sum - j) % h) <= r && ((sum - j) % h) >= l));
      if (j < n)
        up_self(dp[i + 1][j + 1], dp[i][j] + (((sum - j - 1) % h) <= r &&
                                              ((sum - j - 1) % h) >= l));
    }
  }
  cout << *max_element(dp[n].begin(), dp[n].end()) << "\n";
  return 0;
}
