#include <stdio.h>

int main() {
    long long int n_flowers, i, num_ways = 0, biggest_num = 0, smallest_num = 1000000000000, num_times = 0;
    scanf("%lld", &n_flowers);
    long long int beauty_n[n_flowers];

    for (i = 0; i < n_flowers; i++) {
        scanf("%lld", &beauty_n[i]);

        if (beauty_n[i] > biggest_num) {
            biggest_num = beauty_n[i];
        }
        if (beauty_n[i] < smallest_num) {
            smallest_num = beauty_n[i];
        }
    }

    long long int big_dif = biggest_num - smallest_num;

    for (i = 0; i < n_flowers; i++) {
        if (beauty_n[i] == biggest_num) {
            num_times++;
        }

        long long int beauty_dif = biggest_num - beauty_n[i];

        if (beauty_dif == big_dif) {
            num_ways++;
        }
    }

    if (big_dif == 0) {
        printf("0 %lld\n", (n_flowers * (n_flowers - 1)) / 2);
    }

    else printf("%lld %lld\n", big_dif, num_ways * num_times);

    return 0;
}


#include <stdio.h>

int main() {
    long long int n_flowers, i, num_ways = 0, biggest_num = 0, smallest_num = 10000, num_times = 0;
    scanf("%lld", &n_flowers);
    long long int beauty_n[n_flowers];

    for (i = 0; i < n_flowers; i++) {
        scanf("%lld", &beauty_n[i]);

        if (beauty_n[i] > biggest_num) {
            biggest_num = beauty_n[i];
        }
        if (beauty_n[i] < smallest_num) {
            smallest_num = beauty_n[i];
        }
    }

    long long int big_dif = biggest_num - smallest_num;

    for (i = 0; i < n_flowers; i++) {
        if (beauty_n[i] == biggest_num) {
            num_times++;
        }

        long long int beauty_dif = biggest_num - beauty_n[i];

        if (beauty_dif == big_dif) {
            num_ways++;
        }
    }

    if (big_dif == 0) {
        printf("0 %lld\n", n_flowers - 1);
    }

    else printf("%lld %lld\n", big_dif, num_ways * num_times);

    return 0;
}


#include <stdio.h>

int main() {
    long long int n_flowers, i, num_ways = 0, biggest_num = 0, smallest_num = 1000000000000, num_times = 0;
    scanf("%lld", &n_flowers);
    long long int beauty_n[n_flowers];

    for (i = 0; i < n_flowers; i++) {
        scanf("%lld", &beauty_n[i]);

        if (beauty_n[i] > biggest_num) {
            biggest_num = beauty_n[i];
        }
        if (beauty_n[i] < smallest_num) {
            smallest_num = beauty_n[i];
        }
    }

    long long int big_dif = biggest_num - smallest_num;

    for (i = 0; i < n_flowers; i++) {
        if (beauty_n[i] == biggest_num) {
            num_times++;
        }

        long long int beauty_dif = biggest_num - beauty_n[i];

        if (beauty_dif == big_dif) {
            num_ways++;
        }
    }

    if (big_dif == 0) {
        printf("0 %lld\n", n_flowers - 1);
    }

    else printf("%lld %lld\n", big_dif, num_ways * num_times);

    return 0;
}


#include <stdio.h>

int main() {
    int n_flowers, beauty_n, beauty_dif, big_dif = 0, num_ways = 0;
    int i, j;
    scanf("%d", &n_flowers);
    int beauty_nums[n_flowers];

    for (i = 0; i < n_flowers; i++) {
        scanf("%d", &beauty_n);
        beauty_nums[i] = beauty_n;
    }

    for (i = 0; i < n_flowers; i++) {
        for (j = 0; j < n_flowers; j++) {
            beauty_dif = beauty_nums[i] - beauty_nums[j];

            if (beauty_dif > big_dif) {
                big_dif = beauty_dif;
                num_ways = 1;
            }
            else if (beauty_dif == big_dif) {
                num_ways++;
            }
        }
    }

    printf("%d %d\n", big_dif, num_ways);

    return 0;
}


#include <stdio.h>

int main() {
    int n_flowers, i, num_ways = 0, biggest_num = 0, smallest_num = 10000, num_times = 0;
    scanf("%d", &n_flowers);
    int beauty_n[n_flowers];

    for (i = 0; i < n_flowers; i++) {
        scanf("%d", &beauty_n[i]);

        if (beauty_n[i] > biggest_num) {
            biggest_num = beauty_n[i];
        }
        if (beauty_n[i] < smallest_num) {
            smallest_num = beauty_n[i];
        }
    }

    int big_dif = biggest_num - smallest_num;

    for (i = 0; i < n_flowers; i++) {
        if (beauty_n[i] == biggest_num) {
            num_times++;
        }

        int beauty_dif = biggest_num - beauty_n[i];

        if (beauty_dif == big_dif) {
            num_ways++;
        }
    }

    printf("%d %d\n", big_dif, num_ways * num_times);

    return 0;
}


#include <stdio.h>

int main() {
    long long int n_flowers, i, num_ways = 0, biggest_num = 0, smallest_num = 10000, num_times = 0;
    scanf("%lld", &n_flowers);
    long long int beauty_n[n_flowers];

    for (i = 0; i < n_flowers; i++) {
        scanf("%lld", &beauty_n[i]);

        if (beauty_n[i] > biggest_num) {
            biggest_num = beauty_n[i];
        }
        if (beauty_n[i] < smallest_num) {
            smallest_num = beauty_n[i];
        }
    }

    int big_dif = biggest_num - smallest_num;

    for (i = 0; i < n_flowers; i++) {
        if (beauty_n[i] == biggest_num) {
            num_times++;
        }

        int beauty_dif = biggest_num - beauty_n[i];

        if (beauty_dif == big_dif) {
            num_ways++;
        }
    }

    printf("%lld %lld\n", big_dif, num_ways * num_times);

    return 0;
}


#include <stdio.h>
int main()
{
    int n, i, max = 0, maxcnt = 0, min = 1e10 + 10, mincnt = 0, diff;
    scanf("%d", &n);
    int inp[n];
    for (i = 0; i < n; i++)
    {
        scanf("%d", &inp[i]);
        if (inp[i] > max)
        {
            maxcnt = 1;
            max = inp[i];
        }
        else if (inp[i] == max) maxcnt++;
        if (inp[i] < min)
        {
            mincnt = 1;
            min = inp[i];
        }
        else if (inp[i] == min) mincnt++;
    }
    diff = max - min;
    long long perm = (min == max) ? (n*(n-1)/2) : (long long)maxcnt*(long long)mincnt;
    printf("%d %I64d\n", diff, perm);
    return 0;
}


#include <stdio.h>
int main()
{
    int n, i, max = 0, maxcnt = 0, min = 1e10 + 10, mincnt = 0, diff;
    scanf("%d", &n);
    int inp[n];
    for (i = 0; i < n; i++)
    {
        scanf("%d", &inp[i]);
        if (inp[i] >= max) max = inp[i];
        if (inp[i] <= min) min = inp[i];
    }
    for (i = 0; i < n; i++)
    {
        if (inp[i] == max) maxcnt++;
        if (inp[i] == min) mincnt++;
    }
    diff = max - min;
    long long perm = (maxcnt == n) ? (n*(n-1))/2 : (long long)maxcnt*(long long)mincnt;
    printf("%d %I64d\n", diff, perm);
    return 0;
}


#include <stdio.h>
int main()
{
    int n, i, max = 0, maxcnt = 0, min = 1e10 + 10, mincnt = 0, diff;
    scanf("%d", &n);
    int inp[n];
    for (i = 0; i < n; i++)
    {
        scanf("%d", &inp[i]);
        if (inp[i] > max)
        {
            maxcnt = 1;
            max = inp[i];
        }
        else if (inp[i] == max) maxcnt++;
        if (inp[i] < min)
        {
            mincnt = 1;
            min = inp[i];
        }
        else if (inp[i] == min) mincnt++;
    }
    diff = max - min;
    long long perm = (min == max) ? (n*(n-1)/2) : maxcnt*mincnt;
    printf("%d %I64d\n", diff, perm);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<conio.h>
using namespace std;
#define maxn (1<<24)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10],is_vis[maxn+10],q[maxn+10];
int  k, n;
__int64 vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    __int64 res = 0, i, j;
    int head = 0,tail = 0;
    q[0] = 0;
    vis[0] = 1;
    is_vis[0] = 1;
    int sum  = 0;
    while(head<=tail)
    {
        __int64 u = q[head++];
    //  printf("%lld %lld\n",u,vis[u]);
        for(i=0;i<n;++i)
        {
            sum++;
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            if(is_vis[temp]==0)
                   q[++tail] = temp,is_vis[temp] = 1;;
            vis[temp]+=vis[u];
            if(vis[temp]>=MOD) vis[temp]-=MOD;

        }
    }

    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;++i)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    memset(is_vis,0,sizeof(is_vis));
    memset(vis,0,sizeof(vis));
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);++i)
    {
        int temp = i&(-i);
        dp[i] = dp[i^temp]+a[num[temp]];
        for(j=1;j<=k;j++) if(dp[i]==bug[j]) is_vis[i] = 1;
    }
    memset(dp,0,sizeof(dp));
    dp[0]  = 1;
    for(i=1;i<(1<<n);++i)
    {
        if(is_vis[i]==1)
        {
            dp[i] = 0;
            continue;
        }
        for(j=0;j<n;++j)
        {
            if(i&(1<<j))
            {
            //  printf("%d %d\n",i,j);
                dp[i]+=dp[i^(1<<j)];
            }
        }
        dp[i]%=MOD;
    //  printf("%d %lld\n",i,dp[i]);
    }
    printf("%lld\n",dp[(1<<n)-1]);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<conio.h>
using namespace std;
#define maxn (1<<24)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10],is_vis[maxn+10];
int  k, n;
__int64 vis[maxn+10],dp[maxn+10],q[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    memset(is_vis,0,sizeof(is_vis));
    __int64 res = 0, i, j;
    int head = 0,tail = 0;
    q[0] = 0;
    vis[0] = 1;
    is_vis[0] = 1;
    while(head<=tail)
    {
        __int64 u = q[head++];
        //if(vis[u]<=0) printf("%lld\n",u);
        for(i=0;i<n;i++)
        {
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            for(j=1;j<=k;j++) if(dp[temp]==bug[j]) break;
            if(j<=k) continue;
            if(is_vis[temp]==0)
                   q[++tail] = temp,is_vis[temp] = 1;;
            vis[temp]+=vis[u];
            vis[temp]%=MOD;

        }
    }
    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;i++)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);i++)
    {
        int temp = i&(-i);
        dp[i] = dp[i^temp]+a[num[temp]];
    }
//  printf("11111");
    printf("%lld\n",solve());
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<conio.h>
using namespace std;
#define maxn (1<<24)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10],is_vis[maxn+10],q[maxn+10];
int  k, n;
__int64 vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    __int64 res = 0, i, j;
    int head = 0,tail = 0;
    q[0] = 0;
    vis[0] = 1;
    is_vis[0] = 1;
    int sum  = 0;
    while(head<=tail)
    {
        __int64 u = q[head++];
    //  printf("%lld %lld\n",u,vis[u]);
        for(i=0;i<n;++i)
        {
            sum++;
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            if(is_vis[temp]==0)
                   q[++tail] = temp,is_vis[temp] = 1;;
            vis[temp]+=vis[u];
            if(vis[temp]>=MOD) vis[temp]-=MOD;

        }
    }

    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;++i)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    memset(is_vis,0,sizeof(is_vis));
    memset(vis,0,sizeof(vis));
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);++i)
    {
        int temp = i&(-i);
        dp[i] = dp[i^temp]+a[num[temp]];
        for(j=1;j<=k;j++) if(dp[i]==bug[j]) is_vis[i] = 1;
    }
    memset(dp,0,sizeof(dp));
    dp[0]  = 1;
    for(i=1;i<(1<<n);++i)
    {
        if(is_vis[i]==1)
        {
            dp[i] = 0;
            continue;
        }
        for(j=0;j<n;++j)
        {
            if(i&(1<<j))
            {
            //  printf("%d %d\n",i,j);
                dp[i]+=dp[i^(1<<j)];
                dp[i]%=MOD;
            }
        }
    //  printf("%d %lld\n",i,dp[i]);
    }
    printf("%lld\n",dp[(1<<n)-1]);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define maxn (1<<24)
#define MOD  1000000007
int  a[100],bug[3],num[100];
int  k, n;
__int64 js[100],vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    __int64 res = 0, i, j;
    queue<__int64> q;
    q.push(0);
    vis[0] = 1;
    while(!q.empty())
    {
        __int64 u = q.front();
    //  printf("%lld %lld\n",u,vis[u]);
        q.pop();
        for(i=0;i<n;i++)
        {
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            if(vis[temp]) {
             vis[temp]+=vis[u];
             vis[temp]%=MOD;
             continue;
            }
            //printf("11111\n");
            for(j=1;j<=k;j++) if(dp[temp]==bug[j]) break;
            if(j<=k) continue;
            q.push(temp);
            vis[temp]+=vis[u];
            vis[temp]%=MOD;
        }
    }
    return vis[(1<<n)-1];
}
int main()
{
    int i, j;
//  memset(vis,0,sizeof(vis));
    js[0] = 1;
    for(i=1;i<=90;i++)
    {
        js[i] = js[i-1]*i%MOD;
    }
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=0;i<(1<<n);i++)
    {
        for(j=0;j<=24;j++)
        {
            if(i&(1<<j)) continue;
            dp[i^(1<<j)] = dp[i]+a[j+1];
        }
    }
    printf("%lld\n",solve());
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<conio.h>
using namespace std;
#define maxn (1<<24)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10],is_vis[maxn+10],q[maxn+10];
int  k, n;
__int64 vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    __int64 res = 0, i, j;
    int head = 0,tail = 0;
    q[0] = 0;
    vis[0] = 1;
    is_vis[0] = 1;
    int sum  = 0;
    while(head<=tail)
    {
        __int64 u = q[head++];
    //  printf("%lld %lld\n",u,vis[u]);
        for(i=0;i<n;i++)
        {
            sum++;
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            if(is_vis[temp]==0)
                   q[++tail] = temp,is_vis[temp] = 1;;
            vis[temp]+=vis[u];
            if(vis[temp]>=MOD) vis[temp]-=MOD;

        }
    }

    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;i++)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    memset(is_vis,0,sizeof(is_vis));
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);i++)
    {
        int temp = i&(-i);
    //  if(i==5) printf("%d %d %d\n",temp,i^temp,num[temp]);
        dp[i] = dp[i^temp]+a[num[temp]];
    //  if(i==4) printf("%lld\n",dp[4]);
        for(j=1;j<=k;j++) if(dp[i]==bug[j]) is_vis[i] = 1;
    }
    //printf("%lld %lld\n",dp[4],dp[3]);
    printf("%lld\n",solve());
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define maxn (1<<25)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10];
int  k, n;
__int64 vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    __int64 res = 0, i, j;
    queue<__int64> q;
    q.push(0);
    vis[0] = 1;
    while(!q.empty())
    {
        __int64 u = q.front();
        q.pop();
        for(i=0;i<n;i++)
        {
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            if(vis[temp]) {
             vis[temp]+=vis[u];
             vis[temp]%=MOD;
             continue;
            }
            for(j=1;j<=k;j++) if(dp[temp]==bug[j]) break;
            if(j<=k) continue;
            q.push(temp);
            vis[temp]+=vis[u];
            vis[temp]%=MOD;
        }
    }
    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;i++)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);i++)
    {
        int temp = i&(-i);
        dp[i] = dp[i^temp]+a[num[temp]];
    }
    printf("%lld\n",solve());
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<conio.h>
using namespace std;
#define maxn (1<<24)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10],is_vis[maxn+10],q[maxn+10];
int  k, n;
__int64 vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    memset(is_vis,0,sizeof(is_vis));
    __int64 res = 0, i, j;
    int head = 0,tail = 0;
    q[0] = 0;
    vis[0] = 1;
    is_vis[0] = 1;
    while(head<=tail)
    {
        __int64 u = q[head++];
        //if(vis[u]<=0) printf("%lld\n",u);
        for(i=0;i<n;i++)
        {
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            for(j=1;j<=k;j++) if(dp[temp]==bug[j]) break;
            if(j<=k) continue;
            if(is_vis[temp]==0)
                   q[++tail] = temp,is_vis[temp] = 1;;
            vis[temp]+=vis[u];
            vis[temp]%=MOD;

        }
    }
    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;i++)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);i++)
    {
        int temp = i&(-i);
        dp[i] = dp[i^temp]+a[num[temp]];
    }
//  printf("11111");
    printf("%lld\n",solve());
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<conio.h>
using namespace std;
#define maxn (1<<24)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10],is_vis[maxn+10],q[maxn+10];
int  k, n;
__int64 vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    __int64 res = 0, i, j;
    int head = 0,tail = 0;
    q[0] = 0;
    vis[0] = 1;
    is_vis[0] = 1;
    int sum  = 0;
    while(head<=tail)
    {
        __int64 u = q[head++];
    //  printf("%lld %lld\n",u,vis[u]);
        for(i=0;i<n;++i)
        {
            sum++;
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            if(is_vis[temp]==0)
                   q[++tail] = temp,is_vis[temp] = 1;;
            vis[temp]+=vis[u];
            if(vis[temp]>=MOD) vis[temp]-=MOD;

        }
    }

    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;++i)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    memset(is_vis,0,sizeof(is_vis));
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);++i)
    {
        int temp = i&(-i);
        dp[i] = dp[i^temp]+a[num[temp]];
        for(j=1;j<=k;j++) if(dp[i]==bug[j]) is_vis[i] = 1;
    }
    printf("%lld\n",solve());
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<conio.h>
using namespace std;
#define maxn (1<<24)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10],is_vis[maxn+10],q[maxn+10];
int  k, n;
__int64 vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    __int64 res = 0, i, j;
    int head = 0,tail = 0;
    q[0] = 0;
    vis[0] = 1;
    is_vis[0] = 1;
    int sum  = 0;
    while(head<=tail)
    {
        __int64 u = q[head++];
    //  printf("%lld %lld\n",u,vis[u]);
        for(i=0;i<n;i++)
        {
            sum++;
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            if(is_vis[temp]==0)
                   q[++tail] = temp,is_vis[temp] = 1;;
            vis[temp]+=vis[u];
            vis[temp]%=MOD;

        }
    }

    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;i++)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    memset(is_vis,0,sizeof(is_vis));
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);i++)
    {
        int temp = i&(-i);
    //  if(i==5) printf("%d %d %d\n",temp,i^temp,num[temp]);
        dp[i] = dp[i^temp]+a[num[temp]];
    //  if(i==4) printf("%lld\n",dp[4]);
        for(j=1;j<=k;j++) if(dp[i]==bug[j]) is_vis[i] = 1;
    }
    //printf("%lld %lld\n",dp[4],dp[3]);
    printf("%lld\n",solve());
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define maxn (1<<25)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10];
int  k, n;
__int64 js[maxn+10],vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    __int64 res = 0, i, j;
    queue<__int64> q;
    q.push(0);
    vis[0] = 1;
    while(!q.empty())
    {
        __int64 u = q.front();
        q.pop();
        for(i=0;i<n;i++)
        {
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            if(vis[temp]) {
             vis[temp]+=vis[u];
             vis[temp]%=MOD;
             continue;
            }
            for(j=1;j<=k;j++) if(dp[temp]==bug[j]) break;
            if(j<=k) continue;
            q.push(temp);
            vis[temp]+=vis[u];
            vis[temp]%=MOD;
        }
    }
    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;i++)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);i++)
    {
        int temp = i&(-i);
        dp[i] = dp[i^temp]+a[num[temp]];
    }
    printf("%lld\n",solve());
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<conio.h>
using namespace std;
#define maxn (1<<24)
#define MOD  1000000007
int  a[100],bug[3],num[maxn+10],is_vis[maxn+10],q[maxn+10];
int  k, n;
__int64 vis[maxn+10],dp[maxn+10];
__int64 solve()
{
    memset(vis,0,sizeof(vis));
    __int64 res = 0, i, j;
    int head = 0,tail = 0;
    q[0] = 0;
    vis[0] = 1;
    is_vis[0] = 1;
    int sum  = 0;
    while(head<=tail)
    {
        __int64 u = q[head++];
    //  printf("%lld %lld\n",u,vis[u]);
        for(i=0;i<n;++i)
        {
            sum++;
            if(u&(1<<i)) continue;
            __int64 temp = u^(1<<i);
            if(is_vis[temp]==0)
                   q[++tail] = temp,is_vis[temp] = 1;;
            vis[temp]+=vis[u];
            if(vis[temp]>=MOD) vis[temp]-=MOD;

        }
    }

    return vis[(1<<n)-1];
}
void init()
{
    int i;
    int temp = 1;
    for(i=1;i<=25;++i)
    {
        num[temp] = i;
        temp*=2;
    }
}
int main()
{
    memset(is_vis,0,sizeof(is_vis));
    memset(vis,0,sizeof(vis));
    init();
    int i, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&k);
    for(i=1;i<=k;i++) scanf("%d",&bug[i]);
    dp[0] = 0;
    for(i=1;i<(1<<n);++i)
    {
        int temp = i&(-i);
        dp[i] = dp[i^temp]+a[num[temp]];
        for(j=1;j<=k;j++) if(dp[i]==bug[j]) is_vis[i] = 1;
    }
    memset(dp,0,sizeof(dp));
    dp[0]  = 1;
    for(i=1;i<(1<<n);++i)
    {
        if(is_vis[i]==1)
        {
            dp[i] = 0;
            continue;
        }
        for(j=0;j<n;++j)
        {
            if(i&(1<<j))
            {
            //  printf("%d %d\n",i,j);
                dp[i]+=dp[i^(1<<j)];
            }
        }
    //  printf("%d %lld\n",i,dp[i]);
    }
    printf("%lld\n",dp[(1<<n)-1]);
    return 0;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#include <fstream>
#include <functional>
#define mp make_pair
#define pb push_back
#define lo int
#define li long long int
#define db long double
#define FOR(i, n) for(lo i = 0; i < (n); i++)
#define pi 3.14159265358979323
#define eps 1e-4
#define MN 11000
#define sz(a) (lo) (a).size()
#define SM 1<<6
using namespace std;
const li INF = 2e18;

lo dp[1<<24];
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
  // freopen("prediction.in", "r", stdin);
   //freopen("prediction.out", "w", stdout);
#endif
    lo n;
    cin >> n;
    vector<lo> a(n); FOR(i, n) cin >> a[i];
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    lo cant[2] = {-1, -1};
    lo k ; cin >> k; FOR(i, k) cin >> cant[i];
    lo mod = 1000000007;
    FOR(i, (1<<n))
    {
        if(!dp[i])
            continue;
        lo sum = 0;

        FOR(j, n)
        {
            if(i & (1<<j))
            {
                sum += a[j];
            }
            if(sum > cant[0] && sum > cant[1])
                break;
        }
        if(sum == cant[0] || sum == cant[1])
            continue;
        FOR(j, n)
        {
            if(!(i & (1<<j)))
            {
                sum = (i ^ (1<<j));
                dp[sum] = (dp[sum] + dp[i]) % mod;
            }
        }
    }
    cout << dp[(1<<n) - 1];
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#include <fstream>
#include <functional>
#define mp make_pair
#define pb push_back
#define lo int
#define li long long int
#define db long double
#define FOR(i, n) for(lo i = 0; i < (n); i++)
#define pi 3.14159265358979323
#define eps 1e-4
#define MN 11000
#define sz(a) (lo) (a).size()
#define SM 1<<6
using namespace std;
const li INF = 2e18;

li dp[1<<24];
li fac[25];
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
  // freopen("prediction.in", "r", stdin);
   //freopen("prediction.out", "w", stdout);
#endif
    lo n;
    cin >> n;

    vector<lo> a(n); FOR(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    lo cant[2] = {-1, -1};
    lo k ; cin >> k; FOR(i, k) cin >> cant[i];
    lo mod = 1000000007;
    fac[0] = 1;
    for(lo i = 1; i <= n; i++)
    {
        fac[i] = (fac[i - 1] * i) % mod;
    }
    lo out = 0;

    FOR(i, (1<<n))
    {
        if(!dp[i])
            continue;

        li sum = 0;
        lo nm = n;
            FOR(j, n)
            {
                if(i & (1<<j))
                {
                    sum += a[j];
                    nm--;
                }
            }
            if(sum == cant[0] || sum == cant[1])
                continue;
        if(sum > cant[0] && sum > cant[1])
        {
            out = (out + (dp[i] *1LL *  fac[nm]) % mod) % mod;
            continue;
        }
        FOR(j, n)
        {
            if(!(i & (1<<j)))
            {
                dp[i ^ (1<<j)] = (dp[i ^ (1<<j)] + dp[i]) % mod;
            }
        }
    }
    cout << out;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#include <fstream>
#include <functional>
#define mp make_pair
#define pb push_back
#define lo int
#define li long long int
#define db long double
#define FOR(i, n) for(lo i = 0; i < (n); i++)
#define pi 3.14159265358979323
#define eps 1e-4
#define MN 10000001
#define sz(a) (lo) (a).size()
#define SM 1<<6
using namespace std;
const li INF = 2e18;

lo sum[1<<14][2];
lo nu[1<<14][2];
lo cant[2] = {-1, -1};
li fac[25];
lo mod = 1000000007;
void done(lo fr, lo to, lo ind, vector<lo> &a)
{
    lo n = sz(a);
    sum[0][ind] = 0;
    FOR(i, (1<<to))
    {

        FOR(j, to)
        {
            if(!(i & (1<<j)))
            {
                nu[i][ind]++;
                lo val = i ^ (1<<j);
                sum[val][ind] = (sum[i][ind] > cant[1] ? sum[i][ind] : sum[i][ind] + a[j + fr]);
            }
        }
    }
}

bool ch[1<<24];
lo nn[1<<24];
lo dp[1<<24];
vector< pair<pair<pair<lo, lo>, pair<lo, lo> >, lo > > table[MN];
lo ghash(lo s1, lo s2)
{
    li hi[2] = {s1, s2};
    //sort(hi, hi + 2);
    li base = mod % MN, now = base, out = 0, out2 = 0;
    FOR(i, 2)
    {
        now = (now * base) % MN;
        out = (out + ((hi[i] + 1) * now) % MN) % MN;
    }

    return out % MN;
}
void ins(lo s1, lo s2, lo c1, lo c2)
{
    lo out  = ghash(s1, s2);
    bool find = false;
    FOR(i, sz(table[out]))
    {
        if(table[out][i].first == mp(mp(s1, s2), mp(c1, c2)))
        {
            table[out][i].second ++;
            find = true;
            break;
        }
    }
if(!find)
    table[out].pb(mp(mp(mp(s1, s2), mp(c1, c2)), 1));
}
inline lo getme(li a1, li a2, li n)
{
    li out = ((fac[a2] * fac[a1 - a2]) % mod * fac[n - a1]) % mod;
    return out;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
  // freopen("prediction.in", "r", stdin);
   //freopen("prediction.out", "w", stdout);
#endif
    lo n;
    cin >> n;
    fac[0] = 1;
    vector<lo> a(n); FOR(i, n)
    {
        scanf("%d", &a[i]);
        fac[i + 1] = (fac[i] * (i + 1)) % mod;
    }
    sort(a.begin(), a.end());
    lo q; cin >> q;
    FOR(i, q) cin >> cant[i];
    if(cant[1] < cant[0]) swap(cant[1], cant[0]);
    if(cant[1] == cant[0])
        cant[0] = -1;
    memset(ch, 0, sizeof ch);
    done(0, n / 2, 0, a);
    done(n / 2 , n - n / 2, 1, a);
    lo delta = fac[n];
    FOR(i, (1<< (n / 2))) FOR(j, 1<<(n - n / 2))
    {
        li s = sum[i][0] + sum[j][1] ;
        if(s == cant[0] || s == cant[1])
        {
            delta = (delta + mod - (fac[nu[i][0] + nu[j][1]] * fac[n - nu[i][0] - nu[j][1]]) % mod) % mod;
        }
    }
    if(cant[0] != -1)
    {
        FOR(i, (1<<(n - n / 2)))
        {
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                ins(sum[i][1], sum[j][1], n - n / 2 - nu[i][1], n - n / 2 - nu[j][1]);
                if(!j)
                    break;
            }
        }

        FOR(i,( 1<<(n / 2) ))
        {
            if(sum[i][0] > cant[1])
                continue;
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                if(sum[j][0] > cant[0])
                    continue;
                lo wh = ghash(cant[1] - sum[i][0], cant[0] - sum[j][0]);
                FOR(q, sz(table[wh]))
                {
                    if(table[wh][q].first.first != mp(cant[1] - sum[i][0], cant[0] - sum[j][0]))
                        continue;
                    lo s1 = table[wh][q].first.second.first + n / 2 - nu[i][0];
                    lo s2 = table[wh][q].first.second.second + n / 2 - nu[j][0];
                   li numb =table[wh][q].second;
                    li val = getme(s1, s2, n);
                    delta = (delta + (val * numb) % mod) % mod;

                }
                if(!j)
                    break;
            }

        }
    }
    cout << delta;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#include <fstream>
#include <functional>
#define mp make_pair
#define pb push_back
#define lo int
#define li long long int
#define db long double
#define FOR(i, n) for(lo i = 0; i < (n); i++)
#define pi 3.14159265358979323
#define eps 1e-4
#define MN 10000001
#define sz(a) (lo) (a).size()
#define SM 1<<6
using namespace std;
const li INF = 2e18;

lo sum[1<<14][2];
lo nu[1<<14][2];
lo cant[2] = {-1, -1};
li fac[25];
lo mod = 1000000007;
void done(lo fr, lo to, lo ind, vector<lo> &a)
{
    lo n = sz(a);
    sum[0][ind] = 0;
    FOR(i, (1<<to))
    {

        FOR(j, to)
        {
            if(!(i & (1<<j)))
            {
                nu[i][ind]++;
                lo val = i ^ (1<<j);
                sum[val][ind] = (sum[i][ind] > cant[1] ? sum[i][ind] : sum[i][ind] + a[j + fr]);
            }
        }
    }
}

bool ch[1<<24];
lo nn[1<<24];
lo dp[1<<24];
vector< pair<pair<pair<lo, lo>, pair<lo, lo> >, lo > > table[MN];
inline lo ghash(lo s1, lo s2)
{
    li hi[2] = {s1, s2};
    //sort(hi, hi + 2);
    li base = mod % MN, now = base, out = 0, out2 = 0;
    FOR(i, 2)
    {
        now = (now * base) % MN;
        out = (out + ((hi[i] + 1) * now) % MN) % MN;
    }

    return out % MN;
}
void ins(lo s1, lo s2, lo c1, lo c2)
{
    lo out  = ghash(s1, s2);
    bool find = false;
    FOR(i, sz(table[out]))
    {
        if(table[out][i].first == mp(mp(s1, s2), mp(c1, c2)))
        {
            table[out][i].second ++;
            find = true;
            break;
        }
    }
if(!find)
    table[out].pb(mp(mp(mp(s1, s2), mp(c1, c2)), 1));
}
inline lo getme(li a1, li a2, li n)
{
    li out = ((fac[a2] * fac[a1 - a2]) % mod * fac[n - a1]) % mod;
    return out;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
  // freopen("prediction.in", "r", stdin);
   //freopen("prediction.out", "w", stdout);
#endif
    lo n;
    cin >> n;
    fac[0] = 1;
    vector<lo> a(n); FOR(i, n)
    {
        scanf("%d", &a[i]);
        fac[i + 1] = (fac[i] * (i + 1)) % mod;
    }
    sort(a.begin(), a.end());
    lo q; cin >> q;
    FOR(i, q) cin >> cant[i];
    if(cant[1] < cant[0]) swap(cant[1], cant[0]);
    if(cant[1] == cant[0])
        cant[0] = -1;
    memset(ch, 0, sizeof ch);
    done(0, n / 2, 0, a);
    done(n / 2 , n - n / 2, 1, a);
    lo delta = fac[n];
    FOR(i, (1<< (n / 2))) FOR(j, 1<<(n - n / 2))
    {
        li s = sum[i][0] + sum[j][1] ;
        if(s == cant[0] || s == cant[1])
        {
            delta = (delta + mod - (fac[nu[i][0] + nu[j][1]] * fac[n - nu[i][0] - nu[j][1]]) % mod) % mod;
        }
    }
    if(cant[0] != -1)
    {
        FOR(i, (1<<(n - n / 2)))
        {
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                ins(sum[i][1], sum[j][1], n - n / 2 - nu[i][1], n - n / 2 - nu[j][1]);
                if(!j)
                    break;
            }
        }

        FOR(i,( 1<<(n / 2) ))
        {
            if(sum[i][0] > cant[1])
                continue;
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                if(sum[j][0] > cant[0])
                    continue;
                lo wh = ghash(cant[1] - sum[i][0], cant[0] - sum[j][0]);
                FOR(q, sz(table[wh]))
                {
                    if(table[wh][q].first.first != mp(cant[1] - sum[i][0], cant[0] - sum[j][0]))
                        continue;
                    lo s1 = table[wh][q].first.second.first + n / 2 - nu[i][0];
                    lo s2 = table[wh][q].first.second.second + n / 2 - nu[j][0];
                   li numb =table[wh][q].second;
                    li val = getme(s1, s2, n);
                    delta = (delta + (val * numb) % mod) % mod;

                }
                if(!j)
                    break;
            }

        }
    }
    cout << delta;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#include <fstream>
#include <functional>
#define mp make_pair
#define pb push_back
#define lo long long int
#define li long long int
#define db long double
#define FOR(i, n) for(lo i = 0; i < (n); i++)
#define pi 3.14159265358979323
#define eps 1e-4
#define MN 10000001
#define sz(a) (lo) (a).size()
#define SM 1<<6
using namespace std;
const li INF = 2e18;

lo sum[1<<14][2];
lo nu[1<<14][2];
lo cant[2] = {-1, -1};
li fac[25];
lo mod = 1000000007;
void done(lo fr, lo to, lo ind, vector<lo> &a)
{
    lo n = sz(a);
    sum[0][ind] = 0;
    FOR(i, (1<<to))
    {

        FOR(j, to)
        {
            if(!(i & (1<<j)))
            {
                nu[i][ind]++;
                lo val = i ^ (1<<j);
                sum[val][ind] = (sum[i][ind] > cant[1] ? sum[i][ind] : sum[i][ind] + a[j + fr]);
            }
        }
    }
}

bool ch[1<<24];
lo nn[1<<24];
lo dp[1<<24];
vector<pair<pair<lo, lo>, lo > > table[MN];
lo ghash(lo s1, lo s2)
{
    li hi[2] = {s1, s2};
    //sort(hi, hi + 2);
    li base = mod % MN, now = base, out = 0, out2 = 0;
    FOR(i, 2)
    {
        now = (now * base) % MN;
        out = (out + ((hi[i] + 1) * now) % MN) % MN;
    }

    return out % MN;
}
void ins(lo s1, lo s2, lo c1, lo c2)
{
    lo out  = ghash(s1, s2);
    bool find = false;
    FOR(i, sz(table[out]))
    {
        if(table[out][i].first == mp(c1, c2))
        {
            table[out][i].second ++;
            find = true;
            break;
        }
    }
if(!find)
    table[out].pb(mp(mp(c1, c2), 1));
}
inline lo getme(li a1, li a2, li n)
{
    li out = ((fac[a2] * fac[a1 - a2]) % mod * fac[n - a1]) % mod;
    return out;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
  // freopen("prediction.in", "r", stdin);
   //freopen("prediction.out", "w", stdout);
#endif
    lo n;
    cin >> n;
    fac[0] = 1;
    vector<lo> a(n); FOR(i, n)
    {
        scanf("%d", &a[i]);
        fac[i + 1] = (fac[i] * (i + 1)) % mod;
    }
    sort(a.begin(), a.end());
    lo q; cin >> q;
    FOR(i, q) cin >> cant[i];
    if(cant[1] < cant[0]) swap(cant[1], cant[0]);
    memset(ch, 0, sizeof ch);
    done(0, n / 2, 0, a);
    done(n / 2 , n - n / 2, 1, a);
    lo delta = fac[n];
    FOR(i, (1<< (n / 2))) FOR(j, 1<<(n - n / 2))
    {
        li s = sum[i][0] + sum[j][1] ;
        if(s == cant[0] || s == cant[1])
        {
            delta = (delta + mod - (fac[nu[i][0] + nu[j][1]] * fac[n - nu[i][0] - nu[j][1]]) % mod) % mod;
        }
    }
    if(cant[0] != -1)
    {
        FOR(i, (1<<(n - n / 2)))
        {
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                ins(sum[i][1], sum[j][1], n - n / 2 - nu[i][1], n - n / 2 - nu[j][1]);
                if(!j)
                    break;
            }
        }

        FOR(i,( 1<<(n / 2) ))
        {
            if(sum[i][0] > cant[1])
                continue;
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                if(sum[j][0] > cant[0])
                    continue;
                lo wh = ghash(cant[1] - sum[i][0], cant[0] - sum[j][0]);
                FOR(q, sz(table[wh]))
                {

                    lo s1 = table[wh][q].first.first + n / 2 - nu[i][0];
                    lo s2 = table[wh][q].first.second + n / 2 - nu[j][0];
                   li numb =table[wh][q].second;
                    li val = getme(s1, s2, n);
                    delta = (delta + (val * numb) % mod) % mod;

                }
                if(!j)
                    break;
            }

        }
    }
    cout << delta;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo int
#define li long long int
#define db double
#define pi 3.14159265358979323
#define eps 1e-6
#define MN (1<<24) + 201001
using namespace std;
const double INF= 2e50;

lo mod = 1000000007;
li cnt[MN];
bool ini[MN];
bool ch[MN];
li to_go[MN];
lo q[MN];
lo n;
void bfs(vector<lo> &op, li to)
{
    memset(ini, false, sizeof ini);
    for(lo i = 0; i < (1 << n); i++)
    {
        if(!ch[i])
        {
            to_go[i] = 0;
        }
    }
    lo f = 0, s = 0;
    for(lo i = 0; i < n; i++)
    {
        if(ch[1 << i])
            continue;
        cnt[1 << i] = op[i];
        q[s++] = (1 << i);
        ini[1 << i] = true;
        to_go[1 << i] = 1;
    }
    while(s > f)
    {
        lo now = q[f++];
        if(cnt[now] == to)
        {
            ch[now]++;
            continue;
        }
        if(cnt[now] > to)
            continue;
        for(lo i = 0; i < n; i++)
        {
            if(!(now & (1 << i)))
            {
                lo nmask = (now | (1 << i));
                if(ch[nmask])
                    continue;
                to_go[nmask] = (to_go[nmask] + to_go[now]) % mod;
                if(ini[nmask])
                    continue;
                cnt[nmask] = cnt[now] + cnt[1 << i];
                ini[nmask] = true;
                q[s++] = (nmask);
            }
        }
    }
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
    cin >> n;
    vector<lo> op(n);
    bool ag = false;
    for(lo i = 0; i < n; i++)
    {
        cin >> op[i];
        if(op[i] != 1)
        {
            ag = true;
        }
    }
    sort(op.begin(), op.end());
    lo k;
    cin >> k;
    if(!k)
    {
        lo ans = 1;
        for(lo i = n; i >=1; i--)
        {
            ans = (ans * i) % mod;
        }
        cout << ans;
        return 0;
    }
    if(!ag)
    {
        cout << 0;
        return 0;
    }
    vector<lo> cant(k);
    for(lo i = 0; i < k; i++)
    {
        cin >> cant[i];
    }
    sort(cant.begin(), cant.end());
    memset(cnt, 0, sizeof cnt);
    memset(ch, false, sizeof ch);
    memset(to_go, 0, sizeof to_go);
    for(lo i = 0; i < k; i++)
    {
        bfs(op, cant[i]);
    }
    vector<li> fac(n + 1);
    fac[0] = 1;
    for(lo i = 1; i <= n; i++)
    {
        fac[i] = (fac[i - 1] * i) % mod;
    }
    li num = 0;
    for(lo i = 0; i < (1LL << n); i++)
    {
        if(ch[i])
        {
            lo one = 0;
            one = __builtin_popcount(i);

            num = (num + (to_go[i] * fac[n - one]) % mod) % mod;
        }
    }
    cout << (fac[n] + mod - num) % mod << endl;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#include <fstream>
#include <functional>
#define mp make_pair
#define pb push_back
#define lo int
#define li long long int
#define db long double
#define FOR(i, n) for(lo i = 0; i < (n); i++)
#define pi 3.14159265358979323
#define eps 1e-4
#define MN 11000
#define sz(a) (lo) (a).size()
#define SM 1<<6
using namespace std;
const li INF = 2e18;

lo dp[1<<24];
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
  // freopen("prediction.in", "r", stdin);
   //freopen("prediction.out", "w", stdout);
#endif
    lo n;
    cin >> n;
    vector<lo> a(n); FOR(i, n) cin >> a[i];
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    lo cant[2] = {-1, -1};
    lo k ; cin >> k; FOR(i, k) cin >> cant[i];
    lo mod = 1000000007;
    FOR(i, (1<<n))
    {
        if(!dp[i])
            continue;
        li sum = 0;
        FOR(j, n)
        {
            if(i & (1<<j))
            {
                sum += a[j];
            }
        }
        if(sum == cant[0] || sum == cant[1])
            continue;
        FOR(j, n)
        {
            if(!(i & (1<<j)))
            {
                dp[i ^ (1<<j)] = (dp[i ^ (1<<j)] + dp[i]) % mod;
            }
        }
    }
    cout << dp[(1<<n) - 1];
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo long long int
#define pi 3.14159265358979323
#define eps 1e-6
#define MN 1LL << 25
using namespace std;
const lo INF= 2e18;
lo used[MN], mod = 1000000007, num; vector<lo> fac;
lo bitcount(lo a, lo n)
{
	lo ans = 0;
	for(lo i = 0; i < n; i++)
	{
		if(a & (1LL << i)) ans++;
	}
	return ans;
}
lo find_nex(lo us, lo a, lo n)
{
	return ((a + 1) | us);
}
int main()
{
	//freopen("input.txt", "r", stdin);
	memset(used, 0, sizeof used);
	lo n, ans = 0;
	cin >> n;
	vector<lo> op(n);
	fac.resize(n + 1);
	fac[0] = 1;
	for(lo i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod;
	fac[0] = 0;
	for(lo i = 0; i < n;i++) cin >> op[i];
	sort(op.begin(), op.end());
	lo a;
	cin >> a;
	lo b[2] = {-1, -1};
	for(lo i = 0; i < a; i++) cin >> b[i];
	for(lo i = 1; i <= (1LL << (n)); i++)
	{
		lo sum = 0;
		num = 0;
		for(lo j = 0; j < n; j++)
		{
			if(i & (1LL << j )) sum += op[j], num++;
		}
		if(sum == b[0] || sum == b[1])
		{
                        lo f = 0, s = 0;
			if(used[i]) f=  __builtin_popcount(used[i] ^ i), s =  __builtin_popcount(used[i]);
			ans = (ans + (fac[num]+mod - fac[f] * fac[s]) * fac[n - num]) % mod;
			if(!used[i]) used[i] = i;
		}
		if(used[i])
		{
		lo nex = find_nex(used[i], i, n);
		if(!used[nex])
		used[nex] = used[i];
		}
	}
	cout << (fac[n] + mod - ans) % mod;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#include <fstream>
#include <functional>
#define mp make_pair
#define pb push_back
#define lo int
#define li long long int
#define db long double
#define FOR(i, n) for(lo i = 0; i < (n); i++)
#define pi 3.14159265358979323
#define eps 1e-4
#define MN 1000001
#define sz(a) (lo) (a).size()
#define SM 1<<6
using namespace std;
const li INF = 2e18;

lo sum[1<<14][2];
lo nu[1<<14][2];
lo cant[2] = {-1, -1};
li fac[25];
lo mod = 1000000007;
void done(lo fr, lo to, lo ind, vector<lo> &a)
{
    lo n = sz(a);
    sum[0][ind] = 0;
    FOR(i, (1<<to))
    {

        FOR(j, to)
        {
            if(!(i & (1<<j)))
            {
                nu[i][ind]++;
                lo val = i ^ (1<<j);
                sum[val][ind] = (sum[i][ind] > cant[1] ? sum[i][ind] : sum[i][ind] + a[j + fr]);
            }
        }
    }
}

bool ch[1<<24];
lo nn[1<<24];
lo dp[1<<24];
vector<pair<pair<lo, lo>, lo > > table[MN];
lo ghash(lo s1, lo s2)
{
    li hi[2] = {s1, s2};
    //sort(hi, hi + 2);
    li base = 9997, now = base, out = 0, out2 = 0;
    FOR(i, 2)
    {
        now = (now * base) % MN;
        out = (out + ((hi[i] + 1) * now) % MN) % MN;
    }
    base = mod, now = base;
    FOR(i, 2)
    {
        now = (now * base) % MN;
        out2 = (out2 + ((hi[i] + 1) * now) % MN) % MN;
    }
    out = (out * out2) % MN;
    out ^= out2;
    return out % MN;
}
void ins(lo s1, lo s2, lo c1, lo c2)
{
    lo out  = ghash(s1, s2);
    bool find = false;
    FOR(i, sz(table[out]))
    {
        if(table[out][i].first == mp(c1, c2))
        {
            table[out][i].second ++;
            find = true;
            break;
        }
    }
if(!find)
    table[out].pb(mp(mp(c1, c2), 1));
}
inline lo getme(li a1, li a2, li n)
{
    li out = ((fac[a2] * fac[a1 - a2]) % mod * fac[n - a1]) % mod;
    return out;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
  // freopen("prediction.in", "r", stdin);
   //freopen("prediction.out", "w", stdout);
#endif
    lo n;
    cin >> n;
    fac[0] = 1;
    vector<lo> a(n); FOR(i, n)
    {
        scanf("%d", &a[i]);
        fac[i + 1] = (fac[i] * (i + 1)) % mod;
    }
    sort(a.begin(), a.end());
    lo q; cin >> q;
    FOR(i, q) cin >> cant[i];
    if(cant[1] < cant[0]) swap(cant[1], cant[0]);
    memset(ch, 0, sizeof ch);
    done(0, n / 2, 0, a);
    done(n / 2 , n - n / 2, 1, a);
    lo delta = fac[n];
    FOR(i, (1<< (n / 2))) FOR(j, 1<<(n - n / 2))
    {
        li s = sum[i][0] + sum[j][1] ;
        if(s == cant[0] || s == cant[1])
        {
            delta = (delta + mod - (fac[nu[i][0] + nu[j][1]] * fac[n - nu[i][0] - nu[j][1]]) % mod) % mod;
        }
    }
    if(cant[0] != -1)
    {
        FOR(i, (1<<(n - n / 2)))
        {
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                ins(sum[i][1], sum[j][1], n - n / 2 - nu[i][1], n - n / 2 - nu[j][1]);
                if(!j)
                    break;
            }
        }

        FOR(i,( 1<<(n / 2) ))
        {
            if(sum[i][0] > cant[1])
                continue;
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                if(sum[j][0] > cant[0])
                    continue;
                lo wh = ghash(cant[1] - sum[i][0], cant[0] - sum[j][0]);
                FOR(q, sz(table[wh]))
                {

                    lo s1 = table[wh][q].first.first + n / 2 - nu[i][0];
                    lo s2 = table[wh][q].first.second + n / 2 - nu[j][0];
                   li numb =table[wh][q].second;
                    li val = getme(s1, s2, n);
                    delta = (delta + (val * numb) % mod) % mod;

                }
                if(!j)
                    break;
            }

        }
    }
    cout << delta;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#include <fstream>
#include <functional>
#define mp make_pair
#define pb push_back
#define lo long long int
#define li long long int
#define db long double
#define FOR(i, n) for(lo i = 0; i < (n); i++)
#define pi 3.14159265358979323
#define eps 1e-4
#define MN 10000001
#define sz(a) (lo) (a).size()
#define SM 1<<6
using namespace std;
const li INF = 2e18;

lo sum[1<<14][2];
lo nu[1<<14][2];
lo cant[2] = {-1, -1};
li fac[25];
lo mod = 1000000007;
void done(lo fr, lo to, lo ind, vector<lo> &a)
{
    lo n = sz(a);
    sum[0][ind] = 0;
    FOR(i, (1<<to))
    {

        FOR(j, to)
        {
            if(!(i & (1<<j)))
            {
                nu[i][ind]++;
                lo val = i ^ (1<<j);
                sum[val][ind] = (sum[i][ind] > cant[1] ? sum[i][ind] : sum[i][ind] + a[j + fr]);
            }
        }
    }
}

bool ch[1<<24];
lo nn[1<<24];
lo dp[1<<24];
vector< pair<pair<pair<lo, lo>, pair<lo, lo> >, lo > > table[MN];
lo ghash(lo s1, lo s2)
{
    li hi[2] = {s1, s2};
    //sort(hi, hi + 2);
    li base = mod % MN, now = base, out = 0, out2 = 0;
    FOR(i, 2)
    {
        now = (now * base) % MN;
        out = (out + ((hi[i] + 1) * now) % MN) % MN;
    }

    return out % MN;
}
void ins(lo s1, lo s2, lo c1, lo c2)
{
    lo out  = ghash(s1, s2);
    bool find = false;
    FOR(i, sz(table[out]))
    {
        if(table[out][i].first == mp(mp(s1, s2), mp(c1, c2)))
        {
            table[out][i].second ++;
            find = true;
            break;
        }
    }
if(!find)
    table[out].pb(mp(mp(mp(s1, s2), mp(c1, c2)), 1));
}
inline lo getme(li a1, li a2, li n)
{
    li out = ((fac[a2] * fac[a1 - a2]) % mod * fac[n - a1]) % mod;
    return out;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
  // freopen("prediction.in", "r", stdin);
   //freopen("prediction.out", "w", stdout);
#endif
    lo n;
    cin >> n;
    fac[0] = 1;
    vector<lo> a(n); FOR(i, n)
    {
        scanf("%d", &a[i]);
        fac[i + 1] = (fac[i] * (i + 1)) % mod;
    }
    sort(a.begin(), a.end());
    lo q; cin >> q;
    FOR(i, q) cin >> cant[i];
    if(cant[1] < cant[0]) swap(cant[1], cant[0]);
    memset(ch, 0, sizeof ch);
    done(0, n / 2, 0, a);
    done(n / 2 , n - n / 2, 1, a);
    lo delta = fac[n];
    FOR(i, (1<< (n / 2))) FOR(j, 1<<(n - n / 2))
    {
        li s = sum[i][0] + sum[j][1] ;
        if(s == cant[0] || s == cant[1])
        {
            delta = (delta + mod - (fac[nu[i][0] + nu[j][1]] * fac[n - nu[i][0] - nu[j][1]]) % mod) % mod;
        }
    }
    if(cant[0] != -1)
    {
        FOR(i, (1<<(n - n / 2)))
        {
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                ins(sum[i][1], sum[j][1], n - n / 2 - nu[i][1], n - n / 2 - nu[j][1]);
                if(!j)
                    break;
            }
        }

        FOR(i,( 1<<(n / 2) ))
        {
            if(sum[i][0] > cant[1])
                continue;
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                if(sum[j][0] > cant[0])
                    continue;
                lo wh = ghash(cant[1] - sum[i][0], cant[0] - sum[j][0]);
                FOR(q, sz(table[wh]))
                {
                    if(table[wh][q].first.first != mp(cant[1] - sum[i][0], cant[0] - sum[j][0]))
                        continue;
                    lo s1 = table[wh][q].first.second.first + n / 2 - nu[i][0];
                    lo s2 = table[wh][q].first.second.second + n / 2 - nu[j][0];
                   li numb =table[wh][q].second;
                    li val = getme(s1, s2, n);
                    delta = (delta + (val * numb) % mod) % mod;

                }
                if(!j)
                    break;
            }

        }
    }
    cout << delta;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#include <fstream>
#include <functional>
#define mp make_pair
#define pb push_back
#define lo long long int
#define li long long int
#define db long double
#define FOR(i, n) for(lo i = 0; i < (n); i++)
#define pi 3.14159265358979323
#define eps 1e-4
#define MN 10000001
#define sz(a) (lo) (a).size()
#define SM 1<<6
using namespace std;
const li INF = 2e18;

lo sum[1<<14][2];
lo nu[1<<14][2];
lo cant[2] = {-1, -1};
li fac[25];
lo mod = 1000000007;
void done(lo fr, lo to, lo ind, vector<lo> &a)
{
    lo n = sz(a);
    sum[0][ind] = 0;
    FOR(i, (1<<to))
    {

        FOR(j, to)
        {
            if(!(i & (1<<j)))
            {
                nu[i][ind]++;
                lo val = i ^ (1<<j);
                sum[val][ind] = (sum[i][ind] > cant[1] ? sum[i][ind] : sum[i][ind] + a[j + fr]);
            }
        }
    }
}

bool ch[1<<24];
lo nn[1<<24];
lo dp[1<<24];
vector< pair<pair<pair<lo, lo>, pair<lo, lo> >, lo > > table[MN];
lo ghash(lo s1, lo s2)
{
    li hi[2] = {s1, s2};
    //sort(hi, hi + 2);
    li base = mod % MN, now = base, out = 0, out2 = 0;
    FOR(i, 2)
    {
        now = (now * base) % MN;
        out = (out + ((hi[i] + 1) * now) % MN) % MN;
    }

    return out % MN;
}
void ins(lo s1, lo s2, lo c1, lo c2)
{
    lo out  = ghash(s1, s2);
    bool find = false;
    FOR(i, sz(table[out]))
    {
        if(table[out][i].first == mp(mp(s1, s2), mp(c1, c2)))
        {
            table[out][i].second ++;
            find = true;
            break;
        }
    }
if(!find)
    table[out].pb(mp(mp(mp(s1, s2), mp(c1, c2)), 1));
}
inline lo getme(li a1, li a2, li n)
{
    li out = ((fac[a2] * fac[a1 - a2]) % mod * fac[n - a1]) % mod;
    return out;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
  // freopen("prediction.in", "r", stdin);
   //freopen("prediction.out", "w", stdout);
#endif
    lo n;
    cin >> n;
    fac[0] = 1;
    vector<lo> a(n); FOR(i, n)
    {
        scanf("%d", &a[i]);
        fac[i + 1] = (fac[i] * (i + 1)) % mod;
    }
    sort(a.begin(), a.end());
    lo q; cin >> q;
    FOR(i, q) cin >> cant[i];
    if(cant[1] < cant[0]) swap(cant[1], cant[0]);
    if(cant[1] == cant[0])
        cant[0] = -1;
    memset(ch, 0, sizeof ch);
    done(0, n / 2, 0, a);
    done(n / 2 , n - n / 2, 1, a);
    lo delta = fac[n];
    FOR(i, (1<< (n / 2))) FOR(j, 1<<(n - n / 2))
    {
        li s = sum[i][0] + sum[j][1] ;
        if(s == cant[0] || s == cant[1])
        {
            delta = (delta + mod - (fac[nu[i][0] + nu[j][1]] * fac[n - nu[i][0] - nu[j][1]]) % mod) % mod;
        }
    }
    if(cant[0] != -1)
    {
        FOR(i, (1<<(n - n / 2)))
        {
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                ins(sum[i][1], sum[j][1], n - n / 2 - nu[i][1], n - n / 2 - nu[j][1]);
                if(!j)
                    break;
            }
        }

        FOR(i,( 1<<(n / 2) ))
        {
            if(sum[i][0] > cant[1])
                continue;
            for(lo j = i; j >= 0; j = ((j - 1) & i))
            {
                if(sum[j][0] > cant[0])
                    continue;
                lo wh = ghash(cant[1] - sum[i][0], cant[0] - sum[j][0]);
                FOR(q, sz(table[wh]))
                {
                    if(table[wh][q].first.first != mp(cant[1] - sum[i][0], cant[0] - sum[j][0]))
                        continue;
                    lo s1 = table[wh][q].first.second.first + n / 2 - nu[i][0];
                    lo s2 = table[wh][q].first.second.second + n / 2 - nu[j][0];
                   li numb =table[wh][q].second;
                    li val = getme(s1, s2, n);
                    delta = (delta + (val * numb) % mod) % mod;

                }
                if(!j)
                    break;
            }

        }
    }
    cout << delta;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo long long int
#define pi 3.14159265358979323
#define eps 1e-6
#define MN 1LL << 25
using namespace std;
const lo INF= 2e18;
lo used[MN], mod = 1000000007, num; vector<lo> fac;
lo bitcount(lo a, lo n)
{
	lo ans = 0;
	for(lo i = 0; i < n; i++)
	{
		if(a & (1LL << i)) ans++;
	}
	return ans;
}
lo find_nex(lo us, lo a, lo n)
{
	lo f = 0, now = 0;
	for(lo i = 0; i < n; i++)
	{
		if(!(us & (1LL << i )))
		{
			lo fuck = (a & (1LL << i));
			if(fuck)
			f = (f | (1LL << (now++)));
		}
	}
	f += 1;
	now = 0;
	for(lo i = 0; i < n; i++)
	{
		if(!(us & (1LL << i )))
		{
			lo fuck = (f & (1LL << now));
			if(fuck)
			   us = (us | (1LL << i));
			now++;
		}
	}
	return us;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	memset(used, 0, sizeof used);
	lo n, ans = 0;
	cin >> n;
	vector<lo> op(n);
	fac.resize(n + 1);
	fac[0] = 1;
	for(lo i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod;
	fac[0] = 0;
	for(lo i = 0; i < n;i++) cin >> op[i];
	sort(op.begin(), op.end());
	lo a;
	cin >> a;
	lo b[2] = {-1, -1};
	for(lo i = 0; i < a; i++) cin >> b[i];
	for(lo i = 1; i <= (1LL << (n)); i++)
	{
		lo sum = 0;
		num = 0;
		for(lo j = 0; j < n; j++)
		{
			if(i & (1LL << j )) sum += op[j], num++;
		}
		if(sum == b[0] || sum == b[1])
		{
			lo f= bitcount(used[i] ^ i, n), s = bitcount(used[i], n);
			if(!used[i]) f = 0, s = 0;
			ans = (ans + (fac[num]+mod - fac[f] * fac[s]) * fac[n - num]) % mod;
			if(!used[i]) used[i] = i;
		}
		if(used[i])
		{
		lo nex = find_nex(used[i], i, n);
		if(!used[nex])
		used[nex] = used[i];
		}
	}
	cout << (fac[n] + mod - ans) % mod;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo int
#define li long long int
#define db double
#define pi 3.14159265358979323
#define eps 1e-6
#define MN (1<<24) + 2
using namespace std;
const double INF= 2e50;

lo mod = 1000000007;
li cnt[MN];
bool ini[MN];
bool ch[MN];
li to_go[MN];
lo n;
void bfs(vector<lo> &op, li to)
{
    queue<li> q;
    memset(ini, false, sizeof ini);
    for(lo i = 0; i < (1LL << n); i++)
    {
        if(!ch[i])
        {
            to_go[i] = 0;
        }
    }
    for(lo i = 0; i < n; i++)
    {
        if(ch[1LL << i])
            continue;
        cnt[1LL << i] = op[i];
        q.push(1LL << i);
        ini[1LL << i] = true;
        to_go[1LL << i] = 1;
    }
    while(!q.empty())
    {
        li now = q.front();
        q.pop();
        if(cnt[now] == to)
        {
            ch[now]++;
            continue;
        }
        if(cnt[now] > to)
            continue;
        for(lo i = 0; i < n; i++)
        {
            if(!(now & (1LL << i)))
            {
                li nmask = (now | (1LL << i));
                if(ch[nmask])
                    continue;
                to_go[nmask] = (to_go[nmask] + to_go[now]) % mod;
                if(ini[nmask])
                    continue;
                cnt[nmask] = cnt[now] + cnt[1LL << i];
                ini[nmask] = true;
                q.push(nmask);
            }
        }
    }
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif

    cin >> n;
    vector<lo> op(n);
    for(lo i = 0; i < n; i++)
    {
        cin >> op[i];
    }
    sort(op.begin(), op.end());
    lo k;
    cin >> k;
    if(!k)
    {
        lo ans = 1;
        for(lo i = n; i >=1; i--)
        {
            ans = (ans * i) % mod;
        }
        cout << ans;
        return 0;
    }
    vector<lo> cant(k);
    for(lo i = 0; i < k; i++)
    {
        cin >> cant[i];
    }
    sort(cant.begin(), cant.end());
    memset(cnt, 0, sizeof cnt);
    memset(ch, false, sizeof ch);
    memset(to_go, 0, sizeof to_go);
    for(lo i = 0; i < k; i++)
    {
        bfs(op, cant[i]);
    }
    vector<li> fac(n + 1);
    fac[0] = 1;
    for(lo i = 1; i <= n; i++)
    {
        fac[i] = (fac[i - 1] * i) % mod;
    }
    li num = 0;
    for(lo i = 0; i < (1LL << n); i++)
    {
        if(ch[i])
        {
            lo one = 0;
            for(lo j = 0; j < n; j++)
            {
                if(i & (1LL << j))
                    one++;
            }
            num = (num + (to_go[i] * fac[n - one]) % mod) % mod;
        }
    }
    cout << (fac[n] + mod - num) % mod << endl;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo int
#define li long long int
#define db double
#define pi 3.14159265358979323
#define eps 1e-6
#define MN (1<<24) + 201001
using namespace std;
const double INF= 2e50;

lo mod = 1000000007;
li cnt[MN];
li fac[123];
bool ini[MN];
li to_go[MN];
lo q[MN];
lo n;
li ans = 0;
void bfs(vector<lo> &op, vector<li> cant)
{
    memset(ini, false, sizeof ini);
    lo f = 0, s = 0;
    for(lo i = 0; i < n; i++)
    {
        cnt[1 << i] = op[i];
        q[s++] = (1 << i);
        ini[1 << i] = true;
        to_go[1 << i] = 1;
    }
    lo mn = (lo) cant.size() - 1;
    while(s > f)
    {
        lo now = q[f++];
        if(cnt[now] == cant[0] || cnt[now] == cant[mn])
        {
            continue;
        }
        if(cnt[now] > cant[mn])
        {
            lo one = 0;
            for(lo j = 0; j < n; j++)
            {
                if(now & (1<<j))
                    one++;
            }
            ans = (ans + fac[n - one] * to_go[now]) % mod;
            continue;
        }
        for(lo i = 0; i < n; i++)
        {
            if(!(now & (1 << i)))
            {
                lo nmask = (now | (1 << i));
                to_go[nmask] = (to_go[nmask] + to_go[now]) % mod;
                if(ini[nmask])
                    continue;
                cnt[nmask] = cnt[now] + cnt[1 << i];
                ini[nmask] = true;
                q[s++] = (nmask);
            }
        }
    }
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
    cin >> n;
    vector<lo> op(n);
    bool ag = false;
    for(lo i = 0; i < n; i++)
    {
        cin >> op[i];
        if(op[i] != 1)
        {
            ag = true;
        }
    }
    sort(op.begin(), op.end());
    lo k;
    cin >> k;
    if(!k)
    {
        lo ans = 1;
        for(lo i = n; i >=1; i--)
        {
            ans = (ans * i) % mod;
        }
        cout << ans;
        return 0;
    }
    if(!ag)
    {
        cout << 0;
        return 0;
    }
    vector<li> cant(k);
    for(lo i = 0; i < k; i++)
    {
        cin >> cant[i];
    }
    fac[0] = 1;
    for(lo i = 1; i <= n; i++)
    {
        fac[i] = (fac[i - 1] * i) % mod;
    }
    sort(cant.begin(), cant.end());
    memset(cnt, 0, sizeof cnt);
    memset(to_go, 0, sizeof to_go);
    bfs(op, cant);
    cout << ans;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo long long int
#define pi 3.14159265358979323
#define eps 1e-6
#define MN 1000
using namespace std;
const lo INF= 2e18;
lo mod = 1000000007, te[2] = {-1, -1}, fac[MN], ans = 0, n, used[MN];
vector<lo> op;
vector<map<lo, map<lo, pair<lo, lo> > > >q(2);
void dfs(lo now, lo left)
{
	if(now == te[0] || now == te[1])
	{
		ans = (ans + fac[n - left]) % mod;
		return;
	}
	for(lo i = 0; i < n; i++)
	{
		if(now + op[i] > te[1]) return;
		if(!used[i])
		{
			used[i]++;
		    dfs(now + op[i],  left + 1);
			used[i]--;
		}
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	memset(used,0 , sizeof used);
	cin >> n;
	op.resize(n);
	for(lo i = 0; i < n; i++)
	{
		cin >> op[i];
	}
	fac[0] = 1;
	for(lo i = 1; i <= n;i++) fac[i] = (fac[i - 1] * i) % mod;
	sort(op.begin(), op.end());
	lo z;
	cin >> z;
	for(lo i = 0; i < z; i++) cin >> te[i];
	sort(te, te + 2);
	for(lo i = 0; i < n; i++)
	{
		used[i]++;
	    dfs(op[i], 1);
		used[i]--;
	}
	cout << (fac[n] + mod - ans) % mod;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo long long int
#define pi 3.14159265358979323
#define eps 1e-6
#define MN 1LL << 25
using namespace std;
const lo INF= 2e18;
lo used[MN], mod = 1000000007, num; vector<lo> fac;
lo bitcount(lo a, lo n)
{
	lo ans = 0;
	for(lo i = 0; i < n; i++)
	{
		if(a & (1LL << i)) ans++;
	}
	return ans;
}
lo find_nex(lo us, lo a, lo n)
{
	lo f = 0, now = 0;
	for(lo i = 0; i < n; i++)
	{
		if(!(us & (1LL << i )))
		{
			lo fuck = (a & (1LL << i));
			if(fuck)
			f = (f | (1LL << (now++)));
		}
	}
	f += 1;
	now = 0;
	for(lo i = 0; i < n; i++)
	{
		if(!(us & (1LL << i )))
		{
			lo fuck = (f & (1LL << now));
			if(fuck)
			   us = (us | (1LL << i));
			now++;
		}
	}
	return us;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	memset(used, 0, sizeof used);
	lo n, ans = 0;
	cin >> n;
	vector<lo> op(n);
	fac.resize(n + 1);
	fac[0] = 1;
	for(lo i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod;
	fac[0] = 0;
	for(lo i = 0; i < n;i++) cin >> op[i];
	sort(op.begin(), op.end());
	lo a;
	cin >> a;
	lo b[2] = {-1, -1};
	for(lo i = 0; i < a; i++) cin >> b[i];
	for(lo i = 1; i <= (1LL << (n)); i++)
	{
		lo sum = 0;
		num = 0;
		for(lo j = 0; j < n; j++)
		{
			if(i & (1LL << j )) sum += op[j], num++;
		}
		if(sum == b[0] || sum == b[1])
		{
			lo f= bitcount(used[i] ^ i, n), s = bitcount(used[i], n);
			if(!used[i]) f = 0, s = 0;
			ans = (ans + (fac[num]+mod - fac[f] * fac[s]) * fac[n - num]) % mod;
			if(!used[i]) used[i] = i;
		}
		lo nex = find_nex(used[i], i, n);
		if(!used[nex])
		used[nex] = used[i];
	}
	cout << (fac[n] + mod - ans) % mod;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo long long int
#define pi 3.14159265358979323
#define eps 1e-6
#define MN 1LL << 25
using namespace std;
const lo INF= 2e18;
lo used[MN], mod = 1000000007, num; vector<lo> fac;
void bit(lo a, lo n, lo cur)
{
	if(n < 0)
	{
		if(!used[a])
		   used[a] = (fac[num] * fac[cur]) % mod;
		return;
	}
	if(a & (1LL << n)) bit(a, n - 1, cur);
	else
	{
		bit(a, n - 1, cur);
		a = ( a | (1LL << n));
		bit(a, n - 1, cur + 1);
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	memset(used, 0, sizeof used);
	lo n, ans = 0;
	cin >> n;
	vector<lo> op(n);
	fac.resize(n + 1);
	fac[0] = 1;
	for(lo i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod;
	for(lo i = 0; i < n;i++) cin >> op[i];
	sort(op.begin(), op.end());
	lo a;
	cin >> a;
	lo b[2] = {-1, -1};
	for(lo i = 0; i < a; i++) cin >> b[i];
	for(lo i = 1; i <= (1LL << (n)); i++)
	{
		lo sum = 0;
		num = 0;
		for(lo j = 0; j < n; j++)
		{
			if(i & (1LL << j )) sum += op[j], num++;
		}
		if(sum == b[0] || sum == b[1])
		{
			ans = (ans + (fac[num]+mod - used[i]) * fac[n - num]) % mod;
			bit(i, n - 1, 0);
		}
	}
	cout << (fac[n] + mod - ans) % mod;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo long long int
#define pi 3.14159265358979323
#define eps 1e-6
#define MN 1LL << 25
using namespace std;
const lo INF= 2e18;
lo used[MN], mod = 1000000007;
void bit(lo a, lo n, lo cur)
{
	if(n < 0)
	{
		if(!used[a])
		   used[a] = (used[a] + (!cur ? 0 : 1LL << (cur - 1)));
		return;
	}
	if(a & (1LL << n)) bit(a, n - 1, cur);
	else
	{
		bit(a, n - 1, cur);
		a = ( a | (1LL << n));
		bit(a, n - 1, cur + 1);
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	memset(used, 0, sizeof used);
	lo n, ans = 0;
	cin >> n;
	vector<lo> op(n), fac(n + 1);
	fac[0] = 1;
	for(lo i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod;
	for(lo i = 0; i < n;i++) cin >> op[i];
	sort(op.begin(), op.end());
	lo a;
	cin >> a;
	lo b[2] = {-1, -1};
	for(lo i = 0; i < a; i++) cin >> b[i];
	for(lo i = 1; i <= (1LL << (n)); i++)
	{
		lo sum = 0, num = 0;
		for(lo j = 0; j < n; j++)
		{
			if(i & (1LL << j )) sum += op[j], num++;
		}
		if(sum == b[0] || sum == b[1])
		{
			ans = (ans + fac[num] * fac[n - num] + mod - used[i]) % mod;
			bit(i, n - 1, 0);
		}
	}
	cout << (fac[n] + mod - ans) % mod;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <set>
#include <ctime>
#include <fstream>
#define  inf 0XFFFFFFFll
#define  N   666666
#define  mod 1000000007ll
#define  LL  long long
#define  ULL unsigned long long
#define  us  unsigned short int
#define  eps 1e-12
#define  pi  acos(-1.0)
//#define  TXT

using namespace std;

#ifdef TXT
ifstream fi("in.txt");
#define  cin  fi
#endif

int n, k;

LL a[30], dp[1<<24], b[2];

int main()
{
    cin >> n;
    for (int i=0; i<n; i++) cin >> a[i];
    cin >> k;
    for (int i=0; i<k; i++) cin >> b[i];
    for (int i=1; i<(1<<n); i++) {
        LL s = 0;
        for (int j=0; j<24; j++) {
            if (1&(i>>j))
                s += a[j];
        }
        for (int j=0; j<k; j++) {
            if (s == b[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&(i>>j)) {
                dp[i] += dp[i^(1<<j)];
                if (dp[i] >= mod)
                    dp[i] %= mod;
            }
        }
    }
    cout << dp[(1<<n)-1] << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <set>
#include <ctime>
#include <fstream>
#define  inf 0XFFFFFFFll
#define  N   666666
#define  mod 1000000007ll
#define  LL  long long
#define  ULL unsigned long long
#define  us  unsigned short int
#define  eps 1e-12
#define  pi  acos(-1.0)
//#define  TXT

using namespace std;

#ifdef TXT
ifstream fi("in.txt");
#define  cin  fi
#endif

int n, k;

LL a[1<<24], dp[1<<24], b[2];

int main()
{
    cin >> n;
    for (int i=0; i<n; i++) cin >> a[1<<i];
    cin >> k;
    for (int i=0; i<k; i++) cin >> b[i];
    for (int i=1; i<(1<<n); i++) {
        LL s = 0;
        int t = i;
        while (t) {
            s += (a[t&(-t)]);
            t -= t&(-t);
        }
        for (int j=0; j<k; j++) {
            if (s == b[j]) {
                dp[i] = -1;
                break;
            }
        }
    }
    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&(i>>j)) {
                dp[i] += dp[i^(1<<j)];
            }
        }
        if (dp[i] >= mod)
                dp[i] %= mod;
    }
    cout << dp[(1<<n)-1] << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <set>
#include <ctime>
#include <fstream>
#define  inf 0XFFFFFFFll
#define  N   666666
#define  mod 1000000007ll
#define  LL  long long
#define  ULL unsigned long long
#define  us  unsigned short int
#define  eps 1e-12
#define  pi  acos(-1.0)
//#define  TXT

using namespace std;

#ifdef TXT
ifstream fi("in.txt");
#define  cin  fi
#endif

int n, k;

LL a[30], dp[1<<24], b[2];

int main()
{
    cin >> n;
    for (int i=0; i<n; i++) cin >> a[i];
    cin >> k;
    for (int i=0; i<k; i++) cin >> b[i];
    for (int i=1; i<(1<<n); i++) {
        LL s = 0;
        for (int j=0; j<24; j++) {
            if (1&(i>>j))
                s += a[j];
        }
        for (int j=0; j<k; j++) {
            if (s == b[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&(i>>j)) {
                dp[i] += dp[i^(1<<j)];

            }
        }if (dp[i] >= mod)
                    dp[i] %= mod;
    }
    cout << dp[(1<<n)-1] << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <set>
#include <ctime>
#include <fstream>
#define  inf 0XFFFFFFFll
#define  N   666666
#define  mod 1000000007ll
#define  LL  long long
#define  ULL unsigned long long
#define  us  unsigned short int
#define  eps 1e-12
#define  pi  acos(-1.0)
//#define  TXT

using namespace std;

#ifdef TXT
ifstream fi("in.txt");
#define  cin  fi
#endif

LL a[30], sum[1<<24], jie[30];
int n, b[1<<24], num[1<<24];

map<LL, vector<int> > mp;

int main()
{
    int n; cin >> n;
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=1; i<(1<<n); i++) {
        for (int j=0; j<n; j++) {
            b[i] += 1&(i>>j);
            if (1&(i>>j))
                sum[i] += a[j];
        }
        mp[sum[i]].push_back(i);
    }

    jie[0] = 1;
    for (LL i=1; i<=24; i++)
        jie[i] = (jie[i-1]*i)%mod;

    int k;
    cin >> k;
    LL k0 = -1, k1 = -1;
    if (k == 1) cin >> k0;
    if (k == 2) cin >> k0 >> k1;
    if (k == 2 && k0 > k1) swap(k0, k1);
    if (k == 2 && k0 == k1) k=1;

    if (k == 0) {
        cout << jie[n] << endl;
        return 0;
    }

    LL ans = 0;
    for (int i=1; i<(1<<n); i++) {
        if (sum[i] == k0 || sum[i] == k1) {
            num[i]++;
            ans += jie[b[i]] * jie[n-b[i]];
            ans %= mod;
        }
    }

    mp[k0].push_back(-1);
    mp[sum[(1<<n)-1]-k1].push_back(-1);

    for (vector<int>::iterator p1=mp[k0].begin(); p1!=mp[k0].end(); p1++) {
        for (vector<int>::iterator p2=mp[sum[(1<<n)-1]-k1].begin(); p2!=mp[sum[(1<<n)-1]-k1].end(); p2++) {
            if ((*p1) == -1 || (*p2) == -1)
                continue;
            int i = *p1, j = *p2;
            if (b[i]+b[j] != b[i|j])
                continue;
            ans -= jie[b[i]]*jie[b[j]]*jie[n-b[i]-b[j]];
        }
    }

    cout << jie[n] - ans << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <set>
#include <ctime>
#include <fstream>
#define  inf 0XFFFFFFFll
#define  N   666666
#define  mod 1000000007ll
#define  LL  long long
#define  ULL unsigned long long
#define  us  unsigned short int
#define  eps 1e-12
#define  pi  acos(-1.0)
//#define  TXT

using namespace std;

#ifdef TXT
ifstream fi("in.txt");
#define  cin  fi
#endif

int n, k;

LL a[30], dp[1<<24], b[2];

int main()
{
    cin >> n;
    for (int i=0; i<n; i++) cin >> a[i];
    cin >> k;
    for (int i=0; i<k; i++) cin >> b[i];
    for (int i=1; i<(1<<n); i++) {
        LL s = 0;
        for (int j=0; j<24; j++) {
            if (1&(i>>j))
                s += a[j];
        }
        for (int j=0; j<k; j++) {
            if (s == b[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&(i>>j)) {
                dp[i] += dp[i^(1<<j)];
                dp[i] %= mod;
            }
        }
    }
    cout << dp[(1<<n)-1] << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <set>
#include <ctime>
#include <fstream>
#define  inf 0XFFFFFFFll
#define  N   666666
#define  mod 1000000007ll
#define  LL  long long
#define  ULL unsigned long long
#define  us  unsigned short int
#define  eps 1e-12
#define  pi  acos(-1.0)
//#define  TXT

using namespace std;

#ifdef TXT
ifstream fi("in.txt");
#define  cin  fi
#endif

int n, k;

LL a[1<<24], dp[1<<24], b[2];

int main()
{
    cin >> n;
    for (int i=0; i<n; i++) cin >> a[1<<i];
    cin >> k;
    for (int i=0; i<k; i++) cin >> b[i];
    for (int i=1; i<(1<<n); i++) {
        LL s = 0;
        int t = i;
        while (t) {
            s += (a[t&(-t)]);
            t -= t&(-t);
        }
        for (int j=0; j<k; j++) {
            if (s == b[i]) {
                dp[i] = -1;
                break;
            }
        }
    }
    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&(i>>j)) {
                dp[i] += dp[i^(1<<j)];
            }
        }
        if (dp[i] >= mod)
                dp[i] %= mod;
    }
    cout << dp[(1<<n)-1] << endl;
}


#include <cstdio>
#define MOD 1000000007
#define MAXN 24
#define MAXK 2
int N,M,A[MAXN],K,B[MAXK];
long long Sum[1<<MAXN],Dp[1<<MAXN]={1};
bool flag;
int main()
{
    scanf("%d",&N);
    for(int n=0;n<N;++n)
    {
        scanf("%d",A+n);
        Sum[1<<n]=A[n];
    }
    scanf("%d",&K);
    for(int k=0;k<K;++k)
        scanf("%d",B+k);
    M=(1<<N)-1;
    for(int m=3;m<=M;++m)
    {
        int mm=m-1;
        Sum[m]=Sum[m&mm]+Sum[m&(~mm)];
    }
    for(int m=1;m<=M;++m)
    {
        flag=false;
        for(int k=0;k<K;++k)
            if(Sum[m]==B[k])
                flag=true;
        if(flag)
            continue;
        int nn=1;
        for(int n=0;n<N;++n,nn<<=1)
        {
            if(m&nn)
            {
                Dp[m]=(Dp[m]+Dp[m^nn])%MOD;
            }
        }
    }
    printf("%I64d\n",Dp[M]);
    return 0;
}


#include <stdio.h>
#define MOD 1000000007
#define MAXN 24
#define MAXK 2
int N,M,A[MAXN],K,B[MAXK];
long long Sum[1<<MAXN],Dp[1<<MAXN];
bool flag;
int main()
{
    Dp[0]=1;
    scanf("%d",&N);
    for(int n=0;n<N;++n)
    {
        scanf("%d",A+n);
        Sum[1<<n]=A[n];
    }
    scanf("%d",&K);
    for(int k=0;k<K;++k)
        scanf("%d",B+k);
    M=(1<<N)-1;
    for(int m=3;m<=M;++m)
    {
        int mm=m-1;
        Sum[m]=Sum[m&mm]+Sum[m&(~mm)];
    }
    for(int m=1;m<=M;++m)
    {
        flag=false;
        for(int k=0;k<K;++k)
            if(Sum[m]==B[k])
                flag=true;
        if(flag)
            continue;
        for(int nn=1;nn<m;nn<<=1)
            if(m&nn)
                Dp[m]=(Dp[m]+Dp[m^nn])%MOD;
    }
    printf("%I64d\n",Dp[M]);
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
#define MOD 1000000007
#define MAXN 24
#define MAXK 2
int N,M,A[MAXN],K,B[MAXK];
long long Sum[1<<MAXN],Dp[1<<MAXN]={1};
bool flag;
int main()
{
    scanf("%d",&N);
    for(int n=0;n<N;++n)
    {
        scanf("%d",A+n);
        Sum[1<<n]=A[n];
    }
    scanf("%d",&K);
    for(int k=0;k<K;++k)
        scanf("%d",B+k);
    M=(1<<N)-1;
    for(int m=3;m<=M;++m)
    {
        int mm=m-1;
        Sum[m]=Sum[m&mm]+Sum[m&(~mm)];
    }
    for(int m=1;m<=M;++m)
    {
        flag=false;
        for(int k=0;k<K;++k)
            if(Sum[m]==B[k])
                flag=true;
        if(flag)
            continue;
        int nn=1;
        for(int n=0;n<N;++n,nn<<=1)
        {
            if(m&nn)
            {
                Dp[m]=(Dp[m]+Dp[m^nn])%MOD;
            }
        }
    }
    printf("%I64d\n",Dp[M]);
    return 0;
}


#include <stdio.h>
#define MOD 1000000007
#define MAXN 24
#define MAXK 2
int N,M,A[MAXN],K,B[MAXK];
long long Sum[1<<MAXN],Dp[1<<MAXN];
bool flag;
int main()
{
    DP[0]=1;
    scanf("%d",&N);
    for(int n=0;n<N;++n)
    {
        scanf("%d",A+n);
        Sum[1<<n]=A[n];
    }
    scanf("%d",&K);
    for(int k=0;k<K;++k)
        scanf("%d",B+k);
    M=(1<<N)-1;
    for(int m=3;m<=M;++m)
    {
        int mm=m-1;
        Sum[m]=Sum[m&mm]+Sum[m&(~mm)];
    }
    for(int m=1;m<=M;++m)
    {
        flag=false;
        for(int k=0;k<K;++k)
            if(Sum[m]==B[k])
                flag=true;
        if(flag)
            continue;
        int nn=1;
        for(int n=0;n<N;++n,nn<<=1)
        {
            if(m&nn)
            {
                Dp[m]=(Dp[m]+Dp[m^nn])%MOD;
            }
        }
    }
    printf("%I64d\n",Dp[M]);
    return 0;
}


#include <stdio.h>
#define MOD 1000000007
#define MAXN 24
#define MAXK 2
int N,M,A[MAXN],K,B[MAXK];
long long Sum[1<<MAXN],Dp[1<<MAXN];
bool flag;
int main()
{
    Dp[0]=1;
    scanf("%d",&N);
    for(int n=0;n<N;++n)
    {
        scanf("%d",A+n);
        Sum[1<<n]=A[n];
    }
    scanf("%d",&K);
    for(int k=0;k<K;++k)
        scanf("%d",B+k);
    M=(1<<N)-1;
    for(int m=3;m<=M;++m)
    {
        int mm=m-1;
        Sum[m]=Sum[m&mm]+Sum[m&(~mm)];
    }
    for(int m=1;m<=M;++m)
    {
        flag=false;
        for(int k=0;k<K;++k)
            if(Sum[m]==B[k])
                flag=true;
        if(flag)
            continue;
        for(int nn=1;nn<=m;nn<<=1)
            if(m&nn)
                Dp[m]=(Dp[m]+Dp[m^nn])%MOD;
    }
    printf("%I64d\n",Dp[M]);
    return 0;
}


#include <stdio.h>
#define MOD 1000000007
#define MAXN 24
#define MAXK 2
int N,M,A[MAXN],K,B[MAXK];
long long Sum[1<<MAXN],Dp[1<<MAXN];
bool flag;
int main()
{
    Dp[0]=1;
    scanf("%d",&N);
    for(int n=0;n<N;++n)
    {
        scanf("%d",A+n);
        Sum[1<<n]=A[n];
    }
    scanf("%d",&K);
    for(int k=0;k<K;++k)
        scanf("%d",B+k);
    M=(1<<N)-1;
    for(int m=3;m<=M;++m)
    {
        int mm=m-1;
        Sum[m]=Sum[m&mm]+Sum[m&(~mm)];
    }
    for(int m=1;m<=M;++m)
    {
        flag=false;
        for(int k=0;k<K;++k)
            if(Sum[m]==B[k])
                flag=true;
        if(flag)
            continue;
        int nn=1;
        for(int n=0;n<N;++n,nn<<=1)
        {
            if(m&nn)
            {
                Dp[m]=(Dp[m]+Dp[m^nn])%MOD;
            }
        }
    }
    printf("%I64d\n",Dp[M]);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz(a) ((int)(a).size())
#define mp make_pair

typedef pair<int,int> pint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

#define MOD 1000000007

#include <iostream>
int n,k;
ll v[30],vn[3];
ull dp[1<<25];

int main()
{
	scanf("%d",&n);
	for (int i=0; i<n; i++)
		scanf("%lld",v+i);
	scanf("%d",&k);
	vn[0]=vn[1]=-1;
	for (int i=0; i<k; i++)
		scanf("%lld",vn+i);

	dp[(1<<n)-1]=1;
	int s;
	ull ans;
	for (int m=(1<<n)-2; m>=0; m--)
	{
		s=ans=0;
		for (int i=0; i<n; i++)
			if (m&(1<<i))
				s+=v[i];
			else
				ans=(ans+dp[m|(1<<i)])%MOD;
		dp[m]=(s==vn[0]||s==vn[1]?0:ans);
	}
	cout<<dp[0]<<endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz(a) ((int)(a).size())
#define mp make_pair

typedef pair<int,int> pint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

#define MOD 1000000007

int n,k,sum;
ll v[30],vn[3];
ull dp[1<<25];

int main()
{
	scanf("%d",&n);
	int a=1;
	for (int i=0; i<n; i++)
		scanf("%lld",v+i),sum+=v[i],a*=2;
	scanf("%d",&k);
	vn[0]=vn[1]=-1;
	for (int i=0; i<k; i++)
		scanf("%lld",vn+i);

	if (sum==vn[0]||sum==vn[1])printf("0\n");
	else
	{
		a--;
		dp[0]=1;
		int s;
		ull ans;
		for (int m=1; m<=a; m++)
		{
			ans=0,s=sum;
			for (int i=m; i>0; i-=(i&-i))
				ans=(ans+dp[m^(i&-i)])%MOD,s-=v[31-__builtin_clz(i&-i)];
			dp[m]=(s==vn[0]||s==vn[1]?0:ans);
		}
		printf("%llu\n",dp[a]);
	}

	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz(a) ((int)(a).size())
#define mp make_pair

typedef pair<int,int> pint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

#define MOD 1000000007

int n,k,sum;
ll v[30],vn[3];
ull dp[1<<25];

int main()
{
	scanf("%d",&n);
	int a=1;
	for (int i=0; i<n; i++)
		scanf("%lld",v+i),sum+=v[i],a*=2;
	scanf("%d",&k);
	vn[0]=vn[1]=-1;
	for (int i=0; i<k; i++)
		scanf("%lld",vn+i);

	a--;
	dp[0]=1;
	int s;
	ull ans;
	for (int m=1; m<=a; m++)
	{
		ans=0,s=sum;
		for (int i=m; i>0; i-=(i&-i))
			ans=(ans+dp[m^(i&-i)])%MOD,s-=v[31-__builtin_clz(i&-i)];
		dp[m]=(s==vn[0]||s==vn[1]?0:ans);
	}

	printf("%llu\n",dp[a]);

	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

//#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz(a) ((int)(a).size())
#define mp make_pair

typedef pair<int,int> pint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

#define MOD 1000000007

#include <iostream>
int n,k;
ll v[30],vn[5];
ull dp[1<<25];

ull f(int m, int s)
{
	if (m>=(1<<n)||m<0)return 0;
	if (dp[m]==MOD+2)
	{
		for (int i=0; i<k; i++)
			if (s==vn[i])
				return 0;
		ull ans=0;
		for (int i=0; i<(1<<n); i++)
			if (!(m&(1<<i)))
				ans=(ans+f(m|(1<<i),s+v[i]))%MOD;
		return dp[m]=ans;
	}
	return dp[m];
}
int main()
{
	scanf("%d",&n);
	for (int i=0; i<n; i++)
		scanf("%lld",v+i);
	scanf("%d",&k);
	for (int i=0; i<k; i++)
		scanf("%lld",vn+i);

	dp[(1<<n)-1]=1;
	for (int i=(1<<n)-2; i>=0; i--)
		dp[i]=MOD+2;
	cout<<f(0,0)<<endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz(a) ((int)(a).size())
#define mp make_pair

typedef pair<int,int> pint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

#define MOD 1000000007

#include <iostream>
int n,k;
ll v[30],vn[3];
ull dp[1<<25];

int main()
{
	scanf("%d",&n);
	for (int i=0; i<n; i++)
		scanf("%lld",v+i);
	scanf("%d",&k);
	vn[0]=vn[1]=-1;
	for (int i=0; i<k; i++)
		scanf("%lld",vn+i);

	dp[(1<<n)-1]=1;
	int s;
	ull ans;
	for (int m=(1<<n)-2; m>=0; m--)
	{
		s=ans=0;
		for (int i=0; i<n; i++)
			if (m&(1<<i))
			{
				s+=v[i];
				if (s==vn[0]||s==vn[1])
				{
					ans=0;
					break;
				}
			}
			else
				ans=(ans+dp[m|(1<<i)])%MOD;
		dp[m]=ans;
	}
	cout<<dp[0]<<endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz(a) ((int)(a).size())
#define mp make_pair

typedef pair<int,int> pint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

#define MOD 1000000007

int n,k;
ll v[30],vn[3];
ull dp[1<<25];

int main()
{
	scanf("%d",&n);
	int b=1;
	for (int i=0; i<n; i++,b*=2)
		scanf("%lld",v+i);
	scanf("%d",&k);
	vn[0]=vn[1]=-1;
	for (int i=0; i<k; i++)
		scanf("%lld",vn+i);

	int s,i;
	dp[b-1]=1;
	ull ans;
	for (int m=b-2; m>=0; m--)
	{
		s=ans=0;
		for (i=0,b=1; i<n; i++,b*=2)
			if (m&b)
				s+=v[i];
			else
				ans=(ans+dp[m|b])%MOD;
		dp[m]=(s==vn[0]||s==vn[1]?0:ans);
	}
	printf("%llu\n",dp[0]);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz(a) ((int)(a).size())
#define mp make_pair

typedef pair<int,int> pint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

#define MOD 1000000007

#include <iostream>
int n,k;
ll v[30],vn[3];
ull dp[1<<25];

int main()
{
	scanf("%d",&n);
	for (int i=0; i<n; i++)
		scanf("%lld",v+i);
	scanf("%d",&k);
	vn[0]=vn[1]=-1;
	for (int i=0; i<k; i++)
		scanf("%lld",vn+i);

	int s,b=(1<<n)-1,i;
	dp[b]=1;
	ull ans;
	for (int m=b-1; m>=0; m--)
	{
		s=ans=0;
		for (i=0,b=1; i<n; i++,b*=2)
			if (m&b)
				s+=v[i];
			else
				ans=(ans+dp[m|b])%MOD;
		dp[m]=(s==vn[0]||s==vn[1]?0:ans);
	}
	cout<<dp[0]<<endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz(a) ((int)(a).size())
#define mp make_pair

typedef pair<int,int> pint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

#define MOD 1000000007

int n,k;
ll v[30],vn[5];
ull dp[1<<25];

ull f(int m, int s)
{
	if (dp[m]==MOD+2)
	{
		for (int i=0; i<k; i++)
			if (s==vn[i])
				return 0;
		ull ans=0;
		for (int i=0; i<(1<<n); i++)
			if (!(m&(1<<i)))
				ans=(ans+f(m|(1<<i),s+v[i]))%MOD;
		return dp[m]=ans;
	}
	return dp[m];
}
#include <iostream>
int main()
{
	scanf("%d",&n);
	for (int i=0; i<n; i++)
		scanf("%lld",v+i);
	scanf("%d",&k);
	for (int i=0; i<k; i++)
		scanf("%lld",vn+i);

	dp[(1<<n)-1]=1;
	for (int i=(1<<n)-2; i>=0; i--)
		dp[i]=MOD+2;
	cout<<f(0,0)<<endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

//#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz(a) ((int)(a).size())
#define mp make_pair

typedef pair<int,int> pint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

#define MOD 1000000007

#include <iostream>
int n,k;
ll v[30],vn[5];
ull dp[1<<25];

ull f(int m, int s)
{
	if (dp[m]==MOD+2)
	{
		for (int i=0; i<k; i++)
			if (s==vn[i])
				return 0;
		ull ans=0;
		for (int i=0; i<n; i++)
			if (!(m&(1<<i)))
				ans=(ans+f(m|(1<<i),s+v[i]))%MOD;
		return dp[m]=ans;
	}
	return dp[m];
}
int main()
{
	scanf("%d",&n);
	for (int i=0; i<n; i++)
		scanf("%lld",v+i);
	scanf("%d",&k);
	for (int i=0; i<k; i++)
		scanf("%lld",vn+i);

	dp[(1<<n)-1]=1;
	for (int i=(1<<n)-2; i>=0; i--)
		dp[i]=MOD+2;
	cout<<f(0,0)<<endl;
	return 0;
}


#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];
LL s[1<<N];
map<LL,int>  M;
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){DI(x);M[x]=1;}
	MS0(f);f[0]=1;
	rep(i,nn)if(M[s[i]])f[i]=0;else{
		rep(j,n){
			if((i&(1<<j))==0)(f[i+(1<<j)]+=f[i])%=MOD;
		}

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


#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];
map<LL,int>  M;
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[m]);
	MS0(f);f[0]=1;
	rep(i,nn){
		rep(j,m)if(s[i]==b[j])f[i]=0;
		rep(j,n){
			if((i&(1<<j))==0)(f[i+(1<<j)]+=f[i])%=MOD;
		}

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


#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;
		rep(j,n){
			if((i&(1<<j))==0)(f[i+(1<<j)]+=f[i])%=MOD;
		}

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


#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 a[N],b[2];
LL f[1<<N],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<iostream>
#include<algorithm>
#include<cstdio>
#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];
LL s[1<<N];
map<LL,int>  M;
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){DI(x);M[x]=1;}
	MS0(f);f[0]=1;
	rep(i,nn)if(M[s[i]])f[i]=0;else{
		rep(j,n){
			if((i&(1<<j))==0)(f[i+(1<<j)]+=f[i])%=MOD;
		}

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


#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 a[N],b[2];
LL f[1<<N],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;
}