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

using namespace std;

vector<int> war[1000000];
vector<int> licz;
const int M=1000000007;
bool tab[100000];

int main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	string s;getline(cin, s);getline(cin, s);
	int idxwar=0;
	int minn=0;
	for(int i=1;i<s.size();++i){
		int cyfr=0;//cout<<"s[i] "<<s[i]<<" ";

		if(s[i]>=48 && s[i]<=58){cyfr=1;licz.push_back(s[i]-48);}
		else if(s[i]=='~')minn=1;
		if(cyfr==0 && s[i-1]>=48 && s[i-1]<=58){
			int mnoz=1;
			war[idxwar].push_back(0);//cout<<"!!!";
			while(licz.size()>0){
				war[idxwar][war[idxwar].size()-1]+=licz[licz.size()-1]*mnoz;
				mnoz*=10;
				licz.pop_back();
			}
			if(minn)war[idxwar][war[idxwar].size()-1]=-war[idxwar][war[idxwar].size()-1];
			minn=0;//cout<<war[idxwar][war[idxwar].size()-1]<<" ";
		}
		if(s[i]==')')++idxwar;
	}
	int mx=1<<n;
	int wyn=0;
	for(int i=0;i<mx;++i){
		int j=i;
		int k=1;
		while(j>0){
			tab[k]=j%2;
			j/=2;
			++k;
		}
		int aws=1;//cout<<endl;
		//for(int ii=0;ii<n+1;++ii)cout<<tab[ii]<<" ";cout<<endl;
		for(int t=0;t<idxwar;++t){
			int wart=0;
			for(int p=0;p<war[t].size();++p){
				//cout<<"tp  "<<t<<" "<<p<<" "<<"war "<<war[t][p]<<" ";
				if(war[t][p]<0){
					if(tab[-war[t][p]]==0){wart=1;}
				}
				else{
					if(tab[war[t][p]]==1){wart=1;}
				}
			}
			if(wart==0){aws=0;}
		}
		wyn+=aws;

		for(int ii=0;ii<n+1;++ii)tab[ii]=0;
	}

	cout<<wyn%M<<endl;

	return 0;
}