import sys from collections import defaultdict def main(): input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 K = int(data[idx]) idx += 1 X = int(data[idx]) idx += 1 Y = int(data[idx]) idx += 1 A = list(map(int, data[idx:idx+N])) x_mod = X % K y_mod = Y % K if x_mod > y_mod: x_mod, y_mod = y_mod, x_mod current_dp = {(x_mod, y_mod): 0} for a in A: c = a % K next_dp = defaultdict(int) for (a_prev, b_prev), points in current_dp.items(): total = a_prev + b_prev + c new_points = points + (1 if total % K == 0 else 0) # Option 1: Keep a_prev and b_prev key = (a_prev, b_prev) if next_dp[key] < new_points: next_dp[key] = new_points # Option 2: Keep a_prev and c if a_prev <= c: key2 = (a_prev, c) else: key2 = (c, a_prev) if next_dp[key2] < new_points: next_dp[key2] = new_points # Option 3: Keep b_prev and c if b_prev <= c: key3 = (b_prev, c) else: key3 = (c, b_prev) if next_dp[key3] < new_points: next_dp[key3] = new_points current_dp = next_dp if current_dp: print(max(current_dp.values())) else: print(0) if __name__ == "__main__": main()