#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, l, r;
  cin >> n >> h >> l >> r;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int dp[n + 1][n + 1], s = 0;
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    s += a[i - 1];
    for (int j = 0; j <= i; j++) {
      dp[i][j] = max(j ? dp[i - 1][j - 1] : 0, dp[i - 1][j]);
      if ((s - j) % h >= l && (s - j) % h <= r) dp[i][j]++;
    }
  }
  int res = -1;
  for (int j = 0; j <= n; j++) res = max(res, dp[n][j]);
  cout << res << endl;
  return 0;
}
