#include <bits/stdc++.h>
using namespace std;
long long dp[2005][2005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, h, l, r;
  cin >> n >> h >> l >> r;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int k = a[i] % h;
    if (l <= k && k <= r)
      dp[i][0] = dp[i - 1][0] + 1;
    else
      dp[i][0] = dp[i - 1][0];
    for (int j = 1; j <= i; ++j) {
      int t = (a[i] - j) % h;
      if (l <= t && t <= r)
        dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + 1;
      else
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]);
    }
  }
  for (int i = 0; i <= n; ++i) ans = max(ans, dp[n][i]);
  cout << ans;
}
