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
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, n) for(auto &i : n)
#define SZ(x) (int)(x).size()
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

const int MOD = 1000000007;
const int MAX = 10006;

int sum[MAX][2*MAX];
int binac[MAX], binab[MAX], binbc[MAX], binx[MAX];
int pbinac[MAX], pbinab[MAX], pbinbc[MAX], pbinx[MAX];

int bin(int n, int k){
	if(k == 0) return 1;
	int ans = (sum[n][k]-sum[n][k-1]);
	return (ans < 0 ? ans+MOD : ans);
}

int pojed(int n, int r){
	return sum[n][r];
}

int podw(int n, int x, int a, int b){
	int ans = 0;
	FOR(i, n-x+1){
		int aa = a-i;
		int bb = b-((n-x)-i);
		int mn = std::min(std::min(aa, bb), x);
		if(mn >= 0) ans = (1ll*ans+1ll*bin(n-x, i)*sum[x][mn])%MOD;
	}
	return ans;
}

int potr(int n, int x, int ab, int ac, int bc, int a, int b, int c){
	ab -= x; ac -= x; bc -= x;
	//std::cerr << n << " " << x << " " << ab << " " << ac << " " << bc << "\n";
	FOR(i, ab+1) binab[i] = bin(ab, i);
	FOR(i, ac+1) binac[i] = bin(ac, i);
	FOR(i, bc+1) binbc[i] = bin(bc, i);
	FOR(i, x+1) binx[i] = bin(x, i);
	pbinab[0] = pbinac[0] = pbinbc[0] = pbinx[0] = 1;
	REP(i, 1, n+1) pbinab[i] = (pbinab[i-1]+binab[i])%MOD;
	REP(i, 1, n+1) pbinac[i] = (pbinac[i-1]+binac[i])%MOD;
	REP(i, 1, n+1) pbinbc[i] = (pbinbc[i-1]+binbc[i])%MOD;
	REP(i, 1, n+1) pbinx[i] = (pbinx[i-1]+binx[i])%MOD;

	FOR(p, n+1) sum[0][p] = pbinbc[p];
	REP(i, 1, x+1){
		FOR(p, n+1){
			sum[i][p] = (1ll*sum[i-1][p]+
				1ll*binx[i]*(p-i < 0 ? 0 : pbinbc[p-i]))%MOD;
		}
	}

	int ans = 0;
	FOR(j, ab+1){
		int sm = 0;
		FOR(k, ac+1){
			int aa = j+k;
			int bb = j+(ac-k);
			int cc = (ab-j)+k;
			int w = a-aa;
			int u = b-bb;
			int v = c-cc;
			int mn = std::min(u, v);
			if(w < 0 || mn < 0) continue;
			// l <= mn-i
			// l >= bc-w+i;
			int lef = bc-w;
			int rig = mn;
			if(lef > rig) continue;
			int ile = (rig-lef)/2;
			ile = std::min(ile, x);
			//std::cerr << "jestem w " << j << " " << k << ", " << lef << " - " << rig << "\n";
			//std::cerr << "dodaje sum " << ile << " " << rig << "=" << sum[ile][rig] << "\n";
			sm = (1ll*sm+1ll*sum[ile][rig]*binac[k])%MOD;
		}
		ans = (1ll*ans+1ll*sm*binab[j])%MOD;
	}
//	std::cerr << "tera " << ans << std::endl;
	REP(p, -n-1, n+1) sum[0][p+MAX] = (p >= 0 ? pbinbc[p] : 0);
	REP(i, 1, x+1){
		REP(p, -n-1, n+1){
			sum[i][p+MAX] = (1ll*sum[i-1][p+MAX]+
				1ll*binx[i]*(p+i < 0 ? 0 : pbinbc[std::min(bc, p+i)]))%MOD;
		}
	}
	FOR(j, ab+1){
		int sm = 0;
		FOR(k, ac+1){
			int aa = j+k;
			int bb = j+(ac-k);
			int cc = (ab-j)+k;
			int w = a-aa;
			int u = b-bb;
			int v = c-cc;
			int mn = std::min(u, v);
			if(w < 0 || mn < 0) continue;
			// l <= mn-i
			// l >= bc-w+i;
			int lef = bc-w;
			int rig = mn;
			if(lef > rig) continue;
			int ile = (rig-lef)/2;
			ile = std::min(ile, x);
			sm = (1ll*sm+1ll*sum[ile][lef-1+MAX]*binac[k])%MOD;
		}
		ans = (1ll*ans-1ll*sm*binab[j])%MOD;
		if(ans < 0) ans += MOD;
	}
	//std::cerr << "ans " << ans << "\n";
	/*FOR(i, x+1){
		FOR(j, ab+1){
			FOR(k, ac+1){
				FOR(l, bc+1){
					int aa = i+j+k+(bc-l);
					int bb = i+j+l+(ac-k);
					int cc = i+k+l+(ab-j);
					if(aa <= a && bb <= b && cc <= c){
						int add = (1ll*binco[x][i]*binco[ab][j])%MOD;
						add = (1ll*add*binco[ac][k])%MOD;
						add = (1ll*add*binco[bc][l])%MOD;
						ans = (ans+add)%MOD;
					}
				}
			}
		}
	}*/
//	std::cerr << "ans = " << ans << "\n";
	return ans;
}

int wspol(VI a, VI b){
	int ans = 0;
	FOR(i, SZ(a)) if(a[i] == b[i]) ans++;
	return ans;
}
int wspol(VI a, VI b, VI c){
	int ans = 0;
	FOR(i, SZ(a)) if(a[i] == b[i] && a[i] == c[i]) ans++;
	return ans;
}

VI tab[3];
int r[3];

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	sum[0][0] = 1;
	REP(i, 1, MAX){
		sum[i][0] = sum[i][i] = 1;
		REP(j, 1, i) sum[i][j] = (sum[i-1][j-1]+sum[i-1][j])%MOD;
	}
	FOR(i, MAX){
		REP(j, 1, i+1){
			sum[i][j] += sum[i][j-1];
			if(sum[i][j] >= MOD) sum[i][j] -= MOD;
		}
	}
	int n;
	std::cin >> n;
	FOR(i, 3){
		std::cin >> r[i];
		tab[i].resize(n);
		FOR(j, n){
			char ch;
			std::cin >> ch;
			tab[i][j] = (ch == '1' ? 1 : 0);
		}
	}
	int ans = 0;
	FOR(i, 3) ans = (ans+pojed(n, r[i]))%MOD;
	ans = (ans-podw(n, wspol(tab[0], tab[1]), r[0], r[1])+MOD)%MOD;
	ans = (ans-podw(n, wspol(tab[1], tab[2]), r[1], r[2])+MOD)%MOD;
	ans = (ans-podw(n, wspol(tab[0], tab[2]), r[0], r[2])+MOD)%MOD;
	ans = (ans+potr(n, wspol(tab[0], tab[1], tab[2]),
			wspol(tab[0], tab[1]), wspol(tab[0], tab[2]), wspol(tab[1], tab[2]),
			r[0], r[1], r[2]))%MOD;
	std::cout << ans << "\n";
	return 0;
}