#include #define REP(i, n) for(int i = 0;i < n;i++) #define ll long long using namespace std; //typedef vectorvec; //typedef vectorvec; //typedef vector mat; typedef pair P; typedef pair LP; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int INF = 1000000000; const ll LINF = 1000000000000000000;//1e18 const ll MOD = 1000000007; const double PI = acos(-1.0); const double EPS = 1e-10; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } //template inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;}; template struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp& r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp& r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; } friend constexpr ostream& operator << (ostream &os, const Fp& x) noexcept { return os << x.val; } friend constexpr Fp modpow(const Fp &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp; void solve(){ int N, M; cin >> N >> M; vector V(N), R(M); REP(i,N) cin >> V[i]; REP(i,M) cin >> R[i]; ll A, B; cin >> A >> B; vector dpV(101010); vector dpR(101010); dpV[0] = dpR[0] = 1; REP(i,N){ for(int j=101010-1;j>=0;j--){ if(j - V[i] < 0) continue; if(dpV[j-V[i]] == 0) continue; dpV[j] += dpV[j-V[i]]; } } REP(i,M){ for(int j=101010-1;j>=0;j--){ if(j - R[i] < 0) continue; if(dpR[j-R[i]] == 0) continue; dpR[j] += dpR[j-R[i]]; } } vector cumV(101010);//, cumR(101010); for(int i=1;i<101010;i++){ cumV[i] += cumV[i-1] + dpV[i]; //cumR[i] += cumR[i-1]; } // REP(i,20) cout << dpV[i] << " "; // cout << endl; mint ans = 0; for(ll r=1;r<101010;r++){ if(dpR[r] == 0) continue; ll lt = r * A; ll ut = r * B; // cout << lt << " " << ut << endl; if(lt >= 101010) continue; if(ut >= 101010) ut = 101010 - 1; ans += mint(dpR[r]) * (cumV[ut] - cumV[lt-1]); // cout << cumV[ut] << " " << cumV[lt] << endl; } cout << ans << endl; } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); // int T; cin >> T; REP(t,T) solve(); }