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
#include <iostream>
#include <set>
#include <map>
#include <limits>
#include <vector>
#include <queue>

#include <iomanip>               // for std::setw
#include <ios>                   // for std::noskipws, streamsize
#include <istream>               // for std::istream
#include <ostream>               // for std::ostream
#include <sstream>               // for std::ostringstream
#include <cstddef>               // for NULL
#include <stdexcept>             // for std::domain_error
#include <string>                // for std::string implicit constructor
#include <cstdlib>               // for std::abs
#include <limits>                // for std::numeric_limits
#include <cassert>

#include<type_traits>

using namespace std;

// #define DEBUG

#ifdef DEBUG
#define dbg cerr
// #define dbg2 cerr
#define dbg2 0 && cerr
#else
#define dbg 0 && cerr
#define dbg2 0 && cerr
#endif

using coord = uint64_t;

set<coord> done;
int dim;

void count(int distance, coord from) {
    dbg << "now: [" << distance << "] " << from << endl;
    done.insert(from);

    if (distance == 0) {
        return;
    }


    for(int bit = 0; bit < dim; bit++) {
        auto now = from;
        now ^= (1 << bit);

        count(distance-1, now);
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    cin >> dim;

    for(int i = 0; i < 3; ++i) {
        int r;
        string str;
        cin >> r >> str;

        coord val = 0;
        for(int x = 0; x < dim; ++x) {
            val += (1 << x) * (str[x] - '0');
        }

        dbg << val << endl;

        count(r, val);
    }

    cout << done.size() << endl; 
}