#include <bits/stdc++.h>
using namespace std;
long long n;
long long dp[2005][2005];
long long A[200200];
long long r, l, h, ans;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> h >> l >> r;
  for (long long i = 1; i <= n; i++) cin >> A[i];
  for (long long i = 0; i <= n; i++)
    for (long long j = 0; j < h; j++) dp[i][j] = -1e15;
  dp[0][0] = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < h; j++) {
      dp[i][j] =
          max(dp[i][j], dp[i - 1][(j + h - A[i]) % h] + (j <= r && j >= l));
      dp[i][j] =
          max(dp[i][j], dp[i - 1][(j + h - A[i] + 1) % h] + (j <= r && j >= l));
    }
  }
  for (long long i = 0; i < h; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;
}
