from collections import defaultdict N, K, L, U = map(int, input().split()) A = list(map(int, input().split())) diffs = U - L ok = 0 ng = 1000000000000002 while ng - ok > 1: mid = (ok + ng) // 2 lower = 0 upper = 0 for i in range(N): if A[i] < mid: lower += 1 elif A[i] > mid + diffs: upper += 1 if lower <= upper: ok = mid else: ng = mid d = defaultdict(int) for i in range(N): d[A[i]] += 1 ans = 10 ** 18 + 2 now_score = 0 now_L = ok - K now_U = now_L + diffs left_rem = [0 for _ in range(K)] right_rem = [0 for _ in range(K)] for i in range(N): if A[i] < now_L: now_score += (now_L - A[i] + K - 1) // K left_rem[A[i] % K] += 1 if A[i] > now_U: now_score += (A[i] - now_U + K - 1) // K right_rem[A[i] % K] += 1 ans = min(ans, now_score) for i in range(2 * K): left_rem[(now_L % K + K) % K] += d[now_L] now_score += left_rem[(now_L % K + K) % K] now_L += 1 now_U += 1 now_score -= right_rem[(now_U % K + K) % K] right_rem[(now_U % K + K) % K] -= d[now_U] ans = min(ans, now_score) print(ans)