#include <bits/stdc++.h>
using namespace std;
const int INF = 9999999;
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int dp[2010][2010];
int n, h, l, r;
bool fun(int x) {
  if (x >= l and x <= r) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> h >> l >> r;
  int sum = 0, x;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) dp[i][j] = INT_MIN;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    for (int j = 0; j <= n; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + fun((sum - j) % h));
      if (j < n)
        dp[i + 1][j + 1] =
            max(dp[i + 1][j + 1], dp[i][j] + fun((sum - j - 1) % h));
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
