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
#include <bits/stdc++.h>
using namespace std;

const int mod=1e9+7;
const int MAXN=1e4+10;
const int smolMAXN=2e2+10;

int smoldp[smolMAXN][smolMAXN][smolMAXN][2];
int dp[MAXN][MAXN];
int r[3];
string s[3];

int pokrycie(int r1,string a,int r2,string b)
{
    int same=0,diff=0,n=a.size(),i,j;
    for(i=0;i<a.size();i++)
        if(a[i]==b[i])
            same++;
        else
            diff++;
    dp[0][0]=1;
    for(i=1;i<=n;i++)
        for(j=0;j<=i;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j>0)
                dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
        }
    int res=0;
    for(i=0;i<=diff;i++)
        for(j=0;j<=same;j++)
        {
            if(i+j<=r1&&diff-i+j<=r2)
                res=(long long)((long long)res+(long long)dp[diff][i]*(long long)dp[same][j])%(long long)mod;
        }
    res=(mod-res)%mod;
    for(i=0;i<=r1;i++)
    {
        res=(res+dp[n][i])%mod;
    }
    for(i=0;i<=r2;i++)
    {
        res=(res+dp[n][i])%mod;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,a,b,xp,yp,zp,i,x,y,z;
    int res=0;
    cin>>n;
    for(i=0;i<3;i++)
        cin>>r[i]>>s[i];
    if(r[0]==r[1]&&s[0]==s[1])
        cout<<pokrycie(r[2],s[2],r[1],s[1]);
    else
    if(r[1]==r[2]&&s[1]==s[2])
        cout<<pokrycie(r[1],s[1],r[0],s[0]);
    else
    if(r[2]==r[0]&&s[2]==s[0])
        cout<<pokrycie(r[2],s[2],r[1],s[1]);
    else
    {
        smoldp[0][0][0][0]=1;
        for(i=0;i<n;i++)
        {
            for(x=0;x<=n;x++)
            {
                for(y=0;y<=n;y++)
                {
                    for(z=0;z<=n;z++)
                    {
                        xp=(s[0][i]-'0')&1;
                        yp=(s[1][i]-'0')&1;
                        zp=(s[2][i]-'0')&1;
                        smoldp[x+xp][y+yp][z+zp][(i+1)&1]=(smoldp[x+xp][y+yp][z+zp][(i+1)&1]+smoldp[x][y][z][(i&1)])%mod;
                        xp=(xp+1)&1;
                        yp=(yp+1)&1;
                        zp=(zp+1)&1;
                        smoldp[x+xp][y+yp][z+zp][(i+1)&1]=(smoldp[x+xp][y+yp][z+zp][(i+1)&1]+smoldp[x][y][z][(i&1)])%mod;
                        smoldp[x][y][z][i&1]=0;
                    }
                }
            }
        }
        for(x=0;x<=n;x++)
            for(y=0;y<=n;y++)
                for(z=0;z<=n;z++)
                    if(x<=r[0]||y<=r[1]||z<=r[2])
                        res=(res+smoldp[x][y][z][n&1])%mod;
        cout<<res<<'\n';
    }
}