#include <bits/stdc++.h>
using namespace std;
const long long N = 11;
const long long maxn = 2e3 + 9;
const double esp = 1e-6;
long long dp[maxn][maxn];
void solve() {
  long long n, h, l, r;
  cin >> n >> h >> l >> r;
  vector<long long> v(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> v[i];
  }
  fill(dp[0], dp[0] + maxn * maxn, -1);
  dp[0][0] = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= h - 1; j++) {
      if (dp[i - 1][j] != -1) {
        long long k = (j + v[i]) % h;
        if (k >= l && k <= r) {
          dp[i][k] = max(dp[i][k], dp[i - 1][j] + 1);
        } else {
          dp[i][k] = max(dp[i][k], dp[i - 1][j]);
        }
        k = (j + v[i] - 1) % h;
        if (k >= l && k <= r) {
          dp[i][k] = max(dp[i][k], dp[i - 1][j] + 1);
        } else {
          dp[i][k] = max(dp[i][k], dp[i - 1][j]);
        }
      }
    }
  }
  long long ans = -1;
  for (long long i = 0; i <= h - 1; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  solve();
}
