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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>
using namespace std;

typedef long long int LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

const int INF = 1000000001;
const LD EPS = 10e-9;

#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define VAR(v, n) __typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define abs(a) ((a)<0 ? -(a) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

const LL PRIME = 1000000007;

const int C = 3;
const int MAX_K = 10000;
const LL BASE_BOTTOM = 556156297;

LL UPPER[MAX_K+10];
LL BOTTOM[MAX_K+10];

LL pow2(int e)
{
    LL res = 1;
    LL two = 2;

    while(e > 0)
    {
        if(e%2 == 1)
        {
            res = (res * two) % PRIME;
        }
        two = (two * two) % PRIME;

        e /= 2;
    }

    return res;
}

LL subtract(LL a, LL b)
{
    LL res = (a - b) % PRIME;
    if(res < 0)
    {
        res += PRIME;
    }

    return res;
}

LL binomial(const LL k)
{
    return (UPPER[k] * BOTTOM[k]) % PRIME;
}

LL binomialSum(const int to)
{
    LL res = 0;
    for(int i = 0; i <= to; ++i)
    {
        res = (res + binomial(i)) % PRIME;
    }

    return res;
}

void calcValues(const int pow2exp)
{
    const LL n = pow2(pow2exp);
    UPPER[0] = 1;
    for(int i = 0; i < MAX_K; ++i)
    {
        UPPER[i+1] = (UPPER[i] * subtract(n, i)) % PRIME;
    }

    BOTTOM[MAX_K] = BASE_BOTTOM;
    for(int i = MAX_K-1; i >= 0; --i)
    {
        BOTTOM[i] = (BOTTOM[i+1] * (i+1)) % PRIME;
    }
}

int distance(const string& s1, const string& s2)
{
    int diff = 0;
    for(int i = 0; i < s1.size(); ++i)
    {
        if(s1[i] != s2[i])
        {
            ++diff;
        }
    }

    return diff;
}

bool belongs(const LL point, const pair<LL, int>& hiper)
{
    const LL xorr = (point ^ hiper.first);
    return __builtin_popcount(xorr) <= hiper.second;
}

int main()
{
    ios_base::sync_with_stdio(0);

    int n, r, rc1 = 0;
    string s;
    unordered_map<string, int> radiuses;
    unordered_map<LL, int> radiusesNum;

    cin >> n;
    calcValues(n);

    for(int i = 0; i < C; ++i)
    {
        cin >> r >> s;
        radiuses[s] = max(radiuses[s], r);
    }

    for(const auto elem : radiuses)
    {
        //cout << elem.first << ' ' << elem.second << endl;

        if(elem.second == n)
        {
            //cout << "tu" << endl;

            cout << pow2(n) << endl;
            return 0;
        }

        if(elem.second == n-1)
        {
            ++rc1;
        }
    }

    if(rc1 >= 2)
    {
        //cout << "tu2" << endl;

        cout << pow2(n) << endl;
        return 0;
    }

    if(radiuses.size() == 1)
    {
        //cout << "tu3" << endl;

        cout << binomialSum(radiuses.begin()->second) << endl;
        return 0;
    }

    for(const auto& elem : radiuses)
    {
        const LL num = stoll(elem.first, nullptr, 2);
        radiusesNum[num] = elem.second;
    }

    LL maxPow2 = (1LL << n);
    LL res = 0;
    for(LL i = 0; i < maxPow2; ++i)
    {
        bool ok = false;
        for(const auto& elem : radiusesNum)
        {
            if(belongs(i, elem))
            {
                ok = true;
                break;
            }
        }

        if(ok)
        {
            ++res;
        }
    }

    cout << (res % PRIME) << endl;

    return 0;
}