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 // Artur Kraska, II UWr #include #define forr(i, n) for(int i=0; i=b; i--) #define MP make_pair #define PB push_back #define deb(X) X; #define M 1000000007 #define INF 1000000000000000007LL using namespace std; int n, m, a, r[5], l[5]; unsigned int tr[10007][10007], T[10007][10007]; char sl[5][10007]; void trojkat() { FOR(i, 0, 10003) { tr[i][0] = 1; FOR(j, 1, i) tr[i][j] = (tr[i-1][j-1] + tr[i-1][j]) % M; } } long long licz_jedna(int nr) { long long res = 0; FOR(i, 0, r[nr]) res += tr[n][i]; // cout << " dla kulki " << nr << " wyszlo " << res%M << endl; return res % M; } long long licz_dwie(int n1, int n2) { long long res = 0; int la = 0, lb = 0; forr(i, n) { if(sl[n1][i] == sl[n2][i]) la++; else lb++; } // cout << "la: " << la << ", lb: " << lb << endl; FOR(a, 0, la) { FOR(b, 0, lb) { if(la-a + lb-b <= r[n1] && la-a + b <= r[n2]) { // cout << "bangla dla " << a << " i " << b << endl; // cout << "dodaje " << tr[la][a] << " * " << tr[lb][b] << endl; res = (res + tr[la][a] * (long long)tr[lb][b]) % M; } } } // cout << " dla kulek " << n1 << " i " << n2 << " wyszlo " << res << endl; return res; } long long licz_trzy() { int A=0, B=0, C=0, D=0; long long res = 0; forr(i, n) { if(sl[1][i] == '1') { sl[2][i] = '0' + '1' - sl[2][i]; sl[3][i] = '0' + '1' - sl[3][i]; } if(sl[2][i] == '0' && sl[3][i] == '0') A++; else if(sl[2][i] == '0' && sl[3][i] == '1') B++; else if(sl[2][i] == '1' && sl[3][i] == '0') C++; else if(sl[2][i] == '1' && sl[3][i] == '1') D++; } // cout << "A: " << A << ", B: " << B << ", C: " << C << ", D:" << D << endl; // licz tablice pom if(A+B <= 5000) { FOR(apb, 0, A+B) { FOR(amb, -B, A) { T[apb+1][amb+B+1] = 0; if(((apb+amb)&1) == 0) { int a = (apb+amb)/2; int b = (apb-amb)/2; if(0 <= a && a <= A && 0 <= b && b <= B) T[apb+1][amb+B+1] = tr[A][a]*(long long)tr[B][b]%M; } T[apb+1][amb+B+1] = (T[apb+1][amb+B+1] + (long long)T[apb-1+1][amb+B+1] + T[apb+1][amb-1+B+1] - T[apb-1+1][amb-1+B+1] + M)%M; } } FOR(c, 0, C) { FOR(d, 0, D) { int apb = min(min(A+B, r[1]-c-d), r[2]-C-D+c+d); int amb = min(A, r[3]-B-D-c+d); if(apb >= 0 && amb >= -B) { res = (res + (T[apb+1][amb+B+1] * (long long)tr[C][c])%M * tr[D][d]) % M; } } } } else // C+D <= 5000 { //cout << "A: " << A << ", B: " << B << ", C: " << C << ", D:" << D << endl; FOR(cpd, 0, C+D) { FOR(cmd, -D, C) { T[cpd+1][cmd+D+1] = 0; if(((cpd+cmd)&1) == 0) { int c = (cpd+cmd)/2; int d = (cpd-cmd)/2; if(0 <= c && c <= C && 0 <= d && d <= D) T[cpd+1][cmd+D+1] = tr[C][c]*(long long)tr[D][d]%M; } T[cpd+1][cmd+D+1] = (T[cpd+1][cmd+D+1] + (long long)T[cpd-1+1][cmd+D+1] + T[cpd+1][cmd-1+D+1] - T[cpd-1+1][cmd-1+D+1] + M)%M; } } FOR(a, 0, A) { FOR(b, 0, B) { int cpd_g = min(C+D, r[1]-a-b); int cpd_d = -r[2]+C+D+a+b; int cmd = min(C, r[3]-B-D-a+b); if(cpd_g >= 0 && cpd_d <= cpd_g && cmd >= -D) { res = (res + ((T[cpd_g+1][cmd+D+1] - (long long)(cpd_d > 0 ? T[cpd_d-1+1][cmd+D+1] : 0) + M) * (long long)tr[A][a])%M * tr[B][b]) % M; } } } } return res; } int main() { trojkat(); scanf("%d", &n); FOR(i, 1, 3) { scanf("%d %s", &r[i], sl[i]); } long long res = licz_jedna(1) + licz_jedna(2) + licz_jedna(3); res -= licz_dwie(1, 2) + licz_dwie(1, 3) + licz_dwie(2, 3); res += licz_trzy(); res = (res%M + M)%M; printf("%lld\n", res); return 0; }