#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include using namespace std; //using namespace atcoder; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 1000000007 //#define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 #define PI acos(-1.0) const double EPS = 1e-10; using ll = long long; using Pi = pair; using Pl = pair; int dp[2010][2010]; int mx[2010]; int main(){ int n,k,x,y; cin >> n >> k >> x >> y; x %= k; y %= k; vector a(n); rep(i,n) cin >> a[i]; rep(i,n) a[i] %= k; rep(i,2010)rep(j,2010) dp[i][j] = -INF; rep(i,2010) mx[i] = -INF; dp[x][y] = dp[y][x] = 0; mx[x] = mx[y] = 0; rep(i,n){ rep(j,k){ int s = (2*k-j-a[i])%k; if(dp[s][j] != -INF) dp[s][j]++; mx[j] = max(mx[j],dp[s][j]); mx[s] = max(mx[s],dp[s][j]); } rep(j,k){ dp[a[i]][j] = max(dp[a[i]][j],mx[j]); dp[j][a[i]] = max(dp[j][a[i]],mx[j]); } rep(j,k) mx[a[i]] = max(mx[a[i]],mx[j]); } int ans = 0; rep(i,k)rep(j,k) ans = max(ans,dp[i][j]); cout << ans << endl; }