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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(20);
#define inf 1000000007
#define INF 1000000000000000000LL
#define mod 1000000007
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;
#define N 1000007
string s,ss;
int n,pom;
int ans;
VI klauz[N];

bitset <100> czy;

bool check()
{
	FOR(i,1,pom)
	{
		bool bylo=false;
		REP(j,klauz[i].size())
		{
			if ( klauz[i][j]>0 && czy[klauz[i][j]] )
			{
				bylo=true;
				break;
			}
			if ( klauz[i][j]<0 && !czy[abs(klauz[i][j])] )
			{
				bylo=true;
				break;
			}
		}
		if (!bylo)
			return false;
	}
	return true;


}

void solve()
{
	int pom=1<<n;

	REP(i,pom)
	{
		REP(j,n)
		{
			if(i & (1<<j))
				czy[j+1]=1;
			else
				czy[j+1]=0;
		}
		if(check())
			ans++;
	}
	return;
}

void wczytaj()
{
	cin >> n;
	getline (cin,ss);
	getline (cin,s);


	REP(i,s.size())
	{
		if (s[i]=='(')
		{
			pom++;
			continue;
		}
		if (s[i]=='~')
		{
			if (s[i+3]!=' ' && s[i+3]!=')')
			{
				int k=s[i+2]-'0';
				int kk=s[i+3]-'0';

				int ost=10*k+kk;

				klauz[pom].pb(-ost);

				i+=3;
			}
			else
			{
				int k=s[i+2]-'0';
				klauz[pom].pb(-k);

				i+=2;
			}
			continue;
		}
		if (s[i]=='x')
		{
			if (s[i+2]!=' ' && s[i+2]!=')')
			{
				int k=s[i+1]-'0';
				int kk=s[i+2]-'0';

				int ost=10*k+kk;

				klauz[pom].pb(-ost);

				i+=2;
			}
			else
			{
				int k=s[i+1]-'0';
				klauz[pom].pb(k);

				i++;
			}
			continue;
		}
	}
	return;
}

int main()
{
	boost

	wczytaj();
	if (n>20)
	{
		return 0;
	}
	solve();

	cout << ans << endl;
    return 0;
}