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
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	string s;
	getline(cin, s);
	getline(cin, s);
	
	vector<vector<int> > v;
	int clause = -1;
	bool minus = false;
	for (int i=0; i<s.length(); i++)
	{
		if (s[i] == '(')
		{
			clause++; //kolejna klauzula
			vector<int> vv;
			v.push_back(vv);
			minus = false;
		}
		
		if (s[i] == '~') minus = true;
		
		int number = 0;
		while (s[i]>='0' && s[i]<='9')
		{
			number = number * 10;
			number += (s[i]-'0');
			i++;
		}
		if (number > 0)
		{
			if (minus) number *= -1;
			i--;
			v[clause].push_back(number);
			minus = false;
		}
	}
	
	/*for (int i=0; i<v.size(); i++)
	{
		for (int j=0; j<v[i].size(); j++)
			cout << v[i][j] << " ";
		cout << endl;
	}*/
	
	long long int result = 0;
	long long int limit = pow(2,n);
	for (int i=0; i<limit; i++)
	{
		bool isOK = true;
		for (int j=0; j<v.size(); j++)
		{
			bool trueClausule = false;
			for (int k=0; k<v[j].size(); k++)
			{
				if (v[j][k] > 0)
					trueClausule = trueClausule | ((i >> (v[j][k]-1))&1);
				else
					trueClausule = trueClausule | (!((i >> (-v[j][k]-1))&1));
			}
			if (!trueClausule) { isOK = false; break;}
		}
		if (isOK) result++;
	}
	
	cout << result % 1000000007 << endl;
}