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
#include <iostream>
#include <set>

using namespace std;

const int Q = 1000000007;

struct ball {
    int r;
    string s;
};

int PT[10007][10007];
set<string> K;

void calcPT(int n) {
    PT[1][1] = 1;
    
    for (int i=2; i<=n; i++) {
        for (int j=1; j<=i; j++) {
            PT[i][j] = (PT[i-1][j-1] + PT[i-1][j]) % Q;
        }
    }
}

int calcDist(const struct ball& A, const struct ball& B, int n) {
    int diff = 0;
    
    for (int i=0; i<n; i++) {
        if (A.s[i] != B.s[i]) {
            diff++;
        }
    }
    
    return diff;
}

int calcOnly(int r, int n) {
    int only = 0;
    
    for (int i=1; i<=r+1; i++) {
        only = (only + PT[n+1][i]) % Q;
    }
    
    return only;
}

int calcComm(int r1, int r2, int dist, int n) {
    int comm = 0;

    
    
    return comm;
}

void rec(int r, string s, int p) {
    int len = s.size();
    
    if (p == len) {
        K.insert(s);
    } else {
        if (r > 0 && s[p] == '0') {
            s[p] = '1';
            rec(r-1, s, p+1);
            s[p] = '0';
        }
        if (r > 0 && s[p] == '1') {
            s[p] = '0';
            rec(r-1, s, p+1);
            s[p] = '1';
        }
        
        rec(r, s, p+1);
    }
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;
    
    struct ball A, B, C;
    cin >> A.r >> A.s;
    cin >> B.r >> B.s;
    cin >> C.r >> C.s;
    
    bool brut = true;
    int dist;
    
    if ((A.r == B.r && A.s == B.s) || (B.r == C.r && B.s == C.s) || (A.r == C.r && A.s == C.s)) {
        if (A.r == B.r && A.s == B.s) {
            swap(B.r, C.r);
            swap(B.s, C.s);
        }
        
        calcPT(n+1);
        
        dist = calcDist(A, B, n);
        
        if (A.r + B.r <= dist || A.r >= dist + B.r || B.r >= dist + A.r) {
            brut = false;
        }
    }
    
    if (!brut) {
        int commAB = 0;
        
        if (A.r + B.r < dist) {
            commAB = 0;
        } else {
            if (A.r + B.r == dist) {
                commAB = PT[dist+1][A.r+1];
            } else {
                if (A.r >= dist + B.r) {
                    for (int i=1; i<=B.r+1; i++) {
                        commAB = (commAB + PT[n+1][i]) % Q;
                    }
                } else {
                    if (B.r >= dist + A.r) {
                        for (int i=1; i<=A.r+1; i++) {
                            commAB = (commAB + PT[n+1][i]) % Q;
                        }
                    }
                }
                
            }
        }
        
        int onlyA = calcOnly(A.r, n);
        int onlyB = calcOnly(B.r, n);

        cout << onlyA + onlyB - commAB;
    } else {
        K.insert(A.s);
        K.insert(B.s);
        K.insert(C.s);
        
        rec(A.r, A.s, 0);
        rec(B.r, B.s, 0);
        rec(C.r, C.s, 0);
        
        cout << K.size();
    }
    
    return 0;
}