SIZE=10**5+1; MOD=10**9+7 #998244353 #ここを変更する inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): fac[i] = fac[i-1]*i%MOD finv[-1] = pow(fac[-1],MOD-2,MOD) for i in range(SIZE-1,0,-1): finv[i-1] = finv[i]*i%MOD inv[i] = finv[i]*fac[i-1]%MOD def choose(n,r): # nCk mod MOD の計算 if 0 <= r <= n: return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD else: return 0 def popcount(i): # i < 2^32 i = i - ((i >> 1) & 0x55555555) i = (i & 0x33333333) + ((i >> 2) & 0x33333333) return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24 def solve(n,a): p2 = [1]*(n+100) for i in range(1,n+100): p2[i] = p2[i-1]*2%MOD def check(c,x,y): r = 0 sgn = 1 for i in range(0,c+1)[::-1]: r += sgn*choose(c,i)*pow(p2[i],x,MOD)%MOD*pow(p2[i]-1,y,MOD) r %= MOD sgn *= -1 #print(c,x,y,r) return r v = c = 0 ans = 1 for ai in a: c += 1 if ai == -1: continue else: if v|ai != ai: ans = 0 break x = popcount(v&ai) y = popcount(v^ai) ans *= check(c,x,y) ans %= MOD c = 0 v = ai #print(ans) if c: ans *= pow(p2[30]-1,c,MOD) ans %= MOD return ans n = int(input()) *a, = map(int,input().split()) print(solve(n,a))