#include <bits/stdc++.h>
using namespace std;
int dp[2004][2004], a[2004];
int main() {
  int n, h, l, r;
  cin >> n >> h >> l >> r;
  memset(dp, -0x3f3f3f3f, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < h; j++) {
      if ((j + a[i]) % h >= l && (j + a[i]) % h <= r) {
        dp[i][(j + a[i]) % h] = max(dp[i][(j + a[i]) % h], dp[i - 1][j] + 1);
      } else
        dp[i][(j + a[i]) % h] = max(dp[i][(j + a[i]) % h], dp[i - 1][j]);
      if ((j + a[i] - 1) % h >= l && (j + a[i] - 1) % h <= r) {
        dp[i][(j + a[i] - 1) % h] =
            max(dp[i][(j + a[i] - 1) % h], dp[i - 1][j] + 1);
      } else
        dp[i][(j + a[i] - 1) % h] =
            max(dp[i][(j + a[i] - 1) % h], dp[i - 1][j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans;
}
