#include <bits/stdc++.h>

int main() {
    using namespace std;

    constexpr unsigned long MOD = 1000000007;

    unsigned long N;
    cin >> N;

    auto pw = [&MOD](unsigned long a, unsigned long n = 1000000005){
        unsigned long ret = 1;
        while(n){
            if(n & 1)(ret *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return ret;
    };

    vector<unsigned long> fact(N + 1), ifact(N + 1);
    fact[0] = 1;
    for(unsigned long i = 1; i <= N; ++i)fact[i] = fact[i - 1] * i % MOD;
    ifact[N] = pw(fact[N]);
    for(unsigned long i = N; i > 0; --i)ifact[i - 1] = ifact[i] * i % MOD;

    unsigned long A, B, C, D;
    cin >> A >> B >> C >> D;

    vector<vector<unsigned long>> dp(B + 1, vector<unsigned long>(N + 1));
    dp[A - 1][N] = 1;

    for(unsigned long i = A; i <= B; ++i){
        for(unsigned long j = 0; j <= N; ++j){
            dp[i][j] = dp[i - 1][j];
            for(unsigned long k = C, l = j + C * i, m = pw(ifact[i], C); k <= D && l <= N; ++k, l += i, (m *= ifact[i]) %= MOD)dp[i][j] += ((((dp[i - 1][l] * fact[l]) % MOD * ifact[j]) % MOD * m) % MOD * ifact[k]) % MOD;
            dp[i][j] %= MOD;
        }
    }

    cout << dp[B][0] << endl;

    return 0;
}
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct edge{
	int u;	//?????????
	int v;	//??°??????
	int cost;	//??????
	//???????????????????????§?????§?°???¢????????????
	bool operator<(const edge& another) const {
			return cost < another.cost;
	}
};

const int MAX_N = 100;
const int MAX_M = 10000;

edge es[MAX_M];
int par[MAX_N];
int rank[MAX_N];

void initial(int n){		//?????????
	for(int i=0;i<n;i++){
		par[i] = i;
		rank[i] = 0;
	}
}

int find(int x){		//??¨??????????±???????
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

void unite(int x,int y){	//x???????????¨??¨y???????????¨?????????
	x = find(x);	//x???????????¨??????????????????x??¨??????
	y = find(y);	//y???????????¨??????????????????y??¨??????
	if(x == y) return;
	if(rank[x] < rank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rank[x] == rank[y])
			rank[x]++;
	}
}

bool same(int x,int y){	//x,y???????????¨???????????§?????????
	return find(x) == find(y);
}

bool comp(const edge& e1,const edge& e2){
	return e1.cost < e2.cost;
}

int kruskal(int n,int m){
	initial(n);
	int res = 0;
	for(int i=0;i<m;i++){
		edge e = es[i];
		if(!same(e.u,e.v)){
			unite(e.u,e.v);
			res += e.cost;
		}
	}
	return res;
}

int main(){
	int n,m=0,k,l,x;
	cin >> n;	//????????°?????\???
	int cnt=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >> x;
			if(x != -1){
				edge e;
				e.u = i; e.v = j; e.cost = x;
				es[m] = e;
				m++;
			}
		}
	}
	sort(es,es+m);
	cout << kruskal(n,m) << "\n";
}