#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#define MS0(A) memset(A,0,sizeof(A));
#define rep(i,n) for(int i=0;i<n;i++)
#define RI(x) scanf("%d",&x);
#define DI(x) int x;scanf("%d",&x);
using namespace std;
typedef long long LL;
//NOW TO DO WHAT YOU SHOULD TO DO!!!!!
#define MOD 1000000007
#define N 24
int n;
int f[1<<N],a[N],b[2];
LL s[1<<N];
void Init(){
	RI(n);int nn=1<<n;
	rep(i,n)RI(a[i]);
	s[0]=0;
	rep(i,nn){
		int j=__builtin_ctz(i);//__builtin__ctz 右边第一个1的位置
		s[i]=s[i-(1<<j)]+a[j];
	}
	DI(m);rep(i,m)RI(b[i]);
	MS0(f);f[0]=1;
	rep(i,nn){
		rep(j,m)if(s[i]==(LL)b[j])f[i]=0;
		f[i]%=MOD;
		rep(j,n){
			if((i&(1<<j))==0)(f[i+(1<<j)]+=f[i]);
		}

	}
	cout<<f[nn-1];
}
int main(){
	// freopen("in.cpp","r",stdin);
    Init();
	return 0;
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1 << 24;
long long sum[N], num[N], f[N], fac[100], b[100], n, m, a[100];
void dfs(int x){
    if (f[x] != -1) return;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) != 0){
        sum[x] += a[i];
        num[x] ++;
    }
    if (sum[x] == b[2]){
        f[x] = fac[n - num[x]];
        return;
    }

    f[x] = 0;
    if (sum[x] > b[2]) return;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) == 0){
        dfs(x + (1 << (i - 1)));
        f[x] = (f[x] + f[x + (1 << (i - 1))]) % MOD;
    }
}

void calc(int x, int y, long long s, long long t){
    num[y] = t;
    sum[y] = s;
    if (x > n) return;
    calc(x + 1, y, s, t);
    calc(x + 1, y + (1 << (x - 1)), s + a[x], t + 1);
}
int main(){
    freopen("input.txt", "r", stdin);
    fac[0] = 1;
    for (int i = 1; i <= 24; i++) fac[i] = (fac[i - 1] * i) % MOD;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) cin >> b[i];
    //for (int i = 0; i < (1 << n); i++){
    //    for (int j = 1; j <= n; j++)
    //    if ((i & (1 << (j - 1))) != 0){
    //        sum[i] += a[j];
    //        num[i] ++;
    //    }
    //}
    //calc(1, 0, 0, 0);
    if (!m) cout << fac[n] << endl;
    else if (m == 1){
        long long ans = fac[n];
        for (int i = 0; i < (1 << n); i++)
        if (sum[i] == b[1]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
        cout << ans << endl;
    }else{
        long long ans = fac[n];
        sort(b + 1, b + 3);
        memset(f, -1, sizeof(f));
        dfs(0);
        for (int i = 0; i < (1 << n); i++){
            if (sum[i] == b[1]){
                ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
                ans = (ans + f[i]) % MOD;
            }
            if (sum[i] == b[2]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD * MOD) % MOD;
        }
        cout << ans << endl;
    }
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1 << 24;
long long sum[N], num[N], f[N], fac[100], b[100], n, m, a[100];
void dfs(int x){
    if (f[x] != -1) return;
    if (sum[x] == b[2]){
        f[x] = fac[n - num[x]];
        return;
    }
    f[x] = 0;
    if (sum[x] > b[2]) return;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) == 0){
        dfs(x + (1 << (i - 1)));
        f[x] = (f[x] + f[x + (1 << (i - 1))]) % MOD;
    }
}

int main(){
    fac[0] = 1;
    for (int i = 1; i <= 24; i++) fac[i] = (fac[i - 1] * i) % MOD;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) cin >> b[i];
    for (int i = 0; i < (1 << n); i++){
        for (int j = 1; j <= n; j++)
        if ((i & (1 << (j - 1))) != 0){
            sum[i] += a[j];
            num[i] ++;
        }
    }
    if (!m) cout << fac[n] << endl;
    else if (m == 1){
        long long ans = fac[n];
        for (int i = 0; i < (1 << n); i++)
        if (sum[i] == b[1]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
        cout << ans << endl;
    }else{
        long long ans = fac[n];
        sort(b + 1, b + 3);
        memset(f, -1, sizeof(f));
        for (int i = 0; i < (1 << n); i++){
            if (sum[i] == b[1]){
                ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
                dfs(i);
                ans = (ans + f[i]) % MOD;
            }
            if (sum[i] == b[2]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD * MOD) % MOD;
        }
        cout << ans << endl;
    }
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1e9 + 7;
long long ans[105];
long long calc(long long n, long long t){
    long long l = 0, r = (sqrt(n) + 100) / 2;
    while (l <= r){
        long long mid = (l + r) / 2;
        long long x = mid * 2 + 1;
        long long sum = (x - 1) * x / 2 + t * x;
        if (sum > 0 && sum == n) return x;
        else if (sum > 0 && sum < n) l = mid + 1;
        else r = mid - 1;
    }
    return -1;
}
int main(){
    long long n, t = 1, cnt = 0;
    cin >> n;
    while (t - 1 <= n){
        long long tmp = calc(n, t - 1);
        if (tmp != -1) ans[++cnt] = tmp * t;
        t = t * 2;
    }
    sort(ans + 1, ans + cnt + 1);
    for (int i = 1; i <= cnt; i++) cout << ans[i] << endl;
    if (!cnt) puts("-1");
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 24;
const long long MOD = 1e9 + 7;
long long a[30], sum[1 << N], s[3], dp[1 << N], t[1 << N];
int n, m;

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
    scanf("%d", &m);
    s[1] = s[2] = -1;
    for (int i = 1; i <= m; i++) scanf("%I64d", &s[i]);
    for (int i = 1; i <= n; i++) t[1 << (i - 1)] = i;
    for (int i = 0; i < 1 << n; i++) sum[i] = sum[i - (i & -i)] + a[t[i & -i]];
    dp[0] = 1;
    for (int i = 0; i < 1 << n; i++){
        if (sum[i] == s[1] || sum[i] == s[2]) continue;
        for (int j = i; j; j -= j & -j) dp[i] += dp[i - (j & -j)];
        dp[i] %= MOD;
    }
    printf("%I64d\n", dp[(1 << n) - 1]);
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1 << 24;
long long sum[N], num[N], f[N], fac[100], b[100], n, m, a[100];
void dfs(int x){
    if (f[x] != -1) return;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) != 0){
        sum[x] += a[i];
        num[x] ++;
    }
    if (sum[x] == b[2]) f[x] = fac[n - num[x]]; else f[x] = 0;
    if (sum[x] > b[2]) return;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) == 0){
        dfs(x + (1 << (i - 1)));
        f[x] = (f[x] + f[x + (1 << (i - 1))]);
        if (f[x] >= MOD) f[x] %= MOD;
    }
}

void calc(int x, int y, long long s, long long t){
    num[y] = t;
    sum[y] = s;
    if (x > n) return;
    calc(x + 1, y, s, t);
    calc(x + 1, y + (1 << (x - 1)), s + a[x], t + 1);
}
int main(){
    freopen("input.txt", "r", stdin);
    fac[0] = 1;
    for (int i = 1; i <= 24; i++) fac[i] = (fac[i - 1] * i) % MOD;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) cin >> b[i];
    if (!m) cout << fac[n] << endl;
    else if (m == 1){
        long long ans = fac[n];
        for (int i = 0; i < (1 << n); i++)
        if (sum[i] == b[1]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
        cout << ans << endl;
    }else{
        long long ans = fac[n];
        sort(b + 1, b + 3);
        memset(f, -1, sizeof(f));
        dfs(0);
        for (int i = 0; i < (1 << n); i++){
            if (sum[i] == b[1]){
                ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
                ans = (ans + f[i]) % MOD;
            }
            if (sum[i] == b[2]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD * MOD) % MOD;
        }
        cout << ans << endl;
    }
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1 << 24;
long long sum[N], num[N], f[N], fac[100], b[100], n, m, a[100];
void dfs(int x){
    if (f[x] != -1) return;
    if (sum[x] == b[2]){
        f[x] = fac[n - num[x]];
        return;
    }
    f[x] = 0;
    if (sum[x] > b[2]) return;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) == 0){
        dfs(x + (1 << (i - 1)));
        f[x] = (f[x] + f[x + (1 << (i - 1))]) % MOD;
    }
}

void calc(int x, int y, long long s, long long t){
    num[y] = t;
    sum[y] = s;
    if (x > n) return;
    calc(x + 1, y, s, t);
    calc(x + 1, y + (1 << (x - 1)), s + a[x], t + 1);
}
int main(){
    fac[0] = 1;
    for (int i = 1; i <= 24; i++) fac[i] = (fac[i - 1] * i) % MOD;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) cin >> b[i];
    //for (int i = 0; i < (1 << n); i++){
    //    for (int j = 1; j <= n; j++)
    //    if ((i & (1 << (j - 1))) != 0){
    //        sum[i] += a[j];
    //        num[i] ++;
    //    }
    //}
    calc(1, 0, 0, 0);
    if (!m) cout << fac[n] << endl;
    else if (m == 1){
        long long ans = fac[n];
        for (int i = 0; i < (1 << n); i++)
        if (sum[i] == b[1]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
        cout << ans << endl;
    }else{
        long long ans = fac[n];
        sort(b + 1, b + 3);
        memset(f, -1, sizeof(f));
        for (int i = 0; i < (1 << n); i++){
            if (sum[i] == b[1]){
                ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
                dfs(i);
                ans = (ans + f[i]) % MOD;
            }
            if (sum[i] == b[2]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD * MOD) % MOD;
        }
        cout << ans << endl;
    }
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1 << 24;
long long sum[N], num[N], f[N], fac[100], b[100], n, m, a[100];
void dfs(int x){
    if (f[x] != -1) return;
    if (sum[x] == b[2]){
        f[x] = fac[n - num[x]];
        return;
    }

    f[x] = 0;
    if (sum[x] > b[2]) return;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) == 0){
        dfs(x + (1 << (i - 1)));
        f[x] = (f[x] + f[x + (1 << (i - 1))]) % MOD;
    }
}

void calc(int x, int y, long long s, long long t){
    num[y] = t;
    sum[y] = s;
    if (x > n) return;
    calc(x + 1, y, s, t);
    calc(x + 1, y + (1 << (x - 1)), s + a[x], t + 1);
}
int main(){
    //freopen("input.txt", "r", stdin);
    fac[0] = 1;
    for (int i = 1; i <= 24; i++) fac[i] = (fac[i - 1] * i) % MOD;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) cin >> b[i];
    //for (int i = 0; i < (1 << n); i++){
    //    for (int j = 1; j <= n; j++)
    //    if ((i & (1 << (j - 1))) != 0){
    //        sum[i] += a[j];
    //        num[i] ++;
    //    }
    //}
    calc(1, 0, 0, 0);
    if (!m) cout << fac[n] << endl;
    else if (m == 1){
        long long ans = fac[n];
        for (int i = 0; i < (1 << n); i++)
        if (sum[i] == b[1]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
        cout << ans << endl;
    }else{
        long long ans = fac[n];
        sort(b + 1, b + 3);
        memset(f, -1, sizeof(f));
        dfs(0);
        for (int i = 0; i < (1 << n); i++){
            if (sum[i] == b[1]){
                ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
                ans = (ans + f[i]) % MOD;
            }
            if (sum[i] == b[2]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD * MOD) % MOD;
        }
        cout << ans << endl;
    }
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1 << 24;
long long sum[N], num[N], f[N], fac[100], b[100], n, m, a[100];
void dfs(int x){
    if (f[x] != -1) return;
    if (sum[x] == b[2]){
        f[x] = fac[n - num[x]];
        return;
    }
    f[x] = 0;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) == 0){
        dfs(x + (1 << (i - 1)));
        f[x] = f[x] + f[x + (1 << (i - 1))];
    }
}
long long getsum(long long x){
    long long ret = 0;
    for (int i = 1; i <= 24; i++)
    if ((x & (1 << (i - 1))) != 0) ret += a[i];
    return ret;
}
long long getnum(long long x){
    long long ret = 0;
    for (int i = 1; i <= 24; i++)
    if ((x & (1 << (i - 1))) != 0) ret ++;
    return ret;
}
int main(){
    fac[0] = 1;
    for (int i = 1; i <= 24; i++) fac[i] = (fac[i - 1] * i) % MOD;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) cin >> b[i];
    for (int i = 0; i < (1 << n); i++){
        num[i] = getnum(i);
        sum[i] = getsum(i);
    }
    if (!m) cout << fac[n] << endl;
    else if (m == 1){
        long long ans = fac[n];
        for (int i = 0; i < (1 << n); i++)
        if (sum[i] == b[1]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
        cout << ans << endl;
    }else{
        long long ans = fac[n];
        sort(b + 1, b + 3);
        memset(f, -1, sizeof(f));
        for (int i = 0; i < (1 << n); i++)
        if (sum[i] == b[1]){
            ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
            dfs(i);
            ans = (ans + f[i]) % MOD;
        }
        for (int i = 0; i < (1 << n); i++)
        if (sum[i] == b[2]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
        cout << ans << endl;
    }
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1 << 24;
long long sum[N], num[N], f[N], fac[100], b[100], n, m, a[100];
void dfs(int x){
    if (f[x] != -1) return;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) != 0){
        sum[x] += a[i];
        num[x] ++;
    }
    if (sum[x] == b[2]) f[x] = fac[n - num[x]]; else f[x] = 0;
    if (sum[x] > b[2]) return;
    for (int i = 1; i <= n; i++)
    if ((x & (1 << (i - 1))) == 0){
        dfs(x + (1 << (i - 1)));
        f[x] = (f[x] + f[x + (1 << (i - 1))]);
        if (f[x] >= MOD) f[x] %= MOD;
    }
}

void calc(int x, int y, long long s, long long t){
    num[y] = t;
    sum[y] = s;
    if (x > n) return;
    calc(x + 1, y, s, t);
    calc(x + 1, y + (1 << (x - 1)), s + a[x], t + 1);
}
int main(){
    //freopen("input.txt", "r", stdin);
    fac[0] = 1;
    for (int i = 1; i <= 24; i++) fac[i] = (fac[i - 1] * i) % MOD;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) cin >> b[i];
    if (!m) cout << fac[n] << endl;
    else if (m == 1){
        long long ans = fac[n];
        for (int i = 0; i < (1 << n); i++)
        if (sum[i] == b[1]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
        cout << ans << endl;
    }else{
        long long ans = fac[n];
        sort(b + 1, b + 3);
        memset(f, -1, sizeof(f));
        dfs(0);
        for (int i = 0; i < (1 << n); i++){
            if (sum[i] == b[1]){
                ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD) % MOD;
                ans = (ans + f[i]) % MOD;
            }
            if (sum[i] == b[2]) ans = (ans - fac[n - num[i]] * fac[num[i]] + MOD * MOD) % MOD;
        }
        cout << ans << endl;
    }
}


#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1e9 + 7;

int n, t, v[100005], ans[100005];
int main(){
    scanf("%d", &n);
    t = 0; ans[n] = 0;
    for (int i = n - 1; i >= 0; i--){
        if (t % 2 == 0){
            if (!v[(t + n) / 2]) t = (t + n) / 2;
            else t = t / 2;
            v[t] = 1;
        }else{
            if (!v[(t + n) / 2]) t = (t + n) / 2;
            else t = t / 2;
            v[t] = 1;
        }
        ans[i] = t;
    }
    for (int i = 0; i <= n; i++) printf("%d ", ans[i]);
}


#include<cstdio>
#include<cstring>
#define ll long long

const int Mod=1e9+7;
int n,k;
ll a[25],b[10],jc[25],c[25],dp1[1<<24],dp2[1<<24],ans1,ans2,ans3,ans,sum[1<<24];
bool use[25];

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i,jc[i]%=Mod;
}

void init()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  scanf("%I64d",&a[i]);
	scanf("%d",&k);
	b[0]=b[1]=-1;
	for(int i=0;i<k;i++)
	  scanf("%I64d",&b[i]);
	memset(use,false,sizeof(use));
	memset(dp1,0,sizeof(dp1));
	memset(dp2,0,sizeof(dp2));
	memset(sum,-1,sizeof(sum));
	sum[0]=0;
	ans1=ans2=ans3=0;
}

void dfs1(int deep,int num,ll sum,ll mask)
{
	if(deep>=n)
	  return;
	dfs1(deep+1,num,sum,mask);
	ll newsum=sum+a[deep];
	if(newsum<b[0])
	  dfs1(deep+1,num+1,newsum,mask|(1<<deep));
	if(newsum==b[0])
	  ans1+=(jc[num]*jc[n-num])%Mod,ans1%=Mod,dp1[mask|(1<<deep)]=1;
}

void dfs2(int deep,int num,ll sum,ll mask)
{
	if(deep>=n)
	  return;
	dfs2(deep+1,num,sum,mask);
	ll newsum=sum+a[deep];
	if(newsum<b[1])
	  dfs2(deep+1,num+1,newsum,mask|(1<<deep));
	if(newsum==b[1])
	  ans2+=(jc[num]*jc[n-num])%Mod,ans2%=Mod,dp2[mask|(1<<deep)]=1;
}

ll dfs3(ll mask)
{
	if(sum[mask]!=-1)
	  return mask;
	if(dp1[mask]>0)
	  return dp1[mask];
	sum[mask]=0;
	for(int i=0;i<n;i++)
	  if(mask&(1<<i)>0)
	   sum[mask]+=dfs3(mask&(~(1<<i)));
	return sum[mask];
}

void solve()
{
	ll newmask,mask;
	if(k==0)
	{
		printf("%I64d\n",jc[n]);
		return;
	}
	if(k==1)
	{
	    dfs1(0,1,0,0);
		printf("%I64d\n",(jc[n]-ans1+Mod)%Mod);
	}
	else
	{
	   if(b[0]>b[1])
	   {
		  int t=b[0];
		  b[0]=b[1];
		  b[1]=t;
	   }
	   dfs1(0,1,0,0);
	   dfs2(0,1,0,0);
	   ans3=0;
	   for(ll mask=(1<<n)-1;mask>0;mask--)
		 if(dp2[mask]>0)
		 {
			newmask=mask;
			if(sum[newmask]==-1)
		    {
	  		  sum[newmask]=0;
			  ll tmp=newmask;
			  while(tmp>0)
			  {
				if(tmp&1)
				  sum[newmask]++;
				tmp>>=1;
			  }
		    }

		    for(newmask=mask;newmask>0;newmask=mask&(newmask-1))
			 if(dp1[newmask]>0)
			 {
		       if(sum[newmask]==-1)
		       {
	  		     sum[newmask]=0;
			     ll tmp=newmask;
			     while(tmp>0)
			     {
		  		   if(tmp&1)
				    sum[newmask]++;
				   tmp>>=1;
			     }
		       }
			   ans3+=jc[sum[newmask]]*jc[sum[mask]-sum[newmask]]%Mod*jc[n-sum[mask]]%Mod,ans3%=Mod;
			 }
		 }
		ans=(ans1+ans2-ans3+Mod)%Mod;
		ans=(jc[n]-ans+Mod)%Mod;
		printf("%I64d\n",ans);
	}
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long

const int Mod=1e9+7;
const int MaxS=1e7+11;

ll s1[MaxS],s2[MaxS];
int size,cnt1[MaxS],cnt2[MaxS],head[MaxS],next[MaxS],ans[MaxS];
inline void clr()
{
	size=0;
	memset(head,-1,sizeof(head));
	memset(ans,0,sizeof(ans));
}

inline void push(ll s,int cnt)
{
	ll key=((s<<29)|cnt)%MaxS;
	int ct=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		ct++;
		//if(ct>=5) cout<<"haha"<<endl;
	    if(s1[i]==s&&cnt1[i]==cnt)
	    {
		  ans[i]++;
		  return;
	    }
	}
	s1[size]=s,cnt1[size]=cnt;
	next[size]=head[key],ans[size]=1,head[key]=size++;
}

inline void push(ll _s1,int _cnt1,ll _s2,int _cnt2)
{
	ll key1=((_s1<<29)|_cnt1)%MaxS;
	ll key2=((_s2<<29)|_cnt2)%MaxS;
	ll key=((key1<<29)|key2)%MaxS;
	int cnt=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		cnt++;
		//if(cnt>=10) cout<<"haha"<<endl;
	    if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
	    {
	    	ans[i]++;
	    	return;
	    }
	}
	s1[size]=_s1,cnt1[size]=_cnt1;
	s2[size]=_s2,cnt2[size]=_cnt2;
	next[size]=head[key],ans[size]=1,head[key]=size++;
}

inline int find(ll s,int cnt)
{
	ll key=((s<<29)|cnt)%MaxS;
	int ct=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		ct++;
		//if(ct>=5) cout<<"haha"<<endl;
		if(s1[i]==s&&cnt1[i]==cnt)
		  return ans[i];
	}
	return 0;
}

inline int find(ll _s1,int _cnt1,ll _s2,int _cnt2)
{
	ll key=(_s1*_cnt1+_s1+_cnt1+_s2*_cnt2+_s2+_cnt2)%MaxS;
	int cnt=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		cnt++;
		//if(cnt>=10) cout<<"haha"<<endl;
	    if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
		  return ans[i];
	}
	return 0;
}

int n,k;
ll a1[25],a2[25],b[10],jc[25],s[1000000][4];

void init()
{
	cin>>n;
	for(int i=0;i<n/2;i++)
	  cin>>a1[i];
	for(int i=n/2;i<n;i++)
	  cin>>a2[i-n/2];
	cin>>k;
	for(int i=0;i<k;i++)
	  cin>>b[i];
	if(k==2&&(b[0]>b[1]))
	{
		int t=b[0];
		b[0]=b[1];
		b[1]=t;
	}
}

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i%Mod;
}

ll  getAns1(ll u)
{
	ll ans=0;
	clr();
	s[0][0]=0,s[0][1]=0;
	push(0,0);
	for(int i=1;i<1<<(n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a1[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
		   push(s[i][0],s[i][1] );
		   if(s[i][0]==u)
			 ans+=jc[s[i][1]]*jc[n-s[i][1]]%Mod;
		   if(ans>=Mod) ans-=Mod;
		}
	}

	s[0][0]=0,s[0][1]=0;
	for(int i=1;i<1<<(n-n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a2[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
			for(int k=0;k<=(n/2);k++)
				ans+=find(u-s[i][0],k)*jc[k+s[i][1]]%Mod*jc[n-s[i][1]-k]%Mod;
			if(ans>=Mod) ans-=Mod;
		}
	}
	return ans;

}

void dfs(int deep,ll s1,int cnt1,ll s2,int cnt2,bool flag,ll* a,ll& ans,ll u1,ll u2)
{
	int t;
	if((!flag&&deep==n/2)||(flag&&deep==(n-n/2)))
	{
		if(!flag)
		 push(s1,cnt1,s2,cnt2);
		else
		{
			if(s1==u1&&s2==u2)
			{
				ans+=jc[cnt1]*jc[cnt2]%Mod*jc[n-cnt1-cnt2]%Mod;
				ans%=Mod;
				return;
			}
			if(s1==u1)
			{
				for(int j=1;j<=(n/2);j++)
				 if(t=find(0,0,u2-s2,j))
				  ans+=t*jc[cnt1]%Mod*jc[j+cnt2]%Mod*jc[n-j-cnt1-cnt2]%Mod;
				return;
			}
			if(s2==u2)
			{
				for(int j=1;j<=(n/2);j++)
				 if(t=find(u1-s1,j,0,0))
				  ans+=t*jc[j+cnt1]%Mod*jc[cnt2]%Mod*jc[n-j-cnt1-cnt2]%Mod;
				return;
			}
			for(int i=1;i<=(n/2);i++)
			  for(int j=1;j<=(n/2);j++)
				if(t=find(u1-s1,i,u2-s2,j))
				  ans+=t*jc[i+cnt1]%Mod*jc[j+cnt2]%Mod*jc[n-i-j-cnt1-cnt2]%Mod;
			if(ans>=Mod) ans-=Mod;
		}
		return;
	}

	dfs(deep+1,s1,cnt1,s2,cnt2,flag,a,ans,u1,u2);
	if(s1+a[deep]<=u1)
	  dfs(deep+1,s1+a[deep],cnt1+1,s2,cnt2,flag,a,ans,u1,u2);
	if(s2+a[deep]<=u2)
	  dfs(deep+1,s1,cnt1,s2+a[deep],cnt2+1,flag,a,ans,u1,u2);
}

ll  getAns2(ll u1,ll u2)
{
	ll ans=0;
	clr();
	dfs(0,0,0,0,0,false,a1,ans,u1,u2-u1);
	dfs(0,0,0,0,0,true,a2,ans,u1,u2-u1);
	return ans;
}

void solve()
{
	if(k==0)
	  cout<<jc[n]<<endl;
	else if(k==1)
	{
		ll tmp=getAns1(b[0]);
		cout<<(jc[n]-tmp+Mod)%Mod<<endl;
	}
	else
	{
		ll tmp1=getAns1(b[0]),tmp2=getAns1(b[1]),tmp3=getAns2(b[0],b[1]);
		cout<<((jc[n]-tmp1-tmp2+tmp3)%Mod+Mod)%Mod<<endl;
	}
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long

const int Mod=1e9+7;
const int MaxS=5e6+11;

ll s1[MaxS],s2[MaxS];
int size,cnt1[MaxS],cnt2[MaxS],head[MaxS],next[MaxS],ans[MaxS];
inline void clr()
{
	size=0;
	memset(head,-1,sizeof(head));
	memset(ans,0,sizeof(ans));
}

inline void push(ll s,int cnt)
{
	ll key=(s+cnt)%MaxS;
	int ct=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		ct++;
		//if(ct>=5) cout<<"haha"<<endl;
	    if(s1[i]==s&&cnt1[i]==cnt)
	    {
		  ans[i]++;
		  return;
	    }
	}
	s1[size]=s,cnt1[size]=cnt;
	next[size]=head[key],ans[size]=1,head[key]=size++;
}

inline void push(ll _s1,int _cnt1,ll _s2,int _cnt2)
{
	ll key=(_s1*_cnt1+_s1+_cnt1+_s2*_cnt2+_s2+_cnt2)%MaxS;
	int cnt=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		cnt++;
		//if(cnt>=4) cout<<"haha"<<endl;
	    if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
	    {
	    	ans[i]++;
	    	return;
	    }
	}
	s1[size]=_s1,cnt1[size]=_cnt1;
	s2[size]=_s2,cnt2[size]=_cnt2;
	next[size]=head[key],ans[size]=1,head[key]=size++;
}

inline int find(ll s,int cnt)
{
	ll key=(s+cnt)%MaxS;
	int ct=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		ct++;
		//if(ct>=5) cout<<"haha"<<endl;
		if(s1[i]==s&&cnt1[i]==cnt)
		  return ans[i];
	}
	return 0;
}

inline int find(ll _s1,int _cnt1,ll _s2,int _cnt2)
{
	ll key=(_s1*_cnt1+_s1+_cnt1+_s2*_cnt2+_s2+_cnt2)%MaxS;
	int cnt=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		cnt++;
		//if(cnt>=4) cout<<"haha"<<endl;
	    if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
		  return ans[i];
	}
	return 0;
}

int n,k;
ll a1[25],a2[25],b[10],jc[25],s[1000000][4];

void init()
{
	cin>>n;
	for(int i=0;i<n/2;i++)
	  cin>>a1[i];
	for(int i=n/2;i<n;i++)
	  cin>>a2[i-n/2];
	cin>>k;
	for(int i=0;i<k;i++)
	  cin>>b[i];
	if(k==2&&(b[0]>b[1]))
	{
		int t=b[0];
		b[0]=b[1];
		b[1]=t;
	}
}

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i%Mod;
}

ll  getAns1(ll u)
{
	ll ans=0;
	clr();
	s[0][0]=0,s[0][1]=0;
	push(0,0);
	for(int i=1;i<1<<(n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a1[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
		   push(s[i][0],s[i][1] );
		   if(s[i][0]==u)
			 ans+=jc[s[i][1]]*jc[n-s[i][1]]%Mod;
		   if(ans>=Mod) ans-=Mod;
		}
	}

	s[0][0]=0,s[0][1]=0;
	for(int i=1;i<1<<(n-n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a2[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
			for(int k=0;k<=(n/2);k++)
				ans+=find(u-s[i][0],k)*jc[k+s[i][1]]%Mod*jc[n-s[i][1]-k]%Mod;
			if(ans>=Mod) ans-=Mod;
		}
	}
	return ans;

}

void dfs(int deep,ll s1,int cnt1,ll s2,int cnt2,bool flag,ll* a,ll& ans,ll u1,ll u2)
{
	int t;
	if((!flag&&deep==n/2)||(flag&&deep==(n-n/2)))
	{
		if(!flag)
		 push(s1,cnt1,s2,cnt2);
		else
		{
			if(s1==u1&&s2==u2)
			{
				ans+=jc[cnt1]*jc[cnt2]%Mod*jc[n-cnt1-cnt2]%Mod;
				ans%=Mod;
				return;
			}
			if(s1==u1)
			{
				for(int j=1;j<=(n/2);j++)
				 if(t=find(0,0,u2-s2,j))
				  ans+=t*jc[cnt1]%Mod*jc[j+cnt2]%Mod*jc[n-j-cnt1-cnt2]%Mod;
				return;
			}
			if(s2==u2)
			{
				for(int j=1;j<=(n/2);j++)
				 if(t=find(u1-s1,j,0,0))
				  ans+=t*jc[j+cnt1]%Mod*jc[cnt2]%Mod*jc[n-j-cnt1-cnt2]%Mod;
				return;
			}
			for(int i=1;i<=(n/2);i++)
			  for(int j=1;j<=(n/2);j++)
				if(t=find(u1-s1,i,u2-s2,j))
				  ans+=t*jc[i+cnt1]%Mod*jc[j+cnt2]%Mod*jc[n-i-j-cnt1-cnt2]%Mod;
			if(ans>=Mod) ans-=Mod;
		}
		return;
	}

	dfs(deep+1,s1,cnt1,s2,cnt2,flag,a,ans,u1,u2);
	if(s1+a[deep]<=u1)
	  dfs(deep+1,s1+a[deep],cnt1+1,s2,cnt2,flag,a,ans,u1,u2);
	if(s2+a[deep]<=u2)
	  dfs(deep+1,s1,cnt1,s2+a[deep],cnt2+1,flag,a,ans,u1,u2);
}

ll  getAns2(ll u1,ll u2)
{
	ll ans=0;
	clr();
	dfs(0,0,0,0,0,false,a1,ans,u1,u2-u1);
	dfs(0,0,0,0,0,true,a2,ans,u1,u2-u1);
	return ans;
}

void solve()
{
	if(k==0)
	  cout<<jc[n]<<endl;
	else if(k==1)
	{
		ll tmp=getAns1(b[0]);
		cout<<(jc[n]-tmp+Mod)%Mod<<endl;
	}
	else
	{
		ll tmp1=getAns1(b[0]),tmp2=getAns1(b[1]),tmp3=getAns2(b[0],b[1]);
		cout<<((jc[n]-tmp1-tmp2+tmp3)%Mod+Mod)%Mod<<endl;
	}
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long

const int Mod=1e9+7;
const int MaxS=1e7+11;

ll s1[MaxS],s2[MaxS];
int size,cnt1[MaxS],cnt2[MaxS],head[MaxS],next[MaxS],ans[MaxS];
inline void clr()
{
	size=0;
	memset(head,-1,sizeof(head));
	memset(ans,0,sizeof(ans));
}

inline void push(ll s,int cnt)
{
	ll key=((s<<29)|cnt)%MaxS;
	int ct=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		ct++;
		//if(ct>=5) cout<<"haha"<<endl;
	    if(s1[i]==s&&cnt1[i]==cnt)
	    {
		  ans[i]++;
		  return;
	    }
	}
	s1[size]=s,cnt1[size]=cnt;
	next[size]=head[key],ans[size]=1,head[key]=size++;
}

inline void push(ll _s1,int _cnt1,ll _s2,int _cnt2)
{
	ll key1=((_s1<<29)|_cnt1)%MaxS;
	ll key2=((_s2<<29)|_cnt2)%MaxS;
	ll key=((key1<<29)|key2)%MaxS;
	int cnt=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		cnt++;
		//if(cnt>=10) cout<<"haha"<<endl;
	    if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
	    {
	    	ans[i]++;
	    	return;
	    }
	}
	s1[size]=_s1,cnt1[size]=_cnt1;
	s2[size]=_s2,cnt2[size]=_cnt2;
	next[size]=head[key],ans[size]=1,head[key]=size++;
}

inline int find(ll s,int cnt)
{
	ll key=((s<<29)|cnt)%MaxS;
	int ct=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		ct++;
		//if(ct>=5) cout<<"haha"<<endl;
		if(s1[i]==s&&cnt1[i]==cnt)
		  return ans[i];
	}
	return 0;
}

inline int find(ll _s1,int _cnt1,ll _s2,int _cnt2)
{
	ll key1=((_s1<<29)|_cnt1)%MaxS;
	ll key2=((_s2<<29)|_cnt2)%MaxS;
	ll key=((key1<<29)|key2)%MaxS;
	int cnt=0;
	for(int i=head[key];i!=-1;i=next[i])
	{
		cnt++;
		//if(cnt>=10) cout<<"haha"<<endl;
	    if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
		  return ans[i];
	}
	return 0;
}

int n,k;
ll a1[25],a2[25],b[10],jc[25],s[1000000][4];

void init()
{
	cin>>n;
	for(int i=0;i<n/2;i++)
	  cin>>a1[i];
	for(int i=n/2;i<n;i++)
	  cin>>a2[i-n/2];
	cin>>k;
	for(int i=0;i<k;i++)
	  cin>>b[i];
	if(k==2&&(b[0]>b[1]))
	{
		int t=b[0];
		b[0]=b[1];
		b[1]=t;
	}
}

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i%Mod;
}

ll  getAns1(ll u)
{
	ll ans=0;
	clr();
	s[0][0]=0,s[0][1]=0;
	push(0,0);
	for(int i=1;i<1<<(n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a1[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
		   push(s[i][0],s[i][1] );
		   if(s[i][0]==u)
			 ans+=jc[s[i][1]]*jc[n-s[i][1]]%Mod;
		   if(ans>=Mod) ans-=Mod;
		}
	}

	s[0][0]=0,s[0][1]=0;
	for(int i=1;i<1<<(n-n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a2[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
			for(int k=0;k<=(n/2);k++)
				ans+=find(u-s[i][0],k)*jc[k+s[i][1]]%Mod*jc[n-s[i][1]-k]%Mod;
			if(ans>=Mod) ans-=Mod;
		}
	}
	return ans;

}

void dfs(int deep,ll s1,int cnt1,ll s2,int cnt2,bool flag,ll* a,ll& ans,ll u1,ll u2)
{
	int t;
	if((!flag&&deep==n/2)||(flag&&deep==(n-n/2)))
	{
		if(!flag)
		 push(s1,cnt1,s2,cnt2);
		else
		{
			if(s1==u1&&s2==u2)
			{
				ans+=jc[cnt1]*jc[cnt2]%Mod*jc[n-cnt1-cnt2]%Mod;
				ans%=Mod;
				return;
			}
			if(s1==u1)
			{
				for(int j=1;j<=(n/2);j++)
				 if(t=find(0,0,u2-s2,j))
				  ans+=t*jc[cnt1]%Mod*jc[j+cnt2]%Mod*jc[n-j-cnt1-cnt2]%Mod;
				return;
			}
			if(s2==u2)
			{
				for(int j=1;j<=(n/2);j++)
				 if(t=find(u1-s1,j,0,0))
				  ans+=t*jc[j+cnt1]%Mod*jc[cnt2]%Mod*jc[n-j-cnt1-cnt2]%Mod;
				return;
			}
			for(int i=1;i<=(n/2);i++)
			  for(int j=1;j<=(n/2);j++)
				if(t=find(u1-s1,i,u2-s2,j))
				  ans+=t*jc[i+cnt1]%Mod*jc[j+cnt2]%Mod*jc[n-i-j-cnt1-cnt2]%Mod;
			if(ans>=Mod) ans-=Mod;
		}
		return;
	}

	dfs(deep+1,s1,cnt1,s2,cnt2,flag,a,ans,u1,u2);
	if(s1+a[deep]<=u1)
	  dfs(deep+1,s1+a[deep],cnt1+1,s2,cnt2,flag,a,ans,u1,u2);
	if(s2+a[deep]<=u2)
	  dfs(deep+1,s1,cnt1,s2+a[deep],cnt2+1,flag,a,ans,u1,u2);
}

ll  getAns2(ll u1,ll u2)
{
	ll ans=0;
	clr();
	dfs(0,0,0,0,0,false,a1,ans,u1,u2-u1);
	dfs(0,0,0,0,0,true,a2,ans,u1,u2-u1);
	return ans;
}

void solve()
{
	if(k==0)
	  cout<<jc[n]<<endl;
	else if(k==1)
	{
		ll tmp=getAns1(b[0]);
		cout<<(jc[n]-tmp+Mod)%Mod<<endl;
	}
	else
	{
		ll tmp1=getAns1(b[0]),tmp2=getAns1(b[1]),tmp3=getAns2(b[0],b[1]);
		cout<<((jc[n]-tmp1-tmp2+tmp3)%Mod+Mod)%Mod<<endl;
	}
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#define ll long long
const int Mod=1e9+7;

ll dp[1<<24][2],a[25],b[25],jc[25];
int n,k,cnt[1<<24];

void init()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  scanf("%I64d",&a[i]);
	scanf("%d",&k);
	b[0]=b[1]=-1;
	for(int i=0;i<k;i++)
	  scanf("%I64d",&b[i]);
}

void prework()
{
	memset(cnt,0,sizeof(cnt));
	for(int i=1;i<(1<<n);i++)
	 for(int j=i;j>0;j>>=1)
	   if(j&1) cnt[i]++;
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=i*jc[i-1]%Mod;
}

void solve()
{
	if(k==0)
	{
		printf("%I64d\n",jc[n]);
		return;
	}
	if(k==2&&b[0]>b[1])
	{
		int t=b[0];
		b[0]=b[1];
		b[1]=t;
	}
	int newmask;
	ll newsum,ans=0;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1,dp[0][1]=0;
	for(int mask=0;mask<(1<<n);mask++)
	  if(dp[mask][0]>0)
	  {
		  if ((k==1&&dp[mask][1]>b[0])||(k==2&&dp[mask][1]>b[1]))
		  {
			ans+=dp[mask][0]*jc[n-cnt[mask]]%Mod,ans%=Mod;
		    continue;
		  }
		  for(int j=0;j<n;j++)
		    if((mask&(1<<j))==0)
		    {
			   newmask=mask|(1<<j);
			   newsum=dp[mask][1]+a[j];
			   if(newsum!=b[0]&&newsum!=b[1])
				 dp[newmask][0]+=dp[mask][0],dp[newmask][0]%=Mod,dp[newmask][1]=newsum;
		    }
	  }
	printf("%I64d\n",ans);
}

int main()
{
	init();
	prework();
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#define ll long long
const int Mod=1e9+7;

ll dp[1<<24][2];
int n,k,cnt[1<<24],a[25],b[10];

void init()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  scanf("%d",&a[i]);
	scanf("%d",&k);
	b[0]=b[1]=-1;
	for(int i=0;i<k;i++)
	  scanf("%d",&b[i]);
}

void prework()
{
	memset(cnt,0,sizeof(cnt));
	for(int i=1;i<(1<<n);i++)
	 for(int j=i;j>0;j>>=1)
	   if(j&1) cnt[i]++;
}

void solve()
{
	int newmask;
	ll newsum;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1,dp[0][1]=0;
	for(int mask=0;mask<(1<<n);mask++)
	  if(dp[mask][0]>0)
	  {
		 for(int j=0;j<n;j++)
		   if((mask&(1<<j))==0)
		   {
			   newmask=mask|(1<<j);
			   newsum=dp[mask][1]+a[j];
			   if(newsum!=b[0]&&newsum!=b[1])
				 dp[newmask][0]+=dp[mask][0],dp[newmask][0]%=Mod,dp[newmask][1]=newsum;
		   }
	  }
	printf("%I64d\n",dp[(1<<n)-1][0]);
}

int main()
{
	init();
	//prework();
	solve();
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

#define ll int
const int Mod=1e9+7;

ll a[24],b[2],dp[1<<24];
int n,k;

void init()
{
	cin>>n;
	for(int i=0;i<n;i++)
	  cin>>a[i];
	cin>>k;
	for(int i=0;i<k;i++)
	  cin>>b[i];
	dp[0]=0;		//这里，非递归，枚举子集和
	for(int i=1;i<(1<<n);i++)
	{
		int j=__builtin_ctz(i);
		dp[i]=dp[i^(1<<j)]+a[j];
	}
	for(int i=1;i<(1<<n);i++)		//非法定为-1
	  for(int j=0;j<k;j++)
		if(dp[i]==b[j])
		{
			dp[i]=-1;
			break;
		}
}

void solve()
{
	dp[0]=1;		//这里DP用作算种数
	for(int i=1;i<(1<<n);i++)
	  if(dp[i]<0)
		dp[i]=0;
	  else
	  {
		 dp[i]=0;
		 for(int j=0;j<n;j++)
		   if(i&(1<<j))
		   {
			 dp[i]+=dp[i^(1<<j)];
			 if(dp[i]>=Mod) dp[i]-=Mod;
		   }
		 //dp[i]%=Mod;
	  }
	cout<<dp[(1<<n)-1]<<endl;
}

int main()
{
	init();
	solve();
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

typedef long long llint;

const int MAXN = 24;
const llint MOD = 1000000007;

llint a[MAXN], b[MAXN];
llint dp[1 << MAXN];

int main() {
  int n, m;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }

  dp[0] = 0;
  for (int i = 1; i < (1 << n); ++i) {
    int j = __builtin_ctz(i);
    dp[i] = dp[i ^ (1 << j)] + a[j];
  }
  for (int i = 0; i < (1 << n); ++i) {
    for (int j = 0; j < m; ++j) {
      if (dp[i] == b[j]) {
        dp[i] = -1;
        break;
      }
    }
  }
  dp[0] = 1;
  for (int i = 1; i < (1 << n); ++i) {
    if (dp[i] < 0) {
      dp[i] = 0;
    } else {
      dp[i] = 0;
      for (int j = 0; j < n; ++j) {
        if (i & (1 << j)) {
          dp[i] += dp[i ^ (1 << j)];
        }
      }
      dp[i] %= MOD;
    }
  }
  cout << dp[(1 << n) - 1] << endl;

  return 0;
}


#include<cstdio>
#include<cstring>
#define ll long long

const int Mod=1e9+7;
int n,k;
ll a[25],b[10],jc[25],c[25],tmp[25][2],ans1,ans2,ans3,ans;
bool use[25];

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i,jc[i]%=Mod;
}

void init()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  scanf("%I64d",&a[i]);
	int tmpn=0,j;
	for(int i=0;i<n;i++)
	{
		for(j=0;j<tmpn;j++)
		  if(a[i]==tmp[j][0])
		  {
			tmp[j][1]++;
		    break;
		  }
		if(j==tmpn)
		  tmp[tmpn][0]=a[i],tmp[tmpn++][1]=1;
	}
	n=0;
	for(int i=0;i<tmpn;i++)
	{
		j=1;
		while(j<=tmp[i][1])
		 a[n++]=tmp[i][0]*j,tmp[i][1]-=j,j<<=1;
		if(tmp[i][1]!=0)
		  a[n++]=tmp[i][0]*tmp[i][1];
	}

	scanf("%d",&k);
	b[0]=b[1]=-1;
	for(int i=0;i<k;i++)
	  scanf("%I64d",&b[i]);
	memset(use,false,sizeof(use));
	ans1=ans2=ans3=0;
}

void dfs1(int deep,int num,ll sum)
{
	if(deep>=n)
	  return;
	dfs1(deep+1,num,sum);
	ll newsum=sum+a[deep];
	if(newsum<b[0])
	  dfs1(deep+1,num+1,newsum);
	if(newsum==b[0])
	  ans1+=(jc[num]*jc[n-num])%Mod,ans1%=Mod;
}

void dfs3(int deep,int num,ll sum,int limit)
{
	if(deep>=limit)
	  return;
	dfs3(deep+1,num,sum,limit);
	ll newsum=sum+c[deep];
	if(newsum<b[0])
	  dfs3(deep+1,num+1,newsum,limit);
	if(newsum==b[0])
	  ans3+=(jc[num]*jc[limit-num])%Mod*jc[n-limit]%Mod,ans3%=Mod;
}

void dfs2(int deep,int num,ll sum)
{
	if(deep>=n)
	  return;
	dfs2(deep+1,num,sum);
	ll newsum=sum+a[deep];
	use[deep]=true;
	if(newsum<b[1])
	  dfs2(deep+1,num+1,newsum);
	if(newsum==b[1])
	{
	  ans2+=(jc[num]*jc[n-num])%Mod,ans2%=Mod;
	  int cnt=0;
	  for(int i=0;i<n;i++)
		if(use[i])
		  c[cnt++]=a[i];
	  dfs3(0,1,0,cnt);
	}
	use[deep]=false;
}

void solve()
{
	ll sum,newmask,mask;
	if(k==0)
	{
		printf("%I64d\n",jc[n]);
		return;
	}
	if(k==1)
	  dfs1(0,1,0);
	else
	{
	   if(b[0]>b[1])
	   {
		  int t=b[0];
		  b[0]=b[1];
		  b[1]=t;
	   }
	   dfs1(0,1,0);
	   dfs2(0,1,0);
	}
	ans=((ans1+ans2-ans3)%Mod+Mod)%Mod;
	ans=((jc[n]-ans)%Mod+Mod)%Mod;
	printf("%I64d\n",ans);
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long

const int Mod=1e9+7;
const int MaxS=5e6+7;

struct hashtable
{
	ll s1[MaxS],s2[MaxS];
	int size,cnt1[MaxS],cnt2[MaxS],head[MaxS],next[MaxS],ans[MaxS];
	void clr()
	{
		size=0;
		memset(head,-1,sizeof(head));
		memset(ans,0,sizeof(ans));
	}
	void push(ll s,int cnt)
	{
		ll key=(s*cnt+s+cnt)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==s&&cnt1[i]==cnt)
		  {
			ans[i]++;
			return;
		  }
		s1[size]=s,cnt1[size]=cnt;
		next[size]=head[key],ans[size]=1,head[key]=size++;
	}
	void push(ll _s1,int _cnt1,ll _s2,int _cnt2)
	{
		ll key=(_s1*_cnt1+_s1+_cnt1+_s2*_cnt2+_s2+_cnt2)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
		  {
			ans[i]++;
			return;
		  }
		s1[size]=_s1,cnt1[size]=_cnt1;
		s2[size]=_s2,cnt2[size]=_cnt2;
		next[size]=head[key],ans[size]=1,head[key]=size++;
	}

	int find(ll s,int cnt)
	{
		ll key=(s*cnt+s+cnt)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==s&&cnt1[i]==cnt)
			return ans[i];
		return 0;
	}
	int find(ll _s1,int _cnt1,ll _s2,int _cnt2)
	{
		ll key=(_s1*_cnt1+_s1+_cnt1+_s2*_cnt2+_s2+_cnt2)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
			return ans[i];
		return 0;
	}
}l,r;

int n,k;
ll a1[25],a2[25],b[10],jc[25],s[1000000][4];

void init()
{
	cin>>n;
	for(int i=0;i<n/2;i++)
	  cin>>a1[i];
	for(int i=n/2;i<n;i++)
	  cin>>a2[i-n/2];
	cin>>k;
	for(int i=0;i<k;i++)
	  cin>>b[i];
	if(k==2&&(b[0]>b[1]))
	{
		int t=b[0];
		b[0]=b[1];
		b[1]=t;
	}
}

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i%Mod;
}

ll  getAns1(ll u)
{
	ll ans=0;
	l.clr(),r.clr();
	s[0][0]=0,s[0][1]=0;
	l.push(0,0);
	for(int i=1;i<1<<(n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a1[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
		   l.push(s[i][0],s[i][1]);
		   if(s[i][0]==u)
			 ans+=jc[s[i][1]]*jc[n-s[i][1]]%Mod,ans%=Mod;
		}
	}

	s[0][0]=0,s[0][1]=0;
	for(int i=1;i<1<<(n-n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a2[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
			for(int k=1;k<=(n/2);k++)
				ans+=l.find(u-s[i][0],k)*jc[k+s[i][1]]%Mod,ans%=Mod;
			if(s[i][0]==u)
			  ans+=jc[s[i][1]]*jc[n-s[i][1]]%Mod,ans%=Mod;
		}
	}
	return ans;

}

void dfs(int deep,ll s1,int cnt1,ll s2,int cnt2,bool flag,ll* a,ll& ans,ll u1,ll u2)
{
	if((!flag&&deep==n/2)||(flag&&deep==(n-n/2)))
	{
		if(!flag)
		 l.push(s1,cnt1,s2,cnt2);
		else
		{
			for(int i=0;i<=(n/2);i++)
			  for(int j=0;j<=(n/2);j++)
				ans+=l.find(u1-s1,i,u2-s2,j)*jc[i+cnt1]%Mod*jc[j+cnt2]%Mod*jc[n-i-j-cnt1-cnt2]%Mod,ans%=Mod;
		}
		return;
	}
	dfs(deep+1,s1,cnt1,s2,cnt2,flag,a,ans,u1,u2);
	if(s1+a[deep]<=u1)
	  dfs(deep+1,s1+a[deep],cnt1+1,s2,cnt2,flag,a,ans,u1,u2);
	if(s2+a[deep]<=u2)
	  dfs(deep+1,s1,cnt1,s2+a[deep],cnt2+1,flag,a,ans,u1,u2);
}

ll  getAns2(ll u1,ll u2)
{
	ll ans=0;
	l.clr();
	dfs(0,0,0,0,0,false,a1,ans,u1,u2-u1);
	dfs(0,0,0,0,0,true,a2,ans,u1,u2-u1);
	return ans;
}

void solve()
{
	if(k==0)
	  cout<<jc[n]<<endl;
	else if(k==1)
	{
		ll tmp=getAns1(b[0]);
		cout<<(jc[n]-tmp+Mod)%Mod<<endl;
	}
	else
	{
		ll tmp1=getAns1(b[0]),tmp2=getAns1(b[1]),tmp3=getAns2(b[0],b[1]);
		cout<<((jc[n]-tmp1-tmp2+tmp3)%Mod+Mod)%Mod<<endl;
	}
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#define ll long long
const int Mod=1e9+7;

ll dp[1<<24][2],a[25],b[25],jc[25];
int n,k,cnt[1<<24];

void init()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  scanf("%I64d",&a[i]);
	scanf("%d",&k);
	b[0]=b[1]=-1;
	for(int i=0;i<k;i++)
	  scanf("%I64d",&b[i]);
}

void prework()
{
	memset(cnt,0,sizeof(cnt));
	for(int i=1;i<(1<<n);i++)
	 for(int j=i;j>0;j>>=1)
	   if(j&1) cnt[i]++;
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=i*jc[i-1]%Mod;
}

void solve()
{
	if(k==0)
	{
		printf("%I64d\n",jc[n]);
		return;
	}
	int newmask;
	ll newsum,ans=0;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1,dp[0][1]=0;
	for(int mask=0;mask<(1<<n);mask++)
	  if(dp[mask][0]>0)
	  {
		  if ((k==1&&dp[mask][1]>b[0])||(k==2&&dp[mask][1]>b[1]))
		  {
			ans+=dp[mask][0]*jc[n-cnt[mask]]%Mod,ans%=Mod;
		    continue;
		  }
		  for(int j=0;j<n;j++)
		    if((mask&(1<<j))==0)
		    {
			   newmask=mask|(1<<j);
			   newsum=dp[mask][1]+a[j];
			   if(newsum!=b[0]&&newsum!=b[1])
				 dp[newmask][0]+=dp[mask][0],dp[newmask][0]%=Mod,dp[newmask][1]=newsum;
		    }
	  }
	printf("%I64d\n",ans);
}

int main()
{
	init();
	prework();
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#define ll long long

const int Mod=1e9+7;
int n,k;
ll a[25],b[10],jc[25],c[25],ans1,ans2,ans3,ans;
bool use[25];

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i,jc[i]%=Mod;
}

void init()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  scanf("%I64d",&a[i]);
	scanf("%d",&k);
	b[0]=b[1]=-1;
	for(int i=0;i<k;i++)
	  scanf("%I64d",&b[i]);
	memset(use,false,sizeof(use));
	ans1=ans2=ans3=0;
}

void dfs1(int deep,int num,ll sum)
{
	if(deep>=n)
	  return;
	dfs1(deep+1,num,sum);
	ll newsum=sum+a[deep];
	if(newsum<b[0])
	  dfs1(deep+1,num+1,newsum);
	if(newsum==b[0])
	  ans1+=(jc[num]*jc[n-num])%Mod,ans1%=Mod;
}

void dfs3(int deep,int num,ll sum,int limit)
{
	if(deep>=limit)
	  return;
	dfs3(deep+1,num,sum,limit);
	ll newsum=sum+c[deep];
	if(newsum<b[0])
	  dfs3(deep+1,num+1,newsum,limit);
	if(newsum==b[0])
	  ans3+=(jc[num]*jc[limit-num])%Mod*jc[n-limit]%Mod,ans3%=Mod;
}

void dfs2(int deep,int num,ll sum)
{
	if(deep>=n)
	  return;
	dfs2(deep+1,num,sum);
	ll newsum=sum+a[deep];
	use[deep]=true;
	if(newsum<b[1])
	  dfs2(deep+1,num+1,newsum);
	if(newsum==b[1])
	{
	  ans2+=(jc[num]*jc[n-num])%Mod,ans2%=Mod;
	  int cnt=0;
	  for(int i=0;i<n;i++)
		if(use[i])
		  c[cnt++]=a[i];
	  dfs3(0,1,0,cnt);
	}
	use[deep]=false;
}

void solve()
{
	ll sum,newmask,mask;
	if(k==0)
	{
		printf("%I64d\n",jc[n]);
		return;
	}
	if(k==1)
	  dfs1(0,1,0);
	else
	{
	  dfs1(0,1,0);
	  dfs2(0,1,0);
	}
	ans=((ans1+ans2-ans3)%Mod+Mod)%Mod;
	ans=((jc[n]-ans)%Mod+Mod)%Mod;
	printf("%I64d\n",ans);
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;

#define ll long long
const int Mod=1e9+7;

ll dp[1<<24][2],jc[25];
int n,k,cnt[1<<24],a[25],b[25];

void init()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  scanf("%d",&a[i]);
	sort(a,a+n,greater<int>());
	scanf("%d",&k);
	b[0]=b[1]=-1;
	for(int i=0;i<k;i++)
	  scanf("%d",&b[i]);
}

void prework()
{
	memset(cnt,0,sizeof(cnt));
	/*for(int i=1;i<(1<<n);i++)
	 for(int j=i;j>0;j>>=1)
	   if(j&1) cnt[i]++;*/
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=i*jc[i-1]%Mod;
}

void solve()
{
	if(k==0)
	{
		printf("%I64d\n",jc[n]);
		return;
	}
	if(k==2&&b[0]>b[1])
	{
		int t=b[0];
		b[0]=b[1];
		b[1]=t;
	}
	int newmask;
	ll newsum,ans=0;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1,dp[0][1]=0;
	for(int mask=0;mask<(1<<n);mask++)
	  if(dp[mask][0]>0)
	  {
		  if (dp[mask][1]>b[0]||dp[mask][1]>b[1])
		  {
			  for(int j=mask;j>0;j>>=1)
				cnt[mask]+=j&1;
			  ans+=dp[mask][0]*jc[n-cnt[mask]]%Mod;
			  if(ans>=Mod) ans-=Mod;
		      continue;
		  }
		  for(int j=0;j<n;j++)
		    if((mask&(1<<j))==0)
		    {
			   newmask=mask|(1<<j);
			   newsum=dp[mask][1]+a[j];
			   if(newsum!=b[0]&&newsum!=b[1])
			   {
				  dp[newmask][0]+=dp[mask][0];
				  if(dp[newmask][0]>=Mod) dp[newmask][0]-=Mod;
				  dp[newmask][1]=newsum;
			   }
		    }
	  }
	printf("%I64d\n",ans);
}

int main()
{
	init();
	prework();
	solve();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long

const int Mod=1e9+7;
const int MaxS=5e6+7;

struct hashtable
{
	ll s1[MaxS],s2[MaxS];
	int size,cnt1[MaxS],cnt2[MaxS],head[MaxS],next[MaxS],ans[MaxS];
	void clr()
	{
		size=0;
		memset(head,-1,sizeof(head));
		memset(ans,0,sizeof(ans));
	}
	void push(ll s,int cnt)
	{
		ll key=(s*cnt+s+cnt)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==s&&cnt1[i]==cnt)
		  {
			ans[i]++;
			return;
		  }
		s1[size]=s,cnt1[size]=cnt;
		next[size]=head[key],ans[size]=1,head[key]=size++;
	}
	void push(ll _s1,int _cnt1,ll _s2,int _cnt2)
	{
		ll key=(_s1*_cnt1+_s1+_cnt1+_s2*_cnt2+_s2+_cnt2)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
		  {
			ans[i]++;
			return;
		  }
		s1[size]=_s1,cnt1[size]=_cnt1;
		s2[size]=_s2,cnt2[size]=_cnt2;
		next[size]=head[key],ans[size]=1,head[key]=size++;
	}

	int find(ll s,int cnt)
	{
		ll key=(s*cnt+s+cnt)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==s&&cnt1[i]==cnt)
			return ans[i];
		return 0;
	}
	int find(ll _s1,int _cnt1,ll _s2,int _cnt2)
	{
		ll key=(_s1*_cnt1+_s1+_cnt1+_s2*_cnt2+_s2+_cnt2)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
			return ans[i];
		return 0;
	}
}l,r;

int n,k;
ll a1[25],a2[25],b[10],jc[25],s[1000000][4];

void init()
{
	cin>>n;
	for(int i=0;i<n/2;i++)
	  cin>>a1[i];
	for(int i=n/2;i<n;i++)
	  cin>>a2[i-n/2];
	cin>>k;
	for(int i=0;i<k;i++)
	  cin>>b[i];
	if(k==2&&(b[0]>b[1]))
	{
		int t=b[0];
		b[0]=b[1];
		b[1]=t;
	}
}

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i%Mod;
}

ll  getAns1(ll u)
{
	ll ans=0;
	l.clr(),r.clr();
	s[0][0]=0,s[0][1]=0;
	l.push(0,0);
	for(int i=1;i<1<<(n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a1[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
		   l.push(s[i][0],s[i][1]);
		   if(s[i][0]==u)
			 ans+=jc[s[i][1]]*jc[n-s[i][1]]%Mod,ans%=Mod;
		}
	}

	s[0][0]=0,s[0][1]=0;
	for(int i=1;i<1<<(n-n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a2[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
			for(int k=0;k<=(n/2);k++)
				ans+=l.find(u-s[i][0],k)*jc[k+s[i][1]]%Mod*jc[n-s[i][1]-k]%Mod,ans%=Mod;
		}
	}
	return ans;

}

void dfs(int deep,ll s1,int cnt1,ll s2,int cnt2,bool flag,ll* a,ll& ans,ll u1,ll u2)
{
	if((!flag&&deep==n/2)||(flag&&deep==(n-n/2)))
	{
		if(!flag)
		 l.push(s1,cnt1,s2,cnt2);
		else
		{
			for(int i=0;i<=(n/2);i++)
			  for(int j=0;j<=(n/2);j++)
				ans+=l.find(u1-s1,i,u2-s2,j)*jc[i+cnt1]%Mod*jc[j+cnt2]%Mod*jc[n-i-j-cnt1-cnt2]%Mod,ans%=Mod;
		}
		return;
	}
	dfs(deep+1,s1,cnt1,s2,cnt2,flag,a,ans,u1,u2);
	if(s1+a[deep]<=u1)
	  dfs(deep+1,s1+a[deep],cnt1+1,s2,cnt2,flag,a,ans,u1,u2);
	if(s2+a[deep]<=u2)
	  dfs(deep+1,s1,cnt1,s2+a[deep],cnt2+1,flag,a,ans,u1,u2);
}

ll  getAns2(ll u1,ll u2)
{
	ll ans=0;
	l.clr();
	dfs(0,0,0,0,0,false,a1,ans,u1,u2-u1);
	dfs(0,0,0,0,0,true,a2,ans,u1,u2-u1);
	return ans;
}

void solve()
{
	if(k==0)
	  cout<<jc[n]<<endl;
	else if(k==1)
	{
		ll tmp=getAns1(b[0]);
		cout<<(jc[n]-tmp+Mod)%Mod<<endl;
	}
	else
	{
		ll tmp1=getAns1(b[0]),tmp2=getAns1(b[1]),tmp3=getAns2(b[0],b[1]);
		cout<<((jc[n]-tmp1-tmp2+tmp3)%Mod+Mod)%Mod<<endl;
	}
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

#define ll long long
const int Mod=1e9+7;

ll a[24],b[2],dp[1<<24];
int n,k;

void init()
{
	cin>>n;
	for(int i=0;i<n;i++)
	  cin>>a[i];
	cin>>k;
	for(int i=0;i<k;i++)
	  cin>>b[i];
	dp[0]=0;
	for(int i=1;i<(1<<n);i++)
	{
		int j=__builtin_ctz(i);
		dp[i]=dp[i^(1<<j)]+a[j];
	}
	for(int i=1;i<(1<<n);i++)
	  for(int j=0;j<k;j++)
		if(dp[i]==b[j])
		{
			dp[i]=-1;
			break;
		}
}

void solve()
{
	dp[0]=1;
	for(int i=1;i<(1<<n);i++)
	  if(dp[i]<0)
		dp[i]=0;
	  else
	  {
		 dp[i]=0;
		 for(int j=0;j<n;j++)
		   if(i&(1<<j))
			 dp[i]+=dp[i^(1<<j)];
		 dp[i]%=Mod;
	  }
	cout<<dp[(1<<n)-1]<<endl;
}

int main()
{
	init();
	solve();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long

const int Mod=1e9+7;
const int MaxS=1e7+7;

struct hashtable
{
	ll s1[MaxS],s2[MaxS];
	int size,cnt1[MaxS],cnt2[MaxS],head[MaxS],next[MaxS],ans[MaxS];
	void clr()
	{
		size=0;
		memset(head,-1,sizeof(head));
		memset(ans,0,sizeof(ans));
	}
	void push(ll s,int cnt)
	{
		ll key=(s*cnt+s+cnt)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==s&&cnt1[i]==cnt)
		  {
			ans[i]++;
			return;
		  }
		s1[size]=s,cnt1[size]=cnt;
		next[size]=head[key],ans[size]=1,head[key]=size++;
	}
	void push(ll _s1,int _cnt1,ll _s2,int _cnt2)
	{
		ll key=(_s1*_cnt1+_s1+_cnt1+_s2*_cnt2+_s2+_cnt2)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
		  {
			ans[i]++;
			return;
		  }
		s1[size]=_s1,cnt1[size]=_cnt1;
		s2[size]=_s2,cnt2[size]=_cnt2;
		next[size]=head[key],ans[size]=1,head[key]=size++;
	}

	int find(ll s,int cnt)
	{
		ll key=(s*cnt+s+cnt)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==s&&cnt1[i]==cnt)
			return ans[i];
		return 0;
	}
	int find(ll _s1,int _cnt1,ll _s2,int _cnt2)
	{
		ll key=(_s1*_cnt1+_s1+_cnt1+_s2*_cnt2+_s2+_cnt2)%MaxS;
		for(int i=head[key];i!=-1;i=next[i])
		  if(s1[i]==_s1&&cnt1[i]==_cnt1&&s2[i]==_s2&&cnt2[i]==_cnt2)
			return ans[i];
		return 0;
	}
}l,r;

int n,k;
ll a1[25],a2[25],b[10],jc[25],s[1000000][4];

void init()
{
	cin>>n;
	for(int i=0;i<n/2;i++)
	  cin>>a1[i];
	for(int i=n/2;i<n;i++)
	  cin>>a2[i-n/2];
	cin>>k;
	for(int i=0;i<k;i++)
	  cin>>b[i];
	if(k==2&&(b[0]>b[1]))
	{
		int t=b[0];
		b[0]=b[1];
		b[1]=t;
	}
}

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i%Mod;
}

ll  getAns1(ll u)
{
	ll ans=0;
	l.clr(),r.clr();
	s[0][0]=0,s[0][1]=0;
	l.push(0,0);
	for(int i=1;i<1<<(n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a1[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
		   l.push(s[i][0],s[i][1]);
		   if(s[i][0]==u)
			 ans+=jc[s[i][1]]*jc[n-s[i][1]]%Mod,ans%=Mod;
		}
	}

	s[0][0]=0,s[0][1]=0;
	for(int i=1;i<1<<(n-n/2);i++)
	{
		int j=__builtin_ctz(i);
		s[i][0]=s[i^(1<<j)][0]+a2[j];
		s[i][1]=s[i^(1<<j)][1]+1;
		if(s[i][0]<=u)
		{
			for(int k=1;k<=(n/2);k++)
				ans+=l.find(u-s[i][0],k)*jc[k+s[i][1]]%Mod,ans%=Mod;
			if(s[i][0]==u)
			  ans+=jc[s[i][1]]*jc[n-s[i][1]]%Mod,ans%=Mod;
		}
	}
	return ans;

}

void dfs(int deep,ll s1,int cnt1,ll s2,int cnt2,bool flag,ll* a,ll& ans,ll u1,ll u2)
{
	if((!flag&&deep==n/2)||(flag&&deep==(n-n/2)))
	{
		if(!flag)
		 l.push(s1,cnt1,s2,cnt2);
		else
		{
			for(int i=0;i<=(n/2);i++)
			  for(int j=0;j<=(n/2);j++)
				ans+=l.find(u1-s1,i,u2-s2,j)*jc[i+cnt1]%Mod*jc[j+cnt2]%Mod*jc[n-i-j-cnt1-cnt2]%Mod,ans%=Mod;
		}
		return;
	}
	dfs(deep+1,s1,cnt1,s2,cnt2,flag,a,ans,u1,u2);
	if(s1+a[deep]<=u1)
	  dfs(deep+1,s1+a[deep],cnt1+1,s2,cnt2,flag,a,ans,u1,u2);
	if(s2+a[deep]<=u2)
	  dfs(deep+1,s1,cnt1,s2+a[deep],cnt2+1,flag,a,ans,u1,u2);
}

ll  getAns2(ll u1,ll u2)
{
	ll ans=0;
	l.clr();
	dfs(0,0,0,0,0,false,a1,ans,u1,u2-u1);
	dfs(0,0,0,0,0,true,a2,ans,u1,u2-u1);
	return ans;
}

void solve()
{
	if(k==0)
	  cout<<jc[n]<<endl;
	else if(k==1)
	{
		ll tmp=getAns1(b[0]);
		cout<<(jc[n]-tmp+Mod)%Mod<<endl;
	}
	else
	{
		ll tmp1=getAns1(b[0]),tmp2=getAns1(b[1]),tmp3=getAns2(b[0],b[1]);
		cout<<((jc[n]-tmp1-tmp2+tmp3)%Mod+Mod)%Mod<<endl;
	}
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#define ll long long

const int Mod=1e9+7;
int n,k;
ll a[25],b[10],jc[25],c[25],ans1,ans2,ans3,ans;
bool use[25];

void prework()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=jc[i-1]*i,jc[i]%=Mod;
}

void init()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  scanf("%I64d",&a[i]);
	scanf("%d",&k);
	b[0]=b[1]=-1;
	for(int i=0;i<k;i++)
	  scanf("%I64d",&b[i]);
	memset(use,false,sizeof(use));
	ans1=ans2=ans3=0;
}

void dfs1(int deep,int num,ll sum)
{
	if(deep>=n)
	  return;
	dfs1(deep+1,num,sum);
	ll newsum=sum+a[deep];
	if(newsum<b[0])
	  dfs1(deep+1,num+1,newsum);
	if(newsum==b[0])
	  ans1+=(jc[num]*jc[n-num])%Mod,ans1%=Mod;
}

void dfs3(int deep,int num,ll sum,int limit)
{
	if(deep>=limit)
	  return;
	dfs3(deep+1,num,sum,limit);
	ll newsum=sum+c[deep];
	if(newsum<b[0])
	  dfs3(deep+1,num+1,newsum,limit);
	if(newsum==b[0])
	  ans3+=(jc[num]*jc[limit-num])%Mod*jc[n-limit]%Mod,ans3%=Mod;
}

void dfs2(int deep,int num,ll sum)
{
	if(deep>=n)
	  return;
	dfs2(deep+1,num,sum);
	ll newsum=sum+a[deep];
	use[deep]=true;
	if(newsum<b[1])
	  dfs2(deep+1,num+1,newsum);
	if(newsum==b[1])
	{
	  ans2+=(jc[num]*jc[n-num])%Mod,ans2%=Mod;
	  int cnt=0;
	  for(int i=0;i<n;i++)
		if(use[i])
		  c[cnt++]=a[i];
	  dfs3(0,1,0,cnt);
	}
	use[deep]=false;
}

void solve()
{
	ll sum,newmask,mask;
	if(k==0)
	{
		printf("%I64d\n",jc[n]);
		return;
	}
	if(k==1)
	  dfs1(0,1,0);
	else
	{
	   if(b[0]>b[1])
	   {
		  int t=b[0];
		  b[0]=b[1];
		  b[1]=t;
	   }
	   dfs1(0,1,0);
	   dfs2(0,1,0);
	}
	ans=((ans1+ans2-ans3)%Mod+Mod)%Mod;
	ans=((jc[n]-ans)%Mod+Mod)%Mod;
	printf("%I64d\n",ans);
}

int main()
{
	prework();
	init();
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;

#define ll long long
const int Mod=1e9+7;

ll dp[1<<24][2],jc[25],cnt[1<<24],a[25],b[25];
int n,k;

void init()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  scanf("%I64d",&a[i]);
	sort(a,a+n,greater<int>());
	scanf("%d",&k);
	b[0]=b[1]=-1;
	for(int i=0;i<k;i++)
	  scanf("%I64d",&b[i]);
}

void prework()
{
	memset(cnt,0,sizeof(cnt));
	/*for(int i=1;i<(1<<n);i++)
	 for(int j=i;j>0;j>>=1)
	   if(j&1) cnt[i]++;*/
	jc[0]=1;
	for(int i=1;i<=24;i++)
	  jc[i]=i*jc[i-1]%Mod;
}

void solve()
{
	if(k==0)
	{
		printf("%I64d\n",jc[n]);
		return;
	}
	if(k==2&&b[0]>b[1])
	{
		int t=b[0];
		b[0]=b[1];
		b[1]=t;
	}
	int newmask;
	ll newsum,ans=0;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1,dp[0][1]=0;
	for(int mask=0;mask<(1<<n);mask++)
	  if(dp[mask][0]>0)
	  {
		  if (dp[mask][1]>b[0]&&dp[mask][1]>b[1])
		  {
			  for(int j=mask;j>0;j>>=1)
				cnt[mask]+=j&1;
			  ans+=dp[mask][0]*jc[n-cnt[mask]]%Mod;
			  if(ans>=Mod) ans-=Mod;
		      continue;
		  }
		  for(int j=0;j<n;j++)
		    if((mask&(1<<j))==0)
		    {
			   newmask=mask|(1<<j);
			   newsum=dp[mask][1]+a[j];
			   if(newsum!=b[0]&&newsum!=b[1])
			   {
				  dp[newmask][0]+=dp[mask][0];
				  if(dp[newmask][0]>=Mod) dp[newmask][0]-=Mod;
				  dp[newmask][1]=newsum;
			   }
		    }
	  }
	printf("%I64d\n",ans);
}

int main()
{
	init();
	prework();
	solve();
	return 0;
}


//In the name of God
#include <iostream>
#include <algorithm>
using namespace std;

#define num unsigned long long
const num MOD=1e9+7;

int ways[1<<24+10];
int a[30],k,n,bad[5];

inline int dp(int state,num place=0)
{
  if(ways[state]!=-1)
    return ways[state];
  for(int i=1;i<=k;++i)
    if(bad[i]==place)
      return ways[state]=0;
  num ans=0;
  bool some=false;
  for(int i=1;i<=n;++i)
    {
      int has=(state>>(i-1))%2;
      if(has==0)
	{
	  ans+=dp(state|(1<<(i-1)),place+a[i]);
	some=true;
	}
    }
  if(!some)
    return ways[state]=1;
  return ways[state]=ans;
}

int main()
{
  for(int i=0;i<1<<24+10;++i)
    ways[i]=-1;
  cin>>n;
  for(int i=1;i<=n;++i)
    cin>>a[i];
  cin>>k;
  for(int i=1;i<=k;++i)
    cin>>bad[i];
  cout<<fixed<<dp(0)<<endl;
  return 0;
}


//In the name of God
#include <iostream>
#include <algorithm>
using namespace std;

#define num unsigned long long
const num MOD=1e9+7;

int ways[1<<26];
int a[30],k,n,bad[5];

inline int dp(int state,num place=0)
{
  if(ways[state]!=-1)
    return ways[state];
  for(int i=1;i<=k;++i)
    if(bad[i]==place)
      return ways[state]=0;
  num ans=0;
  bool some=false;
  for(int i=1;i<=n;++i)
    {
      int has=(state>>i)%2;
      if(has==0)
	{
	ans+=dp(state|(1<<i),place+a[i]);
	some=true;
	}
    }
  if(!some)
    return ways[state]=1;
  return ways[state]=ans;
}

int main()
{
  for(int i=0;i<1<<26;++i)
    ways[i]=-1;
  cin>>n;
  for(int i=1;i<=n;++i)
    cin>>a[i];
  cin>>k;
  for(int i=1;i<=k;++i)
    cin>>bad[i];
  cout<<fixed<<dp(0)<<endl;
  return 0;
}


//In the name of God
#include <iostream>
using namespace std;

#define num long long
const int M=24;
const num MOD=1e9+7;

int dp[1<<M],a[M+10],bad[3];
int place[1<<M];

int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;++i) cin>>a[i];
  int k; cin>>k; for(int i=0;i<k;++i) cin>>bad[i];
  for(int i=1;i< 1<<n;++i)
    {
    place[i]=place[i^(1<<__builtin_ctz(i))]+a[__builtin_ctz(i)];
    for(int j=0;j<k;++j)
      if(place[i]==bad[j])
	dp[i]=-1;
    }
  dp[0]=1;
  for(int i=1;i< 1<<n;++i)
    {
      if(dp[i]==-1) {dp[i]=0; continue;}
    for(int j=0;j<n;++j)
      if((1<<j)&i)
	dp[i]+=dp[i-(1<<j)];
    //    cerr<<"i:"<<i<<" dp:"<<dp[i]<<endl;
    dp[i]%=MOD;
    }
  cout<<fixed<<dp[(1<<n)-1]<<endl;
  return 0;
}


//In the name of God
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

#define num unsigned long long
const num MOD=1e9+7;

int ways[1<<26];
int a[30],k,n,bad[5];

int dp(int state,set<int>  rem,num place=0)
{
  if(ways[state]!=-1)
    return ways[state];
  for(int i=1;i<=k;++i)
    if(bad[i]==place)
      return ways[state]=0;
  num ans=0;
  bool some=false;
  for(set<int>::iterator iter=rem.begin();iter!=rem.end();++iter)
    {
      int i=*iter;
	{
	  //	  cerr<<"go to:"<<place+a[i];
	set<int> rem1=rem;
	rem1.erase(i);
	ans+=dp(state|(1<<i),rem1,place+a[i]);
	some=true;
	//	cerr<<"back to:"<<place<<endl;
	}
    }
  if(!some)
    return ways[state]=1;
  return ways[state]=ans;
}

int main()
{
  for(int i=0;i<1<<26;++i)
    ways[i]=-1;
  cin>>n;
	set<int> rem;
for(int i=1;i<=n;++i) rem.insert(i);
  for(int i=1;i<=n;++i)
    cin>>a[i];
  cin>>k;
  for(int i=1;i<=k;++i)
    cin>>bad[i];
  cout<<fixed<<dp(0,rem)<<endl;
  return 0;
}


//In the name of God
#include <iostream>
#include <algorithm>
using namespace std;

#define num unsigned long long
const num MOD=1e9+7;

int ways[(1<<24)+10];
int a[30],k,n,bad[5];

inline int dp(int state,num place=0)
{
  if(ways[state]!=-1)
    return ways[state];
  for(int i=1;i<=k;++i)
    if(bad[i]==place)
      return ways[state]=0;
  num ans=0;
  bool some=false;
  for(int i=1;i<=n;++i)
    {
      int has=(state>>(i-1))%2;
      if(has==0)
	{
	  if(ways[state|1<<(i-1)]==-1)
	    dp(state|1<<(i-1),place+a[i]);
	  ans+=ways[state|(1<<(i-1))];
	  ans%=MOD;
	some=true;
	}
    }
  if(!some)
    return ways[state]=1;
  return ways[state]=ans;
}

int main()
{
  for(int i=0;i<(1<<24)+10;++i)
    ways[i]=-1;
  cin>>n;
  for(int i=1;i<=n;++i)
    cin>>a[i];
  cin>>k;
  for(int i=1;i<=k;++i)
    cin>>bad[i];
  cout<<fixed<<dp(0)<<endl;
  return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
long long segtree[1000000];
long long lazy[1000000];
long long ar[100005];

long long read()
{
    char c=getchar();
    long long ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start, int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]|=lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;

    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    return;
}

void update(int pos,int start,int stop,int i,int j, long long q)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]|=lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;

    }
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    if(start>=i && stop<=j)
    {
        segtree[pos]|=q;
        lazy[l]|=q;
        lazy[r]|=q;
        return;
    }
    if(j<=mid)
        update(l,start,mid,i,j,q);
    if(i>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

long long query(int pos,int start,int stop,int i,int j)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]|=lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start>=i && stop<=j)
        return segtree[pos];

    long long aristera=-1,deksia=-1;
    if(j<=mid)
        aristera=query(l,start,mid,i,j);
    if(i>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    long long q;
};

int main()
{
    /*int a=(69|420)|666;
    int b=69|(420|666);

    cout<<a<<" "<<b;*/
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       if(n==1000 && 40<=i && i<80)
        printf("%d %d %d \n",wut[i].left,wut[i].right,wut[i].q);
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        int s=query(0,0,n-1,wut[i].left-1,wut[i].right-1);
        if(s!=wut[i].q)
        {
            /*if(n>100)
            printf("%I64d != %I64d \n",s,wut[i].q);*/
            printf("NO\n");
            return 0;
        }
    }
    fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
long long int segtree[300005];
long long int lazy[300005];
long long int ar[100005];

long long  read()
{
    char c=getchar();
    int ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    segtree[pos]=segtree[l]&segtree[r];
    return;
}

void update(int pos,int start,int stop,int i,int j, long long q)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    if(start>=i &&stop<=j)
    {
        segtree[pos]|=q;
        lazy[l]|=q;
        lazy[r]|=q;
        return;
    }
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

long long query(int pos,int start,int stop,int i,int j)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]||lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    long long q;
};

int main()
{
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        fillpls(0,0,n-1);
        long long  x=query(0,0,n-1,wut[i].left-1,wut[i].right-1);
        if(x!=wut[i].q)
        {
            if(n>1000)
                printf("%d %d %I64d %I64d \n",wut[i].left-1,wut[i].right,x,wut[i].q);
            printf("NO\n");
            return 0;
        }
    }
    //fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
long long int segtree[300005];
long long int lazy[300005];
long long int ar[100005];

long long  read()
{
    char c=getchar();
    int ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    segtree[pos]=segtree[l]&segtree[r];
    return;
}

void update(int pos,int start,int stop,int i,int j, long long q)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    if(start>=i &&stop<=j)
    {
        segtree[pos]|=q;
        lazy[l]|=q;
        lazy[r]|=q;
        return;
    }
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

long long query(int pos,int start,int stop,int i,int j)
{
    /*if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]||lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }*/
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    long long q;
};

int main()
{
    //for(int i=0;i<300000;i++)
      //  lazy[i]=0;
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        fillpls(0,0,n-1);
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    //fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
long long segtree[300005];
long long ar[100005];

void update(int pos,int start,int stop,int i,int j,  long long q)
{
    if(start>j || stop<i || start>stop)
        return;
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    update(l,start,mid,i,j,q);
    update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

 long long query(int pos,int start,int stop,int i,int j)
{
    if(start>=i && stop<=j)
        return segtree[pos];

     long long aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
     long long q;
};

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       scanf("%d %d %I64d",&wut[i].left,&wut[i].right,&wut[i].q);
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%I64d ",ar[i]);
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
int segtree[300005];
int lazy[300005];
int ar[100005];

int read()
{
    char c=getchar();
    int ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    return;
}

void update(int pos,int start,int stop,int i,int j, int q)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
int segtree[300005];
int lazy[300005]={0};
int ar[100005];

int read()
{
    char c=getchar();
    int ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    return;
}

void update(int pos,int start,int stop,int i,int j, int q)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    if(start>=i &&stop<=j)
    {
        segtree[pos]|=q;
        lazy[l]|=q;
        lazy[r]|=q;
        return;
    }
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

int query(int pos,int start,int stop,int i,int j)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]||lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    int q;
};

int main()
{
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}

    {
        segtree[pos]|=q;#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
int segtree[300005];
int lazy[300005]={0};
int ar[100005];

int read()
{
    char c=getchar();
    int ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    return;
}

void update(int pos,int start,int stop,int i,int j, int q)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    if(start>=i &&stop<=j)
    {
        segtree[pos]|=q;
        lazy[l]|=q;
        lazy[r]|=q;
        return;
    }
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

int query(int pos,int start,int stop,int i,int j)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]||lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    int q;
};

int main()
{
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}

        ar[start]|=q;
        return;
    }
    if(start>=i &&stop<=j)
    {
        segtree[pos]|=q;
        lazy[l]|=q;
        lazy[r]|=q;
        return;
    }
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

int query(int pos,int start,int stop,int i,int j)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]||lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    int q;
};

int main()
{
    for(int i=0;i<300000;i++)
        lazy[i]=0;
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<iostream>
using namespace std;
int ar[100005];

struct poulla
{
    int l,r,q;
};

int main()
{
    int n,m;
    cin>>n>>m;
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
        cin>>wut[i].l>>wut[i].r>>wut[i].q;
        for(int j=wut[i].l-1;j<=wut[i].r-1;j++)
            ar[j]|=wut[i].q;
    }
    for(int i=0;i<m;i++)
    {
        int AND=ar[wut[i].l-1];
        for(int j=wut[i].l;j<=wut[i].r-1;j++)
            AND&=ar[j];
        if(AND!=wut[i].q)
        {
            cout<<"NO\n";
            return 0;
        }
    }
    cout<<"YES\n";
    for(int i=0;i<n;i++)
        cout<<ar[i]<<" ";
    cout<<"\n";
    return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
long long int segtree[300005];
long long int lazy[300005];
long long int ar[100005];

long long  read()
{
    char c=getchar();
    int ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]|=lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    segtree[pos]=segtree[l]&segtree[r];
    return;
}

void update(int pos,int start,int stop,int i,int j, long long q)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        if(start!=stop)
        {
            segtree[l]|=lazy[pos];
            segtree[r]|=lazy[pos];
        }
        lazy[pos]=0;
    }
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    /*if(start>=i &&stop<=j)
    {
        lazy[l]|=q;
        lazy[r]|=q;
        segtree[pos]=(segtree[l]|lazy[l])&(segtree[r]|lazy[r]);
        return;
    }*/
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

long long query(int pos,int start,int stop,int i,int j)
{
    /*if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]||lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }*/
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    long long q;
};

int main()
{
    //for(int i=0;i<300000;i++)
      //  lazy[i]=0;
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        fillpls(0,0,n-1);
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    //fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    long long int ar[n];
    for(int i=0;i<n;i++)
        ar[i]=-1;
    long long int l,r,q;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r>>q;
        for(int j=l-1;j<r;j++)
        {
            if(ar[j]!=-1 && ar[j]!=q)
            {
                cout<<"NO\n";
                return 0;
            }
            ar[j]=q;
        }
    }
    cout<<"YES\n";
    for(int i=0;i<n;i++)
        cout<<ar[i]<<" ";
    cout<<"\n";
    return 0;

}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
long long int segtree[300005];
long long int lazy[300005];
long long int ar[100005];

long long  read()
{
    char c=getchar();
    long long ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        if(start!=stop)
        {
            lazy[l]|=lazy[pos];
            lazy[r]|=lazy[pos];
        }
        lazy[pos]=0;
        segtree[pos]=(segtree[l]|lazy[l])&(segtree[r]|lazy[r]);
    }

    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    segtree[pos]=segtree[l]&segtree[r];
    return;
}

void update(int pos,int start,int stop,int i,int j, long long q)
{
    if(lazy[pos]>0)
    {
        if(start!=stop)
        {
            lazy[l]|=lazy[pos];
            lazy[r]|=lazy[pos];
        }
        lazy[pos]=0;
        segtree[pos]=(segtree[l]|lazy[l])&(segtree[r]|lazy[r]);
    }
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    if(start>=i &&stop<=j)
    {
        lazy[l]|=q;
        lazy[r]|=q;
        segtree[pos]=(segtree[l]|lazy[l])&(segtree[r]|lazy[r]);
        return;
    }
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

long long query(int pos,int start,int stop,int i,int j)
{
    if(lazy[pos]>0)
    {
        if(start!=stop)
        {
            lazy[l]|=lazy[pos];
            lazy[r]|=lazy[pos];
        }
        lazy[pos]=0;
        segtree[pos]=(segtree[l]|lazy[l])&(segtree[r]|lazy[r]);
    }
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    long long q;
};

int main()
{
    //for(int i=0;i<300000;i++)
      //  lazy[i]=0;
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        //fillpls(0,0,n-1);
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
int segtree[300005];
int lazy[300005];
int ar[100005];

int read()
{
    char c=getchar();
    int ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    return;
}

void update(int pos,int start,int stop,int i,int j, int q)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    if(start>=i &&stop<=j)
    {
        segtree[pos]|=q;
        lazy[l]|=q;
        lazy[r]|=q;
        return;
    }
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

int query(int pos,int start,int stop,int i,int j)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]||lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    int q;
};

int main()
{
    for(int i=0;i<300000;i++)
        lazy[i]=0;
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
unsigned long long int segtree[300005];
unsigned long long int lazy[300005];
unsigned long long int ar[100005];

unsigned long long  read()
{
    char c=getchar();
    unsigned long long  ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    segtree[pos]=segtree[l]&segtree[r];
    return;
}

void update(int pos,int start,int stop,int i,int j, unsigned long long q)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    if(start>=i &&stop<=j)
    {
        segtree[pos]|=q;
        lazy[l]|=q;
        lazy[r]|=q;
        return;
    }
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

unsigned long long query(int pos,int start,int stop,int i,int j)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]||lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    unsigned long long q;
};

int main()
{
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       if(wut[i].left>=1707 && wut[i].right<=1858 && n>1000)
            printf("%d %d\n",wut[i].left,wut[i].right);
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        fillpls(0,0,n-1);
        unsigned long long  x=query(0,0,n-1,wut[i].left-1,wut[i].right-1);
        if(x!=wut[i].q)
        {
            if(n>1000)
                printf("%I64d %I64d \n",x,wut[i].q);
            printf("NO\n");
            return 0;
        }
    }
    //fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
long long int segtree[300005];
long long int lazy[300005];
long long int ar[100005];

long long  read()
{
    char c=getchar();
    int ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start,int stop)
{
    if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]|=lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    segtree[pos]=segtree[l]&segtree[r];
    return;
}

void update(int pos,int start,int stop,int i,int j, long long q)
{
    /*if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        segtree[l]|=lazy[pos];
        segtree[r]|=lazy[pos];
        lazy[pos]=0;
    }*/
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    /*if(start>=i &&stop<=j)
    {
        segtree[pos]|=q;
        lazy[l]|=q;
        lazy[r]|=q;
        return;
    }*/
    if(i<=mid)
        update(l,start,mid,i,j,q);
    if(j>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

long long query(int pos,int start,int stop,int i,int j)
{
    /*if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]||lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }*/
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    long long q;
};

int main()
{
    //for(int i=0;i<300000;i++)
      //  lazy[i]=0;
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        fillpls(0,0,n-1);
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    //fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
long long segtree[1000000];
long long lazy[1000000];
long long ar[100005];

long long read()
{
    char c=getchar();
    long long ans=0;
    while(c<'0' || c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=getchar();
    }
    return ans;
}

void fillpls(int pos,int start, int stop)
{
    /*if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]|=lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;

    }*/
    if(start==stop)
    {
        ar[start]=segtree[pos];
        return;
    }
    fillpls(l,start,mid);
    fillpls(r,mid+1,stop);
    return;
}

void update(int pos,int start,int stop,int i,int j, long long q)
{
    /*if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]|=lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;

    }*/
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    /*if(start>=i && stop<=j)
    {
        segtree[pos]|=q;
        /*lazy[l]|=q;
        lazy[r]|=q;
        return;
        update(l,start,mid,i,j,q);
        update(r,mid+1,stop,i,j,q);
        return;
    }*/
    if(j<=mid)
        update(l,start,mid,i,j,q);
    if(i>=mid+1)
        update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

long long query(int pos,int start,int stop,int i,int j)
{
    /*if(lazy[pos]>0)
    {
        segtree[pos]|=lazy[pos];
        lazy[l]|=lazy[pos];
        lazy[r]|=lazy[pos];
        lazy[pos]=0;
    }*/
    if(start>=i && stop<=j)
        return segtree[pos];

    long long aristera=-1,deksia=-1;
    if(j<=mid)
        aristera=query(l,start,mid,i,j);
    if(i>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    long long q;
};

int main()
{
    /*int a=(69|420)|666;
    int b=69|(420|666);

    cout<<a<<" "<<b;*/
    int n,m;
    //scanf("%d %d",&n,&m);
    n=read();
    m=read();
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       //scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       wut[i].left=read();
       wut[i].right=read();
       wut[i].q=read();
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        int s=query(0,0,n-1,wut[i].left-1,wut[i].right-1);
        if(s!=wut[i].q)
        {
            /*if(n>100)
            printf("%I64d != %I64d \n",s,wut[i].q);*/
            printf("NO\n");
            return 0;
        }
    }
    fillpls(0,0,n-1);
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}


#include<iostream>
using namespace std;
struct qu
{
    long long int l,r,q;
};
int main()
{

    int n,m;
    cin>>n>>m;
    long long int ar[n];
    for(int i=0;i<n;i++)
        ar[i]=-1;
    qu queries[m];
    for(int i=0;i<m;i++)
    {
        cin>>queries[i].l>>queries[i].r>>queries[i].q;
        for(int j=queries[i].l-1;j<queries[i].r;j++)
        {
           /* if(ar[j]!=-1 && ar[j]!=q)
            {
                cout<<"NO\n";
                return 0;
            }*/
            ar[j]=queries[i].q;
        }
    }
    for(int i=0;i<m;i++)
    {
        int nd=ar[queries[i].l-1];
        for(int j=queries[i].l;j<queries[i].r;j++)
        {

            nd&=ar[j];
        }
        if(nd!=queries[i].q)
        {

            cout<<"NO\n";
            return 0;
        }
    }
    cout<<"YES\n";
    for(int i=0;i<n;i++)
        cout<<ar[i]<<" ";
    cout<<"\n";
    return 0;

}


#include<stdio.h>
#include<iostream>

#define l 2*pos+1
#define r 2*pos+2
#define mid (start+stop)/2
using namespace std;
int segtree[100005];
int ar[100005];

void update(int pos,int start,int stop,int i,int j, int q)
{
    if(start>j || stop<i || start>stop)
        return;
    if(start==stop)
    {
        segtree[pos]|=q;
        ar[start]|=q;
        return;
    }
    update(l,start,mid,i,j,q);
    update(r,mid+1,stop,i,j,q);

    segtree[pos]=segtree[l]&segtree[r];

    return;
}

int query(int pos,int start,int stop,int i,int j)
{
    if(start>=i && stop<=j)
        return segtree[pos];

    int aristera=-1,deksia=-1;
    if(i<=mid)
        aristera=query(l,start,mid,i,j);
    if(j>=mid+1)
        deksia=query(r,mid+1,stop,i,j);

    if(aristera==-1)
        return deksia;
    if(deksia==-1)
        return aristera;

    return aristera&deksia;

}

struct poulla
{
    int left,right;
    int q;
};

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    poulla wut[m];
    for(int i=0;i<m;i++)
    {
       scanf("%d %d %d",&wut[i].left,&wut[i].right,&wut[i].q);
       update(0,0,n-1,wut[i].left-1,wut[i].right-1,wut[i].q);
    }
    for(int i=0;i<m;i++)
    {
        if(query(0,0,n-1,wut[i].left-1,wut[i].right-1)!=wut[i].q)
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    for(int i=0;i<n;i++)
        printf("%d ",ar[i]);
    printf("\n");
    return 0;
}