N, K, X, Y = map(int, input().split()) A = list(map(int, input().split())) mod_A = [a % K for a in A] x = X % K y = Y % K p_initial = min(x, y) q_initial = max(x, y) INF = -1 << 60 current_dp = [[INF] * K for _ in range(K)] current_dp[p_initial][q_initial] = 0 current_states = [(p_initial, q_initial)] for c in mod_A: next_dp = [[INF] * K for _ in range(K)] next_states = set() for (p, q) in current_states: score = current_dp[p][q] sum_mod = (p + q + c) % K add = 1 if sum_mod == 0 else 0 new_score = score + add if next_dp[p][q] < new_score: next_dp[p][q] = new_score next_states.add((p, q)) new_p, new_q = min(p, c), max(p, c) if next_dp[new_p][new_q] < new_score: next_dp[new_p][new_q] = new_score next_states.add((new_p, new_q)) new_p2, new_q2 = min(q, c), max(q, c) if next_dp[new_p2][new_q2] < new_score: next_dp[new_p2][new_q2] = new_score next_states.add((new_p2, new_q2)) current_dp = [row[:] for row in next_dp] current_states = list(next_states) max_score = 0 for p in range(K): for q in range(p, K): if current_dp[p][q] > max_score: max_score = current_dp[p][q] print(max_score)