1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<LL,LL> PLL;
typedef vector<PIL> VPIL;
typedef vector<PLL> VPLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define MOD(x) x%=INF
#define ALL(c) (c).begin(),(c).end()
const int INF=1000000007;
//#define FOREACH(it,c,i) for(auto it=(c).begin()+(i);it!=(c).end();++it)
#define FOREACH(it,c) for(auto it=(c).begin();it!=(c).end();++it)
#define SIZE(c) (int)(c).size()
int pot(int n)
{
    LL res=1,pt=2;
    while(n){
        if(n&1)
            res=res*pt%INF;
        pt=pt*pt%INF;
        n>>=1;
    }
  //  printf("/%lld/\n",res);
    return res;
}
//void prin(VVLL& t){
//    for(auto& it:t){
//        for(auto& it2:it)
//            printf("%lld ",it2);
//        printf("\n");
//    }
//}
int main()
{
    char ch[3][10005];
    int r[4],od[4]={},i,j,n,q;
    scanf("%d",&n);
    const int MAX=n;
    VVI dn(MAX+1,VI(MAX+1));
    for(i=0;i<=MAX;++i)
        dn[i][0]=1;
    for(i=1;i<=MAX;++i)
        for(j=1;j<=i;++j){
            dn[i][j]=dn[i-1][j]+dn[i-1][j-1];
            if(dn[i][j]>=INF)
                dn[i][j]-=INF;
            }
    for(i=0;i<3;++i)
        scanf("%d%s",r+i+1,ch[i]);
    for(i=0;i<n;++i){
        q=ch[0][i]+2*ch[1][i]+4*ch[2][i]-'0'*7;
        if(q>3)
            q=7-q;
        od[q]++;
    }
    for(i=0;i<4;++i){
        r[i]=n-1-r[i];
  //      printf("%d %d\n",od[i],r[i]);
    }
  //  printf("\n");
    const int roz=od[0]+od[1]/2+5;
    VVLL cd(od[0]+1,VLL(od[1]+1)),pra(roz,VLL(od[1]+2)),prb(roz,VLL(od[1]+2));
    for(i=0;i<=od[0];++i)
    {
        for(j=0;j<=od[1];++j)
        {
            cd[i][j]=(LL)dn[od[0]][i]*dn[od[1]][j]%INF;
   //         printf("%d ",cd[i][j]);
        }
   //     puts("");
    }
 //   puts("");
    for(i=1;i<roz;++i)
    {
        int n=od[1];
        for(j=0;j<=n;++j){
            pra[i][j]=prb[i-1][j]+prb[i-1][j+1]-pra[i-1][j];
            if(i-1<=od[0])
                pra[i][j]+=cd[i-1][j];
            MOD(pra[i][j]);
            if(pra[i][j]<0)
                pra[i][j]+=INF;
        }
        for(j=1;j<=n;++j){
            prb[i][j]=pra[i][j]+pra[i][j-1]-prb[i-1][j];
            MOD(prb[i][j]);
            if(prb[i][j]<0)
                prb[i][j]+=INF;
        }
        prb[i][0]=pra[i][0];
        prb[i][n+1]=pra[i][n];
    }
//    prin(pra);
//    prin(prb);
    int X,Y,aa,bb;
    LL res=0;
    for(i=0;i<=od[2];++i)
        for(j=0;j<=od[3];++j){
            LL mul=(LL)dn[od[2]][i]*dn[od[3]][j]%INF;
            X=r[1]-od[1]-i-j;
            Y=min(r[2]-od[2]+i-j,r[3]-od[3]-i+j);
           // printf("%d %d %d %d %d %d\n",i,j,Y+X,Y-X,X,Y);
            if(X>=od[0])
                X=od[0];
            if(Y>=od[0]+od[1])
                Y=od[0]+od[1];
            aa=(X+Y+2)>>1;
            bb=(Y-X)>>1;
           // printf("ss%d %d\n",aa,bb);
            if(bb>od[1]){
                aa-=bb-od[1];
                bb=od[1];
            }
            if((Y+X)&1){
                bb++;
            }
            if(bb<0){
                aa+=bb;
                bb=0;
            }
            if(aa>=0){
                if((Y+X)&1){
              //      printf("<<%lld> %d %d %lld\n",prb[aa][bb],aa,bb,mul);
                    res+=prb[aa][bb]*mul;
                }
                else{
             //       printf("<%lld> %d %d %lld\n",pra[aa][bb],aa,bb,mul);
                    res+=pra[aa][bb]*mul;
                }
                res%=INF;
            }
        }
    res=pot(n)-res;
    if(res<0)
        res+=INF;
    printf("%lld\n",res);
}