#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  long long int res = 1;
  a %= 1000000007;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
long long int modInverse(long long int a) { return power(a, 1000000007 - 2); }
const int N = 500023;
bool vis[N];
vector<int> adj[N];
void solve() {
  long long int n, h, l, r;
  cin >> n >> h >> l >> r;
  vector<long long int> v;
  v.push_back(0);
  for (long long int i = 0; i < n; i++) {
    long long int c;
    cin >> c;
    v.push_back(c);
  }
  long long int dp[n + 1][h + 1];
  for (long long int i = 0; i < n + 1; i++) {
    for (long long int j = 0; j < h + 1; j++) dp[i][j] = -1;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int a = 0; a < h; a++) {
      long long int prev = (a - v[i] + h) % h;
      dp[i][a] = dp[i - 1][prev];
      prev = (a - (v[i] - 1) + h) % h;
      dp[i][a] = max(dp[i][a], dp[i - 1][prev]);
      if (dp[i][a] != -1) {
        if (a >= l && a <= r) dp[i][a]++;
      }
    }
  }
  long long int ans = 0;
  for (int i = 0; i < h; i++) ans = max(ans, dp[n][i]);
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  int t = 0;
  while (t++ < T) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
