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
#include <cstdio>
#include <vector>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define VAR(v,w) __typeof(w) v=(w)
#define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)
#define PB push_back
#define SIZE(c) ((int)(c).size())

typedef vector<int> VI;

int main() {
	int n;
	scanf("%d", &n);
	char c;
	VI clauses, negs;
	do {
		scanf(" %c", &c);
		int clause = 0, neg = 0;
		do {
			scanf(" %c", &c);
			bool isNeg = 0;
			if (c == '~') {
				isNeg = 1;
				scanf("%c", &c);
			}
			int i;
			scanf("%d", &i);
			--i;
			clause |= 1 << i;
			if (isNeg) neg |= 1 << i;
			scanf(" %c", &c);
		} while (c == 'v');
		clauses.PB(clause);
		negs.PB(neg);
	} while (scanf(" %c", &c) == 1);
	int x = clauses.size();
	int n2 = 1 << n;
	int res = 0;
	REP(m,n2) {
		bool ok = 1;
		REP(i,x) if (!(negs[i] ^ (clauses[i] & m))) {
			ok = 0;
			break;
		}
		if (ok) ++res;
	}
	printf("%d\n", res);
}