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

using namespace std;
int n;
string s;

vector<pair<int,int>> parseA(const char* &buf) {
    vector<pair<int, int>> v;
    buf++;
    while (1) {
        int neg = 0;
        int x;
        if (*buf == ')') { buf++; break; }
        if (*buf == ' ') { buf += 3; continue; }
        if (*buf == '~') { neg = 1; buf++; }
        if (*buf == 'x') { buf++; }

        sscanf(buf, "%d", &x);
        x--;

        v.push_back({x, 1-neg});
        while (isdigit(*buf)) buf++;
    }

    return v;
}

vector<vector<pair<int, int>>> parse(string s) {
    vector<vector<pair<int, int>>> v;
    const char *buf = s.c_str();

    int l = strlen(buf);
    const char* e = buf + l;

    while (buf < e) {
        v.push_back(parseA(buf));

        buf += 3;
    }


    return v;

}
int main() {
    ios_base::sync_with_stdio(0);

    cin >> n;
    cin.ignore();
    getline(cin, s);

    auto v = parse(s);

    if (n >= 30) return 0;

    int res = 0;
    for (int i = 0; i < (1<<n); i++) {
        bool zle = false;
        for (auto y: v) {
            bool ok = false;
            for (auto z: y) {
                if (z.second == ((i >> z.first) & 1)) {
                    ok = true;
                    break;
                }
            }

            if (!ok) { zle = true; break; }
        }

        if (!zle) res++;
    }

    cout << res << "\n";

}