#include <bits/stdc++.h>
const int maxn = 2e3 + 5;
using namespace std;
int arr[maxn];
int dp[maxn][maxn];
int check(int x, int lef, int rig) { return (lef <= x && x <= rig ? 1 : 0); }
int main() {
  int n, h, l, r;
  scanf("%d %d %d %d", &n, &h, &l, &r);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  memset((dp), (-1), sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < h; j++) {
      if (dp[i - 1][j] != -1) {
        dp[i][(j + arr[i]) % h] =
            max(dp[i - 1][j] + check((j + arr[i]) % h, l, r),
                dp[i][(j + arr[i]) % h]);
        dp[i][(j + arr[i] - 1) % h] =
            max(dp[i - 1][j] + check((j + arr[i] - 1) % h, l, r),
                dp[i][(j + arr[i] - 1) % h]);
      }
    }
  }
  int ans = -1;
  for (int i = 0; i < h; i++) {
    ans = max(ans, dp[n][i]);
  }
  printf("%d\n", ans);
  return 0;
}
