#include <bits/stdc++.h>
using namespace std;
int a[2005], dp[2005][2005];
int l, r;
bool ok(int x) { return (l <= x && x <= r); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, h;
  cin >> n >> h >> l >> r;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < 2005; i++)
    for (int j = 0; j < 2005; j++) dp[i][j] = -1e9;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < h; j++) {
      int v1 = (j + a[i]) % h;
      int v2 = (j + a[i] - 1) % h;
      dp[i + 1][v1] = max(dp[i + 1][v1], dp[i][j] + ok(v1));
      dp[i + 1][v2] = max(dp[i + 1][v2], dp[i][j] + ok(v2));
    }
  }
  int res = 0;
  for (int i = 0; i < h; i++) res = max(res, dp[n][i]);
  cout << (res) << '\n';
  return 0;
}
