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
#include <iostream>

using namespace std;

const int mod = 1000000007;

inline int sum(string a)
{
	int w = 0, l = a.length();
	for (int i = 0; i < l; i++)
	{
		w += int(a[i]) - 48;
	}
	return w;
}

string m_xor(string a, string b)
{
	string w = "";
	int l = a.length();
	for (int i = 0; i < l; i++)
	{
		if(a[i] == b[i]) w += '0';
		else w += '1';
	}
	return w;
}

inline string inc(string a)
{
	int l = a.length();
	a[l - 1]++;
	for (int i = l - 1; i > 0; i--)
	{
		if(a[i] > '1')
		{
			a[i] = '0';
			a[i - 1]++;
		}
	}
	if (a[0] > '1') return "-1";
	return a;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	int n, wyn = 0; //wymiary, wynik
	cin >> n;
	int prom[n];
	string lokal[n], g = "";
	
	for (int i = 0; i < 3; i++)
	{
		cin >> prom[i] >> lokal[i];	
	}
	for (int i = 0; i < n; i++) g += '0';
	int f = 0;
	while(g != "-1")
	{
		for (int i = 0; i < 3; i++)
		{
			if (sum(m_xor(lokal[i], g)) <= prom[i])
			{
				wyn++;
				break;
			}
		}
		g = inc(g);
		f++;
		if (f % mod == 0)
		{
			wyn %= mod;
			f = 0;
		}
	}
	cout << wyn;
	return 0;
}