#include #include using namespace std; using ll = long long; #define rep(i,n) for (int i = 0; i < (n); i++) #define repSE(i,s,n) for (int i = (s); i < (n); i++) #define rrepSE(i,s,e) for (int i = (s); i > (e); i--) #define ssort(v) sort(v.begin(), v.end()) #define gsort(v) sort(v.rbegin(), v.rend()) template bool chmax(T& m, const T q) { if (m < q) { m = q; return true; } else return false; } template bool chmin(T& m, const T q) { if (q < m) { m = q; return true; } else return false; } const ll MOD = 1000000007; ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll modinv(ll i, ll mod) { return modpow(i, mod - 2, mod); } ll fact(ll n, ll mod) { ll ans = 1; rep(i, n) { ans = ans * (i + 1) % mod; } return ans; } ll comb(ll n, ll a, ll mod) { ll ans = 1, denom = 1; rep(i, a) { ans = ans * (n - i) % mod; denom = denom * (i + 1) % mod; } ans = ans * modinv(denom, mod) % mod; return ans; } ll pow2[35]; ll calc(ll a, ll b, ll c) { ll ret = 0; for (int i = 0; i <= b; i++) { ll v = comb(b, i, MOD) * modpow(pow2[b + c - i] - 1, a, MOD) % MOD; if (i % 2 == 0) { ret += v; ret %= MOD; } else { ret += MOD - v; ret %= MOD; } } return ret; } int main() { int i; pow2[0] = 1; for (i = 0; i < 34; i++) { pow2[i + 1] = pow2[i] * 2; } int n; cin >> n; vector b(n, 0); for (i = 0; i < n; i++) { cin >> b[i]; } ll prev = 0; ll streak = 0; ll ans = 1; for (i = 0; i < n; i++) { if (b[i] == -1) { streak++; } else { ll c01 = 0; ll c11 = 0; for (int j = 0; j < 32; j++) { ll x = (prev >> j) % 2; ll y = (b[i] >> j) % 2; if (x == 0 && y == 1) { c01++; } else if (x == 1 && y == 1) { c11++; } else if (x == 1 && y == 0) { cout << 0 << "\n"; return 0; } } ans *= calc(streak + 1, c01, c11); prev = b[i]; streak = 0; } } cout << ans << "\n"; return 0; }