#include template class ModInt{ public: uint64_t val; constexpr ModInt(): val(0){} constexpr ModInt(std::int64_t n){ if(n >= M) val = n % M; else if(n < 0) val = n % M + M; else val = n; } inline constexpr auto operator+(const ModInt &a) const {return ModInt(val + a.val);} inline constexpr auto operator-(const ModInt &a) const {return ModInt(val - a.val);} inline constexpr auto operator*(const ModInt &a) const {return ModInt(val * a.val);} inline constexpr auto operator/(const ModInt &a) const {return ModInt(val * a.inv().val);} inline constexpr auto& operator=(const ModInt &a){val = a.val; return *this;} inline constexpr auto& operator+=(const ModInt &a){if((val += a.val) >= M) val -= M; return *this;} inline constexpr auto& operator-=(const ModInt &a){if(val < a.val) val += M; val -= a.val; return *this;} inline constexpr auto& operator*=(const ModInt &a){(val *= a.val) %= M; return *this;} inline constexpr auto& operator/=(const ModInt &a){(val *= a.inv().val) %= M; return *this;} inline constexpr bool operator==(const ModInt &a) const {return val == a.val;} inline constexpr bool operator!=(const ModInt &a) const {return val != a.val;} inline constexpr auto& operator++(){*this += 1; return *this;} inline constexpr auto& operator--(){*this -= 1; return *this;} inline constexpr auto operator++(int){auto t = *this; *this += 1; return t;} inline constexpr auto operator--(int){auto t = *this; *this -= 1; return t;} inline constexpr static ModInt power(int64_t n, int64_t p){ if(p < 0) return power(n, -p).inv(); int64_t ret = 1, e = n; for(; p; (e *= e) %= M, p >>= 1) if(p & 1) (ret *= e) %= M; return ret; } inline constexpr static ModInt inv(int64_t a){ int64_t b = M, u = 1, v = 0; while(b){ int64_t t = a / b; a -= t * b; std::swap(a,b); u -= t * v; std::swap(u,v); } u %= M; if(u < 0) u += M; return u; } inline constexpr static auto frac(int64_t a, int64_t b){return ModInt(a) / ModInt(b);} inline constexpr auto power(int64_t p) const {return power(val, p);} inline constexpr auto inv() const {return inv(val);} friend inline constexpr auto operator-(const ModInt &a){return ModInt(-a.val);} friend inline constexpr auto operator+(int64_t a, const ModInt &b){return ModInt(a) + b;} friend inline constexpr auto operator-(int64_t a, const ModInt &b){return ModInt(a) - b;} friend inline constexpr auto operator*(int64_t a, const ModInt &b){return ModInt(a) * b;} friend inline constexpr auto operator/(int64_t a, const ModInt &b){return ModInt(a) / b;} friend std::istream& operator>>(std::istream &s, ModInt &a){s >> a.val; return s;} friend std::ostream& operator<<(std::ostream &s, const ModInt &a){s << a.val; return s;} template inline static auto div(){ static auto value = inv(N); return value; } }; template , typename Minus = std::minus> class CumulativeSum1D{ std::vector data; const int N; const Add add; const Minus minus; bool is_built = false; public: CumulativeSum1D(const std::vector &a, const T &e = 0, const Add &add = Add(), const Minus &minus = Minus()): N(a.size()), add(add), minus(minus) { data.assign(N+1, e); for(int i = 0; i < N; ++i) data[i+1] = a[i]; } CumulativeSum1D(int N, const T &e = 0, const Add &add = Add(), const Minus &minus = Minus()): N(N), add(add), minus(minus) { data.assign(N+1, e); } inline void update(int i, const T &val){ assert(not is_built); data[i+1] = add(data[i+1], val); } inline void build(){ assert(not is_built); for(int i = 0; i < N; ++i) data[i+1] = add(data[i+1], data[i]); is_built = true; } /** * @attention [i, j) */ inline T get(int i, int j) const { assert(is_built); return minus(data[j], data[i]); } }; using mint = ModInt<1000000007>; const int MAX = 100 * 1000 + 100; int main(){ int N, M; std::cin >> N >> M; std::vector V(N), R(M); for(int i = 0; i < N; ++i) std::cin >> V[i]; for(int i = 0; i < M; ++i) std::cin >> R[i]; int A, B; std::cin >> A >> B; mint ans = 0; std::vector> dpv(2, std::vector(MAX + 1)); dpv[0][0] = 1; for(int i = 0; i < N; ++i){ int cur = i % 2, nxt = (i + 1) % 2; for(int j = 0; j <= MAX; ++j){ if(j >= V[i]) dpv[nxt][j] = dpv[cur][j-V[i]] + dpv[cur][j]; else dpv[nxt][j] = dpv[cur][j]; } } CumulativeSum1D c(dpv[N%2]); c.build(); std::vector> dpr(2, std::vector(MAX + 1)); dpr[0][0] = 1; for(int i = 0; i < M; ++i){ int cur = i % 2, nxt = (i + 1) % 2; for(int j = 0; j <= MAX; ++j){ if(j >= R[i]) dpr[nxt][j] = dpr[cur][j-R[i]] + dpr[cur][j]; else dpr[nxt][j] = dpr[cur][j]; } } for(int r = 1; r <= MAX; ++r){ int lb = r * A; if(lb > MAX) lb = MAX; int ub = r * B; if(ub > MAX) ub = MAX; ans += dpr[M%2][r] * c.get(lb, ub+1); } std::cout << ans << std::endl; return 0; }