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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define DBG(X)

int main()
{
  vector<vector<pair<int, int>>> V;
  
  int n;
  scanf("%d\n", &n);
  
  
  
  //for (int i = 0; i < n; i++)
    vector<pair<int, int>> pusty;
    
    
    char c;
    int i = -1;
    
    while (1)
    {
      scanf("%c", &c);
      DBG(printf("%c", c);)
      if (c == '(') {
      	i++;
        V.push_back(pusty);
	  }
        
      else
        break;
      while (c != ')')
      {
        scanf("%c", &c);
        DBG(printf("c1 = %c", c);)
        if (c == 'v')
        {
	        scanf("%c", &c);
	        DBG(printf("c2 = %c", c);)
	        scanf("%c", &c);
	        DBG(printf("c2 = %c", c);)
		}
        int neg = 0;
        if (c == '~')
        {
          neg = 1;
          scanf("%c", &c);
          int a;
          scanf("%d", &a);
          DBG(cout << "neg a " << a << " " << endl;)
          V[i].push_back({a, neg});
        }
        else
        {
          int a;
          scanf("%d", &a);
          DBG(cout << "a " << a << " " << endl;)
          V[i].push_back({a, neg});
        }
        
        scanf("%c", &c);
        DBG(printf("c = %c x\n", c);)
      }
      if (c == ')')
      {
      	scanf("%c", &c);
      	scanf("%c", &c);
	  }
      if (c != '^')
      {
        break;
      }
      scanf("%c", &c);
    }
    
  
  for (int j = 0; j <= i; j++)
  {
    sort(V[j].begin(), V[j].end());
    DBG(for (int k = 0; k < V[j].size(); k++)
    cout << V[j][k].first << " " << V[j][k].second << " ";
    cout << endl;)
  }
  
  int cnt = 0;
  for (int k = 0; k < (1 << n); k++)
  {
    int s = 0;
    DBG(cout << " k " << k << endl;)
    for (int j = 0; j <= i; j++)
    {
      int c = 0;
      DBG(cout << " j " << j << endl;)
      for (int m = 0; m < V[j].size(); m++)
      {
        int a = V[j][m].first;
        a--;
        int b = V[j][m].second;
        DBG(cout << " a " << a << " b " << b << endl;)
        int bit = (1 << a) & k;
        if (bit) bit = 1;
        
        bit ^= b;
        DBG(cout << " bit " << bit << endl;)
        c += bit;
      }
      DBG(cout << " c " << c << endl;)
      if (!c) break;
      s++;
      DBG(cout << " !!! j " << j << " s " << s << endl;)
    }
    if (s == i + 1)
    {
      cnt++;
    }
  }
  
  printf("%d\n", cnt);
  
  return 0; 
}