#include <bits/stdc++.h>
using namespace std;
bool ok(int x, int l, int r) { return x >= l && x <= r; }
void solve() {
  int n, h, l, r;
  cin >> n >> h >> l >> r;
  vector<int> a(n + 3);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int> > dp(n + 10, vector<int>(n + 10, -1e9));
  dp[0][0] = 0;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    for (int j = 0; j <= n; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + ok((sum - j) % h, l, r));
      if (j < n) {
        dp[i + 1][j + 1] =
            max(dp[i + 1][j + 1], dp[i][j] + ok((sum - j - 1) % h, l, r));
      }
    }
  }
  cout << *max_element(dp[n].begin(), dp[n].end());
}
signed main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
