#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e3 + 5;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qmi(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int dp[N][N];
bool book[N][N];
int main() {
  int n, h, l, r;
  cin >> n >> h >> l >> r;
  book[0][0] = true;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    for (int k = 0; k < h; k++) {
      int t = 0;
      if (k >= l && k <= r) t++;
      if (book[i - 1][(k - x + 1 + h) % h])
        dp[i][k] = max(dp[i][k], dp[i - 1][(k - x + 1 + h) % h] + t),
        book[i][k] = true;
      if (book[i - 1][(k - x + h) % h])
        dp[i][k] = max(dp[i][k], dp[i - 1][(k - x + h) % h] + t),
        book[i][k] = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
