#include "bits/stdc++.h" // Begin Header {{{ #define all(x) (x).begin(), (x).end() #define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i) #define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i) #define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i) #define var(type, ...) \ type __VA_ARGS__; \ read(__VA_ARGS__); #ifndef DBG #define dump(...) #endif using namespace std; using i64 = int_fast64_t; using pii = pair; template inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); } template inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); } constexpr int INF = 0x3f3f3f3f; constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL; template inline vector makeV(const T &initValue, size_t sz) { return vector(sz, initValue); } template inline auto makeV(const T &initValue, size_t sz, Args... args) { return vector(initValue, args...))>( sz, makeV(initValue, args...)); } template inline istream &operator>>(istream &is, vector &vec) { for (auto &e : vec) is >> e; return is; } inline void read() {} template inline void read(Head &head, Tail &... tail) { cin >> head; read(tail...); } inline void print() { cout << "\n"; } template inline void print(Head &&head, Tail &&... tail) { cout << head; if (sizeof...(tail)) cout << ' '; print(forward(tail)...); } template inline ostream &operator<<(ostream &os, const vector &vec) { static constexpr const char *delim[] = {" ", ""}; for (const auto &e : vec) os << e << delim[&e == &vec.back()]; return os; } template struct Rev { Container &x_; inline Rev(Container &x) : x_(x) {} inline auto begin() { return rbegin(x_); } inline auto end() { return rend(x_); } }; // }}} End Header constexpr int MOD = int(1e9) + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); var(int, N, M); vector V(N), R(M); read(V, R); var(i64, A, B); constexpr int MX = 1e6 + 1000; vector dpV(MX + 2000); dpV[0] = 1; for (const i64 v : V) { repr(i, MX, 0)(dpV[i + v] += dpV[i]) %= MOD; } vector dpR(MX + 2000); dpR[0] = 1; for (const i64 r : R) { repr(i, MX, 0)(dpR[i + r] += dpR[i]) %= MOD; } vector cumV(MX + 1); rep(i, 0, MX) { cumV[i + 1] = cumV[i] + dpV[i]; } i64 ans = 0; repc(sumR, 1, 1e6) { if (dpR[sumR] == 0) continue; if (A * sumR >= MX || B * sumR >= MX) continue; const i64 vv = (cumV[B * sumR + 1] - cumV[A * sumR]) % MOD; ans += dpR[sumR] * vv % MOD; ans %= MOD; } print(ans); return 0; }