const MOD: usize = 998244353; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut b = String::new(); std::io::stdin().read_line(&mut b).ok(); let b: Vec = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut dp = vec![0usize; n+1]; let mut patterns = 1usize; for i in 0..n { if b[i] == 0 { dp[i+1] = dp[i]; } else if b[i] == 1 { dp[i+1] = if (n-1) & i == i { MOD+patterns-dp[i] } else { dp[i] }; dp[i+1] %= MOD; } else { dp[i+1] = dp[i]; dp[i+1] += if (n-1) & i == i { MOD+patterns-dp[i] } else { dp[i] }; dp[i+1] %= MOD; patterns *= 2; patterns %= MOD; } } println!("{}", dp[n]); }