#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 1;
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  if (f) x = -x;
}
template <typename F>
inline void write(F x, char ed = '\n') {
  static short st[30];
  short tp = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++tp] = x % 10, x /= 10;
  while (x);
  while (tp) putchar('0' | st[tp--]);
  putchar(ed);
}
const int MAX = 1e6 + 7;
const int INF = 1e9;
const int mod = 1e9 + 7;
long long powmod(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;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int dp[2100][2100];
int a[2100];
int main() {
  int n, h, l, r;
  cin >> n >> h >> l >> r;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  memset(dp, -0x3f, sizeof(dp));
  dp[0][0] = 0;
  dp[1][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < h; j++) {
      dp[i][j] = max(dp[i - 1][(h + j - a[i]) % h],
                     dp[i - 1][(h + j - a[i] + 1) % h]) +
                 (j >= l && j <= r);
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    ans = max(dp[n][i], ans);
  }
  cout << ans << endl;
  return 0;
}
