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
#include <cstdio>
#include <cstring>
#include <vector>

static const int MX = 107;
static const int MN = 1e6 + 7;

std::vector<std::vector<int>> adj;
char S[MX];
int n;
int res = 0;
std::vector<int> solution;


void input() {
	scanf("%d", &n);
	solution.resize(n + 1, false);
	int x = 0;
	bool neg = false;

	std::vector<int> vv;

	while (scanf("%s", S) != EOF) {
		int nn = strlen(S);
		for (int i = 0; i < nn; ++i) {
//			printf("%c", S[i]);
//			printf("neg = %d\n", (int)(neg));

			if (S[i] == '(') {
				vv.clear();
				continue;
			}
			if (S[i] == ')') {
				if (neg) x = -x;
				if (x != 0) vv.push_back(x);
				neg = false;
				x = 0;
//				for (auto it : vv) printf("%d ", it); puts("");
				adj.push_back(vv);
				continue;
			}
			if (S[i] == '~') {
				neg = true;
				continue;
			}
			if ((S[i] > '9' || S[i] < '0' ) && S[i] != 'x') {
				if (neg) x = -x;
				if (x != 0) vv.push_back(x);
				x = 0;
				neg = false;
				continue;
			}

			if (S[i] == 'x') continue;

			x *= 10;
			x += S[i] - '0';
		}
		if (neg) x = -x;
		if (x != 0) vv.push_back(x);
		neg = false;
		x = 0;
	}
}

inline bool oki() {
	for (const auto &it : adj) {
		bool ok = false;
		for (const auto &ptr : it) {
			if ((ptr > 0 && solution[ptr]) || (ptr < 0 && !solution[-ptr]))
				ok = true;
		}
		if (ok == false)
			return false;
	}
	return true;
}

void go(int idx) {
	if (idx == n + 1) {
		if (oki()) {
			//for (auto it : solution) 
			//	printf("%d ", it);
			//puts("");
			++res;
		}
		return;
	}
	solution[idx] = true;
	go(idx + 1);
	solution[idx] = false;
	go(idx + 1);
}


int main(void) {
	input();	
//	puts("\n\n");
	go(1);
	printf("%d\n", res);
	return 0;
}