#include <bits/stdc++.h>
using namespace std;
int a[2005];
int sum[2005];
int dp[2005][2005];
int n, h, l, r;
int check(int index, int sub) {
  int temp = (sum[index] - sub) % h;
  if (temp >= l && temp <= r)
    return 1;
  else
    return 0;
}
int main() {
  cin >> n >> h >> l >> r;
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    sum[i] = sum[i - 1] + a[i];
  }
  dp[1][0] = check(1, 0);
  dp[1][1] = check(1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      int temp = min(i - 1, j);
      dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][temp]) + check(i, j);
    }
  }
  int res = -1;
  for (int j = 0; j <= n; j++) {
    res = max(res, dp[n][j]);
  }
  printf("%d\n", res);
  return 0;
}
