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
127
128
129
130
131
132
133
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>

#define PB          push_back
#define ST          first
#define ND          second

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using VII = vector<PII>;
using LL = long long int;
using ULL = unsigned long long int;

const LL MOD = 1000000007LL;
const int MAXN = 1000005;

int n;
LL pow2[MAXN];
LL res = 1;

struct Clause {
  int x;
  vector<bool> val;
};

vector<Clause> clauses;

set<int> seen_literals;

void ReadClause() {
  char c;
  map<int, bool> clause;
  while (true) {
    scanf("%c", &c);
    bool positive = true;
    if (c == ')') {
      break;
    } else if (c == ' ' || c == 'v') {
      continue;
    } else if (c == '~') {
      positive = false;
      scanf("%c", &c);
    }
    int x;
    scanf("%d", &x);
    clause[x] = positive;
    seen_literals.insert(x);
  }
  clauses.emplace_back(Clause());
  clauses.back().x = clause.begin()->ST;
  clauses.back().val.reserve(clause.size());
  for (const auto& p : clause) {
    clauses.back().val.push_back(p.ND);
  }
}

vector<int> rev_literals;

void rec_solve(vector<bool>& values, LL& cnt) {
  if (values.size() == seen_literals.size()) {
    for (const auto& clause : clauses) {
      bool no_matches = true;
      for (int pos = clause.x; pos <= clause.x + clause.val.size() - 1; ++pos) {
        if (clause.val[pos - clause.x] == values[rev_literals[pos]]) {
          no_matches = false;
          break;
        }
      }
      if (no_matches) return;
    }
    cnt = (cnt + 1) % MOD;
    return;
  }
  values.PB(false);
  rec_solve(values, cnt);
  values[values.size() - 1] = true;
  rec_solve(values, cnt);
  values.pop_back();
}

LL Solve() {
  LL cnt = 0;
  vector<bool> values;  
  rec_solve(values, cnt);
  return cnt;
}

int main() {
  scanf("%d\n", &n);
  pow2[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pow2[i] = (2 * pow2[i-1]) % MOD;
  }
  char c;
  while (scanf("%c", &c) != EOF) {
    if (c == '(') {
      ReadClause();
    }
  }
  res = pow2[n - seen_literals.size()];

  rev_literals.resize(n + 1);
  int p = 0;
  for (auto x : seen_literals) {
    rev_literals[x] = p;
    ++p;
  }

  res = (res * Solve()) % MOD;

  printf("%lld\n", res);
  return 0;
}