#include <bits/stdc++.h>
using namespace std;
const long long N = 11;
const long long maxn = 2e3 + 9;
const double esp = 1e-6;
long long dp[maxn][maxn];
long long n, h, l, r;
vector<long long> v(maxn);
long long dfs(long long pos, long long sum) {
  if (pos > n) return 0;
  long long &ret = dp[pos][sum];
  if (ret != -1) return dp[pos][sum];
  long long c = (sum + v[pos] - 1) % h;
  long long d = (sum + v[pos]) % h;
  long long a = dfs(pos + 1, c) + (c >= l && c <= r);
  long long b = dfs(pos + 1, d) + (d >= l && d <= r);
  return dp[pos][sum] = max(a, b);
}
void solve() {
  cin >> n >> h >> l >> r;
  for (long long i = 1; i <= n; i++) {
    cin >> v[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << dfs(1, 0) << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  solve();
}
