#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-8;
const long long INF = 1e18 + 7;
inline long long read() {
  long long X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    X = (X << 3) + (X << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -X : X;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) {
    write(x / 10);
  }
  putchar(x % 10 + '0');
}
const int MAXN = 2e3 + 7;
int n, m, l, r, ans, a[MAXN], dp[MAXN][MAXN];
bool vis[MAXN][MAXN];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> l >> r;
  int i, j;
  for (i = 1; i <= n; i++) cin >> a[i];
  vis[0][0] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 0; j < m; j++) {
      if (vis[i - 1][(j - a[i] + m) % m]) {
        dp[i][j] = max(dp[i][j], dp[i - 1][(j - a[i] + m) % m]);
        vis[i][j] = 1;
      }
      if (vis[i - 1][(j - a[i] + 1 + m) % m]) {
        dp[i][j] = max(dp[i][j], dp[i - 1][(j - a[i] + 1 + m) % m]);
        vis[i][j] = 1;
      }
      if (vis[i][j] && j >= l && j <= r) dp[i][j]++;
    }
  }
  for (i = 0; i < m; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans;
  return 0;
}
