#include <bits/stdc++.h>
using namespace std;
int present(int x, int l, int r) {
  if (l <= x && x <= r)
    return 1;
  else
    return 0;
}
int main() {
  int n, h, l, r;
  scanf("%d %d %d %d", &n, &h, &l, &r);
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<int> > dp(n + 1, vector<int>(n + 1, INT_MIN));
  dp[0][0] = 0;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    for (int j = 0; j <= n; j++) {
      dp[i + 1][j] =
          std::max(dp[i + 1][j], dp[i][j] + present((sum - j) % h, l, r));
      if (j < n)
        dp[i + 1][j + 1] = std::max(
            dp[i + 1][j + 1], dp[i][j] + present((sum - j - 1) % h, l, r));
    }
  }
  sort(dp[n].begin(), dp[n].end());
  cout << dp[n][n] << endl;
}
