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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>

using namespace std;

typedef unsigned long long LL;

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(val) ((val) < 0 ? -(val) : (val))

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define VAR(v, n) __typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define PB push_back
#define ST first
#define ND second

#define M 1000000007ULL




/* Algorytmika praktyczna - Piotr Stańczyk */ 

LL Binom(int n, int k) { 
#define Mark(x, y) for(int w = x, t = 2; w > 1; t++) \
while(!(w % t)) {w /= t; p[t] += y;}
	if (n < k || n < 0) return 0;
	int p[n + 1];
	REP(x, n + 1) p[x] = 0;

	FOR(x, n - k + 1, n) Mark(x, 1);

	FOR(x, 1, k) Mark(x, -1);

	LL r = 1;
	FOR(x, 1, n) while(p[x]--) r *= x;
	return r;
}



/* PA2019 "KUL" */


static const int MAX_DIM = 10005;  
static int sums[MAX_DIM][MAX_DIM] = {};

static int komma[MAX_DIM][MAX_DIM] = {};

int npok(int n, int k) {
	if (sums[n][k] != 0)
		return sums[n][k];
		
	
	int res = Binom (n, k) %M;
	
	sums[n][k] = res;
//	printf("BINOM %d, sums %d\n", res, sums[n][k]);
	return res;
}


int getsumincl(int n, int start, int end) {
	int sum = 0;
	for (int i = start; i <= end; i++)
	{
		sum = (sum + npok(n, i)) %M;
	}
	/*
	int kommar = komma[n][end];
	if (start > 0)
		kommar = (kommar - komma[n][start-1]) %M;
	
//	printf("getsumincl %d, komma %d\n", sum, kommar);
*/
	
	return sum;
}




int calc(bitset<MAX_DIM> v0, bitset<MAX_DIM> v1, bitset<MAX_DIM> v2, int r0, int r1, int r2, int n);

/*
int rec(int n, int k)
{
	if (sums[n][k] != -1)
		return sums[n][k];
	
	if (k > n)
		sums[n][k] = 0;
	else if (k == 0)
		sums[n][k] = 1;
	else
		sums[n][k] = (rec(n-1, k-1) + rec(n-1, k)) %M;
	
	return sums[n][k];
}

int main_ () {
	REP(j, MAX_DIM)
	{
		REP(i, MAX_DIM)
			sums[i][j] = -1;	
	}
	
	REP(j, MAX_DIM)
	{
		REP(i, MAX_DIM)
		{
			int d = rec(i, j);
			//printf("%d %d %d\n", i, j, d);
		}	
		
		printf("%d\n", j);
	}
	
	printf("DONE binomial\n");
	REP(j, MAX_DIM)
	{
		REP(i, MAX_DIM)
		{
			int d = rec(i, j);
			//printf("%d %d %d\n", i, j, d);
		}	
		
		printf("%d\n", j);
	}
	
	REP(j, MAX_DIM)
	{
		
		REP(i, MAX_DIM)
		{
			if (i == 0)
				komma[j][i] = sums[j][i];
			else
				komma[j][i] = (komma[j][i-1] + sums[j][i]) % M;
			
		}	
	}
	
	
	int sum = 0;
	for (int i = 0; i <= end; i++)
	{
		sum += npok(n, i);
	}
	
	return sum;
	
	
	
	
}
*/
	

int main() {
	
	//main_();
	
	
	int n;
	scanf("%d\n", &n);
	
	int r[3];
	bitset<MAX_DIM> v [3] ;
	
	REP(i, 3) {
		char arr [MAX_DIM];
		scanf("%d %s", &r[i], &arr[0]);
		string s(arr, n);	
		//cout << s <<endl;
		reverse(ALL(s));
		v[i] = bitset<MAX_DIM>(s);
	}
	/*
	REP(i, 3)
	{
		REP(k, n)
			cout << v[i][k];
		cout<<endl;
		//cout << v[i] <<endl;
	}
	*/
	bitset<MAX_DIM> tr [3];
	
	tr[1] = v[1] ^ v[0]; 	
	tr[2] = v[2] ^ v[0]; 	
		
	tr[0] = v[0] ^ v[0]; 	 
	
	/*
	REP(i, 3)
	{
		REP(k, n)
			cout << tr[i][k];
		cout<<endl;
		//cout << v[i] <<endl;
	}
	*/
	
	long long int a0 = calc(tr[0], tr[0], tr[0], r[0], r[0], r[0], n);
	long long int a1 = calc(tr[1], tr[1], tr[1], r[1], r[1], r[1], n);
	long long int a2 = calc(tr[2], tr[2], tr[2], r[2], r[2], r[2], n);
	
	long long int a0c1 = calc(tr[0], tr[1], tr[1], r[0], r[1], r[1], n);
	long long int a1c2 = calc(tr[1], tr[2], tr[2], r[1], r[2], r[2], n);
	long long int a0c2 = calc(tr[0], tr[2], tr[2], r[0], r[2], r[2], n);
	
		
	long long int three_common = calc(tr[0], tr[1], tr[2], r[0], r[1], r[2], n);
	
	long long int res = (a0 + a1 + a2) - (a0c1 + a1c2 + a0c2) + three_common;
	
	res = res % M;
	
	/*
	
	printf ("IND %d %d %d\n", a0, a1, a2);

	
	printf("PLU %d\n", res);
	*/
	printf("%lld\n", res);
	
	return 0;
	
}

int calc2 (int ones, int zeros, int r0, int r1) {

  //  printf (" PISO %d %d %d %d\n", ones, zeros, r0, r1);
	
	int p0 = ones;
	int p1 = zeros;

	// m - jedynki w jedynkach
	// s - jedynki w zerach
	
	// p0 - miejsca jedynek
	// p1 - miejsca zer
	// p0 + p1 == n
	
	// 0 <= m <= p0
	// m <= r0
	
	// 0 <= s <= p1
	// s <= r1
	
	// m + s <= r0
	// p0 - m + s <= r1
	
	int smax = (r0 + r1 - p0) /2;
	smax = MIN(smax, p1);
	smax = MIN(smax, r1);
	
	long long int sum = 0;
	
	for (int s = 0; s <= smax; s++)
	{
		int mmin = 0;
		int mmax = MIN(p0, r0);
		mmax = MIN(mmax, r0 - s);
		mmin = MAX(mmin, p0 + s - r1);
		
	//	printf("Summing for s %d and m in range [%d, %d]\n", s, mmin, mmax);	
		
		int ss = npok(p1, s);
		int msum = getsumincl(p0, mmin, mmax);
		
		long long int t =  ss * msum;
		
		sum = (sum + t) % M;
		
	}
	
	return sum;
}

int calc(bitset<MAX_DIM> v0, bitset<MAX_DIM> v1, bitset<MAX_DIM> v2, int r0, int r1, int r2, int n) {
	
	bitset<MAX_DIM> tr [3];
	
	tr[1] = v1 ^ v0; 	
	tr[2] = v2 ^ v0; 	
		
	tr[0] = v0 ^ v0; 
	
	
	int p0 = tr[1].count();
//	cout << "p0 " << p0 << endl;
	
	int cal = calc2(p0, n - p0, r0, r1);
//	printf ("%d cal\n", cal);
	
	int p1 = tr[2].count();
//	cout << "p1 " << p0 << endl;
	
	int cal_ = calc2(p1, n - p1, r0, r2);
//	printf ("%d cal_\n", cal_);
	
	bitset<MAX_DIM> u = tr[1] & tr[2];
	int c = u.count();
	
//	printf ("__ %d %d \n", r1, r2);
	int com = calc2(c, n - c, r0, MAX(r1,r2));
	
//	printf ("%d com\n", com);
	
	int three_common = cal + cal_ - com;
	int absof = MAX(0, three_common);
	
//	printf ("%d common\n", absof);
	return absof;
	

}