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

using namespace std;

typedef long long LL;
typedef pair < int, int > PII;

int n;
string s;

vector < vector < PII > > v;
vector < PII > tmp;

int m;

inline bool b(int i)
{
    return ((m >> i) & 1);
}

int main()
{
    cin >> n;
    getline(cin, s);
    getline(cin, s);
    int li = 0, neg = 0;
    for(int i = 0; i < (int)s.size(); i++)
    {
        if(s[i] == '~') neg = 1;
        if('0' <= s[i] && s[i] <= '9')
        {
            li = 10 * li + s[i] - '0';
        }
        else if(li != 0)
        {
            tmp.push_back({li, neg});
            li = 0;
            neg = 0;
        }
        if(s[i] == ')')
        {
            v.push_back(tmp);
            tmp.clear();
        }
    }
    int res = 0, ok;
    for(m = 0; m < (1 << n); m++)
    {
        ok = 0;
        for(auto x: v)
        {
            for(auto y: x)
            {
                if(b(y.first - 1) ^ y.second)
                {
                    ok++;
                    break;
                }
            }
        }
        if(ok == (int)v.size()) res++;
    }
    printf("%d\n", res);
    return 0;
}