#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int dp[N][N];
int rec[N];
int sum[N];
int n, h, l, r;
int f(int x, int h) {
  if (x % h >= l && x % h <= r) {
    return 1;
  }
  return 0;
}
int main(void) {
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  scanf("%d%d%d%d", &n, &h, &l, &r);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &rec[i]);
  }
  for (int i = 1; i <= n; i++) {
    sum[i] = rec[i] + sum[i - 1];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + f(sum[i + 1] - j, h));
      dp[i + 1][j + 1] =
          max(dp[i + 1][j + 1], dp[i][j] + f(sum[i + 1] - j - 1, h));
    }
  }
  int res = -1;
  for (int i = 0; i <= n; i++) {
    res = max(res, dp[n][i]);
  }
  printf("%d\n", res);
  return 0;
}
