There are N people, conveniently numbered 1 through N.
We want to divide them into some number of groups, under the following two conditions:
 - Every group contains between A and B people, inclusive.
 - Let F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds.
Find the number of these ways to divide the people into groups.
Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways.
Since the number of these ways can be extremely large, print the count modulo 10^9+7.

-----Constraints-----
 - 1≤N≤10^3
 - 1≤A≤B≤N
 - 1≤C≤D≤N

-----Input-----
The input is given from Standard Input in the following format:
N A B C D

-----Output-----
Print the number of ways to divide the people into groups under the conditions, modulo 10^9+7.

-----Sample Input-----
3 1 3 1 2

-----Sample Output-----
4

There are four ways to divide the people:
 - (1,2),(3)
 - (1,3),(2)
 - (2,3),(1)
 - (1,2,3)
The following way to divide the people does not count: (1),(2),(3). This is because it only satisfies the first condition and not the second.

Difficulty: HARD

Solutions:
mod = 10 ** 9 + 7
NN = 10 ** 4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, NN + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
(N, A, B, C, D) = map(int, input().split())
Map = [[] for _ in range(N + 1)]
for n in range(1, N + 1):
	a = 1
	for _ in range(N + 1):
		Map[n].append(a)
		a = a * g2[n] % mod
L = [[] for _ in range(N + 1)]
for n in range(A, B + 1):
	for c in range(C, D + 1):
		if n * c > N:
			continue
		L[n].append(c)
dp = [0] * (N + 1)
dp[0] = 1
for n in range(1, N + 1):
	for (i, c) in enumerate(L[n]):
		if i == 0:
			dp2 = dp[:]
		for nn in range(N + 1 - n * c):
			dp2[nn + n * c] = (dp2[nn + n * c] + dp[nn] * Map[n][c] % mod * Map[c][1] % mod) % mod
		if i == len(L[n]) - 1:
			dp = dp2
ans = dp[N] * g1[N] % mod
print(ans)


def main():
	mod = 10 ** 9 + 7
	inv_n = [0] * 1001
	nCr = [[1] * (i + 1) for i in range(1001)]
	for i in range(1001):
		inv_n[i] = pow(i, mod - 2, mod)
	for i in range(2, 1001):
		for j in range(1, i):
			nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % mod
	(n, a, b, c, d) = map(int, input().split())
	dp = [0] * (n + 1)
	dp[0] = 1
	for A in range(b, a - 1, -1):
		dp2 = [i for i in dp]
		for N in range(n - c * A, -1, -1):
			e = dp[N]
			if e:
				temp = 1
				for C in range(1, c):
					temp = temp * nCr[n - N - (C - 1) * A][A] * inv_n[C] % mod
				for C in range(c, min(d, (n - N) // A) + 1):
					temp = temp * nCr[n - N - (C - 1) * A][A] * inv_n[C] % mod
					dp2[N + C * A] = (dp2[N + C * A] + temp * e) % mod
		dp = dp2
	print(dp[-1])
main()


(N, A, B, C, D) = map(int, input().split())
Z = [1] + [0] * N
M = 10 ** 9 + 7
I = [1, 1]
F = I + []
R = I + []
for i in range(2, N + 1):
	I += [(M - M // i) * I[M % i] % M]
	F += [i * F[-1] % M]
	R += [I[i] * R[-1] % M]
for i in range(A, B + 1):
	Z = [(Z[j] + sum((Z[j - i * k] * F[N - j + i * k] * R[N - j] * pow(R[i], k, M) * R[k] for k in range(C, min(D, j // i) + 1)))) % M for j in range(N + 1)]
print(Z[N])


import sys
input = sys.stdin.readline
import numpy as np
(N, A, B, C, D) = map(int, input().split())
MOD = 10 ** 9 + 7
fact = [1] * (N + 1)
fact_inv = [1] * (N + 1)
for n in range(1, N + 1):
	fact[n] = fact[n - 1] * n % MOD
fact_inv[N] = pow(fact[N], MOD - 2, MOD)
for n in range(N, 0, -1):
	fact_inv[n - 1] = fact_inv[n] * n % MOD
fact = np.array(fact, dtype=np.int64)
fact_inv = np.array(fact_inv, dtype=np.int64)
comb = np.zeros((N + 1, N + 1), dtype=np.int64)
comb[:, 0] = 1
for n in range(1, N + 1):
	comb[n, 1:] = (comb[n - 1, 1:] + comb[n - 1, :-1]) % MOD
dp = np.zeros(N + 1, dtype=np.int64)
dp[0] = 1
for x in range(A, B + 1):
	prev = dp
	dp = prev.copy()
	for n in range(C, D + 1):
		y = n * x
		if y > N:
			break
		coef = fact[y] * pow(int(fact_inv[x]), n, MOD) % MOD * fact_inv[n] % MOD
		dp[y:] += prev[:-y] * comb[N:y - 1:-1, y] % MOD * coef
		dp %= MOD
answer = dp[N]
print(answer)


(N, A, B, C, D) = map(int, input().split())
MOD = 10 ** 9 + 7
fact = [1] * (N + 1)
frev = [1] * (N + 1)
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N + 1):
	v = fact[i] = fact[i - 1] * i % MOD
	frev[i] = pow(v, MOD - 2, MOD)
Y = [None] * (N + 1)
for g in range(A, min(N // C, B) + 1):
	p = C * g
	q = D * g
	y = frev[g]
	Y[p:min(q, N) + 1:g] = (pow(y, j, MOD) * frev[j] for j in range(C, min(D, N // g) + 1))
	dp[p:] = (dp[i] + frev[N - i] * sum((dp[i - j] * fact[N - i + j] * Y[j] for j in range(p, min(q, i) + 1, g))) % MOD for i in range(p, N + 1))
print(dp[N] % MOD)


mod = 10 ** 9 + 7
MAX = 10 ** 3 + 100
g1 = [1, 1]
g2 = [1, 1]
for i in range(2, MAX + 1):
	num_1 = g1[-1] * i % mod
	g1.append(num_1)
	g2.append(pow(num_1, mod - 2, mod))

def cmb(n, r, MOD):
	return g1[n] * g2[r] * g2[n - r] % MOD
(N, A, B, C, D) = map(int, input().split())
data = [[] for i in range(B + 1)]
for i in range(A, B + 1):
	for j in range(C, D + 1):
		if i * j > N:
			break
		data[i].append([i * j, pow(g2[i], j, mod) * g2[j] % mod])
dp = [0] * (N + 1)
dp[0] = 1
for i in range(A, B + 1):
	H = dp[:]
	for (u, v) in data[i]:
		for j in range(u, N + 1):
			H[j] = (H[j] + dp[j - u] * v) % mod
	dp = H
print(dp[N] * g1[N] % mod)