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
#include<cstdio>
#include<cstdlib>

int n;
char** S;
int * r;
int m = 3;

void input() {
  scanf("%d", &n);
  S = new char*[m];
  r = new int[m];
  for (int i = 0; i < m; i++) {
    S[i] = new char[n];
    scanf("%d %s", &r[i], S[i]);
  }
}

void convert(int i, char * s) {
  for (int j = n - 1; j >= 0; j--) {
    s[j] = i % 2 == 0 ? '0' : '1';
    i /= 2;
  }
}

int count(char * p, char * s) {
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] != s[i]) {
      res ++;
    }
  }
  return res;
}

bool check(int i, char * p) {
  return count(p, S[i]) <= r[i];
}

int solve() {
  int res = 0;
  char * p = new char[n + 1];
  p[n] = NULL;
  for (int i = 0; i < (1 << n); i++) {
    convert(i, p);
    for (int j = 0; j < m; j++) {
      if (check(j, p)) {
        res++;
        break;
      }
    }
  }
  return res;
}

int main() {
  input();
  printf("%d\n", solve());
  return 0;
}