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
#include <bits/stdc++.h>
using namespace std;

const long long mod = 1e9+7;

int n;
long long r1, r2, r3, wyn;
long long F[10500];
bitset <10005> B1, B2, B3;

long long NpoK(long long N, long long K)
{
	long long war[10005] = {};
	
	for (long long i = max(N-K+1, K+1); i <= N; i++)
	{
		long long x = i;
		while (F[x] > 0)
		{
			war[F[x]]++;
			x /= F[x];
		}
	}
	
	long long lim = min(N-K, K);
	for (long long i = 2; i <= lim; i++)
	{
		long long x = i;
		while (F[x] > 0)
		{
			war[F[x]]--;
			x /= F[x];
		}
	}
	
	long long ans = 1;
	for (long long i = 2; i <= N; i++)
		while (war[i])
		{
			ans = (ans * i) % mod;
			war[i]--;
		}
	return ans;
}

void add(long long r)
{
	for (long long i = 0; i <= r; i++)
		wyn = (wyn + NpoK(n, i)) % mod;
}

void sub(long long ra, bitset <10005> A, long long rb, bitset <10005> B)
{
	long long dif = 0;
	for (int i = 0; i < n; i++)
		if (A[i] != B[i])
			dif++;
	long long same = n-dif;
	
	long long ans = 0;
	for (long long i = 0; i <= ra; i++)
	{
		for (long long j = 0; j <= rb; j++)
		{
			if (i+j < dif || (i+j-dif)%2)
				continue;
			
			long long poza = (i+j-dif)/2;
			ans = (ans + (NpoK(dif, i-poza) * NpoK(same, poza))) % mod;
		}
	}
	
	wyn = (wyn - ans + mod) % mod;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> r1 >> B1 >> r2 >> B2 >> r3 >> B3;
	
	for (int i = 2; i <= n+10; i++)
		if (!F[i])
		{
			F[i] = i;
			for (int j = i*i; j <= n; j += i)
				F[j] = i;
		}
	
	add(r1);
	add(r2);
	add(r3);
	sub(r1, B1, r2, B2);
	sub(r2, B2, r3, B3);
	sub(r3, B3, r1, B1);
	
	cout << wyn << '\n';
}