#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll dp[n+1][n+1];
    rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=0;
    dp[a-1][0]=1;
    ll nck[1001][1001];
    rep(i,0,1001)nck[i][0]=1;
    rep(i,0,1001)nck[i][i]=1;
  ll gya[1001];
  rep(i,1,1001)gya[i]=gyaku(i);
    rep(i,1,1001){
        rep(j,1,i){
            nck[i][j]=nck[i-1][j-1]+nck[i-1][j];
            nck[i][j]%=mod;
        }
    }
    rep(i,a-1,b){
        int t=0;
        rep(j,0,n+1){
            dp[i+1][j]+=dp[i][j];
            dp[i+1][j]%=mod;
            if(t==1)continue;
            ll sum=1;
            ll now=n-j;
            rep(k,0,c){
                if(now<0){
                    sum=-1;
                    break;
                }
                sum*=nck[now][i+1];
                sum%=mod;
                sum*=gya[k+1];
                sum%=mod;
                now-=i+1;
                
            }
            if(sum==-1){
                t=1;
                continue;
            }
            rep(k,c,d+1){
                if(j+(i+1)*k>n)break;
                dp[i+1][j+(i+1)*k]+=dp[i][j]*sum;
                dp[i+1][j+(i+1)*k]%=mod;
                sum*=nck[n-(j+(i+1)*k)][i+1];
                sum%=mod;
                sum*=gya[k+1];
                sum%=mod;
            }
            
        }
    }
    cout<<dp[b][n]<<endl;
    
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double dlb;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef pair<ll, pair<ll,ll> > iii;

const int kn = 2e5 + 5;
const ll mod = 1e9 + 7;

#define x first
#define y second
#define _it iterator
#define pb push_back
#define pf push_front
#define ms(val,a) memset(a,val,sizeof(a))
#define ff(i,n) for(int i=1;i<=n;i++)
#define _ff(i,n) for(int i=n;i>=1;i--)
#define f(i,a,b) for(int i = a; i <=b; i++)
#define _f(i,a,b) for(int i = b; i>=a;i--)
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll n, par[kn];
ll ans = 0;

struct data{
	int x, y;
	int id;
};

bool option(data cac, data lon)
{
	if(cac.x != lon.x) return cac.x < lon.x;
	return cac.y < lon.y;
}

data a[2][kn];

int Find(int i)
{
	if(par[i] == i) return i;
	return par[i] = Find(par[i]);
}

void dj(int i, int j, int cost)
{
	int pi = Find(i), pj = Find(j);
	if(pi == pj) return;
	par[pi] = pj;
	ans += cost;
}

int la[2][kn], ra[2][kn];

set< iii > pq;

int main() {
	//freopen("a.inp","r",stdin);
	//freopen("a.out","w",stdout);
	cin >> n;
	ff(i,n) par[i] = i;
	ff(i,n)
	{
		cin >> a[0][i].x >> a[0][i].y;
		a[1][i].x = a[0][i].y; a[1][i].y = a[0][i].x;
		a[0][i].id = a[1][i].id = i;
		la[0][i] = la[1][i] = i-1;
		ra[0][i]=ra[1][i] = i+1;
	}
	la[0][1] = la[1][1] = -1;
	ra[0][n] = ra[1][n] = -1;
	sort(a[0]+1,a[0]+n+1,option);
	sort(a[1]+1,a[1]+n+1,option);
	for(int i = 2; i<=n; i++)
	{
		pq.insert(iii(a[0][i].x - a[0][i-1].x, ii(i,0)));
		pq.insert(iii(a[1][i].x - a[1][i-1].x, ii(i,1))); // 0 la day 1, 1 la day 2
	}
	while(pq.size())
	{
		iii tmp = *pq.begin();
		pq.erase(pq.begin());
		dj(a[tmp.y.y][tmp.y.x].id, a[tmp.y.y][tmp.y.x-1].id, a[tmp.y.y][tmp.y.x].x - a[tmp.y.y][tmp.y.x-1].x);
	}
	cout << ans;
}
//hahahahahahahahahhahahahahahaahahahahhahahahahahahah