use std::io::*; const MOD: u64 = 1_000_000_007; mod enumeration { pub struct Enumeration { fact: Vec, finv: Vec, modulo: u64, } impl Enumeration { pub fn new(n: usize, modulo: u64) -> Enumeration { let mut fact: Vec = vec![1; n]; let mut inv: Vec = vec![1; n]; let mut finv: Vec = vec![1; n]; for i in 2..n { fact[i] = fact[i - 1] * (i as u64) % modulo; inv[i] = modulo - (modulo / (i as u64)) * inv[(modulo as usize % i)] % modulo; finv[i] = inv[i] * finv[i - 1] % modulo; } Enumeration { fact: fact, finv: finv, modulo: modulo, } } pub fn c(&self, n: usize, k: usize) -> u64 { if n < k { return 0; } self.fact[n] * self.finv[n - k] % self.modulo * self.finv[k] % self.modulo } } } fn mod_pow(mut x: u64, mut e: u64, m: u64) -> u64 { let mut res = 1; while e > 0 { if e & 1 == 1 { res = res * x % m; } x = x * x % m; e >>= 1; } res } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let mut b: Vec<(i64, i64)> = Vec::new(); b.push((0, -1)); for i in 0..n { if a[i] > 0 { b.push((a[i], i as i64)); } } let en = enumeration::Enumeration::new(32, MOD); let mut ans = 1u64; let m = b.len(); for i in 0..m - 1 { let len = b[i + 1].1 - b[i].1; let c = b[i].0; let d = b[i + 1].0; if d | c != d { println!("0"); return; } let e = c.count_ones(); let f = (c ^ d).count_ones(); let mut tmp = 0; for g in 0..f + 1 { let mul = en.c(f as usize, g as usize) * mod_pow(mod_pow(2, (f + e - g) as u64, MOD) - 1, len as u64, MOD) % MOD; if g % 2 == 0 { tmp = (tmp + mul) % MOD; } else { tmp = (MOD + tmp - mul) % MOD; } } ans = (ans * tmp) % MOD; } println!("{}", ans); }