#include<bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { int n; cin >> n; vector<int> a(n); for (auto &e : a) cin >> e; int x, y; cin >> x >> y; map<int, int> mp; int cur0 = 0, cur1 = 0; mp[0] = 1; for (int i = 0; i < n; i++) { cur0 += (a[i] == 0); cur1 += (a[i] == 1); int f = y * cur0 - x * cur1; mp[f]++; } long long ans = 0, ans2 = 0; for (auto &e : mp) ans += e.second * (e.second - 1) / 2LL; int cnt = 0; for (int i = 0; i < n; i++) { if (a[i] == 2) cnt++; else { ans2 += cnt * (cnt + 1) / 2LL; cnt = 0; } } ans2 += cnt * (cnt + 1) / 2LL; ans %= mod; ans2 %= mod; ans -= ans2; if (ans < 0) ans += mod; ans %= mod; cout << ans << endl; return 0; }