Problem:
Score : 600 points

Problem Statement

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 1

3 1 3 1 2

Sample Output 1

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.

Sample Input 2

7 2 3 1 3

Sample Output 2

105

The only ways to divide the people under the conditions are the ones where there are two groups of two people, and one group of three people.
There are 105 such ways.

Sample Input 3

1000 1 1000 1 1000

Sample Output 3

465231251

Sample Input 4

10 3 4 2 5

Sample Output 4

0

The answer can be 0.

Solution in C (GCC 5.4.1) (judge verdict: Accepted)

/*
cat <<EOF >mistaken-paste
*/

#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>

#define BIG 2000000007
#define VERYBIG 200000000000007LL

#define MOD 1000000007
typedef uint64_t ull;
typedef  int64_t sll;

#define N_MAX 2000
#define M_MAX 200000

typedef struct {
	int32_t a;
	int32_t b;
} hw;

typedef struct {
	sll a;
	sll b;
} hwll;

typedef struct {
	hwll a;
	hwll b;
} linell;


typedef struct {
	ull s;
	ull t;
	int32_t c;
} struct_a;

typedef struct {
	int32_t from;
	int32_t to;
	sll cost;
} struct_b;

ull n, m;
ull h, w;
ull k;
ull q;
ull vua, vub, vuc, vud, vue, vuf;
sll vsa, vsb, vsc, vsd, vse, vsf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
size_t slen;
size_t tlen;
char ch, dh;

ull umin (ull x, ull y) {
	return (x < y) ? x : y;
}

ull umax (ull x, ull y) {
	return (x > y) ? x : y;
}

sll smin (sll x, sll y) {
	return (x < y) ? x : y;
}

sll smax (sll x, sll y) {
	return (x > y) ? x : y;
}

ull bitpow (ull a, ull x, ull modulo) {
	ull result = 1;
	while (x) {
		if (x & 1) {
			result *= a;
			result %= modulo;
		}
		x /= 2;
		a = (a * a) % modulo;
	}
	return result;
}

ull divide (ull a, ull b, ull modulo) {
	return (a * bitpow(b, modulo - 2, modulo)) % modulo;
}

ull dp[N_MAX + 1];
ull amazing[N_MAX + 100];
ull npkdp[N_MAX + 1][N_MAX + 1];
ull division[N_MAX + 1][N_MAX + 1];

ull npk (ull n, ull k) {
	return divide(amazing[n], amazing[n - k], MOD);
}

ull grouping (sll whole, sll members, sll parts) {
	// whole_P_(mem*par)/(members!)^parts / parts!
	if (!division[members][parts]) {
		division[members][parts] = (bitpow(amazing[members], parts, MOD) * amazing[parts]) % MOD;
	}
	return divide(npk(whole, members * parts), division[members][parts], MOD);
}

ull solve () {
	sll i, j, ki;
	// ull result = 0;
	sll result = 0;
	// double result = 0;
	ull maybe = 0;
	// sll maybe = 0;
	ull sum = 0;
	// sll sum = 0;
	ull item;
	ull *dpcell;

	time_t start = time(NULL);

	amazing[0] = 1;
	for (i = 1; i <= n; i++) {
		amazing[i] = (amazing[i - 1] * i) % MOD;
	}
	// printf("%u...\n", time(NULL) - start);

	sll latest = n;
	dp[n] = 1;

	for (i = vua; i <= vub; i++) {
		latest = smax(latest - i * vud, 0);
		for (j = latest; j + i * vuc <= n; j++) {

			for (ki = vuc; ki <= vud; ki++) {
				sll xi = j + i * ki;
				if (xi > n) break;
				if (!dp[xi]) continue;

				dp[j] += dp[xi] * grouping(xi, i, ki);
				dp[j] %= MOD;
			}
			// printf("[%lld]; %llu\n", j, dp[j]);
		}
		// if (i <= 50 || i % 50 == 0) {
		// 	printf("(time: %u) ", time(NULL) - start);
		// 	printf("%lld... [0]:%llu\n", i, dp[0]);
		// 	fflush(stdout);
		// }
	}
	result = dp[0];

	printf("%llu\n", result);

	return 0;
}

int32_t main (void) {
	int32_t i, j;
	int32_t x, y;

	scanf("%llu", &n, &m);
	scanf("%llu%llu%llu%llu", &vua, &vub, &vuc, &vud, &vue, &vuf);

	solve();

	return 0;
}