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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
#define __int64 long long
const ll M=1000000007;
ll n,a,b,c,d;
const int N=3011;
ll dp[N][N];

const int MAX_N=3111;
ll F[MAX_N+1];
ll IF[MAX_N+1];

ll invl(ll a,ll b,ll m){//ap-2乗るを返す
	ll tmp=1;
	while(b){
		if(b&1){
			tmp=(tmp*a)%m;
		}
		a=(a*a)%m;
		b/=2;
	}

	return tmp%m;
}

void init(){
	F[0]=1;
	IF[0]=1;

	for(int i=1;i<=MAX_N;i++){
		F[i]=(F[i-1]*i)%M;
		IF[i]=invl(F[i],M-2,M)%M;//逆元を、フェルマーの小定理を利用して求める
	}
}

ll C(int n,int r){

	if(n<0||r<0||r>n)return (ll)0;
	if(r>n/2)r=n-r;
	
	//cout<<F[n]<<" "<<IF[r]<<" "<<IF[n-r]<<endl;
	ll ret=F[n]*IF[r]%M*IF[n-r]%M;
	return ret;
}

ll dfs(int p,int now){//now人ってる
	//cout<<p<<" "<<now<<endl;


	if(now==n)return dp[p][now]=1;	
	if(dp[p][now]!=-1)return dp[p][now];
	if(now>n||p>b)return dp[p][now]=0;

	ll ret=0;
		ret+=dfs(p+1,now);
		ll x=1,nin=n-now;

		for(int i=c;i<=d;i++){
			if(now+p*i<=n){
				ll tmp=dfs(p+1,now+p*i)%M;

				x=(x*C(nin,p))%M;
				nin-=p;
				tmp=(x*tmp)%M;
				tmp=(tmp*IF[i-c+1])%M;
				ret+=tmp;
				ret%=M;
			}
		}
		return dp[p][now]=ret%M;
}


int main(){
	init();
	//cout<<C(7,4);
	cin>>n>>a>>b>>c>>d;
	rep(i,N)rep(j,N)dp[i][j]=-1;	
	ll ans=dfs(a,0);
	
	cout<<ans<<endl;
	
	return 0;
}