#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 10;
int a[MAXN], dp[MAXN][MAXN];
int n, h, l, r;
bool in(int t) { return l <= t && t <= r; }
int main() {
  scanf("%d %d %d %d", &n, &h, &l, &r);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < h; j++) {
      if (dp[i][j] == -1) continue;
      int nxt = (j + a[i + 1] - 1) % h;
      dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][j] + in(nxt));
      (++nxt) %= h;
      dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][j] + in(nxt));
    }
  }
  int mx = 0;
  for (int i = 0; i < h; i++) mx = max(mx, dp[n][i]);
  printf("%d\n", mx);
  return 0;
}
