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

using namespace std;

const int MAX_N = 1e6 + 9;

bitset<MAX_N> tab;
string s;

int sol = 0;
int n;

bool check()
{
    int val = 0;
    bool neg = false;

    for(int i = 0; i < s.length(); ++i)
    {
        if(s[i] == '~')
            neg = true;

        if(s[i] == 'x')
        {
            ++i;

            int ind = 0;

            while(s[i] >= '0' && s[i] <= '9')
            {
                ind *= 10;
                ind += (int)(s[i] - '0');
                ++i;
            }

            if(neg)
                val |= (!tab[ind]);
            else
                val |= tab[ind];

            neg = false;
        }

        if(s[i] == '^')
        {
            if(val == 0)
                return false;

            val = 0;
        }
    }

    return true;
}

void rec(int lvl = 1)
{
    if(lvl == n)
    {
        if(check())
            ++sol;

        tab[n] = 1;

        if(check())
            ++sol;

        tab[n] = 0;

        return;
    }

    rec(lvl + 1);

    tab[lvl] = 1;

    rec(lvl + 1);

    tab[lvl] = 0;

    return;
}

int main()
{
    string n_str;
    getline(cin, n_str);
    getline(cin, s);

    for(int i = 0; i < n_str.length(); ++i)
    {
        n *= 10;
        n += (int)(n_str[i] - '0');
    }

    rec();

    cout << sol;

    return 0;
}