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

const int maxn = 1000111;

bool claus[maxn];
int n, m, res, x[maxn];
char formula[maxn];

bool parse() {
	int a_claus = -1;
	bool r_claus = false;
	bool ok = true;
	for (int i = 0; i < m; i++) {
		if (formula[i] == '(') {
			r_claus = false;
			a_claus++;
		}
		else if (formula[i] == ')') {
			if (r_claus == true)
				claus[a_claus] = true;
			else
				claus[a_claus] = false;
		}
		else if (formula[i] == 'x') {
			int sz = (ok == true) ? 1 : 0;
			int index = 0;
			++i;
			while (formula[i] >= '0' && formula[i] <= '9') {
				index *= 10;
				index += formula[i] - '0';
				++i;
			}
			--i;
			if (x[index - 1] == sz) {
				r_claus = true;
			}
			ok = true;
		}
		else if (formula[i] == '~') {
			ok = false;
		}
	}
	for (int i = 0; i <= a_claus; i++)
		if (claus[i] == false)
			return false;
	return true;
}

int main () {
	scanf("%d", &n);
	char c = getchar();
	while ((c = getchar()) != EOF) {
		formula[m] = c;
		++m;
	}
	for (int i = 0; i < (1 << n); i++) {
		int y = i;
		for (int bit = 0; bit < n; bit++, y /= 2)
			x[bit] = (y & 1);
		bool query = parse();
		if (query == true) ++res;
	}
	printf("%d\n", res);
	return 0;
}