#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int f[N][N];
int a[N];
int n, mod, l, r;
int get(int x) { return (x % mod + mod) % mod; }
int check(int x) {
  if (x >= l && x <= r) return 1;
  return 0;
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> mod >> l >> r;
  for (int i = 1; i <= n; i++) cin >> a[i];
  memset(f, -0x3f, sizeof f);
  f[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < mod; j++) {
      int t1 = get(j + a[i]);
      int c1 = check(t1);
      int t2 = get(j + a[i] - 1);
      int c2 = check(t2);
      f[i][t1] = max(f[i][t1], f[i - 1][j] + c1);
      f[i][t2] = max(f[i][t2], f[i - 1][j] + c2);
    }
  }
  int res = 0;
  for (int i = 0; i < mod; i++) res = max(res, f[n][i]);
  cout << res << endl;
  return 0;
}
