#include using namespace std; typedef long long ll; const ll MOD = 1000000007; ll com[32][32]; ll dp[100005][32]; int main() { int n; cin >> n; int b[100005]; b[0] = 0; for(int i = 1; i <= n; i++) cin >> b[i]; ll ans = 1; int l = 0; for(int i = 0; i < 30; i++){ com[i][0] = 1; for(int j = 1; j <= i; j++) com[i][j] = (com[i - 1][j] + com[i - 1][j - 1]) % MOD; } for(int i = 1; i <= n; i++){ if(b[i] == -1) continue; if((b[i] & b[l]) != b[l]){ cout << 0 << endl; return 0; } int c = 0; int d = 0; int x = b[l] ^ b[i]; for(int j = 0; j < 30; j++){ c += (x >> j) & 1; d += (b[l] >> j) & 1; } for(int k = 0; k <= i - l; k++){ for(int j = 0; j <= c; j++) dp[k][j] = 0; } dp[0][0] = 1; for(int k = 1; k <= i - l; k++){ for(int j = 0; j <= c; j++){ for(int m = 0; m < j; m++){ dp[k][j] = (dp[k][j] + dp[k - 1][m] * com[c - m][j - m] % MOD * (1 << (d + m))) % MOD; } dp[k][j] = (dp[k][j] + dp[k - 1][j] * ((1 << (d + j)) - 1)) % MOD; } } ans = ans * dp[i - l][c] % MOD; l = i; } cout << ans << endl; }