Vova had a pretty weird sleeping schedule. There are $$$h$$$ hours in a day. Vova will sleep exactly $$$n$$$ times. The $$$i$$$-th time he will sleep exactly after $$$a_i$$$ hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is $$$0$$$). Each time Vova sleeps exactly one day (in other words, $$$h$$$ hours).Vova thinks that the $$$i$$$-th sleeping time is good if he starts to sleep between hours $$$l$$$ and $$$r$$$ inclusive.Vova can control himself and before the $$$i$$$-th time can choose between two options: go to sleep after $$$a_i$$$ hours or after $$$a_i - 1$$$ hours.Your task is to say the maximum number of good sleeping times Vova can obtain if he acts optimally.

The first line of the input contains four integers $$$n, h, l$$$ and $$$r$$$ ($$$1 \le n \le 2000, 3 \le h \le 2000, 0 \le l \le r < h$$$) — the number of times Vova goes to sleep, the number of hours in a day and the segment of the good sleeping time. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i < h$$$), where $$$a_i$$$ is the number of hours after which Vova goes to sleep the $$$i$$$-th time.

Print one integer — the maximum number of good sleeping times Vova can obtain if he acts optimally.

NoteThe maximum number of good times in the example is $$$3$$$.The story starts from $$$t=0$$$. Then Vova goes to sleep after $$$a_1 - 1$$$ hours, now the time is $$$15$$$. This time is not good. Then Vova goes to sleep after $$$a_2 - 1$$$ hours, now the time is $$$15 + 16 = 7$$$. This time is also not good. Then Vova goes to sleep after $$$a_3$$$ hours, now the time is $$$7 + 14 = 21$$$. This time is good. Then Vova goes to sleep after $$$a_4 - 1$$$ hours, now the time is $$$21 + 19 = 16$$$. This time is not good. Then Vova goes to sleep after $$$a_5$$$ hours, now the time is $$$16 + 20 = 12$$$. This time is not good. Then Vova goes to sleep after $$$a_6$$$ hours, now the time is $$$12 + 11 = 23$$$. This time is good. Then Vova goes to sleep after $$$a_7$$$ hours, now the time is $$$23 + 22 = 21$$$. This time is also good.

/*
URL:
https://codeforces.com/problemset/problem/1324/E
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	n, h, l, r int
	A          []int

	dp [2000 + 10][2000 + 10]int
)

func main() {
	n, h, l, r = ReadInt4()
	A = ReadIntSlice(n)

	for i := 0; i <= n; i++ {
		for j := 0; j < h; j++ {
			dp[i][j] = -INF_BIT30
		}
	}
	dp[0][0] = 0

	for i := 0; i < n; i++ {
		a := A[i]
		for j := 0; j < h; j++ {
			nj := (j + a) % h
			if l <= nj && nj <= r {
				ChMax(&dp[i+1][nj], dp[i][j]+1)
			} else {
				ChMax(&dp[i+1][nj], dp[i][j])
			}

			nj = (j + a - 1) % h
			if l <= nj && nj <= r {
				ChMax(&dp[i+1][nj], dp[i][j]+1)
			} else {
				ChMax(&dp[i+1][nj], dp[i][j])
			}
		}
	}

	// for i := 0; i <= n; i++ {
	// 	PrintfDebug("dp[%d]: %v\n", i, dp[i][:h])
	// }

	fmt.Println(Max(dp[n][:h]...))
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

const MIN = -(1 << 31)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	var n, h, l, r int
	scanf("%d %d %d %d\n", &n, &h, &l, &r)
	hour := make([]int, n)
	for i := range hour {
		scanf("%d", &hour[i])
	}
	solve(n, h, l, r, hour)
}

func solve(n, h, l, r int, hour []int) {
	dp := make([]int, h)
	for i := range dp {
		dp[i] = MIN
	}
	dp[0] = 0
	for _, hr := range hour {
		next := make([]int, h)
		for i := range next {
			next[i] = MIN
		}
		for i := range dp {
			h1, h2 := (i+hr)%h, (i+hr-1)%h
			v1, v2 := 0, 0
			if good(h1, l, r) {
				v1 = 1
			}
			if good(h2, l, r) {
				v2 = 1
			}
			next[h1] = max(next[h1], dp[i]+v1)
			next[h2] = max(next[h2], dp[i]+v2)
		}
		dp = next
	}
	res := 0
	for _, n := range dp {
		res = max(res, n)
	}
	printf("%d\n", res)
}

func good(h, l, r int) bool {
	return h >= l && h <= r
}

func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, h, l, r int
	fmt.Fscan(reader, &n, &h, &l, &r)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}
	rls := solve(h, l, r, a)
	fmt.Println(rls)
}

func solve(h, l, r int, a []int) int {
	n := len(a)
	dp := make(map[int]int)
	dp[0] = 0
	for i := 0; i < n; i++ {
		newdp := make(map[int]int)
		for k, v := range dp {
			k1 := (k + a[i]) % h
			k2 := (k + a[i] - 1) % h
			if newdp[k1] <= v {
				newdp[k1] = v
			}
			if newdp[k2] <= v {
				newdp[k2] = v
			}
		}
		dp = newdp
		for k, v := range dp {
			if k >= l && k <= r {
				dp[k] = v + 1
			}
		}
	}
	rls := 0
	for _, v := range dp {
		if rls < v {
			rls = v
		}
	}
	return rls
}

/*
URL:
https://codeforces.com/problemset/problem/1324/E
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	n, h, l, r int
	A          []int

	dp [2000 + 10][2000 + 10]int
)

func main() {
	n, h, l, r = ReadInt4()
	A = ReadIntSlice(n)

	for i := 0; i <= n; i++ {
		for j := 0; j < h; j++ {
			dp[i][j] = -INF_BIT30
		}
	}
	dp[0][0] = 0

	for i := 0; i < n; i++ {
		a := A[i]
		for j := 0; j < h; j++ {
			diff := 0
			// if l <= j && j <= r {
			// 	diff = 1
			// }

			nj := (j + a) % h
			if l <= nj && nj <= r {
				diff = 1
			}
			ChMax(&dp[i+1][nj], dp[i][j]+diff)
			nj = (j + a - 1) % h
			if l <= nj && nj <= r {
				diff = 1
			}
			ChMax(&dp[i+1][nj], dp[i][j]+diff)
		}
	}

	// for i := 0; i <= n; i++ {
	// 	PrintfDebug("dp[%d]: %v\n", i, dp[i][:h])
	// }

	fmt.Println(Max(dp[n][:h]...))
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	var n, h, l, r int
	scanf("%d %d %d %d\n", &n, &h, &l, &r)
	hour := make([]int, n)
	for i := range hour {
		scanf("%d", &hour[i])
	}
	solve(n, h, l, r, hour)
}

func solve(n, h, l, r int, hour []int) {
	dp := make([]int, h)
	for _, hr := range hour {
		next := make([]int, h)
		for i := range dp {
			h1, h2 := (i+hr)%h, (i+hr-1)%h
			v1, v2 := 0, 0
			if good(h1, l, r) {
				v1 = 1
			}
			if good(h2, l, r) {
				v2 = 1
			}
			next[h1] = max(next[h1], dp[i]+v1)
			next[h2] = max(next[h2], dp[i]+v2)
		}
		dp = next
	}
	res := 0
	for _, n := range dp {
		res = max(res, n)
	}
	printf("%d\n", res)
}

func good(h, l, r int) bool {
	return h >= l && h <= r
}

func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}