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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using vi=vector<int>;
using vll=vector<ll>;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
#ifdef LOCAL
#define _upgrade ios_base::sync_with_stdio(0);
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__);
#else
#define _upgrade ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define debug(...) 98;
#define cerr if(0) cout
#endif

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second

#define erase_duplicates(x) sort(all(x)), (x).resize(distance((x).begin(), unique(all(x))));

#define watch(x) cout << (#x) << " is " << (x) << endl;

#define pow2(x) ((x)*(x))
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

#define REP(i, a, b) for(int i = a; i <= b; ++i)
#define REPV(i, b, a) for(int i = b; i >= a; --i)

const double m_pi = acos(-1.0);
const int int_max = 0x3f3f3f3f;
const int M7 = 1000*1000*1000+7;
const int M9 = 1000*1000*1000+9;

int n;
int r[10];
int w[10][100009];

long long dwum[10][100009];

int tab[10009][10009];
long long tabprop[100009];

long long aaadw[10009];


long long dominus1(long long wat){
    int wyk = M7-2;
    long long mnoz=wat;
    long long ret=1;
    while(wyk>0){
        if(wyk%2==1){
            ret*=mnoz;
            ret%=M7;
        }
        mnoz*=mnoz;
        mnoz%=M7;
        wyk/=2;
    }

    return ret;
}


long long sumkul(int a, int b){
    int oba = 0;
    int aaa = 0;
    for(int i=0;i<n;++i){
        if(w[a][i] == w[b][i])++oba;
        else ++aaa;
    }

    for(int j=1;j<=aaa;++j)aaadw[j]=0;
    aaadw[0]=1;
    for(int j=1;j<=aaa;++j){
        aaadw[j]=aaadw[j-1]*(aaa-j+1);
        aaadw[j]%=M7;
        aaadw[j]*=dominus1(j);
        aaadw[j]%=M7;
    }
    for(int j=1;j<=aaa;++j){
        aaadw[j]+=aaadw[j-1];
        aaadw[j]%=M7;
    }

    long long ret =0;
    long long mydw=1;
    for(int i=0;i <= oba;++i){
        // i + x >=  n - r[a]
        int atest = n - r[a] - i;
        // i + aaa - x >= n - r[b]
        // x <= i + aaa - n + r[b]
        int btest = i + aaa - n + r[b];
        //cerr<<"oba: "<<i<<" "<<atest<<" "<<btest<<endl;
        if(btest > aaa)btest=aaa;
        if(atest <= btest && btest >= 0){
            long long temp = aaadw[btest];
            if(atest > 0) temp -= aaadw[atest - 1];
            temp+=M7;
            temp*=mydw;
            temp%=M7;
            ret+=temp;
        }
        mydw*=oba-i;
        mydw%=M7;
        mydw*=dominus1(i+1);
        mydw%=M7;
    }
    ret%=M7;
    //if(ret<0)return 1/0;//cerr<<"pkul: "<<a<<" "<<b<<" "<<ret<<endl;
    return ret;
}

int main(){
    _upgrade
    cout<<fixed<<setprecision(15);

    cin>>n;
    for(int i=0;i<3;++i){
        cin>>r[i+1];
        for(int j=0;j<n;++j){
            char c;cin>>c;
            if(c =='1')w[i+1][j]=1;
        }
    }
    int x1=0;
    int a1=0;
    int b1=0;
    int c1=0;
    for(int i=0;i<n;++i){
        int q = w[1][i];
        int qq = w[2][i];
        int qqq = w[3][i];
        if(q == qq && q == qqq) ++x1;
        else if(q == qq) ++a1;
        else if(q == qqq) ++b1;
        else if(qq == qqq) ++c1;
    }

    for(int i=0;i<4;++i){
        int lim=x1;
        if(i==1)lim=a1;
        if(i==2)lim=b1;
        if(i==3)lim=c1;
        dwum[i][0]=1;
        for(int j=1;j<=lim;++j){
            dwum[i][j]=dwum[i][j-1]*(lim-j+1);
            dwum[i][j]%=M7;
            dwum[i][j]*=dominus1(j);
            dwum[i][j]%=M7;
        }
    }
    //cerr<<"xabc "<<x1<<" "<<a1<<" "<<b1<<" "<<c1<<endl;

    for(int bc=0;bc<=b1 + c1;++bc){
        for(int c=0;c<=c1;++c){
            int b = bc - c;
            if(b < 0 || b > b1)continue;
            long long ile=1;
            ile*=dwum[2][b];
            ile*=dwum[3][c];
            ile%=M7;
            int xa = n - r[1] - b - c1 + c;
            xa = max(xa, n- r[2] - c - b1 +b);
            if(xa<0)xa=0;
            tabprop[xa]+= ile;
            if(tabprop[xa] >= M7) tabprop[xa]-=M7;
            //cerr<<"b: "<<b<<" c: "<<c<<" xa: "<<xa<<" ile: "<<endl;
        }
        long long sum=0;
        for(int i=0;i<=n;++i){
            sum+=tabprop[i];
            tabprop[i]=0;
            if(sum>=M7)sum-=M7;
            tab[bc][i]+=sum;
        }
    }
    /*
    for(int i=0;i<=n; ++i){
        for(int bc = 0; bc <= b1 + c1; ++bc){
            cerr<<tab[bc][i]<<" ";
        }cerr<<endl;
    }*/

    for(int i=0;i<=n; ++i){
        for(int bc = 1; bc <= b1 + c1; ++bc){
            tab[bc][i] += tab[bc-1][i];
            if(tab[bc][i] >= M7)tab[bc][i]-=M7;
        }
    }
    /*cerr<<endl;
    for(int i=0;i<=n; ++i){
        for(int bc = 0; bc <= b1 + c1; ++bc){
            cerr<<tab[bc][i]<<" ";
        }cerr<<endl;
    }*/
    
    long long przec=0;

    for(int x=0;x<=x1;++x){
        for(int a=0;a<=a1;++a){
            int bc = n - r[3] - x - a1 + a;
            if(bc > b1 + c1)bc=b1+c1+1;
            int xa = x + a;
            if(bc<0)bc=0;
            int lew=0;
            if(bc==0)lew=0;
            else lew=tab[bc-1][xa];
            int praw=tab[b1+c1][xa];//cerr<<"x: "<<x<<" a: "<<a<<" bc: "<<bc<<" lp: "<<lew<<" "<<praw<<endl;
            int pos = praw-lew;
            pos+=M7;
            if(pos>=M7)pos-=M7;
            long long ile=1;
            ile*=dwum[0][x];
            ile*=dwum[1][a];
            ile%=M7;
            ile*=pos;
            ile%=M7;
            przec+=ile;
        }
        przec%=M7;
    }
    //if(przec<0)return 1/0;

    long long wyn = sumkul(1, 1) + sumkul(2, 2) + sumkul(3, 3) - sumkul(1, 2) - sumkul(1, 3) - sumkul(2, 3) + przec;
    wyn+=10LL*M7;
    wyn%=M7;

    cout<<wyn<<"\n";

    return 0;
}




/*
    __builtin_popcount count total set bits on a given integer
    (use __builtin_popcountll for long long).


*/