#include <bits/stdc++.h>
using namespace std;
int n, h, l, r, dp[2005][2005];
int main() {
  scanf("%d%d%d%d", &n, &h, &l, &r);
  memset(dp, 0xc0, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    for (int j = 0; j < h; j++) {
      dp[i][j] = max(dp[i][j], dp[i - 1][(j - x + h) % h] + (j >= l && j <= r));
      dp[i][j] =
          max(dp[i][j], dp[i - 1][(j - x + 1 + h) % h] + (j >= l && j <= r));
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) ans = max(ans, dp[n][i]);
  printf("%d", ans);
  return 0;
}
