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
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

const int P = 1000000007;

using namespace std;

inline int mul(int x, int y) {
	return (int)(((int64_t)x * (int64_t)y) % P);
}

vector<vector<int> > pascal;

inline int pas(int n, int k) {
	if ((n < 0) || (k < 0) || (k > n)) {
		return 0;
	}
	return pascal[n][k];
}

void init_pascal(int n) {
	pascal.resize(n + 8);
	pascal[0].push_back(1);
	int i, j;
	for (i = 1; i <= n + 4; ++i) {
		pascal[i].reserve(i + 2);
		for (j = 0; j <= i; ++j) {
			pascal[i].push_back(((j > 0 ? pascal[i - 1][j - 1] : 0) + (j < i ? pascal[i - 1][j] : 0)) % P);
		}
	}
}

int pow2(int x) {
	if (x == 0) {
		return 1;
	}
	int64_t half = (int64_t)pow2(x / 2);
	if (x % 2) {
		return (int)((2 * half * half) % P);
	}
	else {
		return (int)((half * half) % P);
	}
}
vector<vector<int> > fun;

int f(int T, int B, int N) {
	if ((T < 0) || (B + N < 0)) {
		return 0;
	}
	return fun[T][B + N];
}

void init_f(int a, int d, int N, int max_y, int max_x) {
	int i, sum, x, y, x2, nudge;
	fun.resize(N + 8);
	for(i = 0; i <= N + 4; ++i) {
		fun[i].resize(2 * N + 8);
	}
	for(y = 0; y <= max_y; ++y) {
		for(x = 0; x <= max_x; ++x) {
			x2 = x - N;
			nudge = 0;
			if (y % 2 == (x2 + 1000000) % 2) {
				nudge = mul(pas(a, (x2 + y) / 2), pas(d, (y - x2) / 2));
			}
			fun[y][x] = (((f(y, x2 - 1, N) + f(y - 1, x2, N)) % P + P - f(y - 1, x2 - 1, N)) % P + nudge) % P;
		}
	}
}

typedef pair<int, vector<bool> > ball_t;

int main () {
	int N, i, dim, j, l, m, T, B;
	char ch;
	bool second, third;
	scanf("%d", &N);
	init_pascal(N);
	vector<ball_t> balls(3);
	for (i = 0; i < 3; ++i) {
		scanf("%d ", &dim);
		if (dim >= N) {
			printf("%d\n", pow2(N));
			return 0;
		}
		balls[i].first = N - dim - 1;
		for (j = 0; j < N; ++j) {
			scanf("%c", &ch);
			balls[i].second.push_back(ch == '1');
		}
	}
	sort(balls.begin(), balls.end());
	for (i = 0; i < N; ++i) {
		if (balls[0].second[i]) {
			balls[0].second[i] = false;
			balls[1].second[i] = !balls[1].second[i];
			balls[2].second[i] = !balls[2].second[i];
		}
	}
	int a = 0, b = 0, c = 0, d = 0;
	for (i = 0; i < N; ++i) {
		second = balls[1].second[i];
		third = balls[2].second[i];
		if (second && third) {
			++d;
		}
		else if (second && !third) {
			++c;
		}
		else if (!second && third) {
			++b;
		}
		else {
			++a;
		}
	}
	int x = balls[0].first, y = balls[1].first, z = balls[2].first;
	int max_x = 0, max_y = 0;
	for (l = 0; l <= b; ++l) {
		for (m = 0; m <= min(c, x - l); ++m) {
			max_y = max(max_y, x - l - m);
			max_x = max(max_x, min(y - l - c - d + m, z - b - m - d + l));
		}
	}
	init_f(a, d, N, max_y, N + max_x);
	int sum = 0;
	for (l = 0; l <= b; ++l) {
		for (m = 0; m <= min(c, x - l); ++m) {
			T = x - l - m;
			B = min(y - l - c - d + m, z - b - m - d + l);
			sum = (sum + mul(mul(pas(b, l), pas(c, m)), f(T, B, N))) % P;
		}
	}
	printf("%d\n", (pow2(N) - sum + P) % P);
	return 0;
}