#include <bits/stdc++.h>
using namespace std;
int dp[2000][2000] = {0};
int visited[2000][2000] = {0};
long long int n, t, m, h, l, r;
int check(int v) { return v >= l && v <= r; }
void solve() {
  cin >> n >> h >> l >> r;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> t;
    v.push_back(t);
  }
  visited[0][v[0]] = visited[0][v[0] - 1] = 1;
  dp[0][v[0]] = check(v[0]);
  dp[0][v[0] - 1] = check(v[0] - 1);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < h; j++) {
      if (visited[i - 1][j]) {
        visited[i][(v[i] + j) % h] = 1;
        dp[i][(v[i] + j) % h] =
            max(dp[i][(v[i] + j) % h], dp[i - 1][j] + check((v[i] + j) % h));
        visited[i][(v[i] + j - 1) % h] = 1;
        dp[i][(v[i] + j - 1) % h] =
            max(dp[i][(v[i] + j - 1) % h],
                dp[i - 1][j] + check((v[i] + j - 1) % h));
      }
    }
  }
  int mx = 0;
  for (int i = 0; i < h; i++) {
    mx = max(mx, dp[n - 1][i]);
  }
  cout << mx << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  { solve(); }
  return 0;
}
