#include <bits/stdc++.h>
using namespace std;
int dp[5005][5005];
int p[5005][5005];
int A[5005];
int main() {
  int N, L, R, H, i, j, k;
  cin >> N >> H >> L >> R;
  for (i = 1; i <= N; i++) cin >> A[i];
  p[1][A[1]] = 1;
  p[1][A[1] - 1] = 1;
  if (A[1] >= L && A[1] <= R) dp[1][A[1]] = 1;
  if (A[1] - 1 >= L && A[1] - 1 <= R) dp[1][A[1] - 1] = 1;
  for (i = 2; i <= N; i++) {
    for (j = 0; j < H; j++) {
      if (p[i - 1][j]) {
        int curr = (j + A[i]) % H;
        if (curr >= L && curr <= R)
          dp[i][curr] = max(dp[i][curr], dp[i - 1][j] + 1);
        else
          dp[i][curr] = max(dp[i][curr], dp[i - 1][j]);
        p[i][curr] = 1;
        curr = (j + A[i] - 1 + H) % H;
        if (curr >= L && curr <= R)
          dp[i][curr] = max(dp[i][curr], dp[i - 1][j] + 1);
        else
          dp[i][curr] = max(dp[i][curr], dp[i - 1][j]);
        p[i][curr] = 1;
      }
    }
  }
  int ans = 0;
  for (j = 0; j < H; j++) ans = max(ans, dp[N][j]);
  cout << ans;
  return 0;
}
