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
//Filip Wilkowski XIII LO w Szczecinie

#include <bits/stdc++.h>
using namespace std;

bitset<10000> kula, temp;
int n;
vector<bitset<10000>> kostki(3);
vector<int> diff(3);
int ans = 0;
int mod = 1000000007;
bool check(){
	for(int i = 0; i < 3; ++i){
		temp = kula ^ kostki[i];
		if((int)temp.count() <= diff[i])
			return true;
		}
	return false;
}
void backtrack(int i){
	if (i == n){
		if(check()){
			++ans;
			ans %= mod;
		}
		return;
	}
	backtrack(i + 1);
	kula.flip(i);
	backtrack(i + 1);
	kula.flip(i);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	for(int i = 0; i < 3; ++i){
		cin >> diff[i];
		cin >> kostki[i];
	}
	backtrack(0);
	cout << ans;
}