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
#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<vector<int> > tab;
vector<int> perm;
bool jestSpelnialna(){
    for(int i=0;i<tab.size();i++){
        bool b = false;
        for(int j=0;j<tab[i].size();j++){
            if(tab[i][j] != 0){
                if((tab[i][j] == 2 && perm[j] ==0) || (tab[i][j] == 1 && perm[j] ==1)){
                    b = true;
                    break;
                }

            }
        }
        if(b == false)
            return false;
    }
    return true;
}
int ct = 0;
void licz(){
    for(;;){
        if(jestSpelnialna()) ct++;
        int i=0;
        perm[i]++;
        while(perm[i] == 2 && i != perm.size()-1){
            perm[i] = 0;
            i++;
            perm[i]++;
        }
        if(i == perm.size()-1 && perm[i] == 2)
            return;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    perm.resize(n,0);
    cin.ignore();
    string str;
    getline(std::cin,str);
    bool wSrodku = false;
    bool znak = false;
    for(int i=0;i<str.size();i++){
        if(str[i] == '('){
            wSrodku = true;
            tab.push_back(vector<int>());
            tab.back().resize(n);
        }
        if(str[i] == ')')
            wSrodku = false;
        if(str[i] == '~')
            znak = true;
        if(str[i] == ' ')
            znak = false;
        if(str[i] == 'x'){
            int liczba = 0;
            while(str[i+1] >= '0' && str[i+1] <= '9'){
                i++;
                liczba *= 10;
                liczba += (str[i] - '0');
            }
            if(znak)
                tab.back()[liczba-1] = 1;
            else
                tab.back()[liczba-1] = 2;
        }
    }
    /*for(auto a:tab){
        for(auto b:a)
            cout<<b<<" ";
        cout<<endl;
    }*/
    licz();
    cout<<ct<<endl;
    return 0;
}