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