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

const int N = 1e6 + 5;
int n, m, ans;
std::vector<int> a[N];
std::vector<int> b[N];
bool bo[N];
char c;

inline void check() {
  for (int i = 1; i <= m; ++i) {
    bool r = false;
    for (int j = 0; j < a[i].size(); ++j) {
      r |= bo[a[i][j]] ^ b[i][j];
      if (r) break;
    }
    if (!r) return ;
  }
  ++ans;
}

inline void dfs(int x) {
  if (x > n) {
    check();
    return ;
  }
  bo[x] = true;
  dfs(x + 1);
  bo[x] = false;
  dfs(x + 1);
}

int main() {
  scanf("%d", &n);
  
  while (c = getchar(), c > 0) {
    if (c != '(') continue;
    ++m;
    int d = 0, num;
    do {
      c = getchar();
      if (c == 'v') d = 0;
      if (c == '~') d = 1;
      if (c >= '0' && c <= '9') {
        num = c - '0';
        while (c = getchar(), c >= '0' && c <= '9')
          num = num * 10 + c - '0';
        a[m].push_back(num);
        b[m].push_back(d);
      }
      if (c == ')') break;
    } while (true);
  }
  dfs(1);
  printf("%d\n", ans);
  return 0;
}