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: Runtime Error)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

////////////////////////////////////////
#define N 1004
ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else if(p==1)return mod(i);
    else if(p%2==0)return mod(po(mod(mod(i)*mod(i)),p/2));
    else  return mod(mod(i)*mod(po(i,p-1)));
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    for(int i=1;i<N;i++){
        kai[i]=mod(kai[i-1]*i);
        kai2[i]=mod(po(kai[i],i_5));
    }
}
ll comb(ll n,ll k){
    if(n==0){
        if(k==0)return 1;
        else return 0;
    }
    else if(n<k)return 0;
    else return mod(mod(mod(kai[n])*mod(kai2[n-k]))*mod(kai2[k]));
}
///////////////////////////////////

int main(){
    calc();
    ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    ll dp[n+1][2][n+1];memset(dp,0,sizeof(dp));
    rep(j,a,b){
        dp[0][j&1][0]=1;
    }
    rep(i,c,d){
        if(i*a<=n)dp[i*a][a&1][i]=mod(comb(n,a*i)*mod(mod(kai[a*i]*kai2[i])*po(kai2[a],i)));
    }
    
    rep(i,1,n){
        rep(j,a+1,b){
            dp[i][j&1][0]+=dp[i][(j-1)&1][0];
            rep(t,c,d){
                dp[i][j&1][0]+=dp[i][(j-1)&1][t];
            }
            for(int k=1;k<=n/j;k++){
                dp[i][j&1][k]=mod(mod(mod(comb(n-i+k*j,k*j)*kai[i])*mod(kai[n-i+k*j]*kai2[n]))*mod(mod(kai2[k]*po(kai2[j],k))*dp[i-k*j][j&1][0]));
            }
        }
    }
    
    /*rep(i,0,n){
        rep(j,a,b){
            rep(k,0,n){
                cout<<dp[i][j][k]<<" ";
            }cout<<endl;
        }cout<<endl;
    }*/
    ll ans=dp[n][b&1][0];
    rep(k,c,d){
        ans=mod(ans+dp[n][b&1][k]);
    }
    cout<<mod(ans)<<endl;
    
    
    
    return 0;
}