const MOD: usize = 998244353; const OFFSET: isize = 2; fn power(base: usize, times: usize) -> usize { if times == 0 { return 1usize; } if times == 1 { return base; } let temp = power(base, times/2); temp * temp % MOD * power(base, times%2) % MOD } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut p2s = vec![1usize; n+1]; for i in 1..n { p2s[i+1] = p2s[i] * 2 % MOD; } let total = power(power(2, MOD-2), n-1); let mut dp = vec![vec![0usize; 6]; n+1]; dp[0][3] = 1; let mut result = 0usize; for i in 0..n { for j in -2..=3 { let jidx = j + OFFSET; let jidx = jidx as usize; if dp[i][jidx] == 0 { continue; } if a[i].abs() * j.abs() <= 2 { let idx = OFFSET + a[i] * j; let idx = idx as usize; dp[i+1][idx] += dp[i][jidx]; dp[i+1][idx] %= MOD; if idx == 0 { result += dp[i][jidx] * p2s[n-i-1] % MOD; result %= MOD; } } else { dp[i+1][5] += dp[i][jidx]; dp[i+1][5] %= MOD; } if i == 0 { continue; } let idx = OFFSET + a[i]; let idx = idx as usize; dp[i+1][idx] += dp[i][jidx]; dp[i+1][idx] %= MOD; if idx == 0 { result += dp[i][jidx] * p2s[n-i-1] % MOD; result %= MOD; } } } println!("{}", result * total % MOD); }