#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
int a[2005], dp[2005][2005];
int check(int sum, int l, int r) { return sum <= r && sum >= l; }
int main() {
  int n, h, l, r;
  scanf("%d %d %d %d", &n, &h, &l, &r);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  memset(dp, -Inf, sizeof(dp));
  dp[0][0] = 0;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    for (int j = 0; j <= n; j++) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j] + check((sum - j) % h, l, r));
      if (j < n)
        dp[i][j + 1] =
            max(dp[i][j + 1], dp[i - 1][j] + check((sum - j - 1) % h, l, r));
    }
  }
  int mx = -1;
  for (int i = 0; i <= n; i++) {
    mx = max(dp[n][i], mx);
  }
  printf("%d\n", mx);
}
