n, k, L, U = map(int, input().split()) A = list(map(int, input().split())) l = -(1 << 60) r = 1 << 60 while r - l > 1: mid = (l + r) // 2 c = 0 for a in A: x = a + mid if x < L: c += 1 elif x + k >= U: c -= 1 if c > 0: l = mid else: r = mid A = [a + r for a in A] tot = 0 add = {} for a in A: if a < L: tot += (L - a + k - 1) // k x = (L - a) % k if x == 0: x = k add[x] = add.get(x, 0) - 1 elif a + k > U: tot += (a - U + k - 1) // k x = (U - a + 1) % k if x == 0: x = k add[x] = add.get(x, 0) + 1 ans = tot for k in sorted(add.keys()): tot += add[k] ans = min(ans, tot) print(ans)