#include using namespace std; using i64 = long long; #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++) #define all(x) x.begin(),x.end() #define STRINGIFY(n) #n #define TOSTRING(n) STRINGIFY(n) #define PREFIX "#" TOSTRING(__LINE__) "| " #define debug(x) \ { \ std::cout << PREFIX << #x << " = " << x << std::endl; \ } std::ostream& output_indent(std::ostream& os, int ind) { for(int i = 0; i < ind; i++) os << " "; return os; } template std::ostream& operator<<(std::ostream& os, const std::pair& p); template std::ostream& operator<<(std::ostream& os, const std::vector& v); template std::ostream& operator<<(std::ostream& os, const std::pair& p) { return (os << "(" << p.first << ", " << p.second << ")"); } template std::ostream& operator<<(std::ostream& os, const std::vector& v) { os << "["; for(int i = 0;i < v.size();i++) os << v[i] << ", "; return (os << "]"); } template static inline std::vector ndvec(size_t&& n, T val) { return std::vector(n, std::forward(val)); } template static inline auto ndvec(size_t&& n, Tail&&... tail) { return std::vector(tail)...))>(n, ndvec(std::forward(tail)...)); } template struct chain { Cond cond; chain(Cond cond) : cond(cond) {} template bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; } }; template chain make_chain(Cond cond) { return chain(cond); } #include using i64 = long long; template struct modint { i64 a; constexpr modint(const i64 x = 0): a((x%M+M)%M){} constexpr i64 value() const { return a; } constexpr modint inv() const { return this->pow(M-2); } constexpr modint pow(i64 r) const { modint ans(1); modint aa = *this; while(r) { if(r & 1) ans *= aa; aa *= aa; r >>= 1; } return ans; } constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; } constexpr modint& operator+=(const modint r) { a += r.a; if(a >= M) a -= M; return *this; } constexpr modint& operator-=(const modint r) { a -= r.a; if(a < 0) a += M; return *this; } constexpr modint& operator*=(const modint r) { a = a * r.a % M; return *this; } constexpr modint& operator/=(const modint r) { (*this) *= r.inv(); return *this; } constexpr modint operator+(const modint r) const { return modint(*this) += r; } constexpr modint operator-(const modint r) const { return modint(*this) -= r; } constexpr modint operator*(const modint r) const { return modint(*this) *= r; } constexpr modint operator/(const modint r) const { return modint(*this) /= r; } constexpr bool operator!=(const modint r) const { return this->value() != r.value(); } }; template std::ostream& operator<<(std::ostream& os, const modint& m) { os << m.value(); return os; } #include using namespace std; constexpr i64 NTT_PRIMES[][2] = { {1224736769, 3}, // 2^24 * 73 + 1, {1053818881, 7}, // 2^20 * 3 * 5 * 67 + 1 {1051721729, 6}, // 2^20 * 17 * 59 + 1 {1045430273, 3}, // 2^20 * 997 + 1 {1012924417, 5}, // 2^21 * 3 * 7 * 23 + 1 {1007681537, 3}, // 2^20 * 31^2 + 1 {1004535809, 3}, // 2^21 * 479 + 1 {998244353, 3}, // 2^23 * 7 * 17 + 1 {985661441, 3}, // 2^22 * 5 * 47 + 1 {976224257, 3}, // 2^20 * 7^2 * 19 + 1 {975175681, 17}, // 2^21 * 3 * 5 * 31 + 1 {962592769, 7}, // 2^21 * 3^3 * 17 + 1 {950009857, 7}, // 2^21 * 4 * 151 + 1 {943718401, 7}, // 2^22 * 3^2 * 5^2 + 1 {935329793, 3}, // 2^22 * 223 + 1 {924844033, 5}, // 2^21 * 3^2 * 7^2 + 1 {469762049, 3}, // 2^26 * 7 + 1 {167772161, 3}, // 2^25 * 5 + 1 }; template vector> number_theoretic_transform(vector> a) { i64 n = a.size(); for(i64 s = n >> 1; s >= 1; s >>= 1) { modint zeta = modint(primitive).pow((mod - 1) / (s << 1)); for(i64 i = 0; i < n; i += (s << 1)) { modint zi = 1; for(i64 j = 0;j < s;j++) { modint t = a[i + j] - a[s + i + j]; a[i + j] += a[s + i + j]; a[s + i + j] = t * zi; zi = zi * zeta; } } } return a; } template vector> inverse_number_theoretic_transform(vector> a) { i64 n = a.size(); for(i64 s = 1; s < n; s <<= 1) { modint zeta = modint(primitive).pow((mod - 1) / (s << 1)).pow(mod - 2); for(i64 i = 0; i < n; i += (s << 1)) { modint zi = 1; for(i64 j = 0;j < s;j++) { modint t = a[s + i + j] * zi; a[s + i + j] = a[i + j] - t; a[i + j] = a[i + j] + t; zi = zi * zeta; } } } auto inv_n = modint(n).pow(mod - 2); for(int i = 0;i < n;i++) a[i] *= inv_n; return a; } template struct fps_ntt_multiply { using fps_type = modint; using conv_type = modint; static std::vector dft(std::vector arr) { return number_theoretic_transform(std::move(arr)); } static std::vector idft(std::vector arr) { return inverse_number_theoretic_transform(std::move(arr)); } static std::vector multiply(std::vector a, std::vector b) { for(int i = 0;i < a.size();i++) a[i] *= b[i]; return a; } }; #include #include using namespace std; using i64 = long long; i64 pow_mod(i64 x, i64 r, i64 mod) { i64 ans = 1; while(r) { if(r & 1) ans = (ans * x) % mod; r >>= 1; x = x * x % mod; } return ans; } i64 inv_mod(i64 x, i64 mod) { return pow_mod(x, mod - 2, mod); } i64 garner(const vector &x, vector mods, i64 mod) { mods.emplace_back(mod); vector coeffs(x.size() + 1, 1); vector constants(x.size() + 1, 0); for(i64 i = 0; i < x.size(); i++) { i64 v = (x[i] - constants[i]) * inv_mod(coeffs[i], mods[i]) % mods[i]; if(v < 0) v += mods[i]; for(i64 j = i + 1; j < x.size() + 1; j++) { constants[j] = (constants[j] + coeffs[j] * v) % mods[j]; coeffs[j] = (coeffs[j] * mods[i]) % mods[j]; } } return constants.back(); } template struct fps_multiply_arb { using fps_type = std::vector>; using conv_type = std::tuple>...>; const static std::size_t tsize = std::tuple_size::value; template static std::vector> dft_m2(const fps_type& arr) { std::vector> res(arr.size()); for(std::size_t i = 0; i < arr.size(); i++) res[i] = modint(arr[i].value()); return number_theoretic_transform(std::move(res)); } template static std::vector> idft_m2(std::vector> arr) { return inverse_number_theoretic_transform(std::move(arr)); } template static fps_type idft_func(std::index_sequence, conv_type arr) { arr = std::make_tuple(idft_m2(std::get(arr))...); std::size_t len = std::get<0>(arr).size(); static std::vector primes = { NTT_PRIMES[NTTis][0]... }; fps_type res(len); for(std::size_t i = 0; i < len; i++) { std::vector x = { std::get(arr)[i].value()... }; res[i] = modint(garner(x, primes, M)); } return std::move(res); } template static char mult_m2(std::vector>& a, const std::vector>& b) { for(int i = 0;i < a.size();i++) a[i] *= b[i]; return 0; } template static void mult_func(std::index_sequence, conv_type& a, const conv_type& b) { auto res = std::make_tuple(mult_m2(std::get(a), std::get(b))...); } static conv_type dft(fps_type arr) { return std::make_tuple(dft_m2(arr)...); } static fps_type idft(conv_type arr) { return idft_func(std::make_index_sequence(), std::move(arr)); } static conv_type multiply(conv_type a, const conv_type& b) { mult_func(std::make_index_sequence(), a, b); return a; } }; template inline _Size __lg(_Size __n) { _Size __k; for (__k = 0; __n != 0; __n >>= 1) ++__k; return __k - 1; } template struct FPS { std::vector coef; static std::size_t bound_pow2(std::size_t sz) { return 1ll << (__lg(sz - 1) + 1); } FPS(const std::vector& arr): coef(arr) {} size_t size() const { return coef.size(); } void bound_resize() { this->coef.resize(bound_pow2(this->size())); } T operator[](int i) const { if(i < coef.size()) return coef[i]; else return T(); } T & operator[](int i) { return coef[i]; } FPS pre(int n) const { std::vector nex(n); for(int i = 0;i < coef.size() && i < n; i++) nex[i] = coef[i]; return FPS(nex); } // F(0) must not be 0 FPS inv() { FPS g = FPS(std::vector{ T(1) / (*this)[0] }); this->bound_resize(); i64 n = this->size(); for(int i = 1;i < n;i <<= 1) { g = g.pre(i << 1); auto gdft = fps_multiply::dft(g.coef); auto e = fps_multiply::idft( fps_multiply::multiply( fps_multiply::dft(this->pre(i << 1).coef), gdft ) ); for(int j = 0;j < i;j++) { e[j] = T(0); e[j + i] = e[j + i] * T(-1); } auto f = fps_multiply::idft( fps_multiply::multiply( fps_multiply::dft(e), std::move(gdft) ) ); for(int j = 0;j < i;j++) { f[j] = g[j]; } g.coef = std::move(f); } return g.pre(n); } FPS diff() const { FPS res(vector(this->size() - 1, T(0))); for(i64 i = 1;i < this->size();i++) res[i - 1] = coef[i] * T(i); return res; } FPS integral() const { FPS res(vector(this->size() + 1, T(0))); for(i64 i = 0;i < this->size();i++) res[i + 1] = coef[i] / T(i + 1); return res; } // F(0) must be 0 FPS log() { return (this->diff() * this->inv()).integral().pre(this->size()); } FPS exp() const { FPS f(vector{ T(1) }); FPS g = *this; g.bound_resize(); g[0] += T(1); for(i64 i = 1;i < size();i <<= 1 ) { f = (f * (g.pre(i << 1) - f.pre(i << 1).log())).pre(i << 1); } return f; } FPS operator+(const FPS& rhs) { i64 n = std::max(this->size(), rhs.size()); std::vector ans(n); for(int i = 0;i < n;i++) ans[i] = (*this)[i] + rhs[i]; return FPS(ans); } FPS operator-(const FPS& rhs) { i64 n = std::max(this->size(), rhs.size()); std::vector ans(n); for(int i = 0;i < n;i++) ans[i] = (*this)[i] - rhs[i]; return FPS(ans); } FPS operator*(const FPS& rhs) { i64 m = this->size() + rhs.size() - 1; i64 n = bound_pow2(m); auto res = fps_multiply::idft( fps_multiply::multiply( fps_multiply::dft(this->pre(n).coef), fps_multiply::dft(rhs.pre(n).coef) ) ); res.resize(m); return res; } FPS& operator*=(const T& x) { for(int i = 0;i < this->size();i++) { (*this)[i] *= x; } return *this; } }; int main() { i64 T; cin >> T; i64 a, b, c, d, e; cin >> a >> b >> c >> d >> e; i64 shift = std::max({std::abs(a), std::abs(b), std::abs(c)}); using fp = modint<1000000007>; using fps = FPS>; //using fp = modint<998244353>; //using fps = FPS>; vector init(shift * 2 + 1); init[a + shift] += 1; init[b + shift] += 1; init[c + shift] += 1; init[-a + shift] += 1; init[-b + shift] += 1; init[-c + shift] += 1; fps f(init); fps ans(std::vector{ fp(1) }); i64 t = T; while(t) { if(t & 1) { ans = ans * f; } t >>= 1; f = f * f; } fp res = 0; rep(i,d,e + 1) { res += ans[i + shift * T]; } cout << res.a << endl; }