#include #define loop(n) for (int ngtkana_is_geneous = 0; ngtkana_is_geneous < n; ngtkana_is_geneous++) #define rep(i, begin, end) for(int i = begin; i < end; i++) template T inverse(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; std::swap(a, m); u -= t * v; std::swap(u, v); } assert(m == 1); return u; } template class modular { private: int value; public: constexpr modular() = default; constexpr modular(const modular&) = default; constexpr modular(modular&&) = default; modular& operator=(const modular&) = default; modular& operator=(modular&&) = default; template modular (const U& x) {value = normalize(x);} template static auto normalize(const U& x) { int v = static_cast(-mod() <= x && x < mod() ? x : x % mod()); if (v < 0) v += mod(); return v; } auto const& operator()() const { return value; } template explicit operator U() const { return static_cast(value); } constexpr static auto mod() { return T::value; } auto& operator+=(const modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; } auto& operator-=(const modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; } template auto& operator+=(const U& other) {return *this += modular(other); } template auto& operator-=(const U& other) {return *this -= modular(other); } auto operator-() const { return modular(-value); } auto& operator++() {return *this += 1;} auto& operator--() {return *this -= 1;} auto operator++(int) {modular result(*this); operator++(); return result;} auto operator--(int) {modular result(*this); operator--(); return result;} template auto& operator*=(const modular& rhs) { value = normalize(static_cast(value) * static_cast(rhs.value)); return *this; } auto& operator/=(const modular& other) { return *this *= modular(inverse(other.value, mod())); } }; template struct is_modular : std::false_type {}; template struct is_modular > : std::true_type{}; template constexpr bool is_modular_v = is_modular::value; template bool operator==(const modular& lhs, const modular& rhs) { return lhs.value == rhs.value; } template bool operator==(const modular& lhs, U rhs) { return lhs == modular(rhs); } template bool operator==(U lhs, const modular& rhs) { return modular(lhs) == rhs; } template bool operator!=(const modular& lhs, const modular& rhs) { return !(lhs == rhs); } template bool operator!=(const modular& lhs, U rhs) { return !(lhs == rhs); } template bool operator!=(U lhs, const modular& rhs) { return !(lhs == rhs); } template modular operator+(const modular& lhs, const modular& rhs) { return modular(lhs) += rhs; } template modular operator+(const modular& lhs, U rhs) { return modular(lhs) += rhs; } template modular operator+(U lhs, const modular& rhs) { return modular(lhs) += rhs; } template modular operator-(const modular& lhs, const modular& rhs) { return modular(lhs) -= rhs; } template modular operator-(const modular& lhs, U rhs) { return modular(lhs) -= rhs; } template modular operator-(U lhs, const modular& rhs) { return modular(lhs) -= rhs; } template modular operator*(const modular& lhs, const modular& rhs) { return modular(lhs) *= rhs; } template modular operator*(const modular& lhs, U rhs) { return modular(lhs) *= rhs; } template modular operator*(U lhs, const modular& rhs) { return modular(lhs) *= rhs; } template modular operator/(const modular& lhs, const modular& rhs) { return modular(lhs) /= rhs; } template modular operator/(const modular& lhs, U rhs) { return modular(lhs) /= rhs; } template modular operator/(U lhs, const modular& rhs) { return modular(lhs) /= rhs; } template modular pow (const modular& a, U b) { assert(b >= 0); modular x = a, ret = 1; for (; b > 0; b /= 2) { if (b % 2 == 1) ret *= x; x *= x; } return ret; } template std::string to_string(const modular& a) { return std::to_string(a()); } template auto operator<<(std::ostream& os, const T& a) -> std::enable_if_t, std::ostream&>{ return os << a(); } template auto operator>>(std::istream& is, T& a) -> std::enable_if_t, std::istream&> { long long x; is >> x; a = T(x); return is; } using mod_type = int; struct voriable_mod { static mod_type value; }; mod_type voriable_mod::value; // mod_type& md = voriable_mod::value; // using Mint = Modular; constexpr int md = 1'000'000'007; using mint = modular, md>>; int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); int T, a, b, c, d, e; std::cin >> T >> a >> b >> c >> d >> e; std::vector dif = {-a, a, -b, b, -c, c}; int n = 10'000; int N = 2 * n + 1; auto dp = std::vector(N, 0); dp.at(n) = 1; loop(T) { auto new_dp = std::vector(N, 0); rep(i, 0, N) { rep(k, 0, 6) { int j = i + dif.at(k); if (j < 0 || N <= j) continue; new_dp.at(j) += dp.at(i); } } dp = new_dp; } auto ret = std::accumulate(dp.begin() + n + d, dp.begin() + n + e + 1, mint(0)); std::cout << ret << std::endl; return 0; }