#include <bits/stdc++.h>
using namespace std;
long long int n, brr[2002][2002];
long long int result(long long int a, long long int b, long long int *arr,
                     long long int h, long long int l, long long int r) {
  long long int sum = 0, tum = 0, maxi;
  a = a % h;
  if (b >= n) return 0;
  if (brr[a][b] != -1) {
    return brr[a][b];
  }
  if (brr[a][b] == -1) {
    if (a >= l && a <= r) {
      sum++;
      tum++;
    }
    if (b + 1 < n) a = a + arr[b + 1];
    sum = sum + result((a - 1) % h, b + 1, arr, h, l, r);
    tum = tum + result((a % h), b + 1, arr, h, l, r);
    if (b + 1 < n) a = a - arr[b + 1];
    maxi = max(sum, tum);
    brr[a][b] = maxi;
    return brr[a][b];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int h, l, r;
  cin >> n >> h >> l >> r;
  long long int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < 2002; i++) {
    for (int j = 0; j < 2002; j++) brr[i][j] = -1;
  }
  long long int a = (arr[0] - 1) % h, b = arr[0] % h, sum = 0, tum = 0, maxi;
  sum = result(a, 0, arr, h, l, r);
  tum = result(b, 0, arr, h, l, r);
  maxi = max(sum, tum);
  cout << maxi;
  return 0;
}
