#include #define all(vec) vec.begin(), vec.end() #define pb push_back #define eb emplace_back #define fi first #define se second using namespace std; using ll = long long; using P = pair; template using V = vector; constexpr ll INF = (1LL << 30) - 1LL; constexpr ll MOD = 1e9 + 7; constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; template void chmin(T &a, T b) { a = min(a, b); } template void chmax(T &a, T b) { a = max(a, b); } void debug() { cerr << "ok" << endl; } template void printv(const vector &v) { for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' '); } template void readv(vector &v) { for (int i = 0; i < v.size(); i++) cin >> v[i]; } //from http://noshi91.hatenablog.com/entry/2019/03/31/174006 template class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint operator^(const u64 rhs) const noexcept { return modint(*this) ^= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } constexpr modint &operator^=(u64 exp) { modint rhs = modint(*this); a = 1; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } friend ostream &operator<<(ostream &os, const modint &x) { os << x.a; return os; } friend istream &operator>>(istream &is, modint &x) { is >> x.a; return is; } }; using mint = modint; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; V v(n), r(m); readv(v); readv(r); ll a, b; cin >> a >> b; ll ma = 100010; auto calc = [&](V &a) { V> dp(2, V(ma + 1)); int pre = 0, cur = 1; dp[pre][0] = 1; for (int i = 0; i < a.size(); i++) { fill(all(dp[cur]), mint(0)); for (int j = 0; j <= ma; j++) { if (j >= a[i]) { dp[cur][j] += dp[pre][j - a[i]]; } dp[cur][j] += dp[pre][j]; } swap(pre, cur); } return dp[pre]; }; V vs = calc(v), rs = calc(r); for (int i = 1; i <= ma; i++) { vs[i] += vs[i - 1]; } mint res = 0; for (ll i = 1; i <= ma; i++) { res += rs[i] * (vs[min(ma, i * b)] - vs[min(ma, max(0LL, i * a - 1))]); } cout << res << '\n'; }