import math mod = 1_000_000_007 def popcnt(n): c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555) c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333) c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F) c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF) c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF) c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF) return c def COM(n, r): if n < r: return 0 return math.factorial(n) // math.factorial(r) // math.factorial(n - r) % mod n = int(input()) b = list(map(int, input().split())) base, cont, res = 0, 0, 1 for v in b: if v == -1: cont += 1 else: for i in range(30): if base >> i & 1 and v >> i & 1 == 0: print(0) exit() a = popcnt(base) b = popcnt(v) x = b - a tmp = 0 for i in range(0, x + 1): tmp += COM(x, i) * pow((pow(2, b - i, mod) - 1), cont + 1, mod) * (-1 if i % 2 else 1) tmp %= mod res *= tmp cont, base = 0, v print(res)