#include const int MOD = 1e9 + 7; int Dp(int t, int a, int b, int c, int d, int e) { int maxabc = std::max({std::abs(a), std::abs(b), std::abs(c)}); std::vector> dp(2, std::vector(2 * t * maxabc + 1)); dp[0][t * maxabc] = 1; int trans[] = {-a, a, -b, b, -c, c}; for (int i = 0; i < t; ++i) { std::fill(dp[~i & 1].begin(), dp[~i & 1].end(), 0); for (int j = -i * maxabc; j <= i * maxabc; ++j) { for (int k = 0; k < 6; ++k) { (dp[~i & 1][t * maxabc + j + trans[k]] += dp[i & 1][t * maxabc + j]) %= MOD; } } } int res = 0; for (int i = d; i <= e; ++i) { if (t * maxabc + i < 0 || 2 * t * maxabc < t * maxabc + i) continue; (res += dp[t & 1][t * maxabc + i]) %= MOD; } return res; } signed main() { std::ios::sync_with_stdio(false); int T; std::cin >> T; int A, B, C, D, E; std::cin >> A >> B >> C >> D >> E; std::cout << Dp(T, A, B, C, D, E) << std::endl; return 0; }